/* TextNow Scheduler */
:root {
  color-scheme: light;
  --paper: #EEF2F1;
  --surface: #FFFFFF;
  --sunk: #E2E8E6;
  --ink: #17262B;
  --muted: #56676C;
  --line: #D1DAD8;
  --bubble: #1F6F5C;
  --bubble-ink: #FFFFFF;
  --bubble-tint: #DFEEE8;
  --danger: #B3261E;
  --danger-tint: #FBE8E6;
  --warn: #7A5600;
  --warn-tint: #FAF0D7;
  --amber: #C58B00;
  --focus: #0B57D0;
  --body: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --display: Bahnschrift, "DIN Alternate", "Barlow Semi Condensed", "Segoe UI", system-ui, sans-serif;
  --mono: "Cascadia Mono", Consolas, "SF Mono", ui-monospace, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #0F1719;
    --surface: #162124;
    --sunk: #1D2A2D;
    --ink: #DCE6E4;
    --muted: #96A7A9;
    --line: #2A3A3D;
    --bubble: #2F8F76;
    --bubble-ink: #FFFFFF;
    --bubble-tint: #1A3530;
    --danger: #F2867E;
    --danger-tint: #3A1E1C;
    --warn: #E6B652;
    --warn-tint: #33290F;
    --focus: #8AB4F8;
  }
}

* { box-sizing: border-box; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 1rem/1.5 var(--body); }
h1, h2, h3 { font-family: var(--display); font-weight: 600; line-height: 1.15; margin: 0; }
h1 { font-size: 1.9rem; letter-spacing: -0.01em; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; margin-top: 22px; margin-bottom: 8px; }
p { margin: 0 0 10px; }
a { color: var(--bubble); }
code, .mono { font-family: var(--mono); font-size: .88em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -9999px; top: 8px; z-index: 50; background: var(--surface); padding: 6px 10px; border-radius: 6px; }
.skip:focus { left: 8px; }
.hint, .muted { color: var(--muted); font-size: .87rem; font-weight: 400; }
.err-line { color: var(--danger); font-size: .87rem; }
.warn-line { color: var(--warn); font-size: .87rem; }
.num { font-family: var(--display); font-variant-numeric: tabular-nums; font-size: 1.03rem; }

/* ---- buttons and inputs ---- */
.btn {
  font: inherit; font-weight: 600; line-height: 1.2;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn.primary { background: var(--bubble); border-color: var(--bubble); color: var(--bubble-ink); }
.btn.danger { color: var(--danger); }
.btn.quiet { background: transparent; border-color: transparent; color: var(--muted); font-weight: 500; }
.btn.small { padding: 5px 10px; font-size: .88rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

input[type=text], input[type=search], input[type=password], input[type=number], input[type=datetime-local],
input:not([type]), select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0;
}
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
textarea { resize: vertical; line-height: 1.45; }
input[type=checkbox], input[type=radio] { accent-color: var(--bubble); width: 16px; height: 16px; margin: 0; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend, .flabel, .field > label { font-weight: 600; font-size: .92rem; padding: 0; }
.field { display: grid; gap: 6px; margin-bottom: 16px; align-content: start; }
.check, .radio { display: inline-flex; align-items: center; gap: 8px; font-weight: 400; margin-right: 16px; cursor: pointer; }
.check.small { font-size: .88rem; margin-right: 10px; }

.switch { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; }
.switch input {
  appearance: none; -webkit-appearance: none; width: 40px; height: 22px; border-radius: 999px;
  background: var(--line); position: relative; cursor: pointer; flex: none; transition: background .15s;
}
.switch input::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
}
.switch input:checked { background: var(--bubble); }
.switch input:checked::after { transform: translateX(18px); }

/* ---- frame ---- */
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-family: var(--display); font-weight: 600; font-size: 1.15rem; }
.conn {
  margin-left: auto; display: inline-flex; align-items: center; gap: 8px; max-width: 46vw;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  border-radius: 999px; padding: 5px 13px; font: inherit; font-size: .9rem; cursor: pointer;
}
.conn span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; display: inline-block; }
[data-state=ready] .dot, .dot.ready { background: var(--bubble); box-shadow: 0 0 0 3px var(--bubble-tint); }
[data-state=error] .dot, [data-state=stopped] .dot, .dot.error { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-tint); }
[data-state=connecting] .dot, [data-state=login] .dot, [data-state=refreshing] .dot, [data-state=sending] .dot, .dot.busy { background: var(--amber); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.who { display: flex; align-items: center; gap: 6px; margin: 0; }
.who-name { color: var(--muted); }

.shell { display: grid; grid-template-columns: 188px minmax(0, 1fr); min-height: calc(100vh - 53px); }
.side { padding: 18px 10px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.side a { color: var(--ink); text-decoration: none; padding: 8px 12px; border-radius: 8px; }
.side a[aria-current=page] { background: var(--surface); font-weight: 600; box-shadow: inset 3px 0 0 var(--bubble); }
#view { padding: 26px 34px 72px; max-width: 1120px; outline: none; }

.viewhead { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.viewhead p { margin: 8px 0 0; color: var(--muted); max-width: 68ch; }
.section { margin-top: 34px; }
.section.first { margin-top: 0; }
.section > h2 { margin-bottom: 8px; }
.section > p { color: var(--muted); max-width: 70ch; }
.callout { padding: 10px 14px; border-radius: 8px; background: var(--warn-tint); color: var(--warn); max-width: 70ch; }

/* ---- outbox ---- */
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.toolbar input[type=search] { width: 280px; }
.tabs { display: inline-flex; background: var(--sunk); border-radius: 10px; padding: 3px; flex-wrap: wrap; }
.tabs button { font: inherit; border: 0; background: transparent; padding: 6px 14px; border-radius: 8px; color: var(--muted); cursor: pointer; }
.tabs button[aria-selected=true] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(23, 38, 43, .14); }
.tabs .n { font-family: var(--display); font-variant-numeric: tabular-nums; margin-left: 7px; color: var(--muted); font-weight: 400; }

.bulkbar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 12px; margin: 10px 0 4px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; position: sticky; top: 62px; z-index: 5;
}
.bulkbar strong { margin-right: 6px; }

.day { display: flex; align-items: baseline; gap: 12px; margin: 26px 0 4px; font-size: 1.02rem; font-weight: 500; color: var(--muted); }
.day::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.msg { display: grid; grid-template-columns: 26px 98px minmax(0, 580px) minmax(180px, 260px); gap: 4px 14px; align-items: start; padding: 10px 6px; border-radius: 10px; }
.pick { padding-top: 11px; display: flex; justify-content: center; cursor: pointer; }
.when { padding-top: 5px; display: grid; }
.clock { font-family: var(--display); font-size: 1.25rem; font-variant-numeric: tabular-nums; line-height: 1.15; }
.rel, .rep { color: var(--muted); font-size: .84rem; line-height: 1.35; }
.meta { padding-top: 7px; display: grid; gap: 5px; justify-items: start; font-size: .9rem; min-width: 0; }
.meta .err-line { overflow-wrap: anywhere; }
.to { font-variant-numeric: tabular-nums; }

.bubble {
  display: block; width: fit-content; max-width: min(560px, 100%); min-width: 7rem; text-align: left;
  font: inherit; line-height: 1.42; padding: 9px 14px 10px; cursor: pointer;
  border-radius: 18px 18px 5px 18px; border: 1.5px solid var(--bubble);
  background: var(--bubble); color: var(--bubble-ink);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.bubble.queued { background: var(--bubble-tint); color: var(--ink); border-style: dashed; }
.bubble.paused { background: transparent; color: var(--muted); border-color: var(--muted); border-style: dashed; }
.bubble.failed { background: var(--danger-tint); color: var(--ink); border-color: var(--danger); }
.bubble.muted { background: var(--sunk); color: var(--muted); border-color: var(--line); }
.bubble .lbl { display: block; font-size: .8rem; font-weight: 600; opacity: .78; margin-bottom: 2px; white-space: normal; }
.bubble .txt { display: -webkit-box; -webkit-line-clamp: 4; line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.bubble.full { cursor: default; max-width: 100%; }
.bubble.full .txt { display: block; }
.bubble .pics { display: flex; gap: 6px; margin-top: 8px; }
.bubble .pics img { width: 56px; height: 56px; object-fit: cover; border-radius: 9px; display: block; }
.bubble .pics .more { align-self: center; font-size: .85rem; }

.badge { display: inline-flex; align-items: center; font-size: .8rem; font-weight: 600; padding: 2px 10px; border-radius: 999px; background: var(--sunk); color: var(--ink); white-space: nowrap; }
.badge.scheduled, .badge.sending { background: var(--bubble-tint); color: var(--bubble); }
.badge.sent, .badge.completed { background: var(--bubble); color: var(--bubble-ink); }
.badge.failed, .badge.partial { background: var(--danger-tint); color: var(--danger); }
.badge.paused, .badge.missed, .badge.retrying { background: var(--warn-tint); color: var(--warn); }

.empty { padding: 36px 0; max-width: 48ch; }
.empty .empty-title { font-family: var(--display); font-size: 1.25rem; margin-bottom: 4px; }
.empty p { color: var(--muted); }
.empty .btn { margin-top: 8px; }

/* ---- dialogs ---- */
dialog { border: 0; padding: 0; color: var(--ink); background: var(--surface); }
dialog::backdrop { background: rgba(8, 18, 20, .45); }
.sheet { margin: 0 0 0 auto; height: 100vh; max-height: 100vh; width: min(580px, 100vw); max-width: 100vw; box-shadow: -10px 0 40px rgba(0, 0, 0, .18); overflow: auto; }
.sheet[open] { animation: slidein .18s ease-out; }
@keyframes slidein { from { transform: translateX(28px); opacity: .5; } to { transform: none; opacity: 1; } }
.sheet-head, .composer-head {
  display: flex; align-items: center; gap: 12px; padding: 16px 22px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.sheet-head h2, .composer-head h2 { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.close { font-size: 1.1rem; padding: 4px 10px; }
.sheet-body { padding: 20px 22px 32px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 6px; }
.facts { display: grid; grid-template-columns: 128px minmax(0, 1fr); gap: 7px 16px; margin: 18px 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.full-pics { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.full-pics img { max-width: 168px; max-height: 168px; border-radius: 10px; display: block; }
.runs { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.run { border-left: 3px solid var(--line); padding: 2px 0 2px 12px; }
.run.ok { border-color: var(--bubble); }
.run.failed, .run.partial { border-color: var(--danger); }
.run.retrying, .run.missed { border-color: var(--amber); }
.run-items { list-style: none; margin: 4px 0 0; padding: 0; font-size: .88rem; }
.run-items .bad { color: var(--danger); }

.composer { width: min(680px, calc(100vw - 20px)); max-height: calc(100vh - 32px); border-radius: 14px; box-shadow: 0 24px 64px rgba(0, 0, 0, .28); }
.composer[open] { animation: rise .16s ease-out; }
@keyframes rise { from { transform: translateY(10px); opacity: .5; } to { transform: none; opacity: 1; } }
.composer form { display: flex; flex-direction: column; max-height: calc(100vh - 32px); margin: 0; }
.composer-body { padding: 18px 22px 6px; overflow: auto; }
.composer-foot { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--line); }
.composer-foot .summary { margin: 0 auto 0 0; color: var(--muted); font-size: .9rem; }
.form-error { background: var(--danger-tint); color: var(--danger); padding: 10px 12px; border-radius: 8px; margin-bottom: 16px; white-space: pre-line; }
.when-row { display: flex; gap: 6px 4px; align-items: center; flex-wrap: wrap; }
.when-row input[type=datetime-local] { width: auto; min-width: 230px; }
.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days label { cursor: pointer; }
.days input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.days span { display: inline-block; padding: 5px 11px; border-radius: 999px; border: 1px solid var(--line); font-size: .9rem; }
.days input:checked + span { background: var(--bubble); border-color: var(--bubble); color: var(--bubble-ink); }
.days input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: .84rem; padding: 2px 10px; border-radius: 999px; background: var(--bubble-tint); color: var(--bubble); font-variant-numeric: tabular-nums; }
.chip.bad { background: var(--danger-tint); color: var(--danger); }
.pic-list { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.pic { position: relative; width: 84px; height: 84px; border-radius: 10px; overflow: hidden; background: var(--sunk); }
.pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pic.uploading img { opacity: .45; }
.pic .state { position: absolute; left: 4px; bottom: 4px; font-size: .72rem; background: rgba(0, 0, 0, .65); color: #fff; padding: 1px 6px; border-radius: 6px; }
.pic .x { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 50%; background: rgba(0, 0, 0, .6); color: #fff; cursor: pointer; font-size: .8rem; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }

/* ---- tables and forms on the other pages ---- */
.table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-weight: 600; font-size: .86rem; color: var(--muted); background: var(--paper); }
.table tr:last-child td { border-bottom: 0; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.table select.mini { width: auto; padding: 3px 6px; font-size: .85rem; margin-top: 4px; display: block; }
.wrap { overflow-x: auto; }
.addrow { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 14px 0; }
.addrow input { width: auto; flex: 1 1 200px; }
.addrow .checks { flex-basis: 100%; }
.token-form { display: grid; grid-template-columns: minmax(180px, 1.2fr) minmax(250px, 1.6fr) minmax(130px, .8fr) auto; gap: 0 18px; align-items: end; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px 0; margin-bottom: 18px; }
.token-form fieldset { display: flex; flex-wrap: wrap; gap: 6px 0; align-items: center; }
.token-form legend { margin-bottom: 6px; }
.reveal { border: 1.5px dashed var(--bubble); background: var(--bubble-tint); padding: 14px 16px; border-radius: 12px; margin: 0 0 18px; }
.reveal code { display: block; word-break: break-all; font-size: .95rem; padding: 10px 0 2px; color: var(--ink); user-select: all; }
.settings-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0 22px; max-width: 900px; }
.settings-form .end { grid-column: 1 / -1; }
.status-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 20px 6px; max-width: 760px; }
.status-card .facts { margin: 12px 0 0; }
.conn-line { display: flex; align-items: center; gap: 10px; font-size: 1.05rem; }
.log { font-family: var(--mono); font-size: .82rem; line-height: 1.6; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; max-height: 72vh; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
.log .WARN { color: var(--warn); }
.log .ERROR { color: var(--danger); }
pre.code { font-family: var(--mono); font-size: .84rem; line-height: 1.55; background: #132220; color: #D9E8E3; padding: 12px 16px; border-radius: 10px; overflow-x: auto; margin: 8px 0 14px; max-width: 100%; }
.endpoints td:first-child { white-space: nowrap; font-family: var(--mono); font-size: .84rem; }
.endpoints td:nth-child(2) { white-space: nowrap; }

/* ---- toasts ---- */
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 100; width: max-content; max-width: calc(100vw - 24px); }
.toast { background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); }
.toast.bad { background: var(--danger); color: #fff; }

/* ---- sign in / sign out ---- */
body.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-panel { width: min(400px, 100%); }
.auth-panel h1 { font-size: 2.1rem; }
.auth-demo { display: grid; gap: 10px; margin-bottom: 30px; }
.demo-row { display: flex; align-items: center; gap: 12px; }
.demo-time { font-family: var(--display); font-variant-numeric: tabular-nums; color: var(--muted); width: 46px; }
.bubble.demo { cursor: default; }
.auth-sub { color: var(--muted); margin: 8px 0 22px; }
.auth-form { display: grid; gap: 6px; }
.auth-form label { font-weight: 600; font-size: .92rem; }
.auth-form input { margin-bottom: 10px; }
.auth-form .btn { margin-top: 6px; padding: 10px; }
.auth-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.notice { padding: 10px 12px; border-radius: 8px; background: var(--bubble-tint); color: var(--bubble); margin: 0 0 18px; }
.notice.error { background: var(--danger-tint); color: var(--danger); }
.auth-foot { color: var(--muted); font-size: .86rem; margin-top: 22px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.listen { align-self: start; padding: 9px 0; overflow-wrap: anywhere; }

/* ---- shared touch and small-screen pieces ---- */
@media (hover: hover) {
  .btn:hover { border-color: var(--muted); }
  .btn.primary:hover { filter: brightness(1.08); }
  .btn.danger:hover { border-color: var(--danger); }
  .btn.quiet:hover { color: var(--ink); border-color: transparent; background: var(--sunk); }
  .side a:hover { background: var(--sunk); }
  .msg:hover { background: var(--sunk); }
}
a, button, label, summary { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.btn:active { filter: brightness(.94); }
input[type=search] { -webkit-appearance: none; appearance: none; }
select {
  -webkit-appearance: none; appearance: none; padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%236B7B80' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; background-size: 12px 8px;
}
body:has(dialog[open]) { overflow: hidden; }
.offscreen { position: fixed; top: 0; left: -9999px; font-size: 16px; }
.tabbar, .fab { display: none; }
.sheet { height: 100vh; height: 100dvh; max-height: 100vh; max-height: 100dvh; }
.topbar { padding-left: max(20px, env(safe-area-inset-left)); padding-right: max(20px, env(safe-area-inset-right)); }

/* Touchscreens of any size (phones, tablets, touch laptops): bigger targets; 16px text stops iOS zooming into fields */
@media (pointer: coarse) {
  html { font-size: 16px; }
  input[type=text], input[type=search], input[type=password], input[type=number], input[type=datetime-local], input:not([type]), select, textarea { font-size: 16px; min-height: 44px; }
  .btn { min-height: 44px; padding: 10px 16px; }
  .btn.small { min-height: 38px; padding: 7px 12px; }
  .close { min-width: 44px; }
  input[type=checkbox], input[type=radio] { width: 22px; height: 22px; }
  .pick { padding: 6px 0 0; min-height: 44px; align-items: flex-start; }
  .tabs button { min-height: 40px; }
  .days span { padding: 9px 14px; }
  .check, .radio { min-height: 40px; }
  .switch input { width: 46px; height: 26px; }
  .switch input::after { width: 20px; height: 20px; }
  .switch input:checked::after { transform: translateX(20px); }
  .table select.mini { min-height: 40px; font-size: 16px; }
  .conn { min-height: 40px; }
}

/* Tablets and narrow windows: slimmer sidebar, message details under the bubble */
@media (max-width: 1023px) {
  .shell { grid-template-columns: 158px minmax(0, 1fr); }
  #view { padding: 22px 24px 64px; }
  .msg { grid-template-columns: 28px 92px minmax(0, 1fr); }
  .msg .meta { grid-column: 3; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding-top: 2px; }
  .msg .meta .err-line, .msg .meta .warn-line { flex-basis: 100%; }
  .token-form { grid-template-columns: 1fr 1fr; }
  .token-form .field:last-child { grid-column: 1 / -1; }
  .table.stack-md thead { display: none; }
  .table.stack-md, .table.stack-md tbody, .table.stack-md tr, .table.stack-md td { display: block; }
  .table.stack-md tr { padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .table.stack-md tr:last-child { border-bottom: 0; }
  .table.stack-md td { border: 0; padding: 3px 0; }
  .table.stack-md td[data-label] { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 10px; align-items: baseline; }
  .table.stack-md td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .86rem; }
  .table.stack-md td.head { padding-bottom: 6px; }
  .table.stack-md .row-actions { justify-content: flex-start; padding-top: 8px; }
}

/* Phones: bottom tab bar, one column, full-screen panels */
@media (max-width: 700px) {
  html { font-size: 16px; }
  .shell { grid-template-columns: minmax(0, 1fr); min-height: 0; }
  .side { display: none; }
  .topbar { gap: 10px; padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: 8px; padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
  .brand span, .who-name { display: none; }
  .conn { flex: 1 1 auto; min-width: 0; max-width: none; margin-left: 0; justify-content: flex-start; }
  .who .btn { padding-left: 8px; padding-right: 8px; }
  #view { padding: 16px max(14px, env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); }
  h1 { font-size: 1.65rem; }
  .viewhead { margin-bottom: 14px; }

  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 0 7px; min-height: 56px; color: var(--muted); text-decoration: none; font-size: .72rem; }
  .tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .tabbar a[aria-current=page] { color: var(--bubble); font-weight: 600; }
  .tabbar a[aria-current=page] svg { stroke-width: 2.2; }

  .new-top { display: none; }
  .fab {
    display: grid; place-items: center; position: fixed; z-index: 25; width: 58px; height: 58px; border: 0; padding: 0;
    right: max(16px, env(safe-area-inset-right)); bottom: calc(74px + env(safe-area-inset-bottom));
    border-radius: 20px 20px 6px 20px; background: var(--bubble); color: var(--bubble-ink); cursor: pointer;
    box-shadow: 0 6px 18px rgba(15, 50, 42, .32);
  }
  .fab svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
  #view:has(.bulkbar:not([hidden])) .fab { display: none; }

  .toolbar { gap: 10px; }
  .tabs { display: flex; width: 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { flex: 1 0 auto; padding: 6px 10px; }
  .tabs .n { margin-left: 5px; }
  .toolbar input[type=search] { width: 100%; }
  .bulkbar {
    position: fixed; top: auto; left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right));
    bottom: calc(66px + env(safe-area-inset-bottom)); margin: 0; z-index: 26; box-shadow: 0 6px 22px rgba(0, 0, 0, .18);
  }
  .day { margin-top: 20px; }
  .msg { grid-template-columns: 30px minmax(0, 1fr); gap: 4px 10px; padding: 10px 2px; }
  .msg .pick { grid-row: 1 / span 3; }
  .msg .when { display: flex; gap: 4px 10px; align-items: baseline; flex-wrap: wrap; padding-top: 4px; }
  .msg .meta { grid-column: 2; }
  .bubble { max-width: 100%; }

  .sheet { width: 100vw; box-shadow: none; }
  .sheet-head, .composer-head { padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left)); }
  .sheet-body { padding: 16px max(16px, env(safe-area-inset-right)) calc(28px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
  .composer { width: 100vw; max-width: 100vw; height: 100vh; height: 100dvh; max-height: 100vh; max-height: 100dvh; margin: 0; border-radius: 0; box-shadow: none; }
  .composer form { height: 100%; max-height: none; }
  .composer-body { flex: 1 1 auto; padding: 16px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left)); }
  .composer-foot { flex-wrap: wrap; padding: 10px max(16px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
  .composer-foot .summary { flex-basis: 100%; margin: 0 0 2px; font-size: .85rem; }
  .composer-foot .btn { flex: 1 1 0; }
  .when-row input[type=datetime-local] { flex-basis: 100%; min-width: 0; width: 100%; }
  .two, .token-form { grid-template-columns: 1fr; }
  .token-form .field:last-child { grid-column: auto; }
  .token-form .btn { width: 100%; }
  .facts { grid-template-columns: 1fr; gap: 0; }
  .facts dd { margin-bottom: 8px; }
  .addrow input { flex-basis: 100%; }
  .addrow .btn { flex: 1 1 auto; }
  .pic { width: 76px; height: 76px; }

  .table.stack thead { display: none; }
  .table.stack, .table.stack tbody, .table.stack tr, .table.stack td { display: block; }
  .table.stack tr { padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .table.stack tr:last-child { border-bottom: 0; }
  .table.stack td { border: 0; padding: 3px 0; }
  .table.stack td:empty { display: none; }
  .table.stack td[data-label] { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 10px; align-items: baseline; }
  .table.stack td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .86rem; }
  .table.stack td.head { padding-bottom: 6px; }
  .table.stack .row-actions { justify-content: flex-start; padding-top: 8px; }
  .endpoints td.head { white-space: normal; overflow-wrap: anywhere; }

  .log { font-size: .76rem; max-height: none; }
  pre.code { font-size: .76rem; padding: 10px 12px; }
  .toasts { bottom: calc(80px + env(safe-area-inset-bottom)); }
  .status-card { padding: 14px 16px 4px; }
  body.auth { padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom)); place-items: start center; }
  .auth-panel { margin-top: 6vh; }
}