/* archie on your phone. Rules: docs/layout_rules.md and docs/mobile_layout_recommendations.md.
   Touch targets are at least 44 px, readable text at least 13 px, and the main destinations are at the bottom. */
:root {
  --bg: #f5f6f8; --panel: #ffffff; --border: #e2e4e9; --text: #1c1f26; --muted: #656b76;
  --accent: #4F46E5; --accent-text: #ffffff; --danger: #c42b2b; --ok: #1f7a1f;
  /* fills for buttons that carry white text (same in both themes, each at least 4.5:1 against white) */
  --fill-ok: #1f7a1f; --fill-danger: #c42b2b; --fill-accent: #4F46E5; --fill-warn: #8a5600;
  /* the same names the admin UI uses (docs/layout_rules.md section 12: two apps, no shared file) */
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px; --space-6: 32px;
  --fs-sm: 0.8125rem; --fs-md: 0.9rem; --fs-base: 1rem; --fs-lg: 1.05rem;
  --radius: 12px; --radius-sm: 8px;
  --tabs-h: 0px; --kb: 0px; --bar-h: 0px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161b; --panel: #1c1f26; --border: #2c2f38; --text: #e8e9ec; --muted: #9aa0ab; --accent: #818CF8; --accent-text: #0c0d12;
    --danger: #f87171; --ok: #4ade80;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }  /* iOS must not enlarge the text of a row it thinks is wide */
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
body { overscroll-behavior-y: contain; min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); }
body.has-tabs { --tabs-h: 60px; }
body.has-replybar { --bar-h: 76px; }
header { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: var(--space-2); padding: 10px var(--space-4); padding-top: calc(10px + env(safe-area-inset-top)); background: var(--panel); border-bottom: 1px solid var(--border); }
header h1 { flex: 1; margin: 0; font-size: var(--fs-lg); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
main { padding: var(--space-4); padding-bottom: calc(var(--space-4) + var(--tabs-h) + var(--bar-h)); max-width: 640px; margin: 0 auto; }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button.icon { background: none; border: 0; font-size: 1.4rem; min-width: 44px; min-height: 44px; cursor: pointer; color: var(--text); }
.btn { display: inline-block; min-height: 44px; padding: 10px 18px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel); cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn.block { display: block; width: 100%; }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.danger-fill { background: var(--fill-danger); border-color: var(--fill-danger); color: #fff; font-weight: 600; }
input[type=email], input[type=password], input[type=text], input[type=search], input[type=number], input[type=url], input[type=date], select, textarea { width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel); min-height: 44px; }
textarea { min-height: 220px; resize: vertical; }
label.field { display: block; margin: 0 0 14px; font-size: var(--fs-md); color: var(--muted); }
label.field input, label.field textarea { margin-top: 4px; color: var(--text); }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: var(--space-3); }
.row { display: block; width: 100%; text-align: left; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; cursor: pointer; }
.row .who { font-weight: 600; }
.row .subj { margin-top: 2px; }
.row .snip { color: var(--muted); font-size: var(--fs-md); margin-top: 2px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pill { display: inline-block; font-size: var(--fs-sm); padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); margin-left: 6px; vertical-align: middle; }
.pill.draft { color: var(--ok); border-color: var(--ok); }
.pill.order { color: var(--accent); border-color: var(--accent); }
.muted { color: var(--muted); }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.info-toggle { flex: none; min-width: 44px; min-height: 44px; margin: -8px -8px -8px 0; background: none; border: 0; color: var(--muted); font-size: var(--fs-base); font-weight: 700; font-style: italic; font-family: Georgia, serif; cursor: pointer; }
.info-toggle::before { content: ""; }
.info-toggle[aria-expanded="true"] { color: var(--accent); }
.info-note { margin: 0 0 10px; font-size: var(--fs-md); }
.hint { background: var(--panel); border: 1px dashed var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; font-size: var(--fs-md); }
.hint button { float: right; background: none; border: 0; color: var(--muted); font-size: 1.4rem; line-height: 1; cursor: pointer; min-width: 44px; min-height: 44px; margin: -12px -14px 0 0; }
.error { color: var(--danger); margin: 8px 0; }
/* Someone else is working on this reply: who, why it matters, and Take over. */
.lock-notice { background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--fill-warn); border-radius: var(--radius); padding: 12px 14px; margin: var(--space-3) 0; }
.lock-notice .lock-title { font-weight: 600; }
.lock-notice .lock-title::before { content: "F512  "; }
.lock-notice .lock-where { font-size: var(--fs-sm); margin-top: 2px; }
.lock-notice p { margin: var(--space-2) 0 0; font-size: var(--fs-md); }
.original { white-space: pre-wrap; word-break: break-word; max-height: 40vh; overflow: auto; }
.switch { display: flex; align-items: flex-start; gap: var(--space-3); padding: 10px 0; min-height: 44px; }
.switch input { width: 24px; height: 24px; margin-top: 2px; flex: none; }
.actions { display: flex; gap: 10px; margin-top: var(--space-3); }
.actions .btn { flex: 1; }
.center { text-align: center; padding: var(--space-6) 0; }
a { color: var(--accent); }
.attachments .attachment { display: block; width: 100%; margin-top: 8px; text-align: left; overflow-wrap: anywhere; }
.html-view { width: 100%; height: 60vh; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; }
.small { font-size: var(--fs-md); margin-top: 6px; }
.num, .bignum, .cmp-right, .axis, .badge, .when { font-variant-numeric: tabular-nums; }

/* Toast, with an Undo button for anything that changed many records or closed a conversation */
#toast { position: fixed; left: var(--space-4); right: var(--space-4); bottom: calc(var(--space-4) + var(--tabs-h) + var(--bar-h) + env(safe-area-inset-bottom)); background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 10px; z-index: 5; display: flex; align-items: center; gap: var(--space-3); }
#toast[hidden] { display: none; }
#toast .msg { flex: 1; text-align: left; }
#toast button { background: none; border: 1px solid currentColor; border-radius: var(--radius-sm); color: inherit; font-weight: 700; min-height: 44px; min-width: 64px; padding: 0 var(--space-3); cursor: pointer; }

/* Busy strip, offline strip, update banner */
#busybar { position: fixed; top: 0; left: 0; right: 0; z-index: 6; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top)); background: var(--accent); color: var(--accent-text); font-weight: 600; }
#busybar[hidden] { display: none; }
.strip { padding: 8px var(--space-4); text-align: center; font-size: var(--fs-sm); font-weight: 600; }
.strip[hidden] { display: none; }
#offline { background: var(--fill-warn); color: #fff; }
#update { background: var(--accent); color: var(--accent-text); display: flex; align-items: center; justify-content: center; gap: var(--space-3); }
#update button { background: none; border: 1px solid currentColor; border-radius: var(--radius-sm); color: inherit; font-weight: 700; min-height: 44px; padding: 0 var(--space-4); cursor: pointer; }
.wheel.spin { display: inline-block; width: 22px; height: 22px; border: 3px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: archie-spin .8s linear infinite; margin-bottom: 10px; }
#busybar .wheel { width: 16px; height: 16px; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: archie-spin .8s linear infinite; }
.btn .wheel { display: inline-block; width: 14px; height: 14px; margin-right: 8px; vertical-align: -2px; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: archie-spin .8s linear infinite; }
@keyframes archie-spin { to { transform: rotate(360deg); } }
@keyframes archie-pulse { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }

/* Pull to refresh: a small pill that follows the finger, so the gesture is visible */
#ptr { position: fixed; left: 50%; top: calc(56px + env(safe-area-inset-top)); transform: translate(-50%, -80px); z-index: 4; background: var(--panel); border: 1px solid var(--border); border-radius: 999px; padding: 8px 16px; font-size: var(--fs-sm); box-shadow: 0 2px 8px rgba(0, 0, 0, .15); pointer-events: none; opacity: 0; }

/* Bottom tab bar: the main destinations, in the thumb zone */
#tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 3; display: flex; background: var(--panel); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
#tabs[hidden] { display: none; }
#tabs button span:not(.badge) { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#tabs button { flex: 1; min-height: 60px; min-width: 0; background: none; border: 0; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: var(--fs-sm); cursor: pointer; position: relative; padding: 6px 2px; }
#tabs button[aria-current="page"] { color: var(--accent); font-weight: 700; }
#tabs svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#tabs .badge { position: absolute; top: 4px; left: calc(50% + 4px); min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--fill-danger); color: #fff; font-size: var(--fs-sm); font-weight: 700; line-height: 20px; text-align: center; }
#tabs .badge[hidden] { display: none; }

/* The list rows */
.daynav { display: flex; gap: 6px; align-items: center; margin-top: 12px; }
.daynav .btn { padding: 10px 14px; flex: 0 0 auto; min-width: 44px; }
.daynav .btn:disabled { opacity: .4; }
.daynav .daypick { flex: 1 1 auto; min-width: 0; padding: 10px; font-size: var(--fs-base); border-radius: 10px; border: 1px solid var(--border); background: var(--panel); color: inherit; }
.swipe { position: relative; margin-bottom: 10px; border-radius: var(--radius); overflow: hidden; }
.rowcard { position: relative; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.swipe .row { position: relative; margin-bottom: 0; padding-right: 58px; }
.row.convo { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: var(--space-3); align-items: start; }
.row.convo .main { min-width: 0; }
.row.convo .subj { overflow-wrap: anywhere; }
.row.convo.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--border); color: var(--text); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: var(--fs-md); position: relative; }
.avatar .dot { position: absolute; right: -2px; bottom: -2px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--panel); background: var(--accent); }
.avatar .dot.draft { background: var(--ok); }
.avatar .dot.done { background: var(--muted); }
.row.convo .top { display: flex; align-items: baseline; gap: var(--space-2); }
.row.convo .top .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.convo .when { color: var(--muted); font-size: var(--fs-sm); flex: none; }
.more { position: absolute; right: 4px; top: 4px; width: 48px; height: 48px; background: none; border: 0; border-radius: 50%; font-size: 1.5rem; line-height: 1; color: var(--muted); cursor: pointer; z-index: 1; }
.swipe-acts { position: absolute; top: 0; bottom: 0; display: flex; width: 220px; }
.swipe-acts.left { left: 0; }
.swipe-acts.right { right: 0; }
.swipe-btn { flex: 1; border: 0; color: #fff; font-weight: 600; font-size: var(--fs-sm); line-height: 1.2; padding: 0 6px; cursor: pointer; overflow-wrap: anywhere; min-height: 44px; }
.swipe-btn:disabled { opacity: .6; }
.swipe-btn.ok { background: var(--fill-ok); }
.swipe-btn.danger { background: var(--fill-danger); }
.swipe-btn.accent { background: var(--fill-accent); }
.swipe-btn.warn { background: var(--fill-warn); }

/* Loading skeleton */
.skel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; display: grid; grid-template-columns: 40px 1fr; gap: var(--space-3); animation: archie-pulse 1.4s ease-in-out infinite; }
.skel i { display: block; background: var(--border); border-radius: 6px; height: 12px; margin: 6px 0; }
.skel i:first-child { height: 40px; width: 40px; border-radius: 50%; margin: 0; grid-row: span 3; }
.skel i.s { width: 55%; }
.state { text-align: center; padding: var(--space-5) var(--space-4); }
.state .btn { margin-top: var(--space-3); }

/* Bottom sheet: the same actions as a swipe, large and labelled */
.sheet-backdrop { position: fixed; inset: 0; z-index: 7; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--panel); width: 100%; max-width: 640px; border-radius: var(--radius) var(--radius) 0 0; padding: var(--space-3) var(--space-4); padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom)); }
.sheet h2 { font-size: var(--fs-base); margin: 0 0 var(--space-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet .opt { display: block; width: 100%; min-height: 52px; text-align: left; background: none; border: 0; border-top: 1px solid var(--border); padding: 0 var(--space-2); font-size: var(--fs-base); cursor: pointer; }
.sheet .opt.danger { color: var(--danger); }
.sheet .opt:disabled { opacity: .5; }

/* The reply bar: Save draft and Send reply stay on screen above the keyboard */
.replybar { position: fixed; left: 0; right: 0; bottom: var(--kb); z-index: 3; background: var(--panel); border-top: 1px solid var(--border); padding: var(--space-2) var(--space-4); padding-bottom: calc(var(--space-2) + env(safe-area-inset-bottom)); }
.replybar .inner { max-width: 640px; margin: 0 auto; }
.replybar .actions { margin-top: 0; }
.replybar .unsaved { font-size: var(--fs-sm); color: var(--muted); min-height: 1.2rem; }
.replybar .unsaved::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--fill-warn); margin-right: 6px; }
.replybar .unsaved:empty::before { display: none; }

/* Settings sections, folded like the admin UI */
details.fold { margin-bottom: var(--space-3); background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
details.fold > summary { cursor: pointer; list-style: none; min-height: 52px; display: flex; align-items: center; padding: 0 var(--space-3); font-weight: 600; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::before { content: "▸"; flex: none; display: inline-flex; align-items: center; justify-content: center; width: 2rem; height: 2rem; margin-right: var(--space-2); font-size: 1.5rem; line-height: 1; color: var(--text); transition: transform .15s; }
details.fold[open] > summary::before { transform: rotate(90deg); }
details.fold > .body { padding: 0 var(--space-4) var(--space-3); }
.meter { height: 8px; margin-top: 6px; background: var(--border); border-radius: 4px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); }

/* Sales page */
.bignum { font-size: 2.2rem; font-weight: 700; line-height: 1.15; }
.cmp { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-3); padding: 8px 0; border-bottom: 1px solid var(--border); }
.cmp:last-child { border-bottom: 0; }
.cmp-right { text-align: right; }
.delta { font-size: var(--fs-sm); font-weight: 600; }
.delta.up { color: var(--ok); }
.delta.down { color: var(--danger); }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 120px; margin-top: 10px; }
.bars button { flex: 1; height: 100%; display: flex; align-items: flex-end; background: none; border: 0; padding: 0; cursor: pointer; min-width: 0; }
.bars button span { display: block; width: 100%; background: var(--accent); min-height: 1px; border-radius: 2px 2px 0 0; }
.bars button[aria-pressed="true"] span { background: var(--text); }
.pill.late { color: var(--danger); border-color: var(--danger); }
.btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
h2.sect, h3.sect { font-size: var(--fs-lg); margin: var(--space-5) 0 var(--space-2); }
.linechart { display: block; width: 100%; height: auto; margin-top: var(--space-3); overflow: visible; }
input[type=range] { width: 100%; min-height: 44px; margin: var(--space-2) 0; accent-color: var(--accent); }
.brk { margin-top: var(--space-2); }
.hbar { height: 8px; background: var(--accent); border-radius: 4px; }
.bars-read { min-height: 1.4rem; margin-top: var(--space-2); font-size: var(--fs-sm); }
.axis { display: flex; justify-content: space-between; color: var(--muted); font-size: var(--fs-sm); margin-top: 4px; }
.actions.tabs { gap: 6px; }
.actions.tabs .btn { padding: 10px 6px; font-size: var(--fs-md); min-width: 0; line-height: 1.2; display: flex; align-items: center; justify-content: center; text-align: center; }

/* Wide screens (a tablet, or a phone on its side): the list stays on the left while a conversation is open */
#listpane { display: none; }
@media (min-width: 900px) {
  main { max-width: 1100px; }
  body.two-pane main { display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: var(--space-5); align-items: start; }
  body.two-pane #listpane { display: block; position: sticky; top: 72px; max-height: calc(100vh - 150px); overflow: auto; padding-right: var(--space-1); }
  body.two-pane #view { min-width: 0; }
  body:not(.two-pane) main { max-width: 640px; }
}

@media (prefers-reduced-motion: reduce) {
  .wheel, #busybar .wheel, .skel { animation-duration: 2.4s; }
  details.fold > summary::before, .rowcard { transition: none !important; }
}
.sr { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.tags { margin-top: 4px; }
.tags .pill { margin-left: 0; margin-right: 6px; }
.field-title { display: block; margin: 0 0 6px; font-size: var(--fs-md); color: var(--muted); }
.recips { margin: 0 0 12px; padding: 4px 12px; border: 1px solid var(--border); border-radius: 10px; }
.recip { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: var(--fs-md); color: var(--text); overflow-wrap: anywhere; }
.recip input { width: 20px; height: 20px; flex: 0 0 auto; margin: 0; }
.recips-pick { margin: 0 0 4px 30px; }
.card select { width: 100%; min-height: 44px; margin-top: 4px; padding: 8px 10px; font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 10px; }

/* Settings: six groups (folds), each with a one-line description, blocks inside them, and a search box above. */
.settings-search-wrap { position: sticky; top: 0; z-index: 2; padding: var(--space-2) 0 var(--space-3); background: var(--bg); }
.settings-search { width: 100%; font-size: var(--fs-base); }
details.fold > summary .ghead { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: var(--space-2) 0; }
details.fold > summary .gdesc { font-weight: 400; font-size: var(--fs-sm); line-height: 1.3; color: var(--muted); }
.sblock + .sblock { margin-top: var(--space-3); padding-top: var(--space-2); border-top: 1px solid var(--border); }
.sblock > h3.sub { margin: var(--space-2) 0 var(--space-1); font-size: var(--fs-base); font-weight: 600; }

details > summary { min-height: 44px; }
details:not(.fold) > summary { display: flex; align-items: center; cursor: pointer; }
.bars-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.bars-inner { box-sizing: border-box; }
.ticks { display: flex; gap: 2px; margin-top: 4px; color: var(--muted); font-size: var(--fs-sm); }
.ticks span { flex: 1 0 44px; min-width: 44px; text-align: center; }
.bars button { flex: 1 0 44px; min-width: 44px; }

/* A computer (docs/web_app_plan.md): one interface, with the menu down the side and the list beside the conversation. */
.wide-only { display: none !important; }
.bulkbar { margin: 0 0 var(--space-3); }
.bulkbar[hidden] { display: none; }
.select-toggle { margin-bottom: var(--space-3); }
.select-toggle[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.ticked-row { display: grid; grid-template-columns: 44px minmax(0, 1fr); align-items: start; }
.ticked-row .tick { display: flex; align-items: center; justify-content: center; min-height: 44px; min-width: 44px; cursor: pointer; }
.ticked-row .tick input { width: 20px; height: 20px; }
@media (min-width: 900px) {
  .wide-only { display: flex !important; }
  .narrow-only, .select-toggle { display: none !important; }
  body.has-tabs { --tabs-h: 0px; --side: 212px; }
  body.has-tabs header, body.has-tabs main { margin-left: var(--side); }
  body.has-tabs #tabs { top: 0; right: auto; width: var(--side); flex-direction: column; justify-content: flex-start; border-top: 0; border-right: 1px solid var(--border); overflow-y: auto; padding: var(--space-3) var(--space-2); gap: 2px; }
  body.has-tabs #tabs button { flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: var(--space-3); min-height: 44px; font-size: var(--fs-md); padding: 8px 12px; border-radius: 8px; }
  body.has-tabs #tabs button[aria-current="page"] { background: var(--bg); }
  body.has-tabs #tabs .badge { position: static; margin-left: auto; }
  body.has-tabs #menu { display: none; }
  body.has-tabs main { max-width: none; margin-right: 0; padding-left: var(--space-5); padding-right: var(--space-5); }
  body.has-tabs:not(.two-pane) main { max-width: calc(760px + var(--space-5) * 2); }
  body.two-pane #listpane { max-height: calc(100vh - 90px); }
  body.two-pane #view { max-width: 760px; }
  .pick { padding-top: 80px; }
}

