/* BeatWatcher design system. Tokens first, then components, then page bits. */

:root {
  --ink: #17191c;
  --ink-2: #3d4148;
  --muted: #6b717b;
  --surface: #ffffff;
  --surface-2: #f4f5f7;
  --bg: #f7f8fa;
  --line: #e3e6ea;
  --line-2: #cfd4da;
  --accent: #2456d6;
  --accent-ink: #ffffff;
  --accent-soft: #e8eefc;
  --ok: #1f7a3a;
  --ok-soft: #e4f4e8;
  --warn: #9a6100;
  --warn-soft: #fdf1d8;
  --danger: #b3261e;
  --danger-soft: #fbe7e5;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 10px;
  --radius-sm: 7px;
  --sidebar: 15.5rem;
  --topbar: 3.25rem;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e9ebef;
    --ink-2: #c3c7ce;
    --muted: #8d939d;
    --surface: #1b1e24;
    --surface-2: #232730;
    --bg: #14161a;
    --line: #2c313a;
    --line-2: #3b414c;
    --accent: #7ea2ff;
    --accent-ink: #0d1330;
    --accent-soft: #1f2a4d;
    --ok: #6fcf8a;
    --ok-soft: #173321;
    --warn: #e8b455;
    --warn-soft: #3a2d10;
    --danger: #ff8a80;
    --danger-soft: #3d1a17;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.55 var(--font);
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.tiny { font-size: .78rem; }
.mono { font-family: var(--mono); font-size: .85em; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.spacer { flex: 1; }
.right { margin-left: auto; }
.hide { display: none; }

/* --- shell ------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar);
  display: flex; align-items: center; gap: .8rem;
  padding: 0 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 750; color: var(--ink); letter-spacing: -.02em; display: flex; align-items: center; gap: .45rem; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 1.35rem; height: 1.35rem; border-radius: 6px; background: linear-gradient(135deg, var(--accent), #7c4dff); display: inline-block; }
.menu-btn { display: none; }
.shell { display: flex; min-height: calc(100vh - var(--topbar)); }
.sidebar {
  width: var(--sidebar); flex-shrink: 0;
  padding: 1rem .75rem;
  border-right: 1px solid var(--line);
  background: var(--surface);
  position: sticky; top: var(--topbar); height: calc(100vh - var(--topbar));
  overflow-y: auto;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 0 .5rem .6rem; font-size: .78rem; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.side-link {
  display: flex; align-items: center; gap: .5rem;
  padding: .45rem .6rem; border-radius: var(--radius-sm);
  color: var(--ink-2); font-weight: 500;
}
.side-link:hover { background: var(--surface-2); text-decoration: none; }
.side-link.active { background: var(--accent-soft); color: var(--accent); }
.side-link .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-empty { padding: .4rem .6rem; }
.content { flex: 1; min-width: 0; padding: 1.5rem 2rem 5rem; max-width: 72rem; }
.content.narrow { max-width: 44rem; margin: 0 auto; }
.page-header { display: flex; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-header .titles { min-width: 0; flex: 1 1 18rem; }
.page-header .subtitle { color: var(--muted); margin: .15rem 0 0; }
.page-header .actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.crumbs { font-size: .82rem; color: var(--muted); margin-bottom: .3rem; }

@media (max-width: 640px) {
  .topbar .username { display: none; }
}
@media (max-width: 900px) {
  .menu-btn { display: inline-flex; }
  .sidebar {
    position: fixed; left: 0; top: var(--topbar); z-index: 25;
    transform: translateX(-100%); transition: transform .18s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .content { padding: 1rem 1rem 5rem; }
}

/* --- buttons ----------------------------------------------------------- */
.btn {
  font: inherit; font-weight: 550; font-size: .9rem;
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .45rem .85rem;
  border: 1px solid var(--accent); border-radius: var(--radius-sm);
  background: var(--accent); color: var(--accent-ink);
  cursor: pointer; text-decoration: none; line-height: 1.2; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s, transform .06s;
}
.btn:hover { text-decoration: none; filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line-2); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--accent); border-color: transparent; }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: .3rem .6rem; font-size: .82rem; }
.btn-icon { padding: .35rem; width: 2rem; height: 2rem; justify-content: center; }
.btn .htmx-indicator { display: none; }
.btn.htmx-request .htmx-indicator { display: inline-block; }
.btn.htmx-request .label { opacity: .6; }
.spinner { width: .85em; height: .85em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- pills & badges ---------------------------------------------------- */
.pill {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .12rem .55rem; border-radius: 999px;
  font-size: .76rem; font-weight: 600; line-height: 1.5;
  background: var(--surface-2); color: var(--ink-2);
  white-space: nowrap;
}
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-danger { background: var(--danger-soft); color: var(--danger); }
.pill-accent { background: var(--accent-soft); color: var(--accent); }
.badge { display: inline-block; min-width: 1.4rem; text-align: center; padding: 0 .4rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: .74rem; font-weight: 650; line-height: 1.5rem; }
.side-link.active .badge { background: var(--accent); color: var(--accent-ink); }
.dot { width: .5rem; height: .5rem; border-radius: 50%; background: currentColor; display: inline-block; }

/* --- cards & lists ----------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem 1.1rem;
}
.card + .card { margin-top: .75rem; }
.card-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .6rem; }
.grid { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr)); }
.topic-card { display: flex; flex-direction: column; gap: .6rem; }
.topic-card h3 a { color: var(--ink); }
.topic-card .desc { color: var(--muted); font-size: .88rem; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.topic-card .stats { display: flex; gap: .9rem; flex-wrap: wrap; font-size: .82rem; color: var(--muted); }
.topic-card .stats strong { color: var(--ink); font-weight: 650; }
.topic-card .foot { margin-top: auto; display: flex; gap: .5rem; padding-top: .4rem; }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty-state h2 { color: var(--ink); margin-bottom: .4rem; }
.steps { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); max-width: 46rem; margin: 1.4rem auto; text-align: left; }
.step { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; }
.step .n { display: inline-block; width: 1.5rem; height: 1.5rem; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; text-align: center; line-height: 1.5rem; font-size: .8rem; margin-bottom: .4rem; }

/* --- tabs & segmented control ----------------------------------------- */
.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--line); margin-bottom: 1.1rem; overflow-x: auto; }
.tab {
  font: inherit; font-weight: 550; font-size: .9rem;
  padding: .55rem .8rem; border: none; background: none; color: var(--muted); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab .badge { margin-left: .3rem; }
.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .18rem; gap: .18rem; }
.segmented a, .segmented button {
  font: inherit; font-size: .84rem; font-weight: 550; color: var(--muted);
  padding: .3rem .7rem; border-radius: 5px; border: none; background: none; cursor: pointer; white-space: nowrap;
}
.segmented a:hover { text-decoration: none; color: var(--ink); }
.segmented .active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip {
  font: inherit; font-size: .8rem; font-weight: 550;
  padding: .25rem .65rem; border-radius: 999px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2); cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* --- forms ------------------------------------------------------------- */
.field { margin-bottom: .9rem; }
.field label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: .3rem; }
.field .help { color: var(--muted); font-size: .8rem; margin-top: .3rem; }
.field .error { color: var(--danger); font-size: .8rem; margin-top: .3rem; }
.field.has-error input, .field.has-error textarea, .field.has-error select { border-color: var(--danger); }
input[type=text], input[type=url], input[type=password], input[type=email], input[type=search], textarea, select {
  width: 100%; font: inherit; color: var(--ink);
  padding: .5rem .65rem;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color .12s, box-shadow .12s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 7rem; resize: vertical; line-height: 1.5; }
select { appearance: auto; }
.input-sm { padding: .3rem .5rem; font-size: .85rem; }
.form-actions { display: flex; gap: .5rem; align-items: center; margin-top: 1.1rem; }
.form-grid { display: grid; gap: .6rem 1rem; grid-template-columns: 1fr auto; align-items: end; }
.errorlist { color: var(--danger); font-size: .85rem; margin: .3rem 0 .6rem; padding-left: 1.1rem; }
.auth { max-width: 24rem; margin: 3rem auto; }
.auth .card { padding: 1.6rem; }
.auth h1 { margin-bottom: 1rem; }
.auth .field label { font-size: .85rem; }

/* --- toasts ------------------------------------------------------------ */
.toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 60; display: flex; flex-direction: column; gap: .5rem; max-width: 24rem; }
.toast {
  display: flex; align-items: flex-start; gap: .6rem;
  padding: .7rem .9rem; border-radius: var(--radius-sm);
  background: var(--ink); color: var(--bg); box-shadow: var(--shadow); font-size: .88rem;
}
.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--ok); color: #fff; }
.toast-close { margin-left: auto; background: none; border: none; color: inherit; opacity: .7; cursor: pointer; font-size: 1rem; line-height: 1; padding: 0; }

/* --- sources list ------------------------------------------------------ */
.source-row { display: flex; align-items: center; gap: .8rem; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.source-row:last-child { border-bottom: none; }
.source-row .icon { font-size: 1.3rem; width: 1.8rem; text-align: center; flex-shrink: 0; }
.source-row .main { flex: 1; min-width: 0; }
.source-row .name { font-weight: 600; }
.source-row .url { color: var(--muted); font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.source-row .meta { display: flex; gap: .6rem; align-items: center; font-size: .8rem; color: var(--muted); flex-wrap: wrap; justify-content: flex-end; }
.status-strip { display: flex; gap: 1.2rem; flex-wrap: wrap; align-items: center; padding: .6rem .9rem; border-radius: var(--radius-sm); background: var(--surface-2); font-size: .84rem; color: var(--muted); margin-bottom: 1rem; }
.status-strip strong { color: var(--ink); }
.status-strip.live { outline: 1px solid var(--accent-soft); }

/* --- catalogue --------------------------------------------------------- */
.catalogue-tools { display: flex; gap: .8rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.catalogue-tools input[type=search] { max-width: 20rem; }
.feed-group { margin-bottom: 1.1rem; }
.feed-group-title { display: flex; align-items: center; gap: .5rem; font-weight: 650; margin-bottom: .5rem; }
.feed-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); gap: .6rem; }
.feed-card { display: flex; gap: .6rem; align-items: flex-start; padding: .65rem .75rem; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.feed-card.subscribed { border-color: var(--ok); background: var(--ok-soft); }
.feed-icon { font-size: 1.5rem; line-height: 1; width: 2rem; text-align: center; flex-shrink: 0; }
.feed-body { flex: 1; min-width: 0; }
.feed-name { font-weight: 600; font-size: .92rem; }
.feed-desc { line-height: 1.35; font-size: .8rem; color: var(--muted); }
.feed-action { flex-shrink: 0; }
.feed-action form { margin: 0; }
.feed-subscribed { color: var(--ok); font-weight: 650; font-size: .82rem; white-space: nowrap; }

/* --- digest ------------------------------------------------------------ */
.digest-tools { display: flex; gap: .8rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.item { display: flex; gap: .8rem; padding: .9rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: .6rem; outline: 2px solid transparent; transition: outline-color .1s; }
.item.focus { outline-color: var(--accent); }
.item .src-icon { width: 2.1rem; height: 2.1rem; border-radius: 8px; background: var(--surface-2); display: flex; align-items: center; justify-content: center; font-size: 1.15rem; font-weight: 700; color: var(--muted); flex-shrink: 0; }
.item .body { flex: 1; min-width: 0; }
.item h3 { font-size: 1rem; font-weight: 600; margin-bottom: .15rem; }
.item h3 a { color: var(--ink); }
.item .meta { font-size: .8rem; color: var(--muted); display: flex; gap: .45rem; flex-wrap: wrap; align-items: center; }
.item .reason { margin: .45rem 0 .5rem; font-size: .88rem; color: var(--ink-2); }
.feedback { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; font-size: .84rem; }
.feedback .you { color: var(--ink-2); }
.feedback .note-form { display: flex; gap: .4rem; align-items: center; flex: 1 1 16rem; }
.feedback .note-form input { flex: 1; }
.load-more { display: flex; justify-content: center; padding: 1rem 0; }
.kbd { font: .72rem/1.3 var(--mono); padding: .05rem .35rem; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; background: var(--surface); color: var(--muted); }
.legend { font-size: .78rem; color: var(--muted); display: flex; gap: .8rem; flex-wrap: wrap; align-items: center; }

/* --- prompt ------------------------------------------------------------ */
pre.prompt { white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--line); padding: .8rem .9rem; border-radius: var(--radius-sm); font: .84rem/1.5 var(--mono); max-height: 22rem; overflow: auto; margin: 0; }
.two-col { display: grid; gap: 1.2rem; grid-template-columns: minmax(0, 1fr) 19rem; align-items: start; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }
.example { padding: .55rem 0; border-bottom: 1px solid var(--line); font-size: .84rem; }
.example:last-child { border-bottom: none; }
.stat-row { display: flex; gap: 1.2rem; flex-wrap: wrap; }
.stat { min-width: 6rem; }
.stat .v { font-size: 1.35rem; font-weight: 700; line-height: 1.1; }
.stat .l { font-size: .76rem; color: var(--muted); }

/* --- menus ------------------------------------------------------------- */
.menu { position: relative; }
.menu-panel { position: absolute; right: 0; top: calc(100% + .3rem); min-width: 11rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: .3rem; z-index: 20; }
.menu-panel a, .menu-panel button { display: block; width: 100%; text-align: left; font: inherit; font-size: .88rem; padding: .45rem .6rem; border: none; background: none; color: var(--ink); border-radius: 5px; cursor: pointer; }
.menu-panel a:hover, .menu-panel button:hover { background: var(--surface-2); text-decoration: none; }
.menu-panel .danger { color: var(--danger); }
