/* The portal's shared stylesheet (D1): the tokens, the base elements, and the pages of index.html and
 * meeting.html. Both pages load it by its absolute path (/m/<slug> resolves relative URLs to meeting.html).
 * meeting.css (injected by meeting.js, after this file) holds only the in-call overlay, so it wins every tie.
 *
 * Rules that bind this file (app/portal/README.md, "Styles and tokens"):
 *  - the tokens live in the block below, light by default, dark under the OS preference and under
 *    [data-theme="dark"]; data-theme="light" forces light on a dark OS; --accent is set by theme.js (branding)
 *    and is never redefined here, so fills use --accent and text, borders and rings use --accent-text;
 *  - no hex colour outside the token block, no external origin, no stylesheet import, no font-face rule, no web font;
 *  - a rule that belongs to one page is scoped (#gate, #view-home, header .bar ...): never a bare .actions,
 *    .bar, .state or .when. */

/* tokens:start */
:root {
  color-scheme: light dark;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --fg: #1a1c22;
  --muted: #646a78;
  --line: #e1e4ec;
  --line-strong: #80869a;
  --bg: #ffffff;
  --card: #f8f9fc;
  --accent: #2f6fed;
  --on-accent: #ffffff;
  --accent-text: var(--accent-text-light, #2a64d5);
  --accent-soft: color-mix(in srgb, var(--accent) 12%, var(--bg));
  --warn-bg: #fff6dd;
  --warn-fg: #7a5800;
  --warn-line: #ffe69c;
  --err-bg: #f8d7da;
  --err-fg: #58151c;
  --err-line: #f1aeb5;
  --danger: #c93838;
  --danger-fill: #c93838;
  --on-danger: #ffffff;
  --success: #1e7a46;
  --focus-on-danger: #ffd54f;
  --stage: #15171c;
  --tile: #262a33;
  --tile-fg: #c9cdd6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --fg: #e7e9ee;
    --muted: #9aa1b0;
    --line: #30343e;
    --line-strong: #70778a;
    --bg: #131519;
    --card: #1b1e24;
    --accent-text: var(--accent-text-dark, #6393f2);
    --accent-soft: color-mix(in srgb, var(--accent) 22%, var(--bg));
    --warn-bg: #3a3014;
    --warn-fg: #f1d48a;
    --warn-line: #5c4a10;
    --err-bg: #3d1a1d;
    --err-fg: #f1aeb5;
    --err-line: #6b2a30;
    --danger: #ef6b6b;
    --success: #4cc38a;
    --stage: #0b0c0f;
    --tile: #20232b;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --fg: #e7e9ee;
  --muted: #9aa1b0;
  --line: #30343e;
  --line-strong: #70778a;
  --bg: #131519;
  --card: #1b1e24;
  --accent-text: var(--accent-text-dark, #6393f2);
  --accent-soft: color-mix(in srgb, var(--accent) 22%, var(--bg));
  --warn-bg: #3a3014;
  --warn-fg: #f1d48a;
  --warn-line: #5c4a10;
  --err-bg: #3d1a1d;
  --err-fg: #f1aeb5;
  --err-line: #6b2a30;
  --danger: #ef6b6b;
  --success: #4cc38a;
  --stage: #0b0c0f;
  --tile: #20232b;
}
@supports not (color: color-mix(in srgb, red 50%, blue)) {
  :root { --accent-soft: #e6eefe; }
  @media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --accent-soft: #1d2a45; } }
  :root[data-theme="dark"] { --accent-soft: #1d2a45; }
}
/* tokens:end */

/* --- base -------------------------------------------------------------------------------------------------- */
* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.45; color: var(--fg); background: var(--bg); }
.hidden, [hidden] { display: none !important; } /* wins over the later display rules (grid, flex) */
.sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
a { color: var(--accent-text); }
p button.link, p a { text-decoration: underline; } /* a link in running text needs more than colour */
h2 { font-size: 1.05rem; margin: 0 0 .6rem; text-wrap: balance; }
h3 { font-size: .95rem; margin: 1.25rem 0 .5rem; }
.card > h3:first-child, [role="tabpanel"] > h3:first-child { margin-top: 0; }
h2[tabindex="-1"]:focus { outline: none; }
.muted { color: var(--muted); font-size: .85rem; }
.fine { font-size: .8rem; }
.mono { font-family: var(--mono); font-size: .85rem; font-variant-numeric: tabular-nums; }
.hint { font-size: .78rem; color: var(--muted); margin-top: .2rem; }

/* Controls ------------------------------------------------------------------------------------------------------ */
button { font: inherit; font-size: .9rem; cursor: pointer; border: 1px solid var(--line); background: var(--card); color: var(--fg); border-radius: 8px; padding: .45rem .85rem; }
a.btn, a.big { display: inline-block; text-decoration: none; font-size: .9rem; border: 1px solid var(--line); background: var(--card); color: var(--fg); border-radius: 8px; padding: .45rem .85rem; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.link { border: 0; background: none; color: var(--accent-text); padding: .2rem .35rem; }
button.danger { color: var(--danger); }
button.primary.danger-fill { background: var(--danger-fill); border-color: var(--danger-fill); color: var(--on-danger); }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line-strong); border-radius: 8px; padding: .45rem .6rem; width: 100%; min-width: 0; }
::placeholder { color: var(--muted); opacity: 1; }
input[readonly] { background: var(--card); color: var(--muted); }
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--accent); }
input[type="file"] { border: 0; padding: 0; background: none; width: auto; flex: 1 1 12rem; }
input[type="color"] { padding: .15rem; height: 2.3rem; }
textarea { resize: vertical; }
label { display: block; font-size: .78rem; color: var(--muted); margin: 0 0 .2rem; }
label.check { display: flex; gap: .5rem; align-items: flex-start; font-size: .9rem; color: var(--fg); margin: 0; }
label.check input { margin-top: .2rem; }
/* A visible ring on every interactive element. */
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible,
[tabindex]:not([tabindex="-1"]):focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }
.chips:focus-within { outline: 2px solid var(--accent-text); outline-offset: 2px; }
input::-webkit-calendar-picker-indicator:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 1px; }
/* A scroll container clips a ring drawn outside the box. The second selector outranks the generic tabindex rule above
   (a tab with tabindex=0 matches both). */
.tabs :focus-visible, .tabs [tabindex]:not([tabindex="-1"]):focus-visible { outline-offset: -2px; }

/* Layout helpers ---------------------------------------------------------------------------------------------------- */
.card, #login { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.1rem; margin: 0 0 1rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: .75rem; }
.grid2 > * { min-width: 0; }
.tag { font-size: .72rem; padding: .1rem .5rem; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.tag.on { border-color: var(--accent-text); color: var(--accent-text); }
.tag.live { border-color: var(--success); color: var(--success); }
.tag.cancelled { border-color: var(--danger); color: var(--danger); }
.spinner { width: 2rem; height: 2rem; border: 3px solid var(--line); border-top-color: var(--accent-text); border-radius: 50%; }
@media (prefers-reduced-motion: no-preference) {
  .spinner { animation: spin 1s linear infinite; }
  @keyframes spin { to { transform: rotate(360deg); } }
}

/* --- the portal shell (index.html) ------------------------------------------------------------------------------- */
header { border-bottom: 1px solid var(--line); padding-block: .75rem; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
header .bar { max-width: 52rem; margin: 0 auto; display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; justify-content: space-between; }
header h1 { font-size: 1.1rem; margin: 0; }
.brand { display: flex; align-items: center; gap: .6rem; }
.brand img { height: 1.6rem; width: auto; max-width: 10rem; }
#nav { display: flex; flex-wrap: wrap; gap: .25rem; }
#nav a { color: var(--muted); padding: .35rem .6rem; border-radius: 8px; font-size: .9rem; text-decoration: none; }
#nav a[aria-current="page"] { color: var(--accent-text); background: var(--accent-soft); font-weight: 600; } /* the weight is a cue that is not colour */
main { max-width: 52rem; margin: 0 auto; padding-block: 1.25rem 4rem; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.view h2 { margin-top: 0; }

/* Login: a centred card; the Join box inside it stays left aligned. */
#login { max-width: 30rem; margin: 2rem auto 0; display: grid; gap: .75rem; justify-items: center; text-align: center; }
#login > p { margin: 0; }

/* The Join box (login and Home): a card of its own. */
.join-box { text-align: left; justify-self: stretch; }
#login .join-box { margin: 0; width: 100%; }
.join-box h2 { margin: 0 0 .25rem; }
.join-box .hint { margin: 0 0 .6rem; }
#jl-code, #jh-code { font-family: var(--mono); }
.join-result { margin-top: .5rem; }
.join-msg { margin: 0; }
.join-hint { margin: .3rem 0 0; font-size: .88rem; }
.join-box .join-go { display: block; margin: .75rem 0 0 auto; }

/* Home: the three tiles. */
#view-home .actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; margin-bottom: .75rem; }
#view-home .big { display: grid; gap: .35rem; justify-items: center; padding: 1.1rem .5rem; border-radius: 14px; font-weight: 600; font-size: .9rem; }
.ic { width: 2.6rem; height: 2.6rem; border-radius: 12px; background: var(--accent-soft); color: var(--accent-text); display: grid; place-items: center; font-size: 1.3rem; }
.big.primary .ic { background: var(--on-accent); color: var(--accent); }
#home-msg { margin: 0 0 .75rem; }
#home-msg:empty { margin: 0; } /* a live region stays rendered while it is empty */

/* Meetings: the tabs and the rows. */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: .75rem; overflow-x: auto; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: var(--muted); }
.tabs button[aria-selected="true"] { color: var(--accent-text); border-bottom-color: var(--accent-text); }
.mlist { list-style: none; margin: 0; padding: 0; display: grid; }
.mrow { display: flex; flex-wrap: wrap; gap: .4rem 1rem; align-items: center; padding: .7rem 0; border-top: 1px solid var(--line); }
.mrow:first-child { border-top: 0; }
.mmain { flex: 1 1 14rem; min-width: 0; }
.mtitle { font-weight: 600; overflow-wrap: anywhere; }
.mtags { display: flex; flex-wrap: wrap; gap: .3rem; margin: .3rem 0; }
.mmeta { overflow-wrap: anywhere; }
.mactions { flex: 0 1 auto; display: flex; flex-wrap: wrap; gap: .5rem; }
.mrow .mactions { justify-content: flex-end; } /* beside the text when it fits; the Personal room's own row stays left */
.mpanels, .merr { flex: 1 1 100%; min-width: 0; }
.merr:empty { display: none; }
p.merr, li.merr { color: var(--danger); }
/* Room activity / audit trail, the recordings and history panels. */
.audit { margin-top: .5rem; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.audit-row { padding: .4rem .6rem; border-bottom: 1px solid var(--line); font-size: .82rem; }
.audit-row:last-child { border-bottom: 0; }
.audit-row .when { color: var(--muted); font-size: .75rem; }
/* The Personal room. */
.pfacts { display: grid; grid-template-columns: 1fr; gap: .2rem 1rem; margin: 0 0 .75rem; }
.pfacts dt { display: block; font-size: .78rem; color: var(--muted); margin: .4rem 0 0; }
.pfacts dt:first-child { margin-top: 0; }
.pfacts dd { margin: 0; overflow-wrap: anywhere; }
.pfacts dd.mono, .pval { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.plink { display: block; font-family: var(--mono); font-size: .82rem; word-break: break-all; background: var(--bg); border: 1px dashed var(--line); border-radius: 8px; padding: .5rem .6rem; }

/* The schedule and edit form. */
.mform { display: grid; gap: 1rem; }
.mform fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: .75rem; min-width: 0; }
.mform legend { font-weight: 600; font-size: .9rem; margin-bottom: .5rem; padding: 0; }
.mform .field { margin: 0; min-width: 0; }
.row.nowrap { flex-wrap: nowrap; }
.row.nowrap > input { flex: 1; min-width: 0; }
.ferr { font-size: .82rem; color: var(--danger); margin-top: .2rem; }
.ferr:empty { display: none; }
[aria-invalid="true"] { border-color: var(--danger); }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; border: 1px solid var(--line-strong); border-radius: 8px; padding: .35rem; background: var(--bg); }
.chips:has([aria-invalid="true"]) { border-color: var(--danger); }
.chips input { border: 0; flex: 1 1 10rem; padding: .25rem .3rem; width: auto; }
.chips input:focus-visible { outline-offset: -2px; }
.chiplist { display: contents; }
.chip { display: inline-flex; flex-wrap: wrap; gap: .2rem; align-items: center; background: var(--accent-soft); color: var(--fg); border-radius: 999px; padding: .15rem .3rem .15rem .6rem; font-size: .82rem; max-width: 100%; }
.chip .ctext { overflow-wrap: anywhere; }
.chip .cstate { color: var(--fg); font-weight: 400; }
.chip button { border: 0; background: none; padding: 0 .4rem; color: var(--fg); font-size: 1rem; line-height: 1.4; }
.days .row { gap: .3rem; }
.day { border-radius: 999px; width: 2.4rem; padding: .35rem 0; text-align: center; }
.day[aria-pressed="true"] { background: var(--accent); border-color: var(--accent-text); color: var(--on-accent); }
.legend { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .2rem; }
.checks { display: grid; gap: .45rem; }
.banner { border-radius: 8px; padding: .55rem .8rem; font-size: .85rem; }
.banner.warn { background: var(--warn-bg); color: var(--warn-fg); border: 1px solid var(--warn-line); }
.banner.err { background: var(--err-bg); color: var(--err-fg); border: 1px solid var(--err-line); }
.banner.note { background: var(--accent-soft); border: 1px solid var(--line); }
.row.actions { justify-content: flex-end; gap: .5rem; margin-top: .25rem; }

/* Dialogs. */
dialog { background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.1rem; max-width: min(32rem, calc(100vw - 2rem)); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h2 { margin: 0 0 .6rem; font-size: 1.05rem; overflow-wrap: anywhere; }
dialog p { overflow-wrap: anywhere; }
dialog textarea { width: 100%; }
.dlg-actions { justify-content: flex-end; gap: .5rem; margin-top: 1rem; }

/* Branding admin. */
#view-admin .field + .field, #view-admin .field + .row, #view-admin .row + .field { margin-top: .75rem; }
.field.fixed { flex: 0 0 auto; }
.row.tight { margin-top: .4rem; }
.row.end { justify-content: flex-end; margin-top: .4rem; }
#view-admin .row.end { margin-top: .75rem; }
#view-admin .row { align-items: flex-end; }

/* --- the meeting page (meeting.html) ---------------------------------------------------------------------------------
 * One column of at most 30rem (52rem for the two-column pre-join) with a 16px gutter, so a 390px phone has no
 * horizontal scroll. Every rule is scoped under #gate: the page shares this file with the portal shell. */
main#gate { max-width: 30rem; margin: 0 auto; padding-block: 1.5rem 4rem; }
main#gate:has(#guest:not(.hidden)) { max-width: 52rem; }
#gate .brand { margin-bottom: 1rem; }
#gate .brand img { height: 1.6rem; max-width: 12rem; }
#gate .brand span.name { font-size: 1.1rem; font-weight: 600; }
#gate > .state { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.1rem; margin: 0 0 1rem; }
#gate > .state.center { display: grid; gap: .75rem; justify-items: center; text-align: center; }
#gate .center > * { margin: 0; }
#gate .center .actions { justify-content: center; margin-top: 0; }
#gate .recs { width: 100%; text-align: left; }
#gate h1 { font-size: 1.4rem; margin: 0 0 .3rem; overflow-wrap: anywhere; }
#gate h1:focus { outline: none; }
#gate h1:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 3px; border-radius: 4px; }
#gate h2 { margin: 1rem 0 .4rem; }
#gate p.sub { color: var(--muted); font-size: .9rem; margin: 0 0 1rem; }
#gate p.alt { color: var(--muted); font-size: .85rem; margin: 1rem 0 0; }
#gate .center p.sub { margin: 0; }
#gate .when { color: var(--muted); font-size: .95rem; margin: .2rem 0; }
#gate .count { font-size: 2rem; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: .02em; overflow-wrap: anywhere; margin: .4rem 0; }
#gate .actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1rem; }
#gate .field { margin: 0 0 .9rem; }
#gate form button.primary { margin-top: .75rem; }
#guest-form button.primary { width: 100%; }
#gate .note { margin: 0 0 .75rem; padding: .5rem .7rem; background: var(--accent-soft); border: 1px solid var(--line); border-left: 3px solid var(--accent-text); border-radius: 8px; font-size: .9rem; }
#m-msg { color: var(--danger); margin-top: .8rem; min-height: 1.2em; }

#gate p.alt button.link { padding: 0; }
/* Waiting. */
#gate #waiting { padding-block: 2.5rem; }
/* The portal's own pre-join. */
.pj-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: .75rem; align-items: start; }
.pj-media, .pj-form { min-width: 0; }
.pj-preview { position: relative; width: 100%; aspect-ratio: 16 / 9; max-height: 55vh; background: var(--tile); color: var(--tile-fg); border-radius: 12px; overflow: hidden; margin: 0 0 .75rem; }
.pj-preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); background: var(--tile); }
.pj-off { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--tile-fg); background: var(--tile); font-size: .85rem; }
.pj-toggles { display: flex; gap: .6rem; margin: 0 0 .75rem; }
.pj-toggles .toggle { flex: 1 1 0; min-width: 0; display: flex; align-items: center; justify-content: center; gap: .4rem; padding: .6rem .5rem; }
.pj-toggles .toggle[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent-text); }
.pj-toggles .toggle[aria-pressed="true"] .state { color: var(--accent-text); }
.pj-toggles .toggle.off .state { color: var(--danger); }
/* The microphone level: written as separate rules, because one unknown pseudo-element drops a whole selector list. */
#pj-meter { display: block; appearance: none; width: 100%; height: .4rem; margin-top: .5rem; border: 0; border-radius: 999px; background: var(--line); }
#pj-meter::-webkit-meter-bar { background: var(--line); border: 0; border-radius: 999px; height: .4rem; }
#pj-meter::-webkit-meter-optimum-value { background: var(--accent-text); border-radius: 999px; }
#pj-meter::-webkit-meter-suboptimum-value { background: var(--accent-text); border-radius: 999px; }
#pj-meter::-webkit-meter-even-less-good-value { background: var(--accent-text); border-radius: 999px; }
#pj-meter::-moz-meter-bar { background: var(--accent-text); border-radius: 999px; }
/* The shared recordings of the Before and Ended states. */
#gate .recs ul { list-style: none; margin: 0; padding: 0; }
#gate .recs li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; padding: .55rem 0; border-top: 1px solid var(--line); }
#gate .recs li .rec-msg { flex-basis: 100%; color: var(--muted); font-size: .85rem; }
@media (prefers-reduced-motion: no-preference) { .pj-off { transition: opacity .12s; } }

/* --- phones -------------------------------------------------------------------------------------------------------------- */
@media (max-width: 40rem) {
  #view-home .actions { grid-template-columns: 1fr; }
  #view-home .big { grid-auto-flow: column; justify-content: start; padding: .8rem 1rem; }
  #gate .count { font-size: 1.6rem; }
}
@media (max-width: 30rem) {
  #gate .actions button { flex: 1 1 100%; }
}
