/*
  riltt components — UI pieces shared by the app (translator.html) and documented in
  design-system.html. Tokens come from riltt-tokens.css; load this after it.

  Contents: Icon button · Segmented control · Menu · Count · Search field · Empty note ·
            Deadline row · Group · Status pill · Source quote · Fact row
  Everything here is built from riltt-tokens.css (text, space, surface, motion tokens).

  ── Icon button ────────────────────────────────────────────────────────────────
    <button class="icon-button [is-sm] [is-tinted]" aria-label="…">
      <span class="material-symbols-rounded">close</span>
    </button>
  A ghost control: no border, no fill until hovered. 36px round by default; is-sm is
  28px with an 8px corner, for actions inside a row. is-tinted gives it a resting fill
  (the primary action in a row); is-primary is ink-filled (Save). [aria-pressed="true"] / [aria-expanded="true"] hold
  the hover look while the thing it controls is on or open.

  ── Segmented control ──────────────────────────────────────────────────────────
    <div class="segmented" role="group">
      <button class="segmented-item" aria-pressed="true">Both</button> …
    </div>
  A pill track with pill segments; the chosen one is ink. Selection can be marked with
  aria-pressed, aria-selected or .is-active. [disabled] segments fade.

  ── Menu ───────────────────────────────────────────────────────────────────────
    <div class="menu" role="menu">
      <button class="menu-item" role="menuitem"><span class="material-symbols-rounded">edit</span>Rename</button>
      <div class="menu-sep"></div>
      <button class="menu-item is-danger" role="menuitem">…Delete</button>
    </div>
  The one floating surface: white, hairline, --shadow-pop. Position it where it opens.

  ── Count ──────────────────────────────────────────────────────────────────────
    <span class="count [is-danger]">3</span>
  A small pill number beside a title.

  ── Search field ───────────────────────────────────────────────────────────────
    <div class="search-field [is-pill] [has-value]">
      <span class="material-symbols-rounded">search</span>
      <input type="search" placeholder="Search meetings and transcripts">
      <button class="search-field-clear">…close…</button>   (optional)
    </div>
  White field, hairline that goes ink on focus. The clear button shows only while the field
  is focused and has text (.has-value, set by the page). is-pill is the compact round one.

  ── Empty note ─────────────────────────────────────────────────────────────────
    <div class="empty-note">No history yet. Let riltt listen to your next meeting…</div>
  What a list says when it has nothing in it: a dashed hairline box, centered soft text.

  ── Deadline row ───────────────────────────────────────────────────────────────
  One deadline: a date tile (the "when"), the title, a quiet second line (the meeting it
  came from, or "needs a date"), and icon actions. Used on Home's Deadlines card, the
  Deadlines page and the deadlines inside a meeting's notes — one design everywhere.

    <div class="dl-list">
      <div class="dl-row is-today|is-thisWeek|is-overdue|is-later [needs-date] [is-done]">
        <div class="dl-tile"><small>Sat</small><b>3</b></div>
        <div class="dl-main">
          <div class="dl-title">Submit weekly status report</div>
          <button class="dl-meta">Deliverable EID and Code Submission</button>
        </div>
        <div class="dl-actions">
          <button class="icon-button is-sm">check</button>                      done
          <button class="icon-button is-sm is-tinted [is-added]">…</button>    add to Google Calendar
          <button class="icon-button is-sm dl-quiet">close</button>            dismiss (shows on hover)
        </div>
      </div>
    </div>

  In the app, deadlineRowHtml() in translator.html builds this markup.

  ── Group ──────────────────────────────────────────────────────────────────────
  A titled, collapsible block of rows: the Deadlines page's Today / This week / Later,
  the To-dos page's meetings, "Older meetings", "Done". One heading style everywhere:
  chevron · title · count, rows indented under the title. Tones: default (ink), is-link
  (teal — the title opens something), is-danger (overdue), is-quiet (archive-like folds).

    <section class="group [is-collapsed]" data-group="todo:abc">
      <div class="group-head [is-link|is-danger|is-quiet]">
        <button class="icon-button is-sm group-toggle" data-group-toggle="todo:abc" aria-expanded="true">⌄</button>
        <button class="group-title" data-group-toggle="…" | data-todo-open="…">Title</button>
        <span class="count">3</span>
      </div>
      <div class="group-body">…rows…</div>
    </section>

  In the app, groupHtml() builds it and remembers each group's open/closed state.

  ── Status pill / status dot ───────────────────────────────────────────────────
    <span class="status-pill is-you|is-others|is-stalled|is-done">Waiting on you</span>
    <span class="status-dot is-you|is-others|is-stalled|is-done"></span>
  A thread's one-word state. Marigold when the next step is YOURS (the colour of "due
  today"); ink when someone else has it — moving, not dead, so never grey; a hollow grey
  ring when nothing has moved in three weeks; leaf when it's finished. The dot is the same
  signal at list size.

  ── Source quote ───────────────────────────────────────────────────────────────
    <div class="source-quote">
      <div class="source-quote-orig">「では、方向性Bで進めましょう。」</div>
      <div class="source-quote-trans">"Then let's go with direction B."</div>
      <div class="source-quote-src"><span class="tag">Japanese</span><button>Acme weekly · 27:51</button></div>
    </div>
  The sentence a line came from, in the language it was said in, with the translation
  under it. Usually hidden until a format_quote icon button asks for it.

  ── Fact row ───────────────────────────────────────────────────────────────────
    <div class="fact-list">
      <div class="fact-row">
        <div class="fact-line">
          <span class="fact-date">Sep 30</span>
          <div class="fact-text">Go with direction B<div class="fact-sub">Raised by Kenji</div></div>
          <button class="icon-button is-sm">format_quote</button>
        </div>
        <div class="source-quote" hidden>…</div>
      </div>
    </div>
  A decision or an open question: when, the statement, and where it came from. Lighter
  than a deadline row — there is nothing to tick off.
*/

/* ── Icon button ───────────────────────────────────────────────────────────────── */
.icon-button {
  width: 36px; height: 36px; flex: 0 0 auto; padding: 0; border: 0; border-radius: 50%;
  display: inline-grid; place-items: center; cursor: pointer;
  background: transparent; color: var(--ink-soft);
  transition: background var(--dur-fast) ease, color var(--dur-fast) ease;
}
.icon-button .material-symbols-rounded { font-size: 20px; }
.icon-button:hover,
.icon-button[aria-pressed="true"],
.icon-button[aria-expanded="true"] { background: var(--hover); color: var(--ink); }
.icon-button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.icon-button:disabled { opacity: 0.4; cursor: not-allowed; }
.icon-button.is-sm { width: 28px; height: 28px; border-radius: var(--radius-sm); }
.icon-button.is-sm .material-symbols-rounded { font-size: 18px; }
.icon-button.is-tinted { background: var(--surface-sunken); color: var(--ink); }
.icon-button.is-tinted:hover { background: var(--hover); }
.icon-button.is-primary { background: var(--action, var(--ink)); color: #FFFFFF; }
.icon-button.is-primary:hover { background: var(--action-hover, #3A352C); color: #FFFFFF; }
/* A text label inside an icon button is for screen readers only. */
.icon-button .action-text {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.icon-button[hidden] { display: none; }

/* ── Segmented control ─────────────────────────────────────────────────────────── */
.segmented {
  display: inline-flex; align-items: center; gap: 2px; padding: 2px; box-sizing: border-box;
  border: 1px solid var(--line); border-radius: var(--radius-pill); background: var(--surface);
}
.segmented-item {
  display: inline-flex; align-items: center; justify-content: center;
  height: 26px; padding: 0 var(--space-3); border: 0; border-radius: var(--radius-pill);
  background: transparent; color: var(--ink-soft); cursor: pointer; white-space: nowrap;
  font: inherit; font-size: var(--text-sm); font-weight: 600; line-height: 1;
  transition: background var(--dur-fast) ease, color var(--dur-fast) ease;
}
.segmented-item:hover { color: var(--ink); background: var(--hover); }
.segmented-item[aria-pressed="true"],
.segmented-item[aria-selected="true"],
.segmented-item.is-active { background: var(--ink); color: var(--paper); }
.segmented-item:disabled { opacity: 0.45; cursor: not-allowed; }
.segmented-item:disabled:hover { background: transparent; color: var(--ink-soft); }
.segmented-item:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ── Menu ──────────────────────────────────────────────────────────────────────── */
.menu {
  display: grid; gap: 2px; min-width: 180px; padding: 6px; box-sizing: border-box;
  background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
}
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; box-sizing: border-box;
  padding: var(--space-2) 10px; border: 0; border-radius: var(--radius-sm);
  background: transparent; cursor: pointer; text-align: left;
  font: inherit; font-size: var(--text-md); color: var(--ink);
}
.menu-item:hover, .menu-item:focus-visible { background: var(--paper); outline: none; }
.menu-item .material-symbols-rounded { font-size: 18px; color: var(--ink-soft); }
.menu-item.is-danger, .menu-item.is-danger .material-symbols-rounded { color: var(--text-danger); }
.menu[hidden] { display: none; }
.menu-sep { height: 1px; background: var(--line-soft); margin: var(--space-1) 2px; }

/* ── Search field ──────────────────────────────────────────────────────────────── */
.search-field {
  display: flex; align-items: center; gap: var(--space-2); box-sizing: border-box;
  padding: 9px var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink-faint);
  transition: border-color var(--dur-fast) ease;
}
.search-field:focus-within { border-color: var(--ink); }
.search-field > .material-symbols-rounded { font-size: 18px; flex: 0 0 auto; }
.search-field input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink);
  font: inherit; font-size: var(--text-md); font-weight: 500;
}
.search-field input::-webkit-search-cancel-button { display: none; }
.search-field-clear {
  display: none; align-items: center; padding: 2px; border: 0; border-radius: 50%;
  background: transparent; color: var(--ink-faint); cursor: pointer;
}
.search-field.has-value:focus-within .search-field-clear { display: inline-flex; }
.search-field-clear:hover { color: var(--ink); }
.search-field.is-pill { display: inline-flex; padding: 6px var(--space-3); border-radius: var(--radius-pill); }
.search-field.is-pill > .material-symbols-rounded { font-size: 17px; }

/* ── Empty note ────────────────────────────────────────────────────────────────── */
.empty-note {
  padding: var(--space-8) var(--space-6); text-align: center; box-sizing: border-box;
  border: 1px dashed var(--line); border-radius: var(--radius-md); background: var(--surface);
  color: var(--ink-faint); font-size: var(--text-md); line-height: 1.5;
}

/* ── Count ─────────────────────────────────────────────────────────────────────── */
.count {
  min-width: 20px; height: 20px; padding: 0 7px; box-sizing: border-box; border-radius: var(--radius-pill);
  display: inline-grid; place-items: center; flex: 0 0 auto;
  font-size: var(--text-xs); font-weight: 700; line-height: 1;
  color: var(--ink-soft); background: var(--surface-sunken);
}
.count.is-danger { color: var(--text-danger); background: #FBE1DB; }

.dl-list { display: grid; }
.dl-row {
  display: grid; grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 12px; align-items: center; padding: 10px 2px;
}
.dl-row + .dl-row { border-top: 1px solid var(--line-soft); }
.dl-tile {
  width: 44px; height: 46px; border-radius: 10px;
  display: grid; place-content: center; text-align: center; line-height: 1;
  background: var(--surface-sunken); color: var(--ink);
}
.dl-tile small { font-size: var(--text-xs); font-weight: 600; color: var(--ink-soft); margin-bottom: 3px; }
.dl-tile b { font-size: 18px; font-weight: 800; letter-spacing: -0.02em; }
.dl-row.is-today .dl-tile { background: #FDEBD0; color: var(--marigold-ink, #8A5A02); }
.dl-row.is-today .dl-tile small { color: var(--marigold-ink, #8A5A02); }
.dl-row.is-overdue .dl-tile { background: #FBE1DB; color: var(--text-danger); }
.dl-row.is-overdue .dl-tile small { color: var(--text-danger); }
.dl-main { min-width: 0; display: grid; gap: 2px; }
.dl-title {
  font-size: var(--text-base); font-weight: 650; color: var(--ink); line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.dl-meta {
  all: unset; cursor: pointer; font-size: var(--text-sm); color: var(--ink-faint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dl-meta:hover { color: var(--ink); text-decoration: underline; }
.dl-row.needs-date .dl-meta { color: var(--marigold-ink, #8A5A02); }
.dl-actions { display: flex; align-items: center; gap: 4px; }
/* Row actions are .icon-button.is-sm; the calendar one rests tinted, and turns leaf once added. */
.dl-actions .icon-button.is-added { background: transparent; color: var(--leaf, #12945B); }
.dl-date-input { font: inherit; font-size: 12px; }
/* Dismiss waits for the hover on devices that can hover. */
@media (hover: hover) {
  .dl-row:not(:hover):not(:focus-within) .dl-quiet { opacity: 0; }
}

/* A finished deadline: struck, quiet, with only Undo. */
.dl-row.is-done .dl-title { color: var(--ink-faint); text-decoration: line-through; }
.dl-row.is-done .dl-tile { opacity: 0.55; }

/* ── Group ─────────────────────────────────────────────────────────────────────── */
.group + .group { margin-top: 14px; }
.group-head { display: flex; align-items: center; gap: 2px; min-height: 30px; }
/* An open group's chevron is "expanded" but shouldn't look pressed. */
.group-toggle[aria-expanded]:not(:hover) { background: transparent; color: var(--ink-soft); }
.group-toggle .material-symbols-rounded { font-size: 20px; transition: transform var(--dur-fast) ease; }
.group.is-collapsed > .group-head .group-toggle .material-symbols-rounded { transform: rotate(-90deg); }
.group-title {
  all: unset; box-sizing: border-box; cursor: pointer; min-width: 0;
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--text-base); font-weight: 700; line-height: 1.3; color: var(--ink);
}
.group-title > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-title .material-symbols-rounded { font-size: 17px; }
.group-title:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 4px; }
.group-head.is-link .group-title { color: var(--text-link); }
.group-head.is-link .group-title:hover { color: var(--text-link-hover); text-decoration: underline; text-underline-offset: 3px; }
.group-head.is-danger .group-title { color: var(--text-danger); }
.group-head.is-quiet .group-title { color: var(--ink-soft); font-size: var(--text-md); }
.group-head.is-quiet .group-title:hover { color: var(--ink); }
.group-head .count { margin-left: var(--space-2); }
.group-body { padding: 6px 0 0 28px; }  /* 28px = the toggle, so rows line up with the title */
.group.is-collapsed > .group-body { display: none; }
@media (prefers-reduced-motion: reduce) {
  .group-toggle .material-symbols-rounded { transition: none; }
}

/* ── Ask AI ────────────────────────────────────────────────────────────────────── */
/* The AI entry point: soft warm fill, a 1.5px marigold→leaf rim, ink text. Its icon is
   /public/icons/chat-ai-breakout.svg — an ink bubble with a marigold spark (.ai-spark)
   breaking out of the corner. One per view; it never takes the filled ink style. */
.ai-button {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 16px; border-radius: 999px; cursor: pointer;
  font: inherit; font-size: 15px; font-weight: 600; color: var(--ink);
  border: 1.5px solid transparent;
  background: linear-gradient(var(--ai-fill), var(--ai-fill)) padding-box, var(--ai-rim) border-box;
  transition: background var(--dur-fast) ease;
}
.ai-button:hover,
.ai-button[aria-expanded="true"] {
  background: linear-gradient(var(--ai-fill-hover), var(--ai-fill-hover)) padding-box, var(--ai-rim) border-box;
}
.ai-button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.ai-button.is-round { width: 36px; height: 36px; padding: 0; justify-content: center; }
.ai-chat-icon { width: 20px; height: 20px; flex: 0 0 auto; display: block; }
.ai-chat-icon .ai-spark { fill: var(--ai-spark); }

/* ── Status pill / status dot ──────────────────────────────────────────────────── */
.status-pill {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; box-sizing: border-box;
  border-radius: var(--radius-pill); white-space: nowrap;
  font-size: var(--text-sm); font-weight: 650; line-height: 1;
  background: var(--surface-sunken); color: var(--ink-soft);
}
.status-pill::before,
.status-dot {
  content: ''; width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; box-sizing: border-box;
  background: currentColor;
}
.status-dot { display: inline-block; width: 8px; height: 8px; color: var(--ink-faint); }
.status-pill.is-you, .status-dot.is-you { color: var(--marigold-ink); }
.status-pill.is-you { background: var(--marigold-tint); }
.status-dot.is-you { background: var(--marigold); }
.status-pill.is-others { color: var(--ink); }
.status-dot.is-others { color: var(--ink); background: var(--ink); }
.status-pill.is-stalled { background: transparent; border: 1px dashed var(--line); }
.status-pill.is-stalled::before,
.status-dot.is-stalled { background: transparent; border: 1.5px solid currentColor; }
.status-pill.is-done, .status-dot.is-done { color: var(--leaf); }
.status-pill.is-done { background: var(--leaf-tint); }

/* ── Source quote ──────────────────────────────────────────────────────────────── */
.source-quote {
  margin: var(--space-2) 0 var(--space-1); padding: var(--space-3) var(--space-4); box-sizing: border-box;
  border-left: 3px solid var(--line); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--surface-sunken); font-size: var(--text-md); line-height: 1.5;
}
.source-quote[hidden] { display: none; }
.source-quote-orig { color: var(--ink); }
.source-quote-trans { color: var(--ink-soft); margin-top: 2px; }
.source-quote-src {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2);
  font-size: var(--text-sm); color: var(--ink-faint);
}
.source-quote-src .tag {
  font-size: var(--text-xs); font-weight: 700; padding: 1px 6px; border-radius: var(--radius-xs);
  background: var(--surface); color: var(--ink-soft);
}
.source-quote-src button { all: unset; cursor: pointer; color: var(--text-link); }
.source-quote-src button:hover { color: var(--text-link-hover); text-decoration: underline; }

/* ── Fact row ──────────────────────────────────────────────────────────────────── */
.fact-list { display: grid; }
.fact-row { padding: var(--space-3) 2px; }
.fact-row + .fact-row { border-top: 1px solid var(--line-soft); }
.fact-line { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: var(--space-3); align-items: baseline; }
.fact-line > .icon-button { align-self: center; }
.fact-date { font-size: var(--text-sm); color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.fact-text { font-size: var(--text-base); font-weight: 550; line-height: 1.4; color: var(--ink); }
.fact-sub { font-size: var(--text-sm); font-weight: 400; color: var(--ink-faint); margin-top: 2px; }
.fact-row > .source-quote { margin-left: 68px; }
@media (max-width: 720px) {
  .fact-line { grid-template-columns: minmax(0, 1fr) auto; }
  .fact-date { grid-column: 1 / -1; }
  .fact-row > .source-quote { margin-left: 0; }
}
