/* QS Daily — mobile-first PWA. Dark by default. */
:root {
  --bg: #0f1115;
  --bg-elev: #181b22;
  --bg-elev-2: #21252e;
  --fg: #e8e9ea;
  --fg-muted: #9aa0a6;
  --fg-dim: #6b7280;
  --accent: #4ade80;
  --neg: #f87171;
  --pos: #4ade80;
  --neut: #94a3b8;
  --border: #2a2e36;
  --tab-h: 64px;
  --header-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0);
  --safe-top: env(safe-area-inset-top, 0);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overscroll-behavior-y: none;
}

/* Header */
.app-header {
  position: sticky; top: 0; z-index: 10;
  height: calc(var(--header-h) + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 16px;
  padding-right: 16px;
}
.app-header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
#refresh-btn {
  background: none;
  border: none;
  color: var(--fg);
  font-size: 22px;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 6px;
}
#refresh-btn:active { background: var(--bg-elev-2); }
#refresh-btn.spinning { animation: spin 0.6s linear; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Main view area */
main {
  padding: 16px;
  padding-bottom: calc(var(--tab-h) + var(--safe-bottom) + 24px);
  min-height: calc(100vh - var(--header-h) - var(--tab-h));
}

/* Tab bar */
.tab-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 10;
}
.tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--fg-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  cursor: pointer;
  padding: 6px 0;
  transition: color 0.15s ease;
}
.tab.active { color: var(--accent); }
.tab .icon { font-size: 20px; }
.tab .label { font-size: 11px; letter-spacing: 0.2px; }

/* Cards */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s ease;
}
.card:active { transform: scale(0.99); }
.card:hover { border-color: var(--bg-elev-2); }

.card-title {
  font-size: 15px;
  font-weight: 500;
  line-height: 1.35;
  margin: 0 0 6px;
}
.card-meta {
  font-size: 12px;
  color: var(--fg-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.card-meta .dot { color: var(--fg-dim); }
.card .source {
  font-style: italic;
}

.sentiment-pill {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}
.sentiment-pill.negative { background: var(--neg); }
.sentiment-pill.positive { background: var(--pos); }
.sentiment-pill.neutral  { background: var(--neut); }

.score-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-elev-2);
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-muted);
}
.score-badge.high { color: var(--pos); }

/* Star button */
.star-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--fg-dim);
  padding: 4px;
  margin-left: auto;
}
.star-btn.starred { color: #facc15; }

/* Section headers */
.section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--fg-dim);
  margin: 16px 0 8px;
  padding-left: 4px;
}

/* Mood card (home) */
.mood-card {
  background: linear-gradient(140deg, var(--bg-elev) 0%, var(--bg-elev-2) 100%);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  margin-bottom: 16px;
}
.mood-headline {
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 6px;
}
.mood-sub {
  color: var(--fg-muted);
  font-size: 14px;
  margin-bottom: 12px;
}
.mood-stats {
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: var(--fg-muted);
}
.mood-stats .stat { display: flex; align-items: center; gap: 4px; }

/* Audio player card */
.audio-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
}
.audio-card-title {
  font-size: 14px;
  font-weight: 500;
  margin: 0 0 8px;
}
.audio-card-meta {
  font-size: 12px;
  color: var(--fg-muted);
  margin-bottom: 10px;
}
.audio-card audio {
  width: 100%;
  height: 36px;
}

/* Filters bar (Feed) */
.filter-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 0 12px;
  margin: 0 -16px 8px -16px;
  padding-left: 16px;
  padding-right: 16px;
  scrollbar-width: none;
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-pill {
  flex: 0 0 auto;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--fg-muted);
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}
.filter-pill.active {
  background: var(--accent);
  color: #0f1115;
  border-color: var(--accent);
}

/* Article modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade-in 0.2s ease;
}
.modal.hidden { display: none; }
@keyframes fade-in { from { opacity: 0; } }
.modal-content {
  background: var(--bg-elev);
  width: 100%;
  max-width: 720px;
  max-height: 92vh;
  overflow-y: auto;
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  padding: 28px 20px 60px;
  position: relative;
  animation: slide-up 0.25s ease;
}
@keyframes slide-up { from { transform: translateY(100%); } }
.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  background: var(--bg-elev-2);
  border: none;
  color: var(--fg);
  width: 32px; height: 32px;
  border-radius: 50%;
  font-size: 22px;
  cursor: pointer;
  z-index: 1;
}

#article-body h1 { font-size: 22px; line-height: 1.3; margin-top: 0; }
#article-body h2 { font-size: 17px; margin-top: 24px; }
#article-body p { margin: 12px 0; }
#article-body a { color: var(--accent); }
#article-body blockquote {
  border-left: 3px solid var(--bg-elev-2);
  padding: 4px 12px;
  color: var(--fg-muted);
  margin: 12px 0;
}
#article-body code {
  background: var(--bg-elev-2);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 0.9em;
}
#article-body table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
  margin: 12px 0;
}
#article-body th, #article-body td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
#article-body th { background: var(--bg-elev-2); }

.action-row {
  display: flex;
  gap: 8px;
  margin: 16px 0;
  padding: 12px;
  background: var(--bg-elev-2);
  border-radius: 10px;
}
.action-btn {
  flex: 1;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 10px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.action-btn:active { transform: scale(0.97); }
.action-btn.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}
.action-btn.danger.active { background: var(--neg); border-color: var(--neg); }

.frontmatter-list {
  font-size: 12px;
  color: var(--fg-muted);
  background: var(--bg-elev-2);
  padding: 10px 14px;
  border-radius: 8px;
  margin: 12px 0;
}
.frontmatter-list .item {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
}
.frontmatter-list .key { color: var(--fg-dim); }

.tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
.tag {
  background: var(--bg-elev-2);
  color: var(--fg-muted);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
}
.tag.competency { background: rgba(74, 222, 128, 0.15); color: var(--accent); }

/* Loading */
.loading {
  text-align: center;
  padding: 32px;
  color: var(--fg-muted);
}
.empty {
  text-align: center;
  padding: 48px 16px;
  color: var(--fg-muted);
  font-size: 14px;
}
.empty .icon { font-size: 48px; opacity: 0.5; margin-bottom: 12px; }

/* Watch (entity) cards */
.entity-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}
.entity-card .name { font-weight: 500; }
.entity-card .cat { font-size: 11px; color: var(--fg-dim); margin-top: 2px; }
.entity-card .count {
  background: var(--accent);
  color: var(--bg);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

/* Sentiment trend mini-chart */
.trend-chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 80px;
  padding: 8px 0;
  margin: 12px 0;
}
.trend-bar {
  flex: 1;
  background: var(--bg-elev-2);
  border-radius: 2px 2px 0 0;
  min-height: 2px;
  position: relative;
  transition: opacity 0.2s;
}
.trend-bar.negative { background: var(--neg); }
.trend-bar.positive { background: var(--pos); }
.trend-bar.neutral  { background: var(--neut); }

/* Offline banner */
.offline-banner {
  position: sticky;
  top: calc(var(--header-h) + var(--safe-top));
  z-index: 9;
  background: #f59e0b;
  color: #1a1a1a;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  text-align: center;
  display: none;
}
body.is-offline .offline-banner { display: block; }

/* Cached-for-offline indicator on audio cards */
.cached-tag {
  display: inline-block;
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
  margin-left: 6px;
}

.cache-btn {
  background: var(--bg-elev-2);
  color: var(--fg-muted);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  margin-top: 6px;
}
.cache-btn.cached {
  background: rgba(74, 222, 128, 0.15);
  color: var(--accent);
  border-color: rgba(74, 222, 128, 0.3);
}
.cache-btn:active { transform: scale(0.97); }

/* Light mode (auto) */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f8fafc;
    --bg-elev: #ffffff;
    --bg-elev-2: #f1f5f9;
    --fg: #0f172a;
    --fg-muted: #475569;
    --fg-dim: #94a3b8;
    --border: #e2e8f0;
  }
}
