/* =============================================================
   Design tokens. Ported from the Claude Design redesign
   ("RSS Builder - Design System"). Two ideas drive the system:

     1. ONE accent hex re-themes everything. Set --accent to any
        hex and --accent-strong / -soft / -tint / -ring derive
        from it via color-mix, adapting to the active surface.
     2. Light/dark is a token flip only. [data-theme="dark"]
        overrides the token block; components read tokens, so no
        per-page dark CSS is needed.

   Legacy variable names from the previous token set are kept as
   aliases at the end of :root so the existing pages and the
   component CSS below keep working unchanged. New component
   classes should prefer the new names (--r-md, --sh-2, etc.).
   ============================================================= */
:root {
  /* -- surfaces ------------------------------------------------ */
  --bg:        #f7f8fa;
  --bg-elev:   #ffffff;
  --bg-card:   #ffffff;
  --bg-sunken: #eef0f4;
  --bg-hover:  #f1f3f7;
  --bg-active: #e9ecf3;

  /* -- text ---------------------------------------------------- */
  --fg:        #2b313b;
  --fg-dim:    #6b7280;
  --fg-faint:  #9aa1ad;
  --fg-strong: #11151c;

  /* -- lines --------------------------------------------------- */
  --border:        #e6e8ee;
  --border-strong: #d4d8e0;

  /* -- accent : set this ONE hex, the rest derive -------------- */
  --accent:        #2563eb;   /* Blue (Claude Design palette) */
  --accent-strong: color-mix(in oklab, var(--accent), #000 16%);
  --accent-soft:   color-mix(in oklab, var(--accent), var(--bg-card) 90%);
  --accent-tint:   color-mix(in oklab, var(--accent), var(--bg-card) 94%);
  --accent-ring:   color-mix(in oklab, var(--accent), transparent 70%);
  --accent-fg:     #ffffff;

  /* -- health -------------------------------------------------- */
  --success: #16a34a;
  --warn:    #d97706;
  --danger:  #dc2626;
  --stale:   #64748b;
  --paused:  #94a3b8;
  --success-soft: color-mix(in oklab, var(--success), var(--bg-card) 88%);
  --warn-soft:    color-mix(in oklab, var(--warn),    var(--bg-card) 88%);
  --danger-soft:  color-mix(in oklab, var(--danger),  var(--bg-card) 88%);

  /* -- radius -------------------------------------------------- */
  --r-lg: 14px;
  --r-md: 10px;
  --r-sm: 7px;
  --r-xs: 5px;

  /* -- elevation ----------------------------------------------- */
  --sh-1: 0 1px 2px rgba(16,21,28,.05), 0 1px 1px rgba(16,21,28,.04);
  --sh-2: 0 2px 4px rgba(16,21,28,.06), 0 4px 12px rgba(16,21,28,.06);
  --sh-3: 0 8px 24px rgba(16,21,28,.10), 0 2px 6px rgba(16,21,28,.06);

  /* -- layout -------------------------------------------------- */
  --rail: 252px;
  --header-h: 54px;
  --status-h: 30px;

  /* -- type ---------------------------------------------------- */
  --fs-base: 14px;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;

  /* -- motion -------------------------------------------------- */
  --ease: cubic-bezier(.2, .8, .2, 1);
  --motion-fast: 120ms;
  --motion:      200ms;
  --motion-slow: 320ms;

  /* -- legacy aliases (old name -> new) ------------------------
     Kept so existing markup/CSS keeps working. var() resolves at
     the use site, so these stay theme-correct in dark mode. */
  --radius:          var(--r-md);
  --radius-sm:       var(--r-sm);
  --radius-lg:       var(--r-lg);
  --shadow-1:        var(--sh-1);
  --shadow-2:        var(--sh-2);
  --shadow-3:        var(--sh-3);
  --accent-bg-soft:  var(--accent-soft);
  --success-bg-soft: var(--success-soft);
  --warn-bg-soft:    var(--warn-soft);
  --danger-bg-soft:  var(--danger-soft);
  --font:            var(--font-sans);
  --mono:            var(--font-mono);
  --rail-w:          var(--rail);
  --statusbar-h:     var(--status-h);
}

[data-theme="dark"] {
  /* surfaces */
  --bg:        #0c0f14;
  --bg-elev:   #12161d;
  --bg-card:   #151a22;
  --bg-sunken: #0a0d12;
  --bg-hover:  #1b212b;
  --bg-active: #222a36;

  /* text */
  --fg:        #d6dbe3;
  --fg-dim:    #8c95a3;
  --fg-faint:  #5f6875;
  --fg-strong: #f3f6fa;

  /* lines */
  --border:        #232a34;
  --border-strong: #313a47;

  /* accent stays the same hex; derived values adapt to the dark
     surfaces automatically via color-mix. Only the on-accent text
     is pinned. */
  --accent-fg: #ffffff;

  /* health */
  --success: #34d399;
  --warn:    #fbbf24;
  --danger:  #f87171;
  --stale:   #94a3b8;
  --paused:  #64748b;

  /* elevation (heavier in dark) */
  --sh-1: 0 1px 2px rgba(0,0,0,.4);
  --sh-2: 0 2px 8px rgba(0,0,0,.45);
  --sh-3: 0 10px 30px rgba(0,0,0,.55), 0 2px 8px rgba(0,0,0,.4);
}

html, body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
}

* { transition: background-color var(--motion-fast) var(--ease), border-color var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease); }
*::before, *::after { transition: inherit; }
input, textarea, select, button { transition: none; }

.cmdk-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.4);
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 12vh;
  animation: cmdk-in var(--motion) var(--ease);
}
.cmdk {
  width: min(640px, 90vw); max-height: 70vh;
  background: var(--bg-card); color: var(--fg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.cmdk-input {
  width: 100%; padding: 16px 20px;
  font-size: 16px;
  border: 0; border-bottom: 1px solid var(--border);
  background: transparent; color: var(--fg);
  outline: none; font-family: inherit;
}
.cmdk-input::placeholder { color: var(--fg-dim); }
.cmdk-list { flex: 1; overflow-y: auto; padding: 4px 0; }
.cmdk-group {
  padding: 8px 16px 4px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--fg-dim);
}
.cmdk-item {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 16px; cursor: pointer; color: var(--fg);
}
.cmdk-item.is-active {
  background: var(--accent-bg-soft);
  color: var(--accent-strong);
}
[data-theme="dark"] .cmdk-item.is-active { color: var(--accent); }
.cmdk-item-kind {
  font-size: 11px; padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-hover); color: var(--fg-dim);
  margin-left: auto; font-family: var(--mono);
}
.cmdk-empty { padding: 32px 16px; text-align: center; color: var(--fg-dim); }
@keyframes cmdk-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.statusbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: var(--statusbar-h);
  background: var(--bg-elev); color: var(--fg-dim);
  border-top: 1px solid var(--border);
  font-size: 12px;
  display: flex; align-items: center;
  padding: 0 14px; gap: 16px; z-index: 50;
}
.statusbar .sb-dot {
  width: 8px; height: 8px; border-radius: 999px;
  display: inline-block; vertical-align: middle; margin-right: 6px;
}
.statusbar .sb-dot.healthy { background: var(--success); }
.statusbar .sb-dot.warn { background: var(--warn); }
.statusbar .sb-dot.danger { background: var(--danger); }
.statusbar .sb-spacer { flex: 1; }
body.has-statusbar main { padding-bottom: calc(var(--statusbar-h) + 16px); }

.header-search-wrap { position: relative; margin-right: 12px; }
.header-search {
  width: 220px; height: 32px;
  padding: 0 12px 0 32px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elev); color: var(--fg);
  font-family: inherit; font-size: 13px;
}
.header-search:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg-soft);
}
.header-search-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  pointer-events: none; opacity: .6;
}
.header-search-kbd { display: none; } /* deprecated: hint now lives in placeholder only */

/* Tab-style active state for top nav. Solid blue buttons read as primary
   CTAs and steal attention from real CTAs like "Add feed". A subtle
   accent-tinted pill makes the active link feel like a selected tab. */
.header-link.active {
  background: var(--accent-bg-soft) !important;
  color: var(--accent-strong) !important;
  border-radius: var(--radius) !important;
  border: 0 !important;
  font-weight: 600 !important;
}
[data-theme="dark"] .header-link.active {
  color: var(--accent) !important;
}

/* Tighter inline add-bar replaces the .hero card. */
.inline-add {
  display: flex; gap: 8px; align-items: center;
  margin: 0 0 16px;
}
.inline-add input[type="text"] {
  flex: 1; height: 40px; padding: 0 14px;
  font-size: 14px; font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card); color: var(--fg);
}
.inline-add input[type="text"]:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg-soft);
}
.inline-add .btn { height: 40px; padding: 0 16px; }
.inline-add .dashboard-secondary {
  display: inline-flex; align-items: center; color: var(--fg-dim);
  background: transparent; border: 0;
}

/* Inline toolbar (replaces the .manage-panel card wrapper). */
.dashboard-toolbar {
  display: flex; align-items: center; gap: 12px;
  margin: 0 0 12px; flex-wrap: wrap;
}
.dashboard-search {
  flex: 0 1 280px; min-width: 200px;
  height: 32px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-card); color: var(--fg);
  font-family: inherit; font-size: 13px;
}
.dashboard-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg-soft); }
.dashboard-toolbar .tag-filter-bar { flex: 1; min-width: 0; }
.dashboard-actions { display: flex; gap: 8px; margin-left: auto; }
.dashboard-menu-wrap { position: relative; }
.dashboard-menu-wrap .feed-menu {
  position: absolute; right: 0; top: calc(100% + 4px);
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-2); min-width: 220px; z-index: 80;
  padding: 4px 0;
}

/* Feed card: stats become one dot-separated line, the standalone
   health-dot is removed (left-edge stripe carries it). */
/* Theme-aware card surface. The legacy .card in style.css hard-codes
   white background, which broke in dark mode (white card + white text =
   invisible feed names). Override globally so .card adopts the active
   theme. High specificity via the html prefix without an !important
   war. */
html .card { background: var(--bg-card); color: var(--fg); border-color: var(--border); }

/* App shell main pane: cap the content column at a comfortable reading
   width even on huge monitors. Left-aligned (no margin: 0 auto) so the
   eye picks up from the rail edge instead of swimming through dead
   space. 1280px keeps Read / Config / ⋯ ~900-1100px from the feed name,
   not 1500+ as before. */
body.app-shell > main {
  max-width: 1280px;
  width: 100%;
  margin: 0;
  padding: 24px;
  box-sizing: border-box;
}

/* Feed card layout: flex (not grid) so the actions row sits IMMEDIATELY
   after the body content, not pinned to the far right of the card.
   Body grows up to 880px and then stops; actions follow. Result: on
   wide screens the buttons sit next to the title instead of across the
   continent. overflow:hidden removed so the ⋯ dropdown can bleed out
   of the card. */
.feed-card { padding: 0; background: var(--bg-card); color: var(--fg); border-color: var(--border); position: relative; }
.feed-card .feed-row {
  display: flex; gap: 16px; padding: 12px 16px; align-items: flex-start;
}
.feed-card .feed-body {
  flex: 1 1 auto; min-width: 0; max-width: 880px;
  display: block; color: inherit; text-decoration: none;
  border-radius: var(--radius-sm); padding: 4px 0;
  transition: background var(--motion-fast) var(--ease);
}
.feed-card .feed-actions { flex: 0 0 auto; }

/* Per-row ⋯ dropdown is theme-aware and floats above its card so it
   can extend beyond the card boundary without being clipped. */
html .feed-menu {
  background: var(--bg-card);
  color: var(--fg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-2);
  z-index: 100;
}
html .feed-menu .menu-item { color: var(--fg); }
html .feed-menu .menu-item:hover { background: var(--bg-hover); color: var(--fg); }
html .feed-menu .menu-sep { border-color: var(--border); }
html .feed-menu .menu-item.danger { color: var(--danger); }
html .feed-menu .menu-item.danger:hover { background: var(--danger-bg-soft); }
.feed-card .feed-body:hover { background: var(--bg-hover); }
.feed-card .feed-name { font-weight: 600; font-size: 15px; color: var(--fg-strong); margin-bottom: 4px; }
.feed-card .feed-source { font-size: 12px; color: var(--fg-dim); margin-bottom: 6px; }
.feed-card .feed-stats-line {
  font-size: 12px; color: var(--fg-dim);
  font-variant-numeric: tabular-nums;
}
.feed-card .feed-error {
  margin-top: 6px; padding: 6px 10px;
  background: var(--danger-bg-soft); color: var(--danger);
  border-radius: var(--radius-sm); font-size: 12px;
}
.feed-card .feed-tags { margin-top: 6px; }
.feed-card .feed-actions { display: flex; gap: 6px; align-items: center; }

body.app-shell {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: "header header" "rail main";
  min-height: 100vh;
}
body.app-shell > header { grid-area: header; }
body.app-shell > main { grid-area: main; padding: 24px; max-width: 100%; }
body.app-shell .left-rail { grid-area: rail; }
.left-rail {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px 0;
  position: sticky; top: var(--header-h);
  align-self: start;
  max-height: calc(100vh - var(--header-h) - var(--statusbar-h));
}
.left-rail-section-title {
  padding: 8px 16px;
  font-size: 11px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--fg-dim);
}
.lr-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 16px; cursor: pointer; font-size: 13px;
  color: var(--fg);
}
.lr-item:hover { background: var(--bg-hover); }
.lr-item.is-active {
  background: var(--accent-bg-soft);
  color: var(--accent-strong);
  font-weight: 600;
}
/* In dark mode --accent-strong is a deep indigo that disappears on the
   subtle dark accent tint; use the brighter base accent for the label,
   mirroring .cmdk-item.is-active / .header-link.active below. */
[data-theme="dark"] .lr-item.is-active { color: var(--accent); }
.lr-count {
  margin-left: auto; font-size: 11px;
  color: var(--fg-dim); font-family: var(--mono);
}

.fh-dot { width: 8px; height: 8px; border-radius: 999px; display: inline-block; vertical-align: middle; margin-right: 6px; flex-shrink: 0; }
.fh-dot.healthy { background: var(--success); }
.fh-dot.warn { background: var(--warn); }
.fh-dot.failed { background: var(--danger); }
.fh-dot.paused { background: var(--fg-dim); }

@keyframes shimmer {
  0% { background-position: -200px 0; }
  100% { background-position: calc(200px + 100%) 0; }
}
.skeleton {
  display: inline-block;
  background: linear-gradient(90deg, var(--bg-hover) 0%, var(--bg-elev) 50%, var(--bg-hover) 100%);
  background-size: 200px 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
