/* Shared primitives: the centred page frame, cards, status pills, buttons,
   inline icons, the classic page header and its rail, and the recordings
   list. Loaded by every page.

   SHARED FILE - every page loads it, so two branches editing it collide.
   A rule that belongs to one page goes in that page's css/page-*.css
   instead. See CONTRIBUTING.md, merge magnets.
*/

/* The centred-page rule is for the classic pages (settings, downloads, admin,
   login). The three-pane app opts out with body.app - see the app shell below. */
body:not(.app) {
  font-family: var(--font-sans);
  max-width: 1100px; margin: 0 auto; padding: 1rem 1rem 2rem;
  background: var(--paper); color: var(--ink); line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--ink); text-decoration: underline; font-weight: 550; }
h1 { font-size: 1.3rem; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0; }
audio#audio { width: 100%; margin: 1rem 0; display: block; }
pre { white-space: pre-wrap; background: var(--panel-2); padding: 1rem; }
.login-error { color: var(--err); font-size: 0.95rem; }
.admin-note { color: var(--warn); font-size: 0.9rem; }
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th, .admin-table td { text-align: left; padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border); }

/* generic cards (admin + player) */
.card { background: var(--panel); border: 1px solid var(--border); padding: 1rem 1.25rem; margin: 1rem 0; box-shadow: var(--shadow); border-radius: var(--radius); }
.card h2 { font-size: 1.1rem; margin-top: 0; }
.muted { color: var(--muted); font-size: 0.85rem; }
.stat-row { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.stat { background: var(--panel-2); padding: 0.6rem 0.9rem; min-width: 4.5rem; text-align: center; border-radius: var(--radius); }
.stat-num { font-size: 1.4rem; font-weight: 600; }
.stat-label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; }

/* pills (status chips) */
.pill { display: inline-flex; align-items: center; gap: .35rem; padding: .12rem .6rem; font-size: .78rem; font-weight: 600; border: 1px solid transparent; text-transform: none; border-radius: var(--radius-pill); }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .9; }
.pill-on, .pill-done, .pill.status-done { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.pill-off, .pill-failed, .pill.status-failed { color: var(--err); background: color-mix(in srgb, var(--err) 14%, transparent); }
.pill-unknown, .pill-queued, .pill.status-queued, .pill.status-none { color: var(--muted); background: color-mix(in srgb, var(--muted) 16%, transparent); }
.pill-running, .pill.status-running { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }

.btn { font: inherit; font-size: .85rem; font-weight: 550; padding: .5rem .9rem; border: 1px solid var(--border); background: var(--panel-2); color: var(--ink); cursor: pointer; min-height: 38px; text-align: center; -webkit-tap-highlight-color: transparent; border-radius: var(--radius-pill); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-danger, .btn.danger { border-color: var(--err); color: var(--err); }

/* A count attached to a name: the pending-proposals number in the settings
   nav, and the same number beside a recording's title. It lives here rather
   than in a page file because two unrelated pages now draw it, and a second
   copy of a rule is the thing this repo has already paid for once. Unstyled,
   the number runs into the label and "Triggers 3" reads as a section name. */
.count-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.25em; height: 1.25em; margin-left: .45em; padding: 0 .3em;
  border-radius: var(--radius-pill);
  background: var(--warn); color: var(--paper);
  font-size: .7rem; font-weight: 700; line-height: 1;
  /* The chip's own text can be inverted on .active; the badge keeps its
     contrast either way rather than inheriting and vanishing. */
  vertical-align: baseline;
}
/* The `display` above is author-origin and so beats the browser's own
   `[hidden] { display: none }`. Without this line the recording view's
   badge.hidden = true does nothing and every recording with no pending
   proposals wears a "0". Same companion rule as .menu-dropdown[hidden] and
   .dev-token-out[hidden]; there is no global [hidden] reset. */
.count-badge[hidden] { display: none; }

/* --- classic pages: header, sidebar rail, card grid.
   Still used by settings / downloads / admin; the library itself moved to
   the app shell at the bottom of this file. --- */
.app-shell { display: flex; flex-direction: column; gap: 1rem; }
.app-header { position: sticky; top: 0; z-index: 5; background: var(--paper); padding: .6rem 0; border-bottom: 1px solid var(--border); }
.app-header .topline { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.app-header .conn { margin-left: auto; display: inline-flex; align-items: center; gap: .4rem; font-size: .8rem; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.live { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.dot.down { background: var(--err); }
.user-line { margin-top: .3rem; }
.user-line .sep { margin: 0 .4rem; }

.layout { display: flex; flex-direction: column; gap: 1rem; }
@media (min-width: 800px) {
  .layout { flex-direction: row; align-items: flex-start; }
  .folders { flex: 0 0 200px; position: sticky; top: 4.2rem; }
  .layout main { flex: 1; min-width: 0; } }

.folders { display: flex; flex-direction: row; flex-wrap: wrap; gap: .4rem; }
@media (min-width: 800px) { .folders { flex-direction: column; flex-wrap: nowrap; } }
.folder {
  font: inherit; font-size: .85rem; text-align: left; padding: .5rem .8rem;
  border: 1px solid var(--border); background: var(--panel);
  color: var(--ink); cursor: pointer;
}
.folder.active { background: var(--accent); color: var(--accent-fg); border-color: transparent; }

.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.empty { color: var(--muted); grid-column: 1 / -1; }

.rec-card {
  background: var(--panel); border: 1px solid var(--border);
  padding: 1rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .5rem;
  cursor: grab; border-radius: var(--radius);
}
.rec-card:active { cursor: grabbing; }
.rec-top { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; font-size: .8rem; color: var(--muted); }
.rec-date, .rec-dur { color: var(--muted); }
.rec-topic { font-size: 1rem; margin: 0; font-weight: 650; letter-spacing: -.01em; }

/* ===== Inline icons =====
   The UI draws its glyphs as inline SVG rather than emoji: emoji render at the
   mercy of the platform's font (colour, weight and metrics all differ between
   macOS, Windows and Android), so they never matched the surrounding text.
   These inherit currentColor, so they pick up hover/active states for free. */
.ico {
  width: 1em; height: 1em; flex: 0 0 auto;
  vertical-align: -.13em;  /* sit on the text baseline, not below it */
}
.btn .ico { width: 1.05em; height: 1.05em; }
.feat-ico svg { width: 18px; height: 18px; }
.view-toggle .vt-btn svg { width: 1rem; height: 1rem; display: block; }
.rename-btn .ico { width: .95em; height: .95em; }

/* --- inline rename (recording title) --- */
.rename-btn {
  background: none; border: 0; padding: 0 0 0 .35rem; color: var(--muted);
  font: inherit; font-size: .85em; cursor: pointer; opacity: 0; transition: opacity .12s;
}
.rec-card:hover .rename-btn, .rec-row:hover .rename-btn,
.rename-btn:focus-visible { opacity: 1; }
.rename-btn:hover { color: var(--accent); }
.rename-input {
  font: inherit; font-weight: 650; width: 100%; box-sizing: border-box;
  color: var(--ink); background: var(--panel-2); border: 1px solid var(--accent);
  padding: .2rem .4rem; border-radius: var(--radius);
}
.rec-summary { margin: 0; color: var(--muted); font-size: .88rem; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.rec-tags { display: flex; flex-wrap: wrap; gap: .3rem; }
.chip { display: inline-block; padding: .1rem .55rem; font-size: .72rem; background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); border-radius: var(--radius-pill); }
.rec-actions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: auto; }
.rec-actions .btn { flex: 1 1 auto; }

/* --- speaker editor and transcript primitives, shared with the document
   pane (static/app/detail.js, speakers.js) --- */
.player-wrap { max-width: 780px; margin: 0 auto; }
.back { font-size: .9rem; }
.analysis .summary { margin: 0 0 .6rem; }
.row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.spacer { flex: 1; }
.speaker-block { margin: .5rem 0; padding-bottom: .5rem; border-bottom: 1px solid var(--border); }
.speaker-block:last-child { border-bottom: 0; }
.speaker-row { margin: .2rem 0; }
.speaker-name { font: inherit; font-size: .9rem; padding: .4rem .6rem; border: 1px solid var(--border); background: var(--panel-2); color: var(--ink); min-width: 10rem; border-radius: var(--radius); }
.chip.suggestion { cursor: pointer; border-color: var(--accent); color: var(--ink); }
.chip.suggestion:hover { background: var(--accent); color: var(--accent-fg); }
.chip.auto { border-color: var(--accent); color: var(--accent); background: transparent; }
.play-sample { padding: .35rem .6rem; min-height: 34px; }
.merge-into { font: inherit; font-size: .82rem; padding: .35rem .5rem; border: 1px solid var(--border); background: var(--panel-2); color: var(--ink); border-radius: var(--radius); }
.merged-note { margin-top: .25rem; font-size: .78rem; }
.btn-link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; font-size: .78rem; padding: 0; text-decoration: underline; }
#transcript-body p { margin: .4rem 0; }
#transcript-body b { margin-right: .3rem; }

/* recordings toolbar: search + duration filter */
.toolbar { display: flex; gap: .6rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.toolbar .search {
  flex: 1 1 220px; min-width: 0; font: inherit; font-size: .9rem; padding: .55rem .8rem;
  border: 1px solid var(--border); background: var(--panel); color: var(--ink); border-radius: var(--radius-pill);
}
.toolbar .dur-filter {
  font: inherit; font-size: .9rem; padding: .55rem .7rem; border: 1px solid var(--border); background: var(--panel); color: var(--ink); cursor: pointer; border-radius: var(--radius-pill);
}
.toolbar .result-count { font-size: .8rem; white-space: nowrap; }

.rec-card .chip { cursor: pointer; }
.rec-card .chip:hover { border-color: var(--accent); }

/* ===== View toggle (tiles / list) ===== */
.view-toggle { display: inline-flex; margin-left: auto; border: 1px solid var(--border); overflow: hidden; border-radius: var(--radius-pill); }
.view-toggle .vt-btn {
  font: inherit; font-size: 1rem; line-height: 1; padding: .5rem .7rem; border: none; cursor: pointer;
  background: var(--panel); color: var(--muted);
}
.view-toggle .vt-btn + .vt-btn { border-left: 1px solid var(--border); }
.view-toggle .vt-btn:hover { color: var(--ink); }
.view-toggle .vt-btn.active { background: var(--accent); color: var(--accent-fg); }

/* ===== List view ===== */
.grid-list { display: flex; flex-direction: column; gap: .4rem; }
.rec-row {
  display: flex; align-items: center; gap: .75rem; padding: .55rem .8rem; cursor: pointer;
  border: 1px solid var(--border); background: var(--panel); border-radius: var(--radius);
}
.rec-row:hover { border-color: var(--accent); }
.rec-row:active { cursor: grabbing; }
.rec-row .pill { flex: 0 0 auto; }
.rec-row .row-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: .1rem; }
.rec-row .row-topic { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-row .row-summary { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-row .row-tags { flex: 0 1 auto; display: flex; gap: .3rem; overflow: hidden; }
.rec-row .chip { cursor: pointer; white-space: nowrap; }
.rec-row .chip:hover { border-color: var(--accent); }
.rec-row .row-date, .rec-row .row-dur { flex: 0 0 auto; font-size: .78rem; color: var(--muted); white-space: nowrap; }
.rec-row .row-actions { flex: 0 0 auto; display: flex; gap: .3rem; }
.rec-row .row-actions .btn { padding: .3rem .5rem; }
@media (max-width: 720px) {
  .rec-row .row-tags, .rec-row .row-summary { display: none; } }

/* --- the trigger dry-run report ------------------------------------------
   Shared, not app-only: the same report is rendered by the recording view and
   by /settings/triggers/dryrun (static/app/trigger_dryrun.js renders both), so
   a page stylesheet would leave one of the two unstyled. `.trigger-error` is
   here for the same reason - the report uses it for a failed run. */
/* Shared for the same reason: the recording view's proposal panel
   (static/app/triggers.js) and three settings pages all use this row. It lived
   in page-app.css, which none of those settings pages load, so the buttons sat
   stacked and unspaced there. */
.trigger-actions { display: flex; gap: .75rem; align-items: center; }
.trigger-dryrun { margin-top: 1rem; }
.dryrun-list { list-style: none; padding: 0; margin: .5rem 0 0; }
.dryrun-list li { margin-bottom: .75rem; }
.dryrun-list blockquote {
  margin: .25rem 0 0;
  padding-left: .75rem;
  border-left: 2px solid var(--border);
}
.trigger-error { font-size: .8rem; color: var(--err); }
