/* Klear design system. Rules and rationale: DESIGN.md.
   1. Tokens   2. Base   3. Components   4. Screens (mobile first; wider layouts in min-width queries) */

/* ============ 1. TOKENS ============ */
:root {
  color-scheme: light dark;

  /* colour: one accent, neutrals do the rest */
  --bg: light-dark(#ffffff, #000000);
  --surface: light-dark(#ffffff, #1c1c1e);        /* cards, dialogs */
  --fill: light-dark(#f5f5f7, #1c1c1e);           /* fields, sidebar, quiet buttons */
  --fill-2: light-dark(#e8e8ed, #2c2c2e);         /* hover / pressed fill */
  --text: light-dark(#1d1d1f, #f5f5f7);
  --text-2: light-dark(#6e6e73, #a1a1a6);         /* secondary copy, 5:1 on --bg */
  --line: light-dark(#d2d2d7, #38383a);
  --accent: light-dark(#0071e3, #0a84ff);
  --accent-fill: #0071e3;                         /* behind white text: the dark theme's lighter --accent is for links, white on it is only 3.6:1 */
  --accent-hover: #0077ed;
  --on-accent: #ffffff;
  --danger: light-dark(#d70015, #ff453a);
  --notice: light-dark(#b25000, #ff9f0a);
  --scrim: light-dark(#00000052, #000000a3);

  /* type: the platform's own UI face everywhere (SF on Apple, Segoe on Windows). No web fonts:
     filtered networks block font hosts, and system faces render sharpest. */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  --t-caption: .8125rem;                           /* 13 */
  --t-small: .9375rem;                             /* 15 */
  --t-body: 1.0625rem;                             /* 17 */
  --t-title-3: 1.25rem;                            /* 20 */
  --t-title-2: 1.5rem;                             /* 24 */
  --t-title-1: clamp(1.75rem, 1.4rem + 1.6vw, 2.125rem);   /* 28 to 34 */
  --t-hero: clamp(2.5rem, 1.2rem + 6.4vw, 5rem);           /* 40 to 80 */

  /* space: 4pt grid */
  --s1: .25rem; --s2: .5rem; --s3: .75rem; --s4: 1rem; --s5: 1.5rem; --s6: 2rem; --s7: 3rem; --s8: 4rem;
  --gutter: clamp(1rem, 5vw, 2.5rem);              /* page side padding */
  --measure: 44rem;                                /* reading column */

  /* shape */
  --r-s: 10px; --r-m: 14px; --r-l: 22px; --r-pill: 980px;
  --tap: 2.75rem;                                  /* 44px minimum touch target */
  --shadow: 0 1px 2px light-dark(#0000000a, #0000), 0 12px 40px light-dark(#0000001a, #000000a0);
  --ease: cubic-bezier(.25, .1, .25, 1);
}

/* ============ 2. BASE ============ */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body, #root { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 var(--t-body)/1.47 var(--font); letter-spacing: -.01em;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.15; letter-spacing: -.02em; text-wrap: balance; }
h2 { font-size: var(--t-title-2); }
h3 { font-size: var(--t-title-3); margin-top: var(--s6); }
h4 { font-size: var(--t-body); margin: var(--s4) 0 var(--s1); }
p { margin: var(--s2) 0; text-wrap: pretty; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }
::selection { background: color-mix(in srgb, var(--accent) 25%, transparent); }

/* ============ 3. COMPONENTS ============ */
.brand { margin: 0; font-size: var(--t-title-3); font-weight: 600; letter-spacing: -.02em; }
.hint { color: var(--text-2); font-size: var(--t-small); }
.err { color: var(--danger); font-size: var(--t-small); min-height: 1.4em; margin: var(--s1) 0; }
.row { display: flex; gap: var(--s3); align-items: center; flex-wrap: wrap; }

/* buttons: quiet by default, one filled .primary per view, .link for inline actions */
input, textarea, select, button { font: inherit; color: inherit; letter-spacing: inherit; }
button {
  min-height: var(--tap); padding: 0 var(--s5); border: 0; border-radius: var(--r-pill);
  background: var(--fill); cursor: pointer; transition: background .15s var(--ease), transform .1s var(--ease);
}
button:hover { background: var(--fill-2); }
button:active { transform: scale(.98); }
button.primary { background: var(--accent-fill); color: var(--on-accent); font-weight: 500; }
button.primary:hover { background: var(--accent-hover); }
button.link { min-height: auto; padding: var(--s1) 0; background: none; color: var(--accent); border-radius: 4px; text-align: start; }
button.link:hover { text-decoration: underline; }
button:disabled { opacity: .4; cursor: default; }

/* fields: filled, borderless until focused. 17px text so iOS never zooms. */
label { display: grid; gap: var(--s2); margin: var(--s4) 0; font-size: var(--t-small); color: var(--text-2); }
input, textarea, select {
  width: 100%; min-height: var(--tap); padding: var(--s3) var(--s4); font-size: var(--t-body); color: var(--text);
  background: var(--fill); border: 1px solid transparent; border-radius: var(--r-s);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease), background .15s var(--ease);
}
textarea { resize: vertical; line-height: 1.47; }
input::placeholder, textarea::placeholder { color: var(--text-2); opacity: .75; }
input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: none; background: var(--surface); border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent);
}
.check { display: flex; align-items: center; gap: var(--s3); color: var(--text); font-size: var(--t-body); min-height: var(--tap); margin: 0; }
.check input { width: 1.25rem; height: 1.25rem; min-height: 0; padding: 0; accent-color: var(--accent); }
.inline { display: flex; gap: var(--s2); flex-wrap: wrap; }
.inline input { flex: 1 1 12rem; }

/* invite codes are always shown the same way: spaced tabular digits */
.code { font-variant-numeric: tabular-nums; letter-spacing: .12em; font-weight: 600; }

/* dialog: bottom sheet on phones, centred card from 600px */
dialog {
  border: 0; padding: var(--s5) var(--gutter) var(--s6); color: var(--text); background: var(--surface);
  width: 100%; max-width: none; max-height: 90dvh; margin: auto 0 0; border-radius: var(--r-l) var(--r-l) 0 0; box-shadow: var(--shadow);
}
dialog::backdrop { background: var(--scrim); backdrop-filter: blur(6px); }
dialog .close { margin-top: var(--s5); }

/* data table inside a horizontal scroller */
.scroll { overflow-x: auto; margin-inline: calc(var(--gutter) * -1); padding-inline: var(--gutter); }
table { width: 100%; border-collapse: collapse; font-size: var(--t-small); }
th { color: var(--text-2); font-weight: 500; white-space: nowrap; }
th, td { text-align: start; padding: var(--s3) var(--s4) var(--s3) 0; border-bottom: 1px solid var(--line); vertical-align: top; }
td .link { margin-inline-end: var(--s4); white-space: nowrap; }

/* ============ 4. SCREENS ============ */

.wait { margin-top: var(--s5); color: var(--text-2); font-size: var(--t-small); text-align: center; }
.wait summary { cursor: pointer; color: var(--accent); font-size: var(--t-body); min-height: var(--tap); display: grid; place-items: center; list-style: none; }
.wait summary::-webkit-details-marker { display: none; }
.wait[open] { text-align: start; }

@media (prefers-reduced-motion: no-preference) {
  dialog[open] { animation: rise .5s var(--ease) both; }
  @keyframes rise { from { opacity: 0; transform: translateY(12px) scale(.985); } }
}

/* ---- chat: one column with a slide-over menu on phones; fixed sidebar from 900px */
.app { height: 100%; display: flex; flex-direction: column; }
.bar {
  display: flex; align-items: center; gap: var(--s2); padding: var(--s1) var(--s2); min-height: 3.25rem;
  border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: saturate(180%) blur(20px);
}
.bar .brand { flex: 1; text-align: center; font-size: var(--t-body); }
.bar button { background: none; padding: 0 var(--s3); color: var(--accent); }
.side {
  position: fixed; inset: 0 auto 0 0; z-index: 2; width: min(20rem, 86vw); padding: var(--s4) var(--s3);
  padding-bottom: max(var(--s4), env(safe-area-inset-bottom));
  background: var(--fill); display: flex; flex-direction: column; gap: var(--s3);
  transform: translateX(-100%); visibility: hidden; transition: transform .3s var(--ease), visibility .3s;
}
.side.open { transform: none; visibility: visible; box-shadow: var(--shadow); }
.scrim { position: fixed; inset: 0; z-index: 1; background: var(--scrim); border-radius: 0; opacity: 0; pointer-events: none; transition: opacity .3s var(--ease); }
.scrim:hover { background: var(--scrim); }
.side.open + .scrim { opacity: 1; pointer-events: auto; }
.side .brand { padding: var(--s1) var(--s3); }
.side button { background: none; text-align: start; padding: 0 var(--s3); border-radius: var(--r-s); font-size: var(--t-small); }
.side button:hover { background: var(--fill-2); }
.side .invites { color: var(--accent); font-weight: 500; }
.chats { flex: 1; overflow: hidden auto; display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: 2px; }
.chat { display: flex; border-radius: var(--r-s); }
.chat.on { background: var(--fill-2); }
.chat button:first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat button:last-child { color: var(--text-2); flex: none; }
.foot { display: flex; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: var(--s2); }
.foot button { color: var(--text-2); }

.main { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.log { flex: 1; overflow-y: auto; padding: var(--s5) var(--gutter) var(--s4); overscroll-behavior: contain; }
.log > * { max-width: var(--measure); margin-inline: auto; }
.empty { padding-top: 8vh; }
.empty h2 { font-size: var(--t-title-1); font-weight: 700; letter-spacing: -.03em; margin-bottom: var(--s5); }
.starters { display: grid; gap: var(--s2); }
.starters button { text-align: start; padding: var(--s3) var(--s4); border-radius: var(--r-m); color: var(--text-2); font-size: var(--t-small); line-height: 1.35; }
.starters button:hover { color: var(--text); }
.msg { margin-block: var(--s5); overflow-wrap: anywhere; }
.log > .msg.user {
  width: fit-content; max-width: min(34rem, 86%); margin-inline: auto max(0px, calc((100% - var(--measure)) / 2));
  background: var(--accent-fill); color: var(--on-accent); padding: var(--s2) var(--s4); border-radius: 20px 20px 6px 20px; white-space: pre-wrap;
}
.msg.assistant p:first-child { margin-top: 0; }
.msg.assistant small { display: block; color: var(--text-2); font-size: var(--t-caption); margin-top: var(--s2); }
.msg.wait { color: var(--text-2); }
.msg.note { color: var(--notice); }
.msg pre { background: var(--fill); padding: var(--s4); border-radius: var(--r-m); overflow-x: auto; font: var(--t-small)/1.5 var(--mono); letter-spacing: 0; }
.msg :not(pre) > code { background: var(--fill); padding: .1em .35em; border-radius: 6px; font: .9em var(--mono); letter-spacing: 0; }
.msg ul, .msg ol { padding-inline-start: 1.4rem; margin: var(--s2) 0; }
.msg li { margin: var(--s1) 0; }

.composer {
  width: calc(100% - 2 * var(--gutter)); max-width: var(--measure); margin: 0 auto max(var(--s4), env(safe-area-inset-bottom));
  background: var(--fill); border: 1px solid transparent; border-radius: var(--r-l); padding: var(--s2);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease), background .15s var(--ease);
}
.composer:focus-within { background: var(--surface); border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent); }
.composer textarea, .composer textarea:focus-visible { background: none; border: 0; box-shadow: none; resize: none; min-height: 0; padding: var(--s2) var(--s3); }
.tools { display: flex; align-items: center; gap: var(--s2) var(--s4); flex-wrap: wrap; padding: 0 var(--s1) 0 var(--s3); font-size: var(--t-small); }
.tools button:not(.primary) { min-height: var(--tap); padding: 0; background: none; color: var(--text-2); border-radius: 4px; }
.tools button:not(.primary):hover { color: var(--accent); }
.tools .check { font-size: var(--t-small); color: var(--text-2); }
.tools .primary { margin-inline-start: auto; min-height: 2.5rem; }

@media (min-width: 600px) {
  dialog { width: min(34rem, calc(100% - 2rem)); margin: auto; border-radius: var(--r-l); padding: var(--s6); }
  .starters { grid-template-columns: 1fr 1fr; }
  .empty { padding-top: 14vh; }
}
@media (min-width: 900px) {
  .app { flex-direction: row; }
  .bar, .scrim { display: none; }
  .side { position: static; width: 17.5rem; flex: none; transform: none; visibility: visible; border-inline-end: 1px solid var(--line); box-shadow: none; }
  .chat button:last-child { opacity: 0; }
  .chat:hover button:last-child, .chat button:focus-visible { opacity: 1; }
}

/* ---- invites dialog */
.codes { list-style: none; padding: 0; margin: var(--s4) 0 0; border-top: 1px solid var(--line); }
.codes li { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); min-height: 3.75rem; border-bottom: 1px solid var(--line); }
.codes .code { font-size: var(--t-title-3); }
.codes .used { color: var(--text-2); } .codes .used .code { text-decoration: line-through; font-weight: 400; }
.codes button { color: var(--accent); font-size: var(--t-small); }

/* ---- admin */
.adminpage { height: 100%; overflow-y: auto; }
.adminpage header {
  position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; align-items: center; min-height: 3.25rem; padding: 0 var(--gutter);
  border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: saturate(180%) blur(20px);
}
.adminpage header .brand { font-size: var(--t-body); }
.adminpage main { max-width: 60rem; margin: 0 auto; padding: var(--s5) var(--gutter) var(--s8); }
.adminpage h2 { margin: var(--s7) 0 var(--s2); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr)); gap: var(--s3); margin: 0; }
.stats div { background: var(--fill); border-radius: var(--r-m); padding: var(--s4); }
.stats dt { color: var(--text-2); font-size: var(--t-small); }
.stats dd { margin: var(--s1) 0 0; font-size: var(--t-title-1); font-weight: 600; letter-spacing: -.02em; line-height: 1.15; overflow-wrap: anywhere; }
.minted { line-height: 2; }
.adminpage textarea { font: var(--t-small)/1.5 var(--mono); letter-spacing: 0; }

/* ---- rich answers: tables, charts, forms, and the actions under an answer */
.msg .scroll { margin-block: var(--s3); }
.msg table { font-size: var(--t-small); }
.msg th { color: var(--text); font-weight: 600; border-bottom-color: var(--text); }
.chart { margin: var(--s4) 0; background: var(--fill); border-radius: var(--r-m); padding: var(--s2); }
.chart svg { display: block; width: 100%; height: auto; font-family: var(--font); }
.chart .c-mark { fill: var(--accent); }
.chart .c-slice { stroke: var(--fill); stroke-width: 2; }
.chart .c-line { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.chart .c-axis { stroke: var(--line); stroke-width: 1; }
.chart .c-title { fill: var(--text); font-size: 17px; font-weight: 600; }
.chart .c-value { fill: var(--text); font-size: 13px; font-weight: 600; }
.chart .c-label { fill: var(--text-2); font-size: 13px; }
/* paper form: always black on white, whatever the theme, because it is a picture of the printed page */
.sheet { margin: var(--s4) 0; padding: clamp(1rem, 5vw, 2.5rem); background: #fff; color: #111; border-radius: 4px; box-shadow: 0 0 0 1px var(--line), var(--shadow);
  font-size: .9375rem; line-height: 1.35; letter-spacing: 0; color-scheme: light; }
.sheet header { border-bottom: 2px solid #111; padding-bottom: .5rem; margin-bottom: .9rem; }
.sheet h3 { margin: 0; font-size: 1.5rem; letter-spacing: -.01em; }
.sheet header p { margin: .15rem 0 0; color: #444; }
.sheet .intro, .sheet .foot { color: #333; font-size: .875rem; margin: 0 0 .9rem; }
.sheet .foot { margin: 1.2rem 0 0; padding-top: .6rem; border-top: 1px solid #999; }
.sheet fieldset { border: 0; padding: 0; margin: 0 0 1.1rem; min-width: 0; }
.sheet legend { padding: .2rem .5rem; margin-bottom: .6rem; width: 100%; background: #111; color: #fff; font-weight: 600; font-size: .8125rem; }
.sheet .grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: .9rem 1.2rem; align-items: end; }
.sheet .f { grid-column: span 6; min-width: 0; }
.sheet label { margin: 0; gap: .1rem; color: #111; font-size: inherit; }
.sheet .cap { display: block; font-size: .8125rem; color: #333; }
.sheet input:not([type=checkbox]), .sheet textarea {
  min-height: 1.9rem; padding: .15rem .1rem; background: none; color: #111; font-size: 1rem;
  border: 0; border-bottom: 1px solid #111; border-radius: 0; box-shadow: none; }
.sheet input::placeholder { color: #bbb; opacity: 1; }
.sheet input:focus-visible, .sheet textarea:focus-visible { background: #f2f6ff; border-color: #111; box-shadow: none; outline: none; }
.sheet textarea { resize: none; line-height: 1.9rem; border: 0; padding: 0;      /* ruled writing lines */
  background: repeating-linear-gradient(#fff 0 calc(1.9rem - 1px), #111 calc(1.9rem - 1px) 1.9rem); }
.sheet .box { display: flex; align-items: center; gap: .45rem; min-height: 1.6rem; }
.sheet .box input { appearance: none; width: 1rem; height: 1rem; min-height: 0; flex: none; padding: 0; border: 1.5px solid #111; border-radius: 2px; background: #fff; }
.sheet .box input:checked { background: #111; box-shadow: inset 0 0 0 2.5px #fff; }
.sheet .boxes { display: flex; flex-wrap: wrap; gap: .2rem 1.4rem; margin-top: .25rem; }
.sheet .sign { display: grid; grid-template-columns: 2fr 1fr; gap: 1.5rem; margin-top: 1rem; }
.sheet .sign label { display: flex; flex-direction: column; }
.sheet table { margin-top: .3rem; font-size: .875rem; }
.sheet th, .sheet td { border: 1px solid #111; padding: 0 .35rem; color: #111; }
.sheet th { background: #eee; font-weight: 600; padding-block: .25rem; }
.sheet td input:not([type=checkbox]) { border: 0; }
@media (min-width: 600px) {
  .sheet .f.half { grid-column: span 3; }
  .sheet .f.third { grid-column: span 2; }
}
.actions { display: flex; flex-wrap: wrap; gap: 0 var(--s4); margin-top: var(--s2); }
.actions button { min-height: var(--tap); padding: 0; background: none; color: var(--text-2); font-size: var(--t-small); border-radius: 4px; }
.actions button:hover { color: var(--accent); background: none; }
.chip { display: flex; align-items: center; gap: var(--s2); width: fit-content; max-width: 100%; margin: var(--s1) var(--s2); padding: var(--s1) var(--s3);
  background: var(--fill-2); border-radius: var(--r-s); font-size: var(--t-small); overflow-wrap: anywhere; }
.chip[hidden] { display: none; }
.chip button { min-height: 1.75rem; padding: 0 var(--s2); background: none; color: var(--text-2); }

/* "PDF" = the browser's own print dialog showing only the chosen answer */
@media print {
  body.printing .bar, body.printing .side, body.printing .scrim, body.printing .composer,
  body.printing .actions, body.printing .log > :not(.print-me) { display: none; }
  body.printing, body.printing #root, body.printing .app, body.printing .main, body.printing .log { display: block; height: auto; overflow: visible; background: #fff; color: #000; }
  body.printing .log { padding: 0; }
  body.printing .print-me { max-width: none; margin: 0; }
  body.printing .only-sheet > :not(.sheet) { display: none; }
  .sheet { box-shadow: none; padding: 0; margin: 0; border-radius: 0; font-size: 11pt; }
  .sheet .f.half { grid-column: span 3; } .sheet .f.third { grid-column: span 2; }
  .sheet fieldset, .sheet .f, .sheet tr { break-inside: avoid; }
  .sheet legend, .sheet th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sheet input::placeholder { color: transparent; }
  @page { margin: .6in; }
}

.tools .suggest { display: inline-flex; align-items: center; gap: var(--s2); max-width: 100%; text-align: start; color: var(--text-2); }
.tools .suggest[hidden] { display: none; }
kbd { font: 500 var(--t-caption) var(--font); padding: .1rem .4rem; border: 1px solid var(--line); border-radius: 6px; color: var(--text-2); background: var(--bg); }

/* ---- feedback */
.actions.rate { margin-top: 0; align-items: center; }
.review { display: grid; gap: var(--s3); }
.review article { background: var(--fill); border-radius: var(--r-m); padding: var(--s4); }
.review h4 { font-size: var(--t-small); color: var(--text-2); font-weight: 500; margin: var(--s3) 0 0; }
.review .clip { max-height: 9rem; overflow-y: auto; white-space: pre-wrap; margin: var(--s1) 0; }

.terms { font-size: var(--t-caption); color: var(--text-2); line-height: 1.45; margin: var(--s3) 0 0; }
.terms .link { font-size: inherit; padding: 0; display: inline; }
dialog ul { padding-inline-start: 1.2rem; } dialog li { margin: var(--s2) 0; }

/* ---- icons: actions are icon buttons (name in the tooltip and for screen readers); rows that
   navigate (sidebar, menus) keep icon + words. */
.icon { width: 1.25rem; height: 1.25rem; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn { width: var(--tap); min-height: var(--tap); padding: 0; display: inline-grid; place-items: center; background: none; color: var(--text-2); border-radius: var(--r-s); }
.icon-btn:hover { background: var(--fill-2); color: var(--text); }
.icon-btn.on, .icon-btn[aria-pressed="true"] { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }

.tools { gap: var(--s1); padding-inline-start: var(--s1); }
.tools button.icon-btn { width: 2.5rem; min-height: 2.5rem; border-radius: 50%; }
.tools button.icon-btn:hover { background: var(--fill-2); color: var(--text); }
.tools button.icon-btn[aria-pressed="true"] { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.tools button.icon-btn.rec { color: #fff; background: var(--danger); }
.toast { position: fixed; inset-inline: 0; bottom: max(1.25rem, env(safe-area-inset-bottom)); z-index: 50; width: fit-content; max-width: min(90vw, 28rem); margin-inline: auto; padding: .625rem 1rem; border-radius: 1.25rem; background: var(--text); color: var(--bg); font-size: var(--t-small); text-align: center; box-shadow: var(--shadow); animation: toast-in .18s var(--ease); }
@keyframes toast-in { from { transform: translateY(.5rem); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }
.msg audio.said { display: block; width: 100%; max-width: 20rem; height: 2.25rem; margin-top: var(--s2); }
.tools .send[hidden] { display: none; }
.tools .dictate { margin-inline-start: auto; }
.tools .send:not([hidden]) + .dictate { margin-inline-start: 0; }
.tools .suggest { margin-inline-start: var(--s2); }
/* Send: the Enter arrow, drawn like the microphone beside it. It appears when there is something to send. */
.tools button.send { margin-inline-start: auto; color: var(--text); animation: send-in .14s var(--ease); }
.tools button.send:disabled { opacity: .4; }
.send .icon { stroke-width: 2; }
@keyframes send-in { from { transform: scale(.6); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .tools button.send { animation: none; } }

.actions { gap: 0; align-items: center; margin-inline-start: -.5rem; }
.actions .icon-btn { width: 2.25rem; min-height: 2.25rem; height: 2.25rem; }
.actions .icon-btn:hover { background: var(--fill-2); color: var(--text); }
.actions .icon-btn.on { color: var(--accent); }
.actions .icon { width: 1.125rem; height: 1.125rem; }
.actions .hint { margin-inline-start: var(--s2); font-size: var(--t-caption); }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; }
.menu summary::-webkit-details-marker { display: none; }
.menu > div { position: absolute; z-index: 3; bottom: calc(100% + 4px); inset-inline-start: 0; min-width: 14rem; display: grid; padding: var(--s1);
  background: var(--surface); border-radius: var(--r-m); box-shadow: var(--shadow), 0 0 0 1px var(--line); }
.actions .menu div button { text-align: start; padding: 0 var(--s3); min-height: var(--tap); border-radius: var(--r-s); color: var(--text); font-size: var(--t-small); }
.actions .menu div button:hover { background: var(--fill); color: var(--text); }

.side button { display: flex; align-items: center; gap: var(--s3); min-height: 2.5rem; }
.foot { flex-direction: column; flex-wrap: nowrap; }
.foot button { color: var(--text); }
.chat .icon-btn { width: 2.25rem; min-height: 2.25rem; }
.chat .icon { width: 1rem; height: 1rem; }
.bar .icon-btn { color: var(--accent); }
.chip .icon-btn { width: 1.75rem; min-height: 1.75rem; }
.chip .icon { width: 1rem; height: 1rem; }
.terms { text-align: center; }
.actions .hint { order: 9; }

/* ---- bots */
.botlist { display: grid; gap: var(--s2); margin: var(--s3) 0; }
.bot { display: grid; grid-template-columns: 1fr auto; gap: var(--s1) var(--s3); text-align: start; padding: var(--s3) var(--s4); border-radius: var(--r-m); min-height: 0; }
.bot .hint { grid-column: 1 / -1; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.chipst { font-size: var(--t-caption); color: var(--text-2); white-space: nowrap; }
.bot.waiting .chipst, .bot.needs_person .chipst { color: var(--notice); font-weight: 600; }
.bot.working .chipst, .bot.watching .chipst { color: var(--accent); }
.receipts { margin: var(--s2) 0 var(--s4); padding-inline-start: 1.3rem; font-size: var(--t-small); }
.receipts li { margin: var(--s1) 0; }
.jobgoal { margin: 0 0 var(--s3); padding: var(--s3) var(--s4); background: var(--fill); border-radius: var(--r-m); }
.steps { margin: var(--s3) 0; padding-inline-start: 1.3rem; color: var(--text-2); font-size: var(--t-small); max-height: 14rem; overflow-y: auto; }
.steps li { margin: var(--s1) 0; }
.steps .answer, .steps .instruction { color: var(--text); }
.steps .error { color: var(--danger); }
dialog .msg { margin-block: var(--s3); }
dialog h3 { margin-top: var(--s4); }
dialog { overflow-x: hidden; }
dialog .scroll { margin-inline: 0; padding-inline: 0; }

/* ---- dropdowns */
select {
  appearance: none; -webkit-appearance: none; cursor: pointer; padding-inline-end: 2.75rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236e6e73' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 1rem center; background-size: 1.1rem;
}
[dir="rtl"] select { background-position: left 1rem center; }

/* ---- a bot at work, shown as one quiet line in its chat */
.botline { display: flex; align-items: center; gap: var(--s2); color: var(--text-2); font-size: var(--t-small); margin-block: var(--s3); }
.spin { width: .85rem; height: .85rem; flex: none; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; }
@media (prefers-reduced-motion: no-preference) { .spin { animation: spin .9s linear infinite; } @keyframes spin { to { transform: rotate(360deg); } } }

/* the hidden attribute always wins, even over components that set their own display */
[hidden] { display: none !important; }

/* ---- sidebar: header with the view menu, collapsible sections, chat rows, account row */
.shead { display: flex; align-items: center; justify-content: space-between; padding-inline-start: var(--s3); }
.shead .brand { padding: 0; }
.side .menu > div { bottom: auto; top: calc(100% + 2px); inset-inline: auto 0; min-width: 13.5rem; }
.side .menu div button { min-height: 2.25rem; padding: 0 var(--s3); font-size: var(--t-small); color: var(--text); white-space: nowrap; }
.side .menu div button:hover { background: var(--fill); }
.side .menu div button.danger { color: var(--danger); }
.side .menu hr { border: 0; border-top: 1px solid var(--line); margin: var(--s1) 0; }
.side .icon-btn { width: 2rem; min-height: 2rem; height: 2rem; padding: 0; justify-content: center; }
.side summary.icon-btn { display: inline-grid; }
.group { margin-bottom: var(--s2); }
.ghead { display: flex; align-items: center; }
.side .gname { flex: 1; min-width: 0; min-height: 2rem; padding: 0 var(--s3); gap: var(--s1); color: var(--text-2); font-size: var(--t-caption); font-weight: 600; }
.gname span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gname .icon { width: .9rem; height: .9rem; transition: transform .15s var(--ease); }
.gname[aria-expanded="false"] .icon { transform: rotate(-90deg); }
.gbody { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1px; }
.gbody .hint { padding: 0 var(--s3); margin: var(--s1) 0; font-size: var(--t-caption); }
.chat { align-items: center; }
.side .chat .go { flex: 1; min-width: 0; min-height: 2.25rem; gap: var(--s2); }
.chat .go span[dir] { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: .5rem; height: .5rem; flex: none; border-radius: 50%; background: var(--notice); }
.chats { overflow: visible auto; }
.acct { display: flex; align-items: center; gap: var(--s2); padding: var(--s2) 0 0 var(--s2); }
.acct .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--t-small); }
.avatar { width: 1.75rem; height: 1.75rem; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--accent-fill); color: var(--on-accent); font-size: var(--t-caption); font-weight: 600; }
.acct .menu > div { top: auto; bottom: calc(100% + 2px); }
@media (min-width: 900px) {
  .chat .menu, .ghead .menu, .ghead .icon-btn { opacity: 0; }
  .chat:hover .menu, .chat:focus-within .menu, .chat .menu[open], .ghead:hover .menu, .ghead:hover .icon-btn, .ghead:focus-within .menu, .ghead:focus-within .icon-btn, .ghead .menu[open] { opacity: 1; }
}

/* ---- sidebar top: plain rows for the main actions */
.top { display: grid; gap: 1px; margin-bottom: var(--s2); }
.side .top button { min-height: 2.5rem; font-size: var(--t-body); color: var(--text); }
.grow { flex: 1; }
.top kbd { border: 0; background: none; padding: 0; color: var(--text-2); font-size: var(--t-caption); }
.results { display: grid; gap: 2px; margin-top: var(--s3); max-height: 50dvh; overflow-y: auto; }
.result { display: grid; gap: 2px; text-align: start; padding: var(--s2) var(--s3); border-radius: var(--r-s); background: none; min-height: var(--tap); }
.result:hover, .result:focus-visible { background: var(--fill); }
.result strong { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result .hint { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--t-caption); }
dialog.search { margin-top: 12vh; }
dialog.search .close { display: none; }

.tabs { gap: var(--s2); margin-bottom: var(--s2); }
.tabs button { min-height: 2rem; padding: 0 var(--s3); font-size: var(--t-small); }
.tabs button[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.tabs button:first-letter { text-transform: uppercase; }

.sched { grid-template-columns: 1fr auto; align-items: center; cursor: default; }
.sched .hint { grid-column: 1; }
.sched button { grid-column: 2; grid-row: 1 / span 2; min-height: 2rem; padding: 0 var(--s3); font-size: var(--t-small); }

/* ---- circles */
.circles { display: grid; gap: var(--s2); margin: var(--s3) 0; }
.circle { display: grid; grid-template-columns: 1fr auto; gap: 2px var(--s3); align-items: center; background: var(--fill); border-radius: var(--r-m); padding: var(--s3) var(--s4); }
.circle .hint { grid-column: 1; margin: 0; }
.circle > button { grid-column: 2; grid-row: 1 / span 2; min-height: 2.25rem; padding: 0 var(--s4); background: var(--surface); }
.circle.member { grid-template-columns: 1fr auto auto; }
.circle.member > button { grid-row: auto; grid-column: auto; }
.circle.member select { width: auto; min-height: 2.25rem; padding-block: 0; background-color: var(--surface); }
button.danger { color: var(--danger); }
.adminpage .row input, .adminpage .row select { flex: 1 1 12rem; width: auto; }

/* ---- shared chats: someone else's message sits on the left with their name */
.log > .msg.other { width: fit-content; max-width: min(34rem, 86%); margin-inline: max(0px, calc((100% - var(--measure)) / 2)) auto;
  background: var(--fill); padding: var(--s2) var(--s4); border-radius: 20px 20px 20px 6px; white-space: pre-wrap; }
.msg.other small, .msg.user small { display: block; color: var(--text-2); font-size: var(--t-caption); margin-bottom: 2px; }
.ghead > .icon { width: .9rem; height: .9rem; color: var(--text-2); margin-inline-end: var(--s1); }
.chat .go > .icon { width: .85rem; height: .85rem; color: var(--text-2); }
@media (min-width: 900px) { .ghead > .icon { opacity: 1; } }

/* ---- characters: Klear and the bots */
.character { flex: none; vertical-align: middle; }
.brand { display: flex; align-items: center; gap: var(--s2); }
.bar .brand { justify-content: center; }
.empty .character { display: block; margin-bottom: var(--s3); }
.by { display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s2); }
.botline strong { color: var(--text); font-weight: 600; }
.bot strong { display: flex; align-items: center; gap: var(--s2); }
dialog h2 { display: flex; align-items: center; gap: var(--s3); }

/* ---- Memory */
.entries { display: grid; gap: var(--s2); margin: var(--s3) 0; }
.entry { background: var(--fill); border-radius: var(--r-m); padding: var(--s3) var(--s4); display: grid; gap: var(--s2); }
.entry p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.entry .row { flex-wrap: nowrap; align-items: flex-start; }
.entry.found { margin: var(--s3) 0; outline: 1px solid var(--accent); }
.answerbox { display: grid; grid-template-columns: 1fr auto; gap: var(--s2); align-items: end; }
.answerbox textarea { background: var(--surface); }
label.check { display: flex; align-items: center; gap: var(--s2); }

/* characters come alive: pose follows the bot's status, and a click makes any of them jump */
.character { cursor: pointer; overflow: visible; }
.character .arm { transform-box: fill-box; transform-origin: 50% 12%; }
.character.run { animation: ch-bob .45s ease-in-out infinite alternate; }
.character.run .arm.l { animation: ch-swing .45s ease-in-out infinite alternate; }
.character.run .arm.r { animation: ch-swing .45s ease-in-out infinite alternate-reverse; }
.character.ask .arm.r { transform: translate(4px, -4px) rotate(-160deg) scaleY(1.35); animation: ch-wave .5s ease-in-out infinite alternate; }
.character.rest .arm { stroke: rgba(0, 0, 0, .28); stroke-width: .7; }
.character.rest .arm.l { transform: translate(3px, -1px) rotate(-72deg); }
.character.rest .arm.r { transform: translate(-3px, .5px) rotate(72deg); }
.character.jump { animation: ch-jump .55s cubic-bezier(.3, 0, .3, 1); }
@keyframes ch-bob { from { transform: translateY(0) rotate(-3deg); } to { transform: translateY(-8%) rotate(3deg); } }
@keyframes ch-swing { from { transform: rotate(-40deg); } to { transform: rotate(40deg); } }
@keyframes ch-wave { from { transform: translate(4px, -4px) rotate(-145deg) scaleY(1.35); } to { transform: translate(4px, -4px) rotate(-175deg) scaleY(1.35); } }
@keyframes ch-jump { 0%, 100% { transform: translateY(0) scale(1); } 20% { transform: translateY(6%) scale(1.08, .9); } 50% { transform: translateY(-38%) scale(.95, 1.08); } 80% { transform: translateY(4%) scale(1.05, .94); } }
@media (prefers-reduced-motion: reduce) { .character, .character .arm { animation: none !important; } }

/* alive: everyone blinks and breathes; lights and eyes say how the job is going */
.character .eye, .character .tip, .character .light { transform-box: fill-box; transform-origin: center; }
.character .look { transform: translate(var(--lx, 0), var(--ly, 0)); transition: transform .15s ease-out; }
.character .eye { animation: ch-blink 5.2s infinite; animation-delay: var(--blink, 0s); }
.character:not(.run):not(.jump) { animation: ch-breathe 3.6s ease-in-out infinite; animation-delay: var(--blink, 0s); }
.character:hover .tip { animation: ch-pulse .35s ease-in-out infinite alternate; }
/* working: antenna and chest light pulse, eyes on the job */
.character.run .tip, .character.run .light { animation: ch-pulse .45s ease-in-out infinite alternate; }
.character.run .look { transform: translate(1px, .6px); }
/* needs the member: looks up at its raised hand, blinks often, chest light flashes amber */
.character.ask .look { transform: translate(1px, -1px); }
.character.ask .eye { animation-duration: 1.8s; }
.character.ask .light { fill: #ffb020; fill-opacity: 1; animation: ch-flash .5s steps(2, jump-none) infinite alternate; }
/* finished: eyes closed, content, chest light green */
.character.rest .eye { animation: none; transform: scaleY(.18); }
.character.rest .light { fill: #34c759; fill-opacity: 1; }
/* a click: wide eyes on the way up */
.character.jump .eye { animation: none; transform: scale(1.25); }
@keyframes ch-blink { 0%, 91%, 95%, 100% { transform: scaleY(1); } 93%, 97% { transform: scaleY(.1); } }
@keyframes ch-breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.03, .98) translateY(1%); } }
@keyframes ch-pulse { from { transform: scale(.8); opacity: .65; } to { transform: scale(1.3); opacity: 1; } }
@keyframes ch-flash { from { opacity: .25; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .character .eye, .character .tip, .character .light { animation: none !important; } .character .look { transition: none; } }

/* ---- circles and their boards */
.circle.pick { grid-template-columns: auto 1fr; text-align: start; width: 100%; min-height: 3.5rem; cursor: pointer; }
.circle.pick .character { grid-row: 1 / span 2; }
.circle.pick > span { display: flex; align-items: center; gap: var(--s2); min-width: 0; }
.circle.pick .hint { grid-column: 2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.goal { font-size: var(--t-title, 1.15rem); font-weight: 600; margin: var(--s2) 0; }
.task { display: flex; align-items: center; gap: var(--s3); background: var(--fill); border-radius: var(--r-m); padding: var(--s2) var(--s4); min-height: 2.75rem; }
.task.done > span { color: var(--text-2); text-decoration: line-through; }
.task.done .hint { text-decoration: none; display: inline-block; }
.routine { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.routine input:first-child { grid-column: 1 / -1; }
input[type=checkbox] { width: 1.2rem; height: 1.2rem; min-height: 0; flex: none; padding: 0; margin: 0; accent-color: var(--accent); }
.task .grow { flex: 1; min-width: 0; }
.task.done .hint { margin-inline-start: var(--s2); }

/* Sidebar: circles and busy bots are pinned above the chats; long sections fold to "Show all". */
.group.pinned + .group:not(.pinned) { margin-top: var(--s2); padding-top: var(--s2); border-top: 1px solid var(--fill-2); }
.chat.closed { opacity: .55; }
.side .showall { min-height: 2rem; padding: 0 var(--s3); justify-content: flex-start; color: var(--text-2); font-size: var(--t-caption); }
.ghead .icon-btn { width: 2rem; min-height: 2rem; color: var(--text-2); }
.result strong .character { margin-inline-end: var(--s1); }
.side .chat .go:only-child { opacity: 1; color: inherit; flex: 1; } /* a circle row has no options menu after it */
.side .chat .icon-btn.go { flex: none; }

/* Topics inside a circle: pills to choose one; the chosen one is filled, one you turned off is struck through. */
.topics { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); margin: var(--s3) 0; }
.topics button { min-height: 2rem; padding: 0 var(--s4); border-radius: 999px; background: var(--fill); font-size: var(--t-caption); max-width: 100%; }
.topics button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topics button[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.topics button.muted span { text-decoration: line-through; opacity: .6; }
.topics input { flex: 1 1 7rem; min-width: 7rem; width: auto; min-height: 2rem; border-radius: 999px; font-size: var(--t-caption); }

/* A circle's bots, in the circle window. */
.botrow { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
.botrow > .row { background: none; padding: 0; text-align: start; align-items: center; gap: var(--s3); min-width: 0; }
.botrow .grow { display: grid; gap: 2px; min-width: 0; }
.botrow .grow span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task .icon-btn .character { pointer-events: none; }
.entry .hint .character { margin-inline-end: var(--s1); }

/* A circle in the main pane: a header, what is to do, who is working, then what was said, newest at the bottom. */
.composer[hidden] { display: none; }
.cview { display: grid; gap: var(--s3); padding-bottom: var(--s4); }
.chead { display: flex; align-items: center; gap: var(--s4); }
.chead h2 { margin: 0; font-size: var(--t-title-1); font-weight: 700; letter-spacing: -.03em; overflow-wrap: anywhere; }
.chead .hint { margin: 2px 0 0; }
.chead .grow { flex: 1; min-width: 0; }
.cview .entries { margin: 0; }
.cview .goal { margin: 0; }
.cview > .hint { margin: 0; }
.cview > .hint .icon { width: 1rem; height: 1rem; vertical-align: -2px; }
.cpost { background: var(--fill); border-radius: var(--r-m); padding: var(--s3) var(--s4); }
.cpost .by { margin-bottom: var(--s1); }
.cpost .by .hint { flex: 1; font-size: var(--t-caption); }
.cpost .by .icon-btn { width: 2rem; min-height: 2rem; color: var(--text-2); opacity: 0; }
.cpost:hover .by .icon-btn, .cpost .by .icon-btn:focus-visible { opacity: 1; }
@media (hover: none) { .cpost .by .icon-btn { opacity: 1; } }
.cpost > :last-child { margin-bottom: 0; }
.cwrite { position: sticky; bottom: 0; margin: 0; }
.cwrite textarea { flex: 1; }
.cview label.task { margin: 0; }
.cwrite { display: flex; align-items: flex-end; gap: var(--s2); width: 100%; } /* the same box and round button as a chat's */
.cwrite .send { flex: none; width: 2.5rem; min-height: 2.5rem; padding: 0; border-radius: 50%; display: grid; place-items: center; }
.loop { flex-wrap: nowrap; justify-content: flex-start; width: 100%; }
.loop > span { flex: 1; }
.loop strong, .loop .hint { display: block; }
.chead h2 { font-size: clamp(1.25rem, 4.5vw, 1.75rem); line-height: 1.15; }
.cwrite { box-shadow: 0 0 0 14px var(--bg); }
.cwrite:focus-within { box-shadow: 0 0 0 14px var(--bg); }
.empty .loops .loop { display: flex; text-align: start; }
.empty .loops .loop .character { display: inline; margin: 0; }
.empty .loops .loop > span { display: grid; }
.empty .loops .loop { gap: var(--s3); padding: var(--s3) var(--s4); border-radius: var(--r-m); align-items: center; }

/* Scheduled: the town box for exact Shabbos times, and the matches to pick from */
.place input { display: block; width: 100%; margin-top: var(--s2); }
.towns { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s2); }

/* ============ 5. THE LAYOUT ============
   Four places: Today, Chats, Circles, You. The app element says which is showing (data-screen:
   today | chats | circles | chat | circle | you) and everything below is laid out from that.
   Phones show one screen at a time with tabs at the bottom; from 900px the sidebar holds the two
   lists and is always there. Earlier rules for the old slide-over menu are overridden here. */
.label { margin: 0; font-size: var(--t-caption); font-weight: 600; color: var(--text-2); letter-spacing: 0; }
.avatar { background: var(--line); color: var(--text); }
progress { appearance: none; -webkit-appearance: none; display: block; width: 100%; height: 6px; border: 0; border-radius: 3px; background: var(--fill-2); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--fill-2); }
progress::-webkit-progress-value { background: var(--accent); border-radius: 3px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 3px; }

/* ---- sidebar */
.shead { gap: var(--s1); }
.shead .brand { flex: 1; }
.side .acct { min-height: 3rem; padding: 0 var(--s2); border-radius: var(--r-m); font-size: var(--t-small); }
.side .acct .icon, .srow .icon { width: 1rem; height: 1rem; flex: none; color: var(--text-2); transform: rotate(-90deg); }
.app[data-screen="you"] .side .acct { background: var(--fill-2); font-weight: 600; }

/* ---- the bar over a chat (its name) and, on phones, the way back */
.mhead { display: none; flex: none; align-items: center; gap: var(--s1); min-height: 3.25rem; padding: 0 var(--s2); border-bottom: 1px solid var(--fill-2); }
.mhead h1 { flex: 1; min-width: 0; margin: 0; font-size: var(--t-body); font-weight: 600; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mhead .icon-btn { color: var(--accent); }
.app[data-screen="chat"] .mhead, .app[data-screen="circle"] .mhead { display: flex; }

/* ---- tabs (phones) */
.tabbar { flex: none; display: flex; border-top: 1px solid var(--fill-2); background: var(--bg); padding-bottom: env(safe-area-inset-bottom); }
.tab { flex: 1; min-height: 3.5rem; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 0; background: none; border-radius: 0; font-size: .6875rem; color: var(--text-2); }
.tab:hover { background: none; color: var(--text); }
.tab .icon { width: 1.5rem; height: 1.5rem; }
.app[data-screen="today"] .t-today, .app[data-screen="chats"] .t-chats, .app[data-screen="circles"] .t-circles, .app[data-screen="you"] .tab.t-you { color: var(--accent); font-weight: 600; }
.app[data-screen="chat"] .tabbar, .app[data-screen="circle"] .tabbar { display: none; }

/* ---- Today: the date, a greeting, the box to ask in, then what is waiting */
.empty { padding-top: var(--s5); }
.empty h2 { margin: 0; font-size: var(--t-title-1); font-weight: 600; letter-spacing: -.02em; }
.dateline { margin: 0 0 var(--s2); min-height: 1.4em; color: var(--text-2); font-size: var(--t-small); }
.below { display: none; width: calc(100% - 2 * var(--gutter)); max-width: var(--measure); margin: 0 auto; gap: var(--s5); align-content: start; }
.app[data-screen="today"] .below { display: grid; }
.app[data-screen="today"] .main { overflow-y: auto; }
.app[data-screen="today"] .log { flex: none; overflow: visible; padding-bottom: var(--s4); }
.app[data-screen="today"] .composer { background: var(--surface); border-color: var(--line); box-shadow: var(--shadow); }
.homeloop { display: grid; gap: var(--s2); }
.homeloop:empty { display: none; }
.loops { display: grid; background: var(--fill); border-radius: var(--r-m); overflow: hidden; }
.loops .loop { display: flex; align-items: center; gap: var(--s3); width: 100%; min-height: 3.75rem; padding: var(--s2) var(--s4); background: none; border-radius: 0; text-align: start; border-bottom: 1px solid var(--fill-2); }
.loops .loop:last-child { border-bottom: 0; }
.loops .loop:hover { background: var(--fill-2); }
.loops .loop > span:last-child { display: grid; flex: 1; min-width: 0; }
.loop strong, .loop .hint { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { width: 2.25rem; height: 2.25rem; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--surface); }
.badge .icon { width: 1.25rem; height: 1.25rem; }
.shabbos { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); width: 100%; padding: var(--s3) var(--s4); background: none; border: 1px solid var(--fill-2); border-radius: var(--r-m); text-align: start; }
.shabbos:hover { background: var(--fill); }
.shabbos > span { display: grid; min-width: 0; }
.shabbos > span + span { text-align: end; flex: none; }
.shabbos strong { font-weight: 600; }
.shabbos .hint { font-size: var(--t-caption); }
.log > .msg.user { background: var(--fill); color: var(--text); border-radius: 22px; }

/* ---- You: grouped rows */
.you { display: grid; gap: var(--s5); padding-bottom: var(--s6); }
.me { display: flex; align-items: center; gap: var(--s3); }
.me .avatar { width: 3.25rem; height: 3.25rem; font-size: var(--t-title-3); }
.me h2 { font-size: var(--t-title-1); font-weight: 600; }
.me .hint { margin: 0; overflow-wrap: anywhere; }
.sgroup { display: grid; gap: var(--s2); }
.sgroup .label { padding-inline: var(--s4); }
.sgroup > div { display: grid; background: var(--fill); border-radius: var(--r-m); overflow: hidden; }
.srow { display: flex; align-items: center; gap: var(--s3); min-height: 3.25rem; padding: 0 var(--s4); background: none; border-radius: 0; text-align: start; font-size: var(--t-body); border-bottom: 1px solid var(--fill-2); }
.srow:last-child { border-bottom: 0; }
.srow:hover { background: var(--fill-2); }
.srow .hint { max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.srow.danger { color: var(--danger); }
.srow.danger .icon { display: none; }

/* ---- a circle: the conversation, with the goal and to-dos in one line that opens (phones) or beside it (wide) */
.cview { align-content: start; gap: var(--s4); }
.chead h2 { font-size: var(--t-title-3); font-weight: 600; letter-spacing: -.02em; }
.cside { background: var(--fill); border-radius: var(--r-m); padding: 0 var(--s4);
  --surface: light-dark(#ffffff, #2c2c2e); } /* in the dark the panel is already grey, so what sits on it goes one step lighter */
.cside input:not([type=checkbox]) { background: var(--surface); }
.cside[open] { padding-bottom: var(--s4); }
.cside summary { display: flex; align-items: center; gap: var(--s3); min-height: 3rem; cursor: pointer; list-style: none; font-weight: 600; }
.cside summary::-webkit-details-marker { display: none; }
.cside summary progress { width: 5rem; flex: none; }
.cside summary .icon { width: 1rem; height: 1rem; flex: none; color: var(--text-2); transition: transform .15s var(--ease); }
.cside[open] summary .icon { transform: rotate(180deg); }
.cside .label { margin: var(--s4) 0 var(--s2); }
.cside .task { background: var(--surface); }
.cside .coming { margin: 0; }
.goalbox { display: grid; gap: var(--s2); }
.goalbox .label, .goalbox .goal, .goalbox .hint { margin: 0; }
.goalbox .goal { font-weight: 600; }
.cfeed { display: grid; gap: var(--s4); min-width: 0; }
.cfeed .cpost { margin: 0; padding: 0; background: none; }
.cfeed > .hint { margin: 0; }

@media (max-width: 899.98px) {
  /* the sidebar is the Chats screen or the Circles screen, full size, shown only for those two */
  .side { position: static; transform: none; visibility: visible; transition: none; box-shadow: none; display: none; flex: 1; width: auto; min-height: 0; padding: var(--s5) var(--s4) var(--s2); background: var(--bg); }
  .app[data-screen="chats"] .side, .app[data-screen="circles"] .side { display: flex; }
  .app[data-screen="chats"] .main, .app[data-screen="circles"] .main { display: none; }
  .app[data-screen="chats"] .group.pinned, .app[data-screen="circles"] .group:not(.pinned) { display: none; }
  .side .acct { display: none; }
  .side .chat .go { min-height: var(--tap); font-size: var(--t-body); }
  .side .gname { font-size: var(--t-small); }
  .group.pinned + .group:not(.pinned) { border-top: 0; }
  /* Today: the box to ask in stays at the bottom, above the tabs */
  .app[data-screen="today"] .below { order: 1; flex: 1 0 auto; padding-bottom: var(--s4); }
  .app[data-screen="today"] .composer { order: 2; position: sticky; bottom: var(--s3); background: light-dark(var(--surface), #2c2c2e); } /* it floats over the cards, and a shadow does not show in the dark */
  .app[data-screen="today"] .composer::after { content: ''; position: absolute; inset: 100% -1px auto; height: var(--s4); margin-top: 1px; background: var(--bg); } /* nothing shows between the box and the tabs */
}
@media (min-width: 900px) {
  .tabbar { display: none; }
  .side { width: 16.5rem; border-inline-end-color: var(--fill-2); }
  .mhead { padding: 0 var(--s5); }
  .mhead .icon-btn, .app[data-screen="circle"] .mhead { display: none; }
  .app[data-screen="today"] .main { padding-top: 8vh; }
  .app[data-screen="today"] .below { margin-top: var(--s5); padding-bottom: var(--s6); }
}
@media (min-width: 1100px) {
  .log > .cview { max-width: 66rem; }
  .cview { grid-template-columns: minmax(0, 1fr) 19rem; column-gap: var(--s6); }
  .chead { grid-column: 1 / -1; padding-bottom: var(--s4); border-bottom: 1px solid var(--fill-2); }
  .cfeed { grid-column: 1; grid-row: 2; }
  .cside { grid-column: 2; grid-row: 2; align-self: start; position: sticky; top: 0; padding: 0 0 0 var(--s5); background: none; border-radius: 0; border-inline-start: 1px solid var(--fill-2); }
  .cside summary { display: none; }
  .cside .label:first-of-type, .cside .goalbox .label { margin-top: 0; }
  .cside .task { background: var(--fill); }
}

/* a circle fills the screen like a chat: the box to write in sits at the bottom */
.log > .cview { min-height: 100%; }
.cview { grid-template-rows: auto auto 1fr; }
.cfeed { display: flex; flex-direction: column; }
.cfeed .cwrite { margin-top: auto; }
@media (min-width: 1100px) { .cview { grid-template-rows: auto 1fr; } }

/* the two lists on phones: a large title, roomy rows, and for a circle the last thing said */
.ptitle, .side .join, .sub { display: none; }
.names { flex: 1; min-width: 0; display: grid; }
.names span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 899.98px) {
  .shead { padding-inline-start: 0; }
  .shead .brand { display: none; }
  .ptitle { display: block; flex: 1; margin: 0; font-size: var(--t-title-1); font-weight: 600; letter-spacing: -.02em; }
  .app[data-screen="circles"] .group.pinned .ghead { display: none; }
  .app[data-screen="circles"] .side .join { display: flex; justify-content: center; min-height: 3rem; background: var(--fill); border-radius: var(--r-m); font-size: var(--t-body); }
  .app[data-screen="circles"] .side .chat { border-bottom: 1px solid var(--fill-2); border-radius: 0; }
  .app[data-screen="circles"] .side .chat .go { min-height: 4.25rem; gap: var(--s3); padding-inline: 0; }
  .app[data-screen="circles"] .side .chat .go:hover { background: none; }
  .app[data-screen="circles"] .side .chat .character { width: 3rem; height: 3rem; flex: none; }
  .app[data-screen="circles"] .names span:first-child { font-weight: 600; }
  .app[data-screen="circles"] .sub { display: block; color: var(--text-2); font-size: var(--t-small); }
}

/* ============ 6. WINDOWS, WELCOME, BOT CARD ============
   Every pop-up window is one frame: its name and a close button stay at the top, the body scrolls.
   A sheet from the bottom on phones, a centred card from 600px. Inside, the same quiet labels and
   grouped rows as the You page. */
dialog { padding: 0; overflow: hidden;
  --fill: light-dark(#f5f5f7, #2c2c2e); --fill-2: light-dark(#e8e8ed, #3a3a3c); } /* in the dark a window is already grey, so its groups go one step lighter */
dialog[open] { display: flex; flex-direction: column; }
.dhead { flex: none; display: flex; align-items: center; gap: var(--s3); min-height: 3.5rem; padding: var(--s2) var(--s3) var(--s2) var(--s5); border-bottom: 1px solid var(--fill-2); }
.dhead h2 { flex: 1; min-width: 0; font-size: var(--t-body); font-weight: 600; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dhead .icon-btn { flex: none; width: 2.25rem; min-height: 2.25rem; border-radius: 50%; background: var(--fill); }
.dbody { flex: 1; min-height: 0; overflow: hidden auto; overscroll-behavior: contain; padding: var(--s4) var(--s5) max(var(--s5), env(safe-area-inset-bottom)); }
.dbody > :first-child { margin-top: 0; }
.dbody > :last-child { margin-bottom: 0; }
.dbody h3 { margin: var(--s5) 0 var(--s2); font-size: var(--t-caption); font-weight: 600; color: var(--text-2); letter-spacing: 0; }
.dbody .hint:empty, .dbody .err:empty { display: none; }
.dbody > button:not(.link):not(.result):not(.circle), .dbody .fold > div > button { margin-top: var(--s2); }
.row.end { justify-content: flex-end; margin-top: var(--s5); }
dialog.search .dhead { display: none; }
dialog.search .dbody { padding-top: var(--s5); }
@media (max-width: 599.98px) {
  /* a sheet: a small grip at the top says it can be put away */
  dialog::before { content: ""; flex: none; align-self: center; width: 2.25rem; height: .3rem; margin-top: var(--s2); border-radius: 3px; background: var(--line); }
  .dhead { border-bottom: 0; min-height: 3rem; }
  .dbody { padding-top: 0; }
}
@media (min-width: 600px) {
  dialog { padding: 0; max-height: min(44rem, 86dvh); }
}

/* lists inside a window: one grey group, hairlines between rows */
.results { gap: 0; background: var(--fill); border-radius: var(--r-m); overflow: hidden auto; }
.results:empty { display: none; }
.result { border-radius: 0; padding: var(--s3) var(--s4); border-bottom: 1px solid var(--fill-2); }
.result:last-child { border-bottom: 0; }
.result:hover, .result:focus-visible { background: var(--fill-2); }
.results > .hint { margin: 0; padding: var(--s3) var(--s4); }
.sched button { background: var(--surface); }
.codes { border: 0; background: var(--fill); border-radius: var(--r-m); padding: 0 var(--s4); }
.codes li { margin: 0; border-bottom-color: var(--fill-2); }
.codes li:last-child { border-bottom: 0; }
.codes button { background: var(--surface); min-height: 2.25rem; padding: 0 var(--s4); }
.circle.pick:hover { background: var(--fill-2); }
.steps { list-style: none; padding: var(--s3) var(--s4); background: var(--fill); border-radius: var(--r-m); }
.steps:empty { display: none; }
.dbody .answerbox input, .dbody .answerbox textarea { background: var(--fill); }
.dbody .entry .answerbox input, .dbody .entry .answerbox textarea { background: var(--surface); }
.place { display: block; margin: var(--s3) 0; padding: var(--s3) var(--s4); background: var(--fill); border-radius: var(--r-m); }
.place button { min-height: 2.25rem; padding: 0 var(--s4); background: var(--surface); font-size: var(--t-small); }
.place input { background: var(--surface); }

/* Settings: rows that open in place, one at a time */
.folds { display: grid; margin-top: var(--s3); background: var(--fill); border-radius: var(--r-m); overflow: hidden; }
.fold { border-bottom: 1px solid var(--fill-2); }
.fold:last-child { border-bottom: 0; }
.fold summary { display: flex; align-items: center; gap: var(--s3); min-height: 3.25rem; padding: 0 var(--s4); cursor: pointer; list-style: none; }
.fold summary::-webkit-details-marker { display: none; }
.fold summary:hover { background: var(--fill-2); }
.fold summary .icon { width: 1rem; height: 1rem; color: var(--text-2); transform: rotate(-90deg); transition: transform .15s var(--ease); }
.fold[open] summary { font-weight: 600; }
.fold[open] summary .icon { transform: none; }
.fold > div { padding: var(--s2) var(--s4) var(--s4); }
.fold > div > :first-child { margin-top: 0; }
.fold input, .fold textarea, .fold select { background-color: var(--surface); }
.fold button:not(.link) { background: var(--surface); }

/* ---- welcome: one centred column */
.welcome { min-height: 100%; max-width: 24.5rem; margin: 0 auto; padding: clamp(2.5rem, 9vh, 4.5rem) var(--s5) var(--s5); display: flex; flex-direction: column; gap: var(--s6); }
.hello { display: grid; justify-items: center; gap: var(--s3); text-align: center; }
.hello h1 { font-size: var(--t-title-1); }
.hello p { margin: 0; color: var(--text-2); max-width: 19rem; text-wrap: balance; }
.enter { display: grid; gap: var(--s3); }
.enter label { margin: 0; font-size: var(--t-caption); font-weight: 600; }
.enter input { min-height: 3.25rem; background: var(--bg); border-color: var(--line); border-radius: var(--r-m); font-weight: 400; }
.enter .err:empty { display: none; }
.enter .primary { min-height: 3.25rem; margin-top: var(--s2); font-weight: 600; }
.enter > .link { justify-self: center; min-height: var(--tap); }
.enter .terms { margin: 0; }
.welcome .wait { margin: calc(var(--s4) * -1) 0 0; }
.callin a { white-space: nowrap; }
/* the page a bot handed over: a picture of it, always on white like the page itself */
.pageshot { display: block; width: 100%; max-width: 412px; margin: var(--s3) auto; background: #fff; border-radius: var(--r-s); box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.pagekeys { margin-top: var(--s3); gap: var(--s2); }
.pagekeys button { min-height: 2.25rem; padding: 0 var(--s3); font-size: var(--t-small); }
/* Klear HQ: tabs under the header (they scroll sideways on a phone), problems as a list, two weeks as bars */
.hqtabs { display: flex; gap: var(--s1); padding: var(--s2) var(--gutter); overflow-x: auto; border-bottom: 1px solid var(--fill-2); position: sticky; top: 0; background: var(--bg); z-index: 1; }
.hqtabs { scrollbar-width: none; }
.hqtabs button { flex: none; min-height: 2.25rem; padding: 0 var(--s4); background: none; color: var(--text-2); font-size: var(--t-small); }
.hqtabs button:hover { background: var(--fill); }
.hqtabs button.on { background: var(--fill-2); color: var(--text); font-weight: 600; }
.adminpage main > h2:first-child { margin-top: var(--s3); }
.stats .stat { display: grid; gap: var(--s1); text-align: start; background: var(--fill); border-radius: var(--r-m); padding: var(--s4); min-height: 0; }
.stats .stat span { color: var(--text-2); font-size: var(--t-small); }
.stats .stat strong { font-size: var(--t-title-2, 1.5rem); font-weight: 600; }
.issues { display: grid; background: var(--fill); border-radius: var(--r-m); overflow: hidden; }
.issue { display: flex; align-items: center; gap: var(--s3); width: 100%; min-height: 3rem; padding: var(--s3) var(--s4); background: none; border-radius: 0; text-align: start; border-bottom: 1px solid var(--fill-2); }
.issue:last-child { border-bottom: 0; }
.issue:hover { background: var(--fill-2); }
.issue .dot { flex: none; width: .6rem; height: .6rem; border-radius: 50%; background: var(--text-2); }
.issue.bad .dot { background: var(--danger); }
.issue.warn .dot { background: var(--notice); }
.trend { display: flex; align-items: flex-end; gap: var(--s1); height: 9rem; padding: var(--s4) var(--s4) var(--s2); background: var(--fill); border-radius: var(--r-m); }
.trend div { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: var(--s1); min-width: 0; }
.trend i { width: 100%; max-width: 2rem; min-height: 2px; background: var(--accent-fill); border-radius: 3px 3px 0 0; }
.trend small { color: var(--text-2); font-size: var(--t-caption); }
.conn label.task { color: var(--text); }
.brief { margin: var(--s3) 0 var(--s4); padding: var(--s3) var(--s4); background: var(--fill); border-radius: var(--r-m); display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3); }
.brief label { margin: 0; }
.brief input[type=time] { width: auto; min-height: 2.25rem; background: var(--surface); }
.brief .hint { margin: 0; flex-basis: 100%; }
.starters .more { color: var(--accent); background: none; text-align: center; }
.link.small { font-size: var(--t-caption); min-height: 0; padding: 0; }
.toolrow { padding: var(--s2) 0; border-bottom: 1px solid var(--fill-2); }
.toolrow label { margin: 0; }
.toolrow .check { margin-inline-start: 2rem; font-size: var(--t-caption); color: var(--text-2); }
.conn { padding: var(--s3) 0; border-bottom: 1px solid var(--fill-2); }
.conn label.task { margin: 0; background: none; padding: 0; }
.conn .hint { margin: var(--s1) 0 0; }
.conns + .err:empty { display: none; }
.callin { margin: auto 0 0; display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); background: var(--fill); border-radius: var(--r-m); font-size: var(--t-small); }
@media (min-width: 900px) {
  .welcome { justify-content: center; }
  .callin { margin-top: 0; }
}

/* ---- a bot at work in its chat: a card with who is on it and its last steps; then its question's likely answers */
.botcard { display: grid; gap: var(--s3); margin-block: var(--s4); padding: var(--s4); border: 1px solid var(--fill-2); border-radius: var(--r-m); font-size: var(--t-small); }
.botcard .row { flex-wrap: nowrap; }
.botcard .grow { display: grid; min-width: 0; }
.botcard strong { font-weight: 600; }
.botcard ul { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); color: var(--text-2); }
.botcard li { display: flex; align-items: flex-start; gap: var(--s2); margin: 0; }
.botcard li .icon { width: 1rem; height: 1rem; margin-top: .2rem; color: #1f8a4c; stroke-width: 2.6; }
.botcard li .spin { margin-top: .25rem; }
.replies { display: flex; flex-wrap: wrap; gap: var(--s2); margin-block: var(--s3); }
.replies button { background: var(--bg); border: 1px solid var(--line); padding: 0 var(--s4); font-size: var(--t-small); }
.replies button:hover { background: var(--fill); }
.replies button.primary { background: var(--accent-fill); border-color: transparent; color: var(--on-accent); }

/* ---- the open chat's options, at the end of its title bar */
.mmenu { flex: none; display: flex; }
.mhead .menu > div { bottom: auto; top: calc(100% + 2px); inset-inline: auto 0; min-width: 13.5rem; }
.mhead .menu div button { min-height: 2.5rem; padding: 0 var(--s3); background: none; border-radius: var(--r-s); text-align: start; font-size: var(--t-small); color: var(--text); white-space: nowrap; }
.mhead .menu div button:hover { background: var(--fill); }
.mhead .menu div button.danger { color: var(--danger); }
.mhead .menu hr { border: 0; border-top: 1px solid var(--line); margin: var(--s1) 0; }
.mhead summary.icon-btn { color: var(--text-2); }
@media (min-width: 900px) { .mhead .mmenu .icon-btn { display: inline-grid; } }

/* ---- sidebar top: the name is the way home; new chat and search are icons beside it */
.side .shead .brand { flex: 1; min-width: 0; min-height: 2.5rem; padding: 0 var(--s2); white-space: nowrap; background: none; font-size: var(--t-title-3); font-weight: 600; border-radius: var(--r-s); }
.side .shead .brand:hover { background: var(--fill-2); }
.side .shead .icon-btn { width: 2.25rem; min-height: 2.25rem; height: 2.25rem; color: var(--text); }
.side .shead { padding-inline-start: 0; margin-bottom: var(--s2); }
@media (min-width: 900px) { .side { width: 17.5rem; } }
.side .top { margin: 0 0 var(--s3); }
.side .top button { min-height: 2.5rem; border-radius: var(--r-s); font-size: var(--t-body); }
@media (min-width: 900px) { .side .shead .icon-btn.ph { display: none; } }
@media (max-width: 899.98px) { .side .top { display: none; } }
.app[data-screen="today"] .side .top .home { background: var(--fill-2); font-weight: 600; }

/* ---- service circles and plans */
.cside textarea { background: var(--surface); margin-bottom: var(--s2); }
.sendto { display: block; font-size: var(--t-caption); }
.task.done .sendto { display: none; }

/* tabs inside a window (a circle's settings): the same buttons as the HQ tabs, sitting in the window */
.dtabs { position: static; padding: 0 0 var(--s3); margin-bottom: var(--s3); background: none; flex-wrap: wrap; }
