/* Voice Notes
   Cool paper, slate ink, one signal red reserved for things that need you (missing labels, errors).
   Grotesk for the interface, a serif for what you read (notes and transcripts). */

:root {
  --paper: #EDF0F3;
  --surface: #FFFFFF;
  --ink: #18212B;
  --muted: #5F6B78;
  --faint: #8C97A3;
  --rule: #D3D9E0;
  --rule-strong: #B8C1CB;
  --signal: #D7372C;
  --signal-wash: #FBE9E7;
  --focus: #1F5FBF;
  --hover: #F5F7F9;

  --sky: #3D7EAA;
  --moss: #5E8C4A;
  --amber: #B7811A;
  --plum: #8A4F7D;
  --teal: #2F8F83;
  --brick: #A8443A;
  --slate: #5F6B78;

  --sans: "Schibsted Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Newsreader", ui-serif, Georgia, "Times New Roman", serif;

  --step--1: 0.8125rem;
  --step-0: 0.9375rem;
  --step-1: 1.125rem;
  --step-2: 1.5rem;
  --step-3: 2rem;

  --radius-s: 6px;
  --radius-m: 10px;
  --page: min(1180px, 100% - 2.5rem);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 var(--step-0)/1.45 var(--sans);
  font-variant-numeric: tabular-nums;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- Buttons ---------- */

button { cursor: pointer; }
.primary, .quiet, .danger, .upload {
  border-radius: var(--radius-s);
  padding: 0.5rem 0.9rem;
  font-weight: 600;
  font-size: var(--step--1);
  line-height: 1.2;
  white-space: nowrap;
}
.primary { background: var(--ink); color: var(--surface); border: 1px solid var(--ink); }
.primary:hover { background: #2A3644; }
.quiet { background: var(--surface); border: 1px solid var(--rule-strong); }
.quiet:hover { background: var(--hover); }
.danger { background: none; border: 1px solid transparent; color: var(--signal); }
.danger:hover { border-color: var(--signal); }
button:disabled { opacity: 0.45; cursor: default; }
.link-button { background: none; border: 0; padding: 0; text-decoration: underline; text-underline-offset: 2px; font-weight: 600; }

/* ---------- Top bar ---------- */

.top {
  width: var(--page);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 1.1rem 0 0.9rem;
}
.brand {
  font-weight: 800;
  font-size: var(--step-1);
  letter-spacing: -0.02em;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.55rem;
}
.brand-mark { display: inline-flex; gap: 2px; align-items: center; height: 18px; }
.brand-mark i { display: block; width: 3px; border-radius: 2px; background: var(--ink); }
.brand-mark i:nth-child(1) { height: 8px; }
.brand-mark i:nth-child(2) { height: 16px; }
.brand-mark i:nth-child(3) { height: 11px; }
.brand-mark i:nth-child(4) { height: 18px; }
.nav { display: flex; gap: 1.1rem; margin-right: auto; }
.nav a { text-decoration: none; color: var(--muted); font-weight: 500; padding: 0.2rem 0; border-bottom: 2px solid transparent; }
.nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--ink); }
.upload { background: var(--ink); color: var(--surface); border: 1px solid var(--ink); display: inline-flex; align-items: center; gap: 0.4rem; }
.upload input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.upload:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }

main { width: var(--page); margin: 0 auto; padding-bottom: 6rem; }

/* ---------- Home: toolbar ---------- */

.toolbar { display: flex; flex-wrap: wrap; gap: 0.75rem 1rem; align-items: center; margin: 0.75rem 0 1rem; }
.search {
  flex: 0 1 300px;
  border: 1px solid var(--rule-strong);
  background: var(--surface);
  border-radius: var(--radius-s);
  padding: 0.5rem 0.75rem;
}
.filters { display: grid; gap: 0.5rem; }
.filter-row { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.filter-row.sub { padding-left: 0.9rem; border-left: 2px solid var(--rule-strong); }
.filter-row.sub .filter { font-size: 0.78rem; padding: 0.22rem 0.65rem; }
.filter {
  border: 1px solid var(--rule-strong);
  background: transparent;
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font-size: var(--step--1);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.filter .count { color: var(--faint); font-weight: 400; }
.filter[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.filter[aria-pressed="true"] .count { color: var(--rule-strong); }
.filter.unlabeled .dot { background: transparent; box-shadow: inset 0 0 0 1.5px var(--signal); }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--slate)); flex: none; }

/* ---------- Home: recordings table ---------- */

.sheet { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); overflow: hidden; }
.recordings { width: 100%; border-collapse: collapse; }
.recordings th {
  text-align: left;
  font-size: var(--step--1);
  font-weight: 600;
  color: var(--muted);
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--rule);
  background: var(--surface);
}
.recordings td { padding: 0.85rem 1rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
.recordings tbody tr:last-child td { border-bottom: 0; }
.recordings tbody tr { cursor: pointer; }
.recordings tbody tr:hover { background: var(--hover); }
.col-date { width: 9.5rem; white-space: nowrap; color: var(--muted); }
.col-length { width: 12.5rem; }
.col-size { width: 6rem; white-space: nowrap; color: var(--muted); text-align: right; }
th.col-size { text-align: right; }
.col-label { width: 11rem; }
.rec-title { font-weight: 600; display: block; }
.rec-sub { display: block; color: var(--muted); font-size: var(--step--1); margin-top: 0.15rem; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; }
.rec-sub.busy::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--focus); margin-right: 0.4rem; vertical-align: 1px; animation: pulse 1.4s ease-in-out infinite; }
.rec-sub.bad { color: var(--signal); }
@keyframes pulse { 50% { opacity: 0.25; } }

/* The tape counter: length against a 3-hour scale, with hour ticks. */
.tape { display: flex; align-items: center; gap: 0.6rem; }
.tape-track {
  position: relative;
  flex: none;
  width: 72px;
  height: 6px;
  border-radius: 3px;
  background:
    linear-gradient(var(--rule-strong), var(--rule-strong)) calc(100% / 3) 0 / 1px 100% no-repeat,
    linear-gradient(var(--rule-strong), var(--rule-strong)) calc(200% / 3) 0 / 1px 100% no-repeat,
    var(--paper);
  overflow: hidden;
}
.tape-fill { position: absolute; inset: 0 auto 0 0; background: var(--ink); border-radius: 3px; }
.tape-text { white-space: nowrap; }

.empty { padding: 3rem 1.5rem; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: var(--step-1); margin-bottom: 0.35rem; }

/* ---------- Label picker (a native select dressed as a chip) ---------- */

.label-pick { position: relative; display: inline-flex; align-items: center; max-width: 100%; }
.label-pick::before {
  content: "";
  position: absolute;
  left: 0.65rem;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--c, var(--slate));
  pointer-events: none;
}
.label-pick select {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--rule-strong);
  background: var(--surface);
  border-radius: 999px;
  padding: 0.28rem 1.6rem 0.28rem 1.45rem;
  font-size: var(--step--1);
  font-weight: 600;
  max-width: 100%;
  text-overflow: ellipsis;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 0.85rem) 55%, calc(100% - 0.6rem) 55%;
  background-size: 4px 4px;
  background-repeat: no-repeat;
}
.label-pick.missing::before { content: "+"; width: auto; height: auto; background: none; color: var(--signal); font-weight: 700; left: 0.7rem; }
.label-pick.missing select { border-color: var(--signal); color: var(--signal); background-color: var(--signal-wash); }

/* ---------- Detail ---------- */

.back { display: inline-block; margin: 0.25rem 0 1rem; color: var(--muted); text-decoration: none; font-weight: 500; }
.back:hover { color: var(--ink); }
.title-input {
  display: block;
  width: 100%;
  resize: none;
  overflow: hidden;
  font-family: var(--sans);
  border: 1px solid transparent;
  border-radius: var(--radius-s);
  background: transparent;
  font-size: var(--step-3);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  padding: 0.15rem 0.35rem;
  margin-left: -0.35rem;
}
.title-input:hover { border-color: var(--rule); }
.title-input:focus { background: var(--surface); border-color: var(--rule-strong); }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.25rem; margin: 0.6rem 0 1.25rem; color: var(--muted); }
.notion-state { display: inline-flex; align-items: center; gap: 0.5rem; }
.notion-state.bad { color: var(--signal); }
.notion-state a { color: var(--ink); font-weight: 600; text-underline-offset: 2px; }

.banner {
  display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; justify-content: space-between;
  border: 1px solid var(--rule-strong);
  background: var(--surface);
  border-radius: var(--radius-m);
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
}
.banner.busy p::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--focus); margin-right: 0.55rem; animation: pulse 1.4s ease-in-out infinite; }
.banner.bad { border-color: var(--signal); background: var(--signal-wash); }
.banner p { margin: 0; }

.columns { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 1.25rem; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 1.1rem 1.25rem 1.35rem; }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 0.75rem; margin-bottom: 0.75rem; }
.panel-head h2 { margin: 0; font-size: var(--step-1); font-weight: 700; letter-spacing: -0.01em; }
.panel-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.notes { font-family: var(--serif); font-size: 1.0625rem; line-height: 1.6; overflow-wrap: anywhere; }
.notes > :first-child { margin-top: 0; }
.notes h3, .notes h4, .notes h5 { font-family: var(--sans); font-weight: 700; margin: 1.25rem 0 0.35rem; line-height: 1.3; }
.notes h3 { font-size: var(--step-1); }
.notes h4 { font-size: var(--step-0); }
.notes h5 { font-size: var(--step--1); color: var(--muted); }
.notes p { margin: 0 0 0.5rem; max-width: 68ch; }
.notes ul, .notes ol { margin: 0 0 0.5rem; padding-left: 1.25rem; }
.notes li { margin: 0.25rem 0; }
.notes blockquote { margin: 0.5rem 0; padding: 0.1rem 0 0.1rem 0.9rem; border-left: 3px solid var(--rule-strong); color: var(--muted); }
.notes hr { border: 0; border-top: 1px solid var(--rule); margin: 1rem 0; }
.notes code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.85em; background: var(--hover); border: 1px solid var(--rule); border-radius: 4px; padding: 0 0.25em; }
.notes a { text-underline-offset: 2px; }
.notes .todos { list-style: none; padding-left: 0; }
.notes .todos label { display: grid; grid-template-columns: 1.2rem minmax(0, 1fr); gap: 0.5rem; cursor: pointer; }
.notes .todos input { width: 1rem; height: 1rem; margin: 0.36rem 0 0; accent-color: var(--ink); cursor: pointer; }
.notes .todos li.done span { color: var(--faint); text-decoration: line-through; text-decoration-color: var(--rule-strong); }
.notes-empty { color: var(--muted); font-family: var(--sans); font-size: var(--step-0); }

/* Notes editor */
.primary.small { padding: 0.4rem 0.85rem; }
.save-state { align-self: center; font-size: var(--step--1); color: var(--muted); min-width: 6.5rem; text-align: right; }
.md-toolbar {
  position: sticky; top: 0.5rem; z-index: 2;
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem;
  padding: 0.3rem; margin-bottom: 0.5rem;
  border: 1px solid var(--rule); border-radius: var(--radius-s); background: var(--hover);
}
.md-toolbar .tool {
  min-width: 2.1rem; height: 2.1rem; padding: 0 0.55rem;
  border: 1px solid transparent; border-radius: 5px; background: none;
  font-size: var(--step-0); line-height: 1;
}
.md-toolbar .tool:hover { background: var(--surface); border-color: var(--rule-strong); }
.md-toolbar .tool-gap { width: 1px; align-self: stretch; margin: 0.25rem 0.2rem; background: var(--rule-strong); }
.notes-editor {
  display: block; width: 100%; min-height: 280px; resize: vertical;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--rule-strong); border-radius: var(--radius-s); background: var(--surface);
  font: 400 0.9375rem/1.6 var(--sans);
  tab-size: 2;
}
.notes-editor:focus { outline: 2px solid var(--focus); outline-offset: 1px; }
.notes-panel .hint { margin-top: 0.5rem; }

.speakers { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; padding: 0.75rem 0 0.9rem; border-bottom: 1px solid var(--rule); margin-bottom: 0.5rem; }
.speaker { display: flex; align-items: center; gap: 0.45rem; }
.speaker label { font-size: var(--step--1); color: var(--muted); white-space: nowrap; }
.speaker input { width: 9.5rem; border: 1px solid var(--rule-strong); border-radius: var(--radius-s); padding: 0.3rem 0.5rem; font-size: var(--step--1); background: var(--surface); }
.hint { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; font-size: var(--step--1); color: var(--muted); margin: 0.25rem 0 0.5rem; }

.segments { list-style: none; margin: 0; padding: 0; }
.segment {
  display: grid;
  grid-template-columns: 4.2rem minmax(0, 1fr);
  gap: 0.25rem 0.75rem;
  padding: 0.6rem 0.5rem 0.6rem 0.6rem;
  border-left: 3px solid var(--c, var(--rule));
  border-radius: 0 var(--radius-s) var(--radius-s) 0;
  margin: 0.15rem 0;
}
.segment.playing { background: #EEF3FA; }
.segment .time {
  grid-row: span 2;
  background: none; border: 0; padding: 0.1rem 0;
  color: var(--muted); font-size: var(--step--1); text-align: left; align-self: start;
}
.segment .time:hover { color: var(--ink); text-decoration: underline; }
.segment .name { font-size: var(--step--1); font-weight: 700; color: var(--c, var(--ink)); }
.segment .text { font-family: var(--serif); font-size: 1.0625rem; line-height: 1.6; margin: 0; max-width: 72ch; cursor: pointer; }
.segment textarea {
  width: 100%;
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.55;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-s);
  padding: 0.45rem 0.6rem;
  resize: vertical;
  field-sizing: content;
  min-height: 3.2rem;
}
.segment textarea.changed { border-color: var(--focus); }

.danger-zone { display: flex; flex-wrap: wrap; gap: 0.75rem; justify-content: flex-end; margin-top: 1.25rem; }

/* Sticky player */
.player {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--rule);
  padding: 0.6rem 0 calc(0.6rem + env(safe-area-inset-bottom));
}
.player-inner { width: var(--page); margin: 0 auto; display: flex; gap: 0.75rem; align-items: center; }
.player audio { flex: 1; min-width: 0; height: 40px; }
.speed { min-width: 3.4rem; }

/* ---------- Labels page ---------- */

.page-title { font-size: var(--step-3); letter-spacing: -0.02em; margin: 0.5rem 0 0.35rem; }
.lede { color: var(--muted); max-width: 62ch; margin: 0 0 1.5rem; }
.label-list { display: grid; gap: 0.75rem; }
.label-form { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 1rem 1.1rem; display: grid; grid-template-columns: minmax(10rem, 1fr) auto minmax(14rem, 2fr) auto; gap: 0.75rem 1rem; align-items: end; }
.label-form.new { border-style: dashed; border-color: var(--rule-strong); }
.field { display: grid; gap: 0.3rem; }
.field > span { font-size: var(--step--1); color: var(--muted); font-weight: 500; }
.field input[type="text"], .field input[type="url"] { border: 1px solid var(--rule-strong); border-radius: var(--radius-s); padding: 0.45rem 0.6rem; background: var(--surface); width: 100%; }
.swatches { display: flex; gap: 0.3rem; padding: 0.35rem 0; border: 0; margin: 0; }
.swatches legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.swatches label { position: relative; }
.swatches input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.swatches span { display: block; width: 22px; height: 22px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 2px var(--surface); border: 2px solid transparent; }
.swatches input:checked + span { border-color: var(--ink); }
.swatches input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.label-actions { display: flex; gap: 0.4rem; align-items: center; }
.label-foot { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; font-size: var(--step--1); color: var(--muted); }
.form-error { grid-column: 1 / -1; color: var(--signal); font-size: var(--step--1); margin: 0; }

/* ---------- Sign in ---------- */

.login { min-height: 100svh; display: grid; place-items: center; padding: 1.5rem; }
.login form { width: min(360px, 100%); display: grid; gap: 0.9rem; }
.login h1 { margin: 0 0 0.5rem; font-size: var(--step-3); letter-spacing: -0.02em; display: flex; align-items: center; gap: 0.6rem; }
.login input { border: 1px solid var(--rule-strong); border-radius: var(--radius-s); padding: 0.65rem 0.75rem; background: var(--surface); }
.login .primary { padding: 0.7rem; font-size: var(--step-0); }

/* ---------- Dialog and toast ---------- */

dialog { border: 1px solid var(--rule-strong); border-radius: var(--radius-m); padding: 1.2rem; width: min(360px, calc(100% - 2rem)); background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgb(24 33 43 / 0.35); }
#ask-form { display: grid; gap: 0.6rem; }
#ask-form label { font-weight: 700; }
#ask-form input { border: 1px solid var(--rule-strong); border-radius: var(--radius-s); padding: 0.55rem 0.7rem; }
.ask-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.4rem; }

#toast {
  position: fixed; left: 50%; bottom: 5.5rem; transform: translateX(-50%);
  background: var(--ink); color: var(--surface);
  padding: 0.6rem 1rem; border-radius: var(--radius-s);
  font-size: var(--step--1); font-weight: 500;
  max-width: calc(100% - 2rem);
  z-index: 10;
}
#toast.bad { background: var(--signal); }

/* ---------- Narrow screens ---------- */

@media (max-width: 860px) {
  .columns { grid-template-columns: 1fr; }
  .label-form { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  :root { --page: calc(100% - 1.5rem); --step-3: 1.6rem; }
  .top { flex-wrap: wrap; gap: 0.6rem 1rem; padding-bottom: 0.4rem; }
  .brand { white-space: nowrap; margin-right: auto; }
  .nav { order: 3; width: 100%; }
  .upload .long { display: none; }
  .search { flex: 1 1 100%; }
  .recordings thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .recordings, .recordings tbody, .recordings tr, .recordings td { display: block; width: auto; }
  .recordings tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "title title" "label label" "date size" "length length";
    gap: 0.35rem 0.75rem;
    padding: 0.85rem 0.9rem;
    border-bottom: 1px solid var(--rule);
  }
  .recordings tbody tr:last-child { border-bottom: 0; }
  .recordings td { padding: 0; border: 0; }
  .recordings .col-title { grid-area: title; }
  .recordings .col-date { grid-area: date; font-size: var(--step--1); align-self: center; }
  .recordings .col-label { grid-area: label; justify-self: start; max-width: 100%; min-width: 0; }
  .recordings td { min-width: 0; }
  .recordings .col-length { grid-area: length; font-size: var(--step--1); }
  .recordings .col-size { grid-area: size; font-size: var(--step--1); align-self: center; }
  .segment { grid-template-columns: 1fr; }
  .segment .time { grid-row: auto; }
  .speaker input { width: 8rem; }
}

@media (prefers-reduced-motion: reduce) {
  .rec-sub.busy::before, .banner.busy p::before { animation: none; }
}

/* ---------- Sign in (passkeys) ---------- */

.login-box { width: min(380px, 100%); display: grid; gap: 0.9rem; }
.login-box .lede { margin: 0; }
.login-password { display: grid; gap: 0.9rem; }
.login-switch { justify-self: center; color: var(--muted); font-weight: 500; }

/* ---------- Security page ---------- */

.sec-top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.sec-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; margin-top: 1rem; }
.sec .panel-head { margin-bottom: 0.4rem; }
.sec-help { color: var(--muted); margin: 0 0 0.75rem; max-width: 70ch; }
.sec-warn { color: var(--signal); margin: 0; }
.sec-list { list-style: none; margin: 0; padding: 0; }
.sec-list li {
  display: grid;
  grid-template-columns: minmax(10rem, 1fr) minmax(0, 2fr) auto;
  gap: 0.25rem 1rem;
  align-items: center;
  padding: 0.6rem 0;
  border-top: 1px solid var(--rule);
}
.sec-list li.sec-empty { display: block; color: var(--muted); }
.sec-list.events li { grid-template-columns: minmax(10rem, 1fr) minmax(0, 1fr); }
.sec-list li.bad .sec-name-text { color: var(--signal); }
.sec-name { border: 1px solid transparent; border-radius: var(--radius-s); padding: 0.3rem 0.4rem; margin-left: -0.4rem; font-weight: 600; background: transparent; }
.sec-name:hover, .sec-name:focus { border-color: var(--rule-strong); background: var(--surface); }
.sec-name-text { font-weight: 600; display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.sec-meta { color: var(--muted); font-size: var(--step--1); }
.sec-tag { font-size: var(--step--1); font-weight: 600; color: var(--moss); border: 1px solid currentColor; border-radius: 999px; padding: 0 0.45rem; }
.token-box { border: 1px solid var(--moss); background: #EEF5EA; border-radius: var(--radius-s); padding: 0.75rem 0.9rem; margin-bottom: 0.75rem; }
.token-box p { margin: 0 0 0.5rem; }
.token-row { display: flex; gap: 0.5rem; }
.token-value { flex: 1; min-width: 0; border: 1px solid var(--rule-strong); border-radius: var(--radius-s); padding: 0.45rem 0.6rem; font-size: var(--step--1); background: var(--surface); }

/* ---------- Trim ---------- */

.trim { margin-bottom: 1.25rem; }
.trim-bar { position: relative; height: 14px; border-radius: 7px; background: var(--paper); border: 1px solid var(--rule); margin: 0.4rem 0 0.9rem; overflow: hidden; }
.trim-keep { position: absolute; top: 0; bottom: 0; background: var(--ink); border-radius: 6px; }
.trim-row { display: grid; grid-template-columns: 3rem minmax(8rem, 1fr) 6.5rem 11.5rem 11.5rem; gap: 0.6rem; align-items: center; margin: 0.5rem 0; }
.trim-row .quiet { width: 100%; }
.trim-label { font-weight: 600; }
.trim-row input[type="range"] { width: 100%; accent-color: var(--ink); }
.trim-time { border: 1px solid var(--rule-strong); border-radius: var(--radius-s); padding: 0.35rem 0.5rem; text-align: center; }
.trim-summary { margin: 0.75rem 0; color: var(--muted); }
.trim-actions { justify-content: flex-end; }

@media (max-width: 680px) {
  .sec-list li, .sec-list.events li { grid-template-columns: 1fr auto; }
  .sec-list li .sec-meta { grid-column: 1 / -1; grid-row: 2; }
  .sec-list.events li { grid-template-columns: 1fr; }
  .trim-row { grid-template-columns: 3rem 1fr 5.5rem; }
  .trim-row .quiet { grid-column: span 3; justify-self: start; width: auto; }
}

/* ---------- Upload panel and drop target ---------- */

.up-panel {
  position: fixed;
  right: 1.25rem;
  bottom: 5.5rem;
  z-index: 20;
  width: min(440px, calc(100% - 1.5rem));
  max-height: min(70vh, 560px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-m);
  box-shadow: 0 12px 32px rgb(24 33 43 / 0.18);
  padding: 1rem 1.1rem;
}
.up-panel h2 { margin: 0; font-size: var(--step-1); }
.up-label { margin-bottom: 0.6rem; }
.up-label select { border: 1px solid var(--rule-strong); border-radius: var(--radius-s); padding: 0.4rem 0.5rem; background: var(--surface); }
.up-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; border-top: 1px solid var(--rule); }
.up-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.1rem 0.75rem; padding: 0.5rem 0; border-bottom: 1px solid var(--rule); font-size: var(--step--1); }
.up-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-size { color: var(--muted); }
.up-note { grid-column: 1 / -1; color: var(--muted); }
.up-item.done .up-note { color: var(--moss); }
.up-item.failed .up-note { color: var(--signal); }
.up-bar { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: var(--paper); overflow: hidden; }
.up-bar span { display: block; height: 100%; background: var(--ink); }
.up-actions { justify-content: flex-end; margin-top: 0.75rem; }

.drop-hint {
  position: fixed; inset: 0.75rem; z-index: 30;
  border: 2px dashed var(--ink);
  border-radius: var(--radius-m);
  background: rgb(237 240 243 / 0.88);
  display: grid; place-items: center;
  pointer-events: none;
}
.drop-hint p { font-size: var(--step-2); font-weight: 700; margin: 0; }

@media (max-width: 680px) {
  .up-panel { right: 0.75rem; bottom: 0.75rem; }
}

/* ---------- Label chips and the label editor ---------- */

.label-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  max-width: 100%;
  border: 1px solid var(--rule-strong);
  background: var(--surface);
  border-radius: 999px;
  padding: 0.28rem 0.7rem 0.28rem 0.6rem;
  font-size: var(--step--1);
  text-align: left;
}
.label-chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--slate)); flex: none; }
.label-chip:hover { background: var(--hover); }
.chip-main { font-weight: 600; white-space: nowrap; }
.chip-subs { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; padding-left: 0.4rem; border-left: 1px solid var(--rule-strong); }
.label-chip.missing { border-color: var(--signal); color: var(--signal); background: var(--signal-wash); font-weight: 600; }
.label-chip.missing::before { content: "+"; width: auto; height: auto; background: none; font-weight: 700; }
.col-label { width: 13rem; }

.label-dialog { width: min(420px, calc(100% - 2rem)); }
.label-dialog h2 { margin: 0 0 0.5rem; font-size: var(--step-1); }
.ld-body { display: grid; gap: 0.75rem; max-height: 60vh; overflow-y: auto; }
.ld-group { border: 0; margin: 0; padding: 0; display: grid; gap: 0.15rem; }
.ld-group legend { font-size: var(--step--1); font-weight: 600; color: var(--muted); padding: 0; margin-bottom: 0.3rem; }
.ld-option { display: flex; align-items: center; gap: 0.55rem; padding: 0.35rem 0.25rem; border-radius: var(--radius-s); cursor: pointer; }
.ld-option:hover { background: var(--hover); }
.ld-option input { margin: 0; accent-color: var(--ink); width: 16px; height: 16px; }
.ld-new { justify-self: start; margin: 0.25rem 0 0 0.25rem; font-size: var(--step--1); }
.ld-empty { color: var(--muted); margin: 0.2rem 0.25rem; font-size: var(--step--1); }

.up-subs { display: grid; gap: 0; margin-top: 0.35rem; padding-left: 0.5rem; border-left: 2px solid var(--rule-strong); }

/* ---------- Labels page: main labels with their sub-labels ---------- */

.label-group { display: grid; gap: 0; }
.label-group > .label-form { border-radius: var(--radius-m) var(--radius-m) 0 0; }
.sub-section {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-top: 0;
  border-radius: 0 0 var(--radius-m) var(--radius-m);
  padding: 0.75rem 1.1rem 1rem 2rem;
}
.sub-section h3 { margin: 0 0 0.4rem; font-size: var(--step--1); color: var(--muted); font-weight: 600; }
.sub-list { list-style: none; margin: 0 0 0.6rem; padding: 0; }
.sub-list li { display: grid; grid-template-columns: minmax(8rem, 16rem) 1fr auto auto; gap: 0.5rem; align-items: center; padding: 0.3rem 0; }
.sub-list input, .sub-add input { border: 1px solid var(--rule-strong); border-radius: var(--radius-s); padding: 0.35rem 0.55rem; background: var(--surface); }
.sub-add { display: flex; gap: 0.5rem; }
.sub-add input { flex: 0 1 16rem; }

@media (max-width: 680px) {
  .sub-section { padding-left: 1.1rem; }
  .sub-list li { grid-template-columns: 1fr auto auto; }
  .sub-list li .sec-meta { grid-column: 1 / -1; grid-row: 2; }
}

/* ---------- Labels page tools: Notion page and bulk add ---------- */

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.label-tools { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1rem; align-items: start; margin-bottom: 1.25rem; }
.tool h2 { margin: 0 0 0.35rem; font-size: var(--step-1); }
.tool-row { display: flex; gap: 0.5rem; }
.tool-row input { flex: 1; min-width: 0; border: 1px solid var(--rule-strong); border-radius: var(--radius-s); padding: 0.45rem 0.6rem; background: var(--surface); }
#bulk-text {
  width: 100%;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-s);
  padding: 0.6rem 0.7rem;
  font: 400 var(--step-0)/1.5 var(--sans);
  resize: vertical;
  background: var(--surface);
}
.bulk-check { display: flex; align-items: center; gap: 0.5rem; margin: 0.6rem 0 0.2rem; font-size: var(--step--1); }
.bulk-check input { accent-color: var(--ink); width: 16px; height: 16px; margin: 0; }
.bulk-check.small { margin: 0.35rem 0 0; color: var(--muted); }
.bulk-actions { justify-content: flex-end; margin-top: 0.6rem; }
.bulk-err { display: block; }
.bulk-preview { margin-top: 0.75rem; border-top: 1px solid var(--rule); max-height: 320px; overflow-y: auto; }
.bulk-list { list-style: none; margin: 0; padding: 0; }
.bulk-list li { padding: 0.55rem 0; border-bottom: 1px solid var(--rule); }
.bulk-main { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.bulk-tag { font-size: 0.75rem; font-weight: 600; color: var(--muted); border: 1px solid var(--rule-strong); border-radius: 999px; padding: 0 0.45rem; }
.bulk-tag.new { color: var(--moss); border-color: var(--moss); }
.bulk-subs { display: flex; flex-wrap: wrap; gap: 0.3rem; margin: 0.35rem 0 0 0.9rem; }
.bulk-sub { font-size: var(--step--1); color: var(--muted); background: var(--paper); border-radius: 999px; padding: 0.05rem 0.55rem; }
.bulk-sub.new { color: var(--ink); background: #EEF5EA; }

@media (max-width: 860px) {
  .label-tools { grid-template-columns: 1fr; }
}

/* Phones: 16px text stops iOS zooming into the editor; the toolbar buttons get a bigger tap area. */
@media (max-width: 680px) {
  .notes-editor { font-size: 16px; }
  .md-toolbar { gap: 0.1rem; padding: 0.2rem; flex-wrap: nowrap; }
  .md-toolbar .tool { min-width: 2.15rem; height: 2.5rem; padding: 0 0.4rem; flex: 1 1 auto; }
  .md-toolbar .tool-gap { display: none; }
  .save-state { min-width: 0; }
}

/* ---------- Approving a Claude connection ---------- */

.authorize { min-height: 100svh; display: grid; place-items: center; padding: 1.5rem; }
.auth-card {
  width: min(440px, 100%);
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m);
  padding: 1.6rem 1.6rem 1.4rem;
}
.auth-card h1 { margin: 0 0 1rem; font-size: var(--step-2); line-height: 1.2; letter-spacing: -0.015em; }
.auth-lead { margin: 0 0 0.4rem; font-weight: 600; }
.auth-can { margin: 0 0 1rem; padding-left: 1.2rem; }
.auth-can li { margin: 0.3rem 0; }
.auth-cannot { margin: 0 0 0.75rem; padding: 0.6rem 0.75rem; background: var(--hover); border-radius: var(--radius-s); font-size: var(--step--1); }
.auth-where { margin: 0 0 1.25rem; color: var(--muted); font-size: var(--step--1); }
.auth-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.auth-actions .primary { padding: 0.65rem 1.1rem; font-size: var(--step-0); }
.auth-actions .quiet { padding: 0.65rem 1rem; font-size: var(--step-0); }
.auth-card a.quiet { display: inline-block; text-decoration: none; margin-top: 0.5rem; }

/* Optional Notion sections, collapsed until used */
details.optional > summary, .notion-field > summary { list-style: none; cursor: pointer; }
details.optional > summary::-webkit-details-marker, .notion-field > summary::-webkit-details-marker { display: none; }
details.optional > summary { display: flex; align-items: baseline; justify-content: space-between; gap: 0.75rem; }
details.optional > summary h2 { margin: 0; display: inline-flex; align-items: center; gap: 0.5rem; }
details.optional > summary h2::before, .notion-field > summary::before {
  content: ""; width: 0.45rem; height: 0.45rem; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg); transition: transform 0.15s; flex: none;
}
details.optional[open] > summary h2::before, .notion-field[open] > summary::before { transform: rotate(45deg); }
.summary-state { font-size: var(--step--1); color: var(--muted); }
details.optional[open] > summary { margin-bottom: 0.5rem; }
.notion-field > summary { display: inline-flex; align-items: center; gap: 0.45rem; font-size: var(--step--1); color: var(--muted); font-weight: 600; padding: 0.4rem 0; }
.notion-field[open] { display: grid; gap: 0.4rem; }
@media (prefers-reduced-motion: reduce) { details.optional > summary h2::before, .notion-field > summary::before { transition: none; } }
