* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f5f5;
  color: #333;
  min-height: 100vh;
}

/* ========== Auth Page ========== */
.auth-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
}

.auth-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}

.auth-card h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
  text-align: center;
}

.auth-card p.subtitle {
  color: #888;
  text-align: center;
  margin-bottom: 30px;
  font-size: 14px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 6px;
  color: #555;
}

.form-group input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid #ddd;
  border-radius: 10px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: #333;
}

.auth-toggle {
  text-align: center;
  margin-top: 20px;
  font-size: 14px;
  color: #888;
}

.auth-toggle a {
  color: #111;
  font-weight: 500;
  text-decoration: none;
}

.auth-toggle a:hover {
  text-decoration: underline;
}

.error-msg {
  color: #e74c3c;
  font-size: 13px;
  margin-top: 10px;
  text-align: center;
  display: none;
}

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid #ddd;
  background: #fff;
  color: #333;
  transition: all 0.2s;
  text-decoration: none;
}

.btn:hover { background: #f9f9f9; border-color: #ccc; }

.btn-primary {
  background: #111;
  color: #fff;
  border-color: #111;
  width: 100%;
}

.btn-primary:hover { background: #333; }
.btn-primary:disabled { background: #999; border-color: #999; cursor: not-allowed; }

.btn-danger { color: #e74c3c; border-color: #e74c3c; }
.btn-danger:hover { background: #fdf2f2; }

.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
  border-radius: 8px;
  width: auto;
}

/* ========== SPA App Layout ========== */
#app {
  max-width: 600px;
  margin: 0 auto;
  padding-bottom: 130px; /* room for player + tab bar */
}

.tab-page {
  display: none;
}

.tab-page.active {
  display: block;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 8px;
  position: sticky;
  top: 0;
  background: #f5f5f5;
  z-index: 10;
}

.page-header h2 {
  font-size: 20px;
  font-weight: 700;
}

.header-date, .header-user {
  font-size: 13px;
  color: #888;
}

.header-right-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-body {
  padding: 8px 20px 20px;
}

/* ========== Bottom Tab Bar ========== */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 1px solid #eee;
  display: flex;
  justify-content: space-around;
  padding: 6px 0 env(safe-area-inset-bottom, 8px);
  z-index: 50;
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 12px;
  color: #999;
  font-size: 11px;
  font-weight: 500;
  transition: color 0.2s;
}

.tab-item svg { color: inherit; }

.tab-item.active {
  color: #111;
}

/* ========== News Page ========== */
.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: #999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.empty-icon {
  font-size: 48px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 15px;
}

.empty-state .btn {
  margin-top: 8px;
  width: auto;
}

.digest-stats {
  display: flex;
  gap: 6px;
  font-size: 13px;
  color: #888;
  margin-bottom: 12px;
}

.digest-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
}

.digest-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.digest-title-row .digest-title {
  margin-bottom: 0;
  flex: 1;
}

.digest-play-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: #111;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.digest-play-btn:hover {
  background: #333;
}

.digest-summary {
  font-size: 14px;
  color: #666;
  margin-bottom: 20px;
  line-height: 1.5;
}

/* Transcript Viewer */
.transcript-viewer {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.transcript-section {}

.section-title {
  font-size: 15px;
  font-weight: 600;
  color: #111;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid #eee;
}

.transcript-paragraph {
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 8px;
  transition: background 0.3s, box-shadow 0.3s;
  border-left: 3px solid transparent;
}

.transcript-paragraph.active {
  background: #f0f7ff;
  border-left-color: #3b82f6;
  box-shadow: 0 1px 4px rgba(59,130,246,0.15);
}

.para-en {
  font-size: 15px;
  line-height: 1.7;
  margin-bottom: 4px;
}

.para-zh {
  font-size: 14px;
  line-height: 1.7;
  color: #666;
}

.para-sources {
  font-size: 12px;
  color: #aaa;
  margin-top: 6px;
}

.para-sources:hover {
  color: #3b82f6;
}

/* ========== History Page ========== */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-card {
  background: #fff;
  border: 1px solid #eee;
  border-radius: 12px;
  overflow: hidden;
}

.history-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  cursor: pointer;
}

.history-card-header:hover {
  background: #fafafa;
}

.history-info { flex: 1; }

.history-date {
  font-size: 12px;
  color: #888;
  margin-bottom: 2px;
}

.history-title {
  font-size: 15px;
  font-weight: 600;
}

.history-meta {
  font-size: 12px;
  color: #aaa;
  margin-top: 2px;
}

.history-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.expand-icon {
  font-size: 12px;
  color: #999;
}

.history-card-body {
  padding: 0 16px 16px;
  border-top: 1px solid #f0f0f0;
}

.history-summary {
  font-size: 14px;
  color: #666;
  line-height: 1.5;
  margin-bottom: 12px;
  margin-top: 12px;
}

.history-paragraph {
  margin-bottom: 8px;
}

.history-paragraph p {
  font-size: 14px;
  line-height: 1.6;
}

/* ========== Radio Page ========== */
.radio-search {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.radio-search input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #ddd;
  border-radius: 10px;
  font-size: 14px;
  outline: none;
}

.radio-search input:focus {
  border-color: #333;
}

.radio-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.radio-tab {
  padding: 6px 16px;
  border-radius: 20px;
  border: 1px solid #ddd;
  background: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: #666;
  transition: all 0.2s;
}

.radio-tab.active {
  background: #111;
  color: #fff;
  border-color: #111;
}

.station-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.station-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  border: 1px solid #eee;
  border-radius: 12px;
  padding: 12px 14px;
}

.station-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  background: #f0f0f0;
}

.station-info { flex: 1; min-width: 0; }

.station-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.station-meta {
  font-size: 12px;
  color: #999;
}

.station-actions {
  display: flex;
  gap: 6px;
}

.fav-btn { font-size: 18px; }
.fav-btn.fav-active { color: #f59e0b; border-color: #f59e0b; }

.empty-text {
  text-align: center;
  color: #999;
  padding: 30px;
  font-size: 14px;
}

/* ========== My Page ========== */
.settings-section {
  background: #fff;
  border: 1px solid #eee;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 14px;
}

.settings-section h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
}

.setting-item {
  margin-bottom: 12px;
}

.setting-item label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #555;
  margin-bottom: 4px;
}

.setting-item select,
.setting-item input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  background: #fff;
}

.setting-item select:focus,
.setting-item input:focus {
  border-color: #333;
}

/* Account chips */
.add-account-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.add-account-row input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
}

.add-account-row input:focus {
  border-color: #333;
}

.account-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.account-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #f5f5f5;
  border-radius: 20px;
  padding: 4px 10px 4px 4px;
  font-size: 13px;
}

.chip-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #ddd;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: #555;
}

.chip-handle {
  color: #333;
}

.chip-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: #999;
  font-size: 16px;
  padding: 0 2px;
  line-height: 1;
}

.chip-remove:hover { color: #e74c3c; }

.recommended-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.rec-label {
  font-size: 12px;
  color: #999;
  margin-right: 4px;
}

.rec-chip {
  padding: 4px 10px;
  border-radius: 14px;
  border: 1px dashed #ccc;
  background: none;
  font-size: 12px;
  color: #555;
  cursor: pointer;
}

.rec-chip:hover {
  border-color: #111;
  color: #111;
}

/* (Interest areas reuse .account-chip and .rec-chip styles) */

/* Custom Time Picker */
.time-picker-wrapper {
  position: relative;
}

.time-picker-btn {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  cursor: pointer;
  text-align: left;
  color: #333;
}

.time-picker-btn:focus {
  border-color: #333;
  outline: none;
}

.time-picker-popup {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  z-index: 20;
  padding: 12px;
  margin-top: 4px;
}

.time-picker-columns {
  display: flex;
  gap: 12px;
  margin-bottom: 10px;
}

.time-picker-col {
  flex: 1;
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid #eee;
  border-radius: 8px;
}

.time-picker-col div {
  padding: 8px 12px;
  text-align: center;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}

.time-picker-col div:hover {
  background: #f5f5f5;
}

.time-picker-col div.selected {
  background: #111;
  color: #fff;
}

.time-picker-ok {
  width: 100%;
}

/* ========== Audio Player Bar ========== */
.player-bar {
  position: fixed;
  bottom: 52px; /* above tab bar */
  left: 0;
  right: 0;
  background: #fff;
  border-top: 1px solid #eee;
  padding: 0;
  z-index: 40;
  display: none;
  flex-direction: column;
}

.player-row-progress {
  width: 100%;
  padding: 0;
}

.player-row-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 6px 16px 8px;
}

.player-btn {
  background: #111;
  color: #fff;
  border: none;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.player-btn:hover { background: #333; }

.progress-bar {
  width: 100%;
  height: 4px;
  background: #eee;
  cursor: pointer;
  position: relative;
}

.progress-fill {
  height: 100%;
  background: #111;
  width: 0%;
  transition: width 0.1s;
}

.progress-time {
  font-size: 12px;
  color: #999;
  min-width: 36px;
  text-align: center;
}

/* ========== Admin Page ========== */
.app-container {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px;
}

.user-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  padding: 14px 16px;
  border: 1px solid #eee;
  border-radius: 12px;
  margin-bottom: 8px;
}

.user-info .user-name { font-weight: 500; font-size: 15px; }
.user-info .user-role { font-size: 12px; color: #999; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
}

.badge-admin { background: #111; color: #fff; }
.badge-user { background: #f0f0f0; color: #666; }

/* ========== Loading & Toast ========== */
.loading-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(255,255,255,0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #eee;
  border-top-color: #111;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay p {
  margin-top: 14px;
  font-size: 14px;
  color: #666;
}

.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: #111;
  color: #fff;
  padding: 10px 22px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 300;
  transition: transform 0.3s ease;
  white-space: nowrap;
}

.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { background: #e74c3c; }

/* ========== Modal ========== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-card {
  background: #fff;
  border-radius: 14px;
  width: 90%;
  max-width: 420px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 18px;
  border-bottom: 1px solid #eee;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: #999;
  padding: 0 4px;
}

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
}

.source-tweet {
  padding: 10px 0;
  border-bottom: 1px solid #f0f0f0;
}

.source-tweet:last-child { border-bottom: none; }

.tweet-handle {
  font-size: 13px;
  font-weight: 600;
  color: #3b82f6;
  margin-bottom: 4px;
}

.tweet-time {
  font-size: 11px;
  color: #aaa;
  margin-bottom: 4px;
}

.tweet-content {
  font-size: 14px;
  line-height: 1.5;
  color: #444;
}

/* ========== Responsive ========== */
@media (max-width: 480px) {
  .page-body { padding: 8px 14px 14px; }
  .page-header { padding: 14px 14px 6px; }
  .digest-title { font-size: 19px; }
  .settings-section { padding: 14px; }
}
