/* app.css — Local 651 Portal (SPEC §11, §14.3).
   Palette from the public site (AFSCME green #0E9C4C / deep #046A35, blue #0032A0).
   System fonts only (no web fonts). WCAG AA contrast in light and dark; visible focus;
   44px+ touch targets; prefers-reduced-motion respected. Loaded under style-src 'self':
   no inline styles anywhere — dynamic sizes are set through the CSSOM by app.js. */

:root {
  --green: #0E9C4C;
  --green-deep: #046A35;
  --green-tint: #E4F4EA;
  --blue: #0032A0;
  --blue-deep: #00227A;
  --blue-tint: #E7EDFB;

  --bg: #F3F7F4;
  --surface: #FFFFFF;
  --surface-2: #F7FAF8;
  --surface-3: #EDF2EE;
  --border: #DFE7E1;
  --border-strong: #B9C7BD;
  --ink: #16202B;
  --ink-soft: #4E5B67;
  --link: #0032A0;
  --accent-text: #046A35;
  --primary: #0A7F3E;            /* AFSCME green darkened: 5.1:1 with white text */
  --primary-hover: #046A35;
  --on-primary: #FFFFFF;
  --topbar: #046A35;
  --on-topbar: #FFFFFF;
  --badge: #0032A0;
  --on-badge: #FFFFFF;
  --danger: #B3261E;
  --danger-hover: #8C1D17;
  --danger-tint: #FDECEA;
  --warn-bg: #FFF4D6;
  --warn-border: #E3B341;
  --warn-ink: #4D3800;
  --info-bg: #E7EDFB;
  --info-border: #9DB2E8;
  --own-bubble: #E4F4EA;
  --own-border: #B8DEC7;
  --other-bubble: #FFFFFF;
  --focus: #0032A0;
  --shadow: 0 1px 2px rgba(22, 32, 43, .06), 0 6px 24px rgba(22, 32, 43, .08);
  --radius: 14px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
  --mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
  --body: var(--font);           /* scanner.css reads --body */
  --tap: 44px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0B1218;
    --surface: #131C24;
    --surface-2: #18232D;
    --surface-3: #1F2B37;
    --border: #2A3744;
    --border-strong: #46576A;
    --ink: #E8EEF2;
    --ink-soft: #A9B6C2;
    --link: #8DB8FF;
    --accent-text: #6FD49B;
    --primary: #0A7F3E;
    --primary-hover: #046A35;
    --topbar: #0F1A14;
    --on-topbar: #E8EEF2;
    --badge: #3567D6;
    --on-badge: #FFFFFF;
    --danger: #FF8A80;
    --danger-hover: #FFB4AB;
    --danger-tint: #3B1715;
    --warn-bg: #33290A;
    --warn-border: #8A6D1D;
    --warn-ink: #FFE08A;
    --info-bg: #142039;
    --info-border: #34518F;
    --own-bubble: #12372A;
    --own-border: #1E5A42;
    --other-bubble: #1A252F;
    --focus: #FFD34D;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: anywhere;
}

[hidden] { display: none !important; }

h1, h2, h3, p, ul, ol, figure { margin: 0; }
ul, ol { padding: 0; }

a { color: var(--link); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}
:focus:not(:focus-visible) { outline: none; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.skip-link {
  position: fixed; left: 8px; top: 8px; z-index: 1001;
  padding: 10px 16px; min-height: var(--tap);
  font: inherit; font-weight: 700;
  color: var(--ink); background: var(--surface);
  border: 2px solid var(--focus); border-radius: var(--radius-sm);
  transform: translateY(-200%);
}
.skip-link:focus { transform: none; }

.icon {
  width: 22px; height: 22px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-sm { width: 18px; height: 18px; }

/* ---- Boot (static HTML before app.js runs) ------------------------------------------------ */

.boot, .auth {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}
.boot-card { text-align: center; display: grid; gap: 10px; justify-items: center; max-width: 360px; }
.boot-title { font-weight: 800; font-size: 1.25rem; }
.boot-msg { color: var(--ink-soft); }
.boot-slow { color: var(--ink-soft); font-size: .9rem; opacity: 0; animation: reveal 0s linear 10s forwards; }
.boot-noscript { color: var(--danger); font-weight: 600; }
@keyframes reveal { to { opacity: 1; } }

.brand-mark {
  /* The official AFSCME mark (icon-192.png, white background) — never a home-made "651" lockup. */
  display: block;
  width: 48px; height: 48px;
  border-radius: 12px;
  background: #FFFFFF;
  object-fit: contain;
  flex: 0 0 auto;
}

/* ---- Buttons & form controls ------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  font: inherit;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn:disabled, .btn[aria-disabled='true'] { opacity: .55; cursor: not-allowed; }
.btn[aria-busy='true'] { cursor: progress; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-3); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: currentColor; }
.btn-danger:hover:not(:disabled) { background: var(--danger-tint); }
.btn-ghost { background: transparent; color: var(--ink); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); }
.btn-link {
  background: none; border: 0; padding: 8px 4px; min-height: var(--tap);
  color: var(--link); text-decoration: underline; font-weight: 600;
}
.btn-lg { min-height: 56px; font-size: 1.08rem; padding: 12px 22px; }
.btn-sm { min-height: 40px; padding: 6px 12px; font-size: .92rem; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: var(--tap); height: var(--tap);
  border-radius: var(--radius-sm);
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  flex: 0 0 auto;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-3); }
.icon-btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.btn-row-end { justify-content: flex-end; }

.stack { display: grid; gap: 16px; }
.stack-sm { display: grid; gap: 8px; }

.field { display: grid; gap: 6px; }
.field > label, .label { font-weight: 700; font-size: .95rem; }
.hint { color: var(--ink-soft); font-size: .9rem; }

input[type='text'], input[type='password'], input[type='email'], input[type='number'],
input[type='search'], select, textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  font: inherit;
  font-size: 16px;                 /* ≥16px stops iOS zooming on focus */
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
}
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--focus); }
input[aria-invalid='true'] { border-color: var(--danger); }
input[readonly] { background: var(--surface-2); }
select { appearance: auto; }

.pw-wrap { display: flex; gap: 8px; }
.pw-wrap input { flex: 1 1 auto; min-width: 0; }
.pw-toggle { flex: 0 0 auto; min-width: 72px; }

.code-input {
  font-family: var(--mono);
  font-size: 1.35rem !important;
  letter-spacing: .2em;
  text-align: center;
}

.check {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1.5px solid var(--border);
  cursor: pointer; font-weight: 600;
}
.check input { width: 24px; height: 24px; margin: 0; flex: 0 0 auto; accent-color: var(--primary); }

.form-error {
  color: var(--danger);
  background: var(--danger-tint);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-weight: 600;
}
.form-error ul { margin: 6px 0 0 18px; font-weight: 500; }

.notice {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  border: 1.5px solid var(--info-border);
  background: var(--info-bg);
}
.notice-warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-ink); }
.notice-ok { background: var(--green-tint); border-color: var(--own-border); color: var(--ink); }
@media (prefers-color-scheme: dark) { .notice-ok { background: var(--own-bubble); } }
.notice p + p { margin-top: 6px; }
.notice strong { font-weight: 800; }

.chip {
  display: inline-flex; align-items: center;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: .78rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase;
  background: var(--surface-3); color: var(--ink);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.chip-green { background: var(--green-tint); color: var(--green-deep); border-color: var(--own-border); }
.chip-blue { background: var(--blue-tint); color: var(--blue); border-color: var(--info-border); }
.chip-red { background: var(--danger-tint); color: var(--danger); border-color: currentColor; }
@media (prefers-color-scheme: dark) {
  .chip-green { background: var(--own-bubble); color: var(--accent-text); }
  .chip-blue { background: var(--info-bg); color: var(--link); }
}

.badge {
  display: inline-grid; place-items: center;
  min-width: 24px; height: 24px; padding: 0 7px;
  border-radius: 999px;
  background: var(--badge); color: var(--on-badge);
  font-size: .8rem; font-weight: 800; line-height: 1;
}

.muted { color: var(--ink-soft); }
.mono { font-family: var(--mono); }

/* ---- Auth screens ---------------------------------------------------------------------- */

.auth-card {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}
.auth-band { height: 8px; background: linear-gradient(90deg, var(--green) 0 55%, var(--blue) 55% 100%); }
.auth-inner { padding: 24px 22px 26px; display: grid; gap: 18px; }
.auth-brand { display: flex; gap: 12px; align-items: center; }
.auth-brand strong { display: block; font-weight: 900; letter-spacing: .01em; }
.auth-brand span span { display: block; color: var(--ink-soft); font-size: .92rem; }
.auth-title { font-size: 1.45rem; font-weight: 800; line-height: 1.25; }
.auth-sub { color: var(--ink-soft); }
.auth-foot { color: var(--ink-soft); font-size: .92rem; border-top: 1px solid var(--border); padding-top: 14px; }

.divider {
  display: flex; align-items: center; gap: 12px;
  color: var(--ink-soft); font-size: .9rem; font-weight: 600;
}
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.option {
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: grid; gap: 12px;
  background: var(--surface-2);
}
.option-recommended { border-color: var(--primary); }
.option-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.option-head h2 { font-size: 1.1rem; font-weight: 800; }

.steps { margin: 0; padding-left: 22px; display: grid; gap: 6px; }

.qr-wrap { display: grid; justify-items: center; gap: 6px; }
canvas.qr {
  width: 220px; height: auto; max-width: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-radius: 8px;
  background: #FFFFFF;
  border: 1px solid var(--border);
}

.secret-key {
  display: block;
  font-family: var(--mono);
  font-size: 1.12rem;
  letter-spacing: .06em;
  word-spacing: .3em;
  padding: 10px 12px;
  background: var(--surface-3);
  border-radius: var(--radius-sm);
  user-select: all;
  -webkit-user-select: all;
}

.codes {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  counter-reset: code;
}
.codes li {
  counter-increment: code;
  display: flex; gap: 8px; align-items: baseline;
  padding: 8px 10px;
  background: var(--surface-3);
  border-radius: 8px;
}
.codes li::before { content: counter(code) '.'; color: var(--ink-soft); font-size: .85rem; min-width: 1.6em; }
.codes code { font-family: var(--mono); font-size: 1rem; letter-spacing: .03em; white-space: nowrap; }
/* One column on phones so a code is never split across lines (easy to copy wrong). */
@media (max-width: 480px) { .codes { grid-template-columns: 1fr; } }

/* ---- App shell -------------------------------------------------------------------------- */

.shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  min-height: calc(56px + env(safe-area-inset-top));
  background: var(--topbar);
  color: var(--on-topbar);
}
.topbar .brand {
  display: flex; align-items: center; gap: 10px;
  color: inherit; text-decoration: none; font-weight: 900; letter-spacing: .01em;
  min-height: var(--tap); margin-right: auto;
}
.topbar .brand-mark { width: 34px; height: 34px; border-radius: 8px; box-shadow: 0 0 0 2px rgba(255, 255, 255, .7); }
.topbar :focus-visible { outline-color: #FFD34D; }
.topnav { display: flex; gap: 4px; }
.topnav a {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: var(--tap);
  padding: 6px 12px;
  color: inherit; text-decoration: none; font-weight: 700;
  border-radius: var(--radius-sm);
}
.topnav a:hover { background: rgba(255, 255, 255, .12); }
.topnav a[aria-current='page'] { background: rgba(0, 0, 0, .25); box-shadow: inset 0 -3px 0 #FFFFFF; }   /* darken: keeps white text ≥ 4.5:1 */
@media (prefers-color-scheme: dark) { .topnav a[aria-current='page'] { background: rgba(255, 255, 255, .16); } }
.topnav .badge { background: #FFFFFF; color: var(--green-deep); }
@media (max-width: 520px) {
  .topbar .brand-text { display: none; }
  .topnav a { padding: 6px 10px; }
  .topnav .nav-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

.banner {
  flex: 0 0 auto;
  padding: 8px 16px;
  font-weight: 600;
  text-align: center;
  background: var(--warn-bg);
  color: var(--warn-ink);
  border-bottom: 1px solid var(--warn-border);
}

.view {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.view:focus { outline: none; }

.page {
  max-width: 860px;
  margin: 0 auto;
  padding: 20px 16px calc(40px + env(safe-area-inset-bottom));
  display: grid;
  gap: 20px;
}
.page-title { font-size: 1.6rem; font-weight: 800; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  display: grid;
  gap: 14px;
}
.card > h2, .section-title { font-size: 1.15rem; font-weight: 800; }
.card h3 { font-size: 1rem; font-weight: 800; }
.card-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.sub-section { display: grid; gap: 10px; padding-top: 14px; border-top: 1px solid var(--border); }

.item-list { list-style: none; display: grid; gap: 10px; }
.item {
  display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.item-main { display: grid; gap: 2px; min-width: 0; flex: 1 1 220px; }
.item-title { font-weight: 700; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.item-meta { color: var(--ink-soft); font-size: .9rem; }
.empty { color: var(--ink-soft); padding: 8px 0; }

.loading { color: var(--ink-soft); display: flex; gap: 10px; align-items: center; }
.spinner {
  width: 18px; height: 18px;
  border: 3px solid var(--border-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

details.more > summary {
  cursor: pointer; font-weight: 700; color: var(--link);
  min-height: var(--tap); display: inline-flex; align-items: center;
  list-style: none;
}
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::after { content: ' ▾'; }
details.more[open] > summary::after { content: ' ▴'; }
details.more .btn-row { margin-top: 6px; }

/* ---- Tabs (admin) ------------------------------------------------------------------------ */

.tabs {
  display: flex; gap: 4px;
  overflow-x: auto;
  border-bottom: 2px solid var(--border);
  scrollbar-width: thin;
}
.tabs a {
  flex: 0 0 auto;
  display: inline-flex; align-items: center;
  min-height: var(--tap);
  padding: 8px 14px;
  color: var(--ink-soft);
  font-weight: 700;
  text-decoration: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
}
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current='page'] { color: var(--accent-text); border-bottom-color: var(--primary); }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th, table.data td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data th { background: var(--surface-2); font-weight: 800; white-space: nowrap; }
table.data tr:last-child td { border-bottom: 0; }
table.data td.nowrap { white-space: nowrap; }
table.data code { font-family: var(--mono); font-size: .85rem; word-break: break-all; }

.member-picks { list-style: none; display: grid; gap: 6px; max-height: 45vh; overflow: auto; padding: 2px; }
.member-picks label { display: flex; gap: 10px; align-items: center; min-height: var(--tap); padding: 4px 8px; border-radius: 8px; cursor: pointer; }
.member-picks label:hover { background: var(--surface-3); }
.member-picks input { width: 22px; height: 22px; accent-color: var(--primary); }

/* ---- Messaging layout -------------------------------------------------------------------- */

.msg-layout {
  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  height: 100%;
  min-height: 0;
}

.room-pane {
  display: flex; flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
}
.pane-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 12px 10px 16px;
  border-bottom: 1px solid var(--border);
}
.pane-title { font-size: 1.2rem; font-weight: 800; }
.room-scroll { flex: 1 1 auto; overflow-y: auto; min-height: 0; padding-bottom: env(safe-area-inset-bottom); }
.room-list { list-style: none; }
.room-link {
  display: flex; align-items: center; gap: 12px;
  min-height: 64px;
  padding: 10px 14px 10px 16px;
  color: var(--ink); text-decoration: none;
  border-bottom: 1px solid var(--border);
}
.room-link:hover { background: var(--surface-2); }
.room-link[aria-current='true'] { background: var(--green-tint); box-shadow: inset 4px 0 0 var(--primary); }
@media (prefers-color-scheme: dark) { .room-link[aria-current='true'] { background: var(--own-bubble); } }
.room-icon {
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--surface-3); color: var(--accent-text);
  flex: 0 0 auto;
}
.room-main { flex: 1 1 auto; min-width: 0; display: grid; }
.room-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-link.unread .room-name { font-weight: 900; }
.room-sub { color: var(--ink-soft); font-size: .86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-side { display: grid; justify-items: end; gap: 4px; flex: 0 0 auto; }
.room-time { color: var(--ink-soft); font-size: .8rem; }
.rooms-empty { padding: 20px 16px; color: var(--ink-soft); display: grid; gap: 12px; }

.convo-pane {
  display: flex; flex-direction: column;
  min-height: 0; min-width: 0;
  background: var(--bg);
  position: relative;
}
.convo-placeholder { margin: auto; padding: 24px; text-align: center; color: var(--ink-soft); display: grid; gap: 8px; justify-items: center; max-width: 380px; }
.convo-placeholder .icon { width: 44px; height: 44px; color: var(--border-strong); }

.convo-head {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  min-height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.convo-head .back-btn { display: none; }
.convo-title-wrap { min-width: 0; display: grid; }
.convo-title { font-size: 1.1rem; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo-members {
  justify-self: start;
  background: none; border: 0; padding: 0; font: inherit;
  color: var(--ink-soft); font-size: .86rem; cursor: pointer; text-align: left;
  min-height: 24px;
}
.convo-members:hover { text-decoration: underline; }

.convo-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
  padding: 12px 12px 16px;
  overscroll-behavior: contain;
}
.older-wrap { display: flex; justify-content: center; padding: 4px 0 12px; }
.msg-list { list-style: none; display: grid; gap: 2px; max-width: 900px; margin: 0 auto; }
.convo-status { text-align: center; color: var(--ink-soft); padding: 24px 12px; }

.day-sep { display: flex; align-items: center; gap: 12px; margin: 14px 0 8px; color: var(--ink-soft); font-size: .82rem; font-weight: 700; }
.day-sep::before, .day-sep::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.msg { display: grid; justify-items: start; margin-top: 10px; }
.msg.cont { margin-top: 2px; }
.msg.own { justify-items: end; }
.msg-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; padding: 0 4px 2px; font-size: .84rem; }
.msg.cont .msg-meta { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.msg-sender { font-weight: 800; }
.msg-time { color: var(--ink-soft); }
.msg-bubble {
  max-width: min(640px, 86%);
  background: var(--other-bubble);
  border: 1px solid var(--border);
  border-radius: 4px 16px 16px 16px;
  padding: 8px 12px;
  display: grid; gap: 8px;
}
.msg.own .msg-bubble { background: var(--own-bubble); border-color: var(--own-border); border-radius: 16px 4px 16px 16px; }
.msg.cont .msg-bubble { border-radius: 16px; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-text a { color: var(--link); }
/* Links show the ASCII form of the address (app.js linkify) and are isolated from the
   direction of the text around them, so bidi controls can't reorder what they display. */
.msg-unreadable { color: var(--ink-soft); font-style: italic; }
.msg-link { direction: ltr; unicode-bidi: isolate; overflow-wrap: anywhere; word-break: break-all; }

/* A person: display name (isolated) + the unique @username next to it. */
.person { display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 0 6px; min-width: 0; }
.person-name { unicode-bidi: isolate; }
.person-handle { color: var(--ink-soft); font-weight: 600; font-size: .9em; direction: ltr; unicode-bidi: isolate; }
.msg-files { list-style: none; display: grid; gap: 6px; }
.file-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  min-height: 52px;
  padding: 8px 12px;
  text-align: left;
  font: inherit; color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.file-btn:hover:not(:disabled) { border-color: var(--primary); }
.file-btn .file-text { display: grid; min-width: 0; flex: 1 1 auto; }
.file-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { color: var(--ink-soft); font-size: .84rem; }
.msg-del {
  background: none; border: 0; padding: 2px 4px; font: inherit; font-size: .82rem;
  color: var(--ink-soft); text-decoration: underline; cursor: pointer; min-height: 24px;
}
.msg-del:hover { color: var(--danger); }
.convo-empty { text-align: center; color: var(--ink-soft); padding: 32px 12px; }
@media (pointer: coarse) {
  .msg-del { min-height: 36px; padding: 6px 8px; }
  .convo-members { min-height: 32px; }
}

.jump-new {
  position: absolute;
  left: 50%; transform: translateX(-50%);
  bottom: 96px;
  z-index: 2;
  box-shadow: var(--shadow);
}

.composer {
  flex: 0 0 auto;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  display: grid; gap: 6px;
}
.composer-row { display: flex; align-items: flex-end; gap: 4px; max-width: 900px; width: 100%; margin: 0 auto; }
.composer-input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 48px !important;
  max-height: 40vh;
  resize: none;
  field-sizing: content;
  line-height: 1.4;
}
.composer-send { width: 52px; min-width: 52px; padding: 0; height: 48px; }
.composer-count { font-size: .82rem; color: var(--ink-soft); text-align: right; max-width: 900px; width: 100%; margin: 0 auto; }
.composer-count.over { color: var(--danger); font-weight: 700; }
.pending { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; max-width: 900px; width: 100%; margin: 0 auto; }
.pending-item {
  display: flex; align-items: center; gap: 8px;
  max-width: 100%;
  padding: 4px 4px 4px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  border: 1px solid var(--border);
}
.pending-item.error { border-color: var(--danger); }
.pending-text { display: grid; min-width: 0; }
.pending-name { font-weight: 700; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.pending-status { font-size: .8rem; color: var(--ink-soft); }
.pending-item.error .pending-status { color: var(--danger); font-weight: 700; }
.pending-item progress { width: 90px; height: 6px; accent-color: var(--primary); }

@media (max-width: 759px) {
  .msg-layout { grid-template-columns: 1fr; }
  .msg-layout[data-pane='list'] .convo-pane { display: none; }
  .msg-layout[data-pane='room'] .room-pane { display: none; }
  .room-pane { border-right: 0; }
  .convo-head .back-btn { display: inline-grid; }
  .msg-bubble { max-width: 92%; }
}

/* ---- Dialogs ------------------------------------------------------------------------------- */

dialog.modal {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  overflow: auto;
  overscroll-behavior: contain;
}
dialog.modal-wide { width: min(720px, calc(100vw - 24px)); }
dialog.modal::backdrop { background: rgba(8, 14, 20, .6); }
.modal-head {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 14px 10px 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 1.15rem; font-weight: 800; }
.modal-body { padding: 18px 20px 22px; display: grid; gap: 16px; }
.pick-list { list-style: none; display: grid; gap: 4px; max-height: 50vh; overflow-y: auto; }
.pick-btn {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 52px;
  padding: 8px 12px;
  font: inherit; font-weight: 700; color: var(--ink); text-align: left;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer;
}
.pick-btn:hover:not(:disabled) { border-color: var(--primary); }
.pick-btn .person { flex: 1 1 auto; }

.filters { display: flex; flex-wrap: wrap; gap: 12px; }
.filters .field { flex: 1 1 200px; min-width: 0; }
.filters select { width: 100%; }
.storage-bar { display: block; width: 100%; max-width: 320px; height: 8px; margin-top: 6px; accent-color: var(--primary); }

/* ---- Toasts ------------------------------------------------------------------------------- */

.toasts {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 1000;
  display: grid; gap: 8px;
  width: min(480px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: var(--bg);
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: toast-in .2s ease-out;
}
.toast-error { background: var(--danger); color: #FFFFFF; }
@media (prefers-color-scheme: dark) { .toast-error { background: #B3261E; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---- Motion ------------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  .boot-slow { animation-delay: 10s !important; }
  .spinner { animation: none; border-top-color: var(--border-strong); }
}

@media (forced-colors: active) {
  .btn, .file-btn, .pick-btn, .icon-btn { border: 1px solid ButtonText; }
  .badge { border: 1px solid CanvasText; }
}

@media print {
  .topbar, .composer, .toasts, .room-pane, .btn, .icon-btn { display: none !important; }
  .shell, .view { height: auto; overflow: visible; }
}
