/* =====================================================================
   Components + app shell. Uses tokens.css only.
   Naming: .c-name for components, .is-* for states, .v-* not used;
   variants are modifier classes listed in DESIGN.md.
   ===================================================================== */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font-sans); font-size: var(--text-md); line-height: var(--lh-md);
  color: var(--color-ink); background: var(--color-canvas);
  font-feature-settings: "cv11", "ss01"; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: var(--text-2xl); line-height: var(--lh-2xl); font-weight: var(--weight-semibold); letter-spacing: -0.015em; }
h2 { font-size: var(--text-xl); line-height: var(--lh-xl); font-weight: var(--weight-semibold); letter-spacing: -0.01em; }
h3 { font-size: var(--text-lg); line-height: var(--lh-lg); font-weight: var(--weight-semibold); }
h4 { font-size: var(--text-sm); line-height: var(--lh-sm); font-weight: var(--weight-semibold); color: var(--color-ink-2); }
a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible, .is-focus { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--color-ink-2); }
.meta { color: var(--color-ink-3); font-size: var(--text-xs); line-height: var(--lh-xs); }
.small { font-size: var(--text-sm); line-height: var(--lh-sm); }
.strong { font-weight: var(--weight-semibold); }
.truncate { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; min-width: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.stack { display: flex; flex-direction: column; }
.row-flex { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.spacer { flex: 1; }
.gap-1 { gap: var(--space-1); } .gap-2 { gap: var(--space-2); } .gap-3 { gap: var(--space-3); } .gap-4 { gap: var(--space-4); } .gap-5 { gap: var(--space-5); }
.hide { display: none !important; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
svg.i-sm { width: 16px; height: 16px; }
svg.i-lg { width: 22px; height: 22px; }
svg.i-xl { width: 28px; height: 28px; }

/* ---------------------------------------------------------------------
   Buttons: primary / secondary (default) / tertiary(ghost) + danger, call
   --------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: var(--control-h); padding: 0 var(--space-3); border-radius: var(--radius-sm);
  border: 1px solid var(--color-line-strong); background: var(--color-surface); color: var(--color-ink);
  font-size: var(--text-md); font-weight: var(--weight-medium); white-space: nowrap; text-decoration: none;
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast), color var(--dur-fast), transform var(--dur-fast);
}
.btn:hover, .btn.is-hover { background: var(--color-surface-2); text-decoration: none; }
.btn:active, .btn.is-active { background: var(--color-surface-3); transform: translateY(0.5px); }
.btn-primary { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-ink-inverse); }
.btn-primary:hover, .btn-primary.is-hover { background: var(--color-accent-hover); border-color: var(--color-accent-hover); }
.btn-primary:active, .btn-primary.is-active { background: var(--color-accent-pressed); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--color-ink-2); }
.btn-ghost:hover, .btn-ghost.is-hover { background: var(--color-surface-2); color: var(--color-ink); }
.btn-danger { background: var(--color-danger); border-color: var(--color-danger); color: #fff; }
.btn-danger:hover, .btn-danger.is-hover { background: var(--color-danger-hover); border-color: var(--color-danger-hover); }
.btn-danger-quiet { color: var(--color-bad); }
.btn-call { background: var(--color-call); border-color: var(--color-call); color: #fff; }
.btn-call:hover, .btn-call.is-hover { background: var(--color-call-hover); }
.btn[disabled], .btn.is-disabled { opacity: 1; background: var(--color-surface-2); border-color: var(--color-line); color: var(--color-ink-3); cursor: not-allowed; transform: none; }
.btn-ghost[disabled] { background: transparent; border-color: transparent; }
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after { content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-color: rgba(255,255,255,.9) rgba(255,255,255,.9) transparent transparent; animation: spin .8s linear infinite; }
.btn:not(.btn-primary):not(.btn-danger):not(.btn-call).is-loading::after { border-color: var(--color-ink-2) var(--color-ink-2) transparent transparent; }
.btn-lg { height: var(--control-h-touch); padding: 0 var(--space-4); font-size: var(--text-lg); }
.btn-sm { height: 28px; padding: 0 var(--space-2); font-size: var(--text-sm); }
.btn-icon { width: var(--control-h); padding: 0; }
.btn-icon.btn-lg { width: var(--control-h-touch); }
.btn-block { width: 100%; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .btn.is-loading::after { animation-duration: 2.4s; } }

/* ---------------------------------------------------------------------
   Form controls
   --------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-size: var(--text-sm); line-height: var(--lh-sm); font-weight: var(--weight-medium); color: var(--color-ink); }
.hint, .field .hint { font-size: var(--text-sm); line-height: var(--lh-sm); color: var(--color-ink-3); }
.field .error { font-size: var(--text-sm); line-height: var(--lh-sm); color: var(--color-bad); display: flex; gap: 6px; align-items: flex-start; }
.input, .select, .textarea {
  width: 100%; height: var(--control-h); padding: 0 var(--space-3); border: 1px solid var(--color-control-border);
  border-radius: var(--radius-sm); background: var(--color-surface); font-size: var(--text-md); color: var(--color-ink);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.textarea { height: auto; min-height: 88px; padding: var(--space-2) var(--space-3); resize: vertical; line-height: var(--lh-md); }
.select { appearance: none; padding-right: 32px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23464c57' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
.input::placeholder, .textarea::placeholder { color: var(--color-ink-3); }
.input:hover, .select:hover, .textarea:hover, .input.is-hover { border-color: var(--color-ink-2); }
.input:focus, .select:focus, .textarea:focus, .input.is-focus { outline: none; border-color: var(--color-accent); box-shadow: 0 0 0 3px rgba(34, 81, 204, .18); }
.input.is-invalid, .select.is-invalid, .textarea.is-invalid { border-color: var(--color-bad); }
.input.is-invalid:focus { box-shadow: 0 0 0 3px rgba(180, 35, 24, .16); }
.input[disabled], .select[disabled], .textarea[disabled] { background: var(--color-surface-2); color: var(--color-ink-3); border-color: var(--color-line); cursor: not-allowed; }
.input[readonly] { background: var(--color-surface-2); }
.input-group { display: flex; align-items: stretch; }
.input-group .addon { display: inline-flex; align-items: center; padding: 0 var(--space-3); border: 1px solid var(--color-control-border); border-right: 0; border-radius: var(--radius-sm) 0 0 var(--radius-sm); background: var(--color-surface-2); color: var(--color-ink-2); font-size: var(--text-md); }
.input-group .input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.check { display: inline-flex; align-items: flex-start; gap: var(--space-2); font-size: var(--text-md); cursor: pointer; min-height: 24px; }
.check input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--color-accent); flex: none; }
.switch { position: relative; display: inline-flex; width: 36px; height: 20px; flex: none; }
.switch input { position: absolute; inset: -12px -6px; width: auto; height: auto; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: var(--radius-pill); background: var(--color-control-border); transition: background var(--dur-fast); }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-1); transition: transform var(--dur-fast) var(--ease-out); }
.switch input:checked + span { background: var(--color-accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { box-shadow: var(--focus-ring); }
.switch input:disabled + span { opacity: .5; }

/* Segmented control (view switch, pipeline switch on phone) */
.seg { display: inline-flex; padding: 2px; border-radius: var(--radius-sm); background: var(--color-surface-2); border: 1px solid var(--color-line); gap: 2px; }
.seg button, .seg a { border: 0; background: transparent; height: 30px; padding: 0 var(--space-3); border-radius: 4px; font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-ink-2); display: inline-flex; align-items: center; gap: 6px; text-decoration: none; white-space: nowrap; }
.seg button:hover, .seg a:hover { color: var(--color-ink); text-decoration: none; }
.seg [aria-pressed="true"], .seg [aria-current="page"], .seg [aria-selected="true"] { background: var(--color-surface); color: var(--color-ink); box-shadow: var(--shadow-1); }

/* Tabs (underline): page-level sub views */
.tabs { display: flex; gap: var(--space-5); border-bottom: 1px solid var(--color-line); padding: 0 var(--space-5); min-height: 44px; align-items: stretch; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a, .tabs button { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; padding: 0; color: var(--color-ink-2); font-weight: var(--weight-medium); font-size: var(--text-md); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; text-decoration: none; }
.tabs a:hover, .tabs button:hover { color: var(--color-ink); text-decoration: none; }
.tabs [aria-selected="true"], .tabs [aria-current="page"] { color: var(--color-ink); border-bottom-color: var(--color-ink); }
.tabs .count { font-size: var(--text-xs); color: var(--color-ink-3); font-weight: var(--weight-medium); }

/* ---------------------------------------------------------------------
   Pills, tags, avatars, marks
   --------------------------------------------------------------------- */
.pill { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 var(--space-2); border-radius: var(--radius-pill); font-size: var(--text-xs); line-height: 1; font-weight: var(--weight-semibold); white-space: nowrap; background: var(--color-hist-bg); color: var(--color-hist); }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.pill.no-dot::before { display: none; }
.pill-good { background: var(--color-good-bg); color: var(--color-good); }
.pill-wait { background: var(--color-wait-bg); color: var(--color-wait); }
.pill-attn { background: var(--color-attn-bg); color: var(--color-attn); }
.pill-bad  { background: var(--color-bad-bg);  color: var(--color-bad); }
.pill-hist { background: var(--color-hist-bg); color: var(--color-hist); }
.pill-outline { background: transparent; box-shadow: inset 0 0 0 1px var(--color-line-strong); color: var(--color-ink-2); }
.tag { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 var(--space-2); border-radius: var(--radius-sm); background: var(--color-surface-2); color: var(--color-ink-2); font-size: var(--text-xs); font-weight: var(--weight-medium); white-space: nowrap; }
.doctype { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 var(--space-2); border-radius: var(--radius-sm); font-size: var(--text-xs); font-weight: var(--weight-bold); letter-spacing: .08em; text-transform: uppercase; }
.doctype.quote { background: var(--color-quote-bg); color: var(--color-quote); }
.doctype.invoice { background: var(--color-invoice); color: #fff; }
.doctype-lg { white-space: nowrap; height: 28px; font-size: var(--text-sm); padding: 0 var(--space-3); }
.avatar { --av: 32px; width: var(--av); height: var(--av); border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; flex: none; background: var(--color-surface-3); color: var(--color-ink-2); font-size: calc(var(--av) * .38); font-weight: var(--weight-semibold); letter-spacing: .01em; }
.avatar.sm { --av: 24px; } .avatar.lg { --av: 48px; } .avatar.xl { --av: 72px; }
.avatar .i { width: 55%; height: 55%; }
.avatar-stack { display: inline-flex; } .avatar-stack .avatar { box-shadow: 0 0 0 2px var(--color-surface); margin-left: -6px; } .avatar-stack .avatar:first-child { margin-left: 0; }
.ws-mark { --m: 28px; width: var(--m); height: var(--m); border-radius: var(--radius-sm); display: inline-flex; align-items: center; justify-content: center; flex: none; color: #fff; font-size: calc(var(--m) * .4); font-weight: var(--weight-bold); letter-spacing: .02em; background: var(--ws, #464c57); }
.ws-mark.lg { --m: 40px; } .ws-mark.sm { --m: 22px; border-radius: 4px; }
.chan { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: var(--radius-sm); background: var(--color-surface-2); color: var(--color-ink); flex: none; }
.chan .i { width: 16px; height: 16px; }
.chan.missed { background: var(--color-attn-bg); color: var(--color-attn); }
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--radius-pill); background: var(--color-ink); color: #fff; font-size: var(--text-xs); font-weight: var(--weight-semibold); line-height: 1; }
.badge.bad { background: var(--color-ink); }
.badge.quiet { background: var(--color-surface-3); color: var(--color-ink-2); }
.kbd { display: inline-flex; align-items: center; height: 20px; padding: 0 6px; border: 1px solid var(--color-line-strong); border-bottom-width: 2px; border-radius: 4px; font-size: var(--text-xs); color: var(--color-ink-2); background: var(--color-surface); font-family: var(--font-sans); }
.demo-label { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-xs); color: var(--color-ink-3); }

/* ---------------------------------------------------------------------
   Surfaces
   --------------------------------------------------------------------- */
.card { background: var(--color-surface); border: 1px solid var(--color-line); border-radius: var(--radius-md); }
.card-pad { padding: var(--space-4); }
.card-head { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-line); min-height: 48px; }
.card-head h3 { font-size: var(--text-md); line-height: var(--lh-md); }
.divider { height: 1px; background: var(--color-line); border: 0; margin: 0; }
.dl { display: grid; grid-template-columns: minmax(96px, 128px) 1fr; gap: var(--space-2) var(--space-4); font-size: var(--text-md); margin: 0; }
.dl dt { color: var(--color-ink-3); font-size: var(--text-sm); line-height: var(--lh-md); }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* Banners: page-level, inline, never blocking */
.banner { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); font-size: var(--text-md); background: var(--color-wait-bg); color: var(--color-ink); border: 1px solid transparent; }
.banner > .i { margin-top: 1px; color: var(--color-wait); }
.banner .banner-body { flex: 1; min-width: 0; }
.banner .banner-title { font-weight: var(--weight-semibold); }
.banner .banner-actions { display: flex; gap: var(--space-2); flex: none; align-self: center; }
.banner-attn { background: var(--color-attn-bg); } .banner-attn > .i { color: var(--color-attn); }
.banner-bad { background: var(--color-bad-bg); } .banner-bad > .i { color: var(--color-bad); }
.banner-good { background: var(--color-good-bg); } .banner-good > .i { color: var(--color-good); }
.banner-flat { border-radius: 0; border-width: 0 0 1px; border-color: var(--color-line); }

/* Save state indicator (editor header, forms) */
.savestate { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-sm); color: var(--color-ink-3); white-space: nowrap; height: 28px; padding: 0 var(--space-2); border-radius: var(--radius-sm); border: 0; background: transparent; }
.savestate .i { width: 16px; height: 16px; }
.savestate.saved .i { color: var(--color-good); }
.savestate.saving .i { animation: spin 1s linear infinite; }
.savestate.queued { background: var(--color-attn-bg); color: var(--color-attn); font-weight: var(--weight-medium); }
.savestate.failed { background: var(--color-bad-bg); color: var(--color-bad); font-weight: var(--weight-medium); }
@media (prefers-reduced-motion: reduce) { .savestate.saving .i { animation: none; } }

/* Connection chip (shell): only appears when not normal */
.conn { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 var(--space-2); border-radius: var(--radius-pill); font-size: var(--text-sm); font-weight: var(--weight-medium); background: var(--color-attn-bg); color: var(--color-attn); border: 0; white-space: nowrap; }
.conn .i { width: 16px; height: 16px; }

/* Toast */
.toast-wrap { position: fixed; z-index: var(--z-toast); left: 50%; bottom: var(--space-5); transform: translateX(-50%); display: flex; flex-direction: column; gap: var(--space-2); align-items: center; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: var(--space-3); min-height: 44px; padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4); border-radius: var(--radius-md); background: var(--color-ink); color: #fff; box-shadow: var(--shadow-2); font-size: var(--text-md); max-width: min(560px, calc(100vw - 32px)); }
.toast .btn-ghost { color: #c9d6ff; } .toast .btn-ghost:hover { background: rgba(255,255,255,.08); color: #fff; }
.toast .i { color: #8fe3b4; }
@media (prefers-reduced-motion: no-preference) { .toast { animation: toast-in var(--dur-base) var(--ease-out); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* Menus / popovers */
.menu { position: absolute; z-index: var(--z-popover); min-width: 240px; padding: var(--space-1); background: var(--color-surface); border: 1px solid var(--color-line); border-radius: var(--radius-md); box-shadow: var(--shadow-2); }
.menu-item { display: flex; align-items: center; gap: var(--space-3); width: 100%; min-height: 36px; padding: var(--space-2); border: 0; background: none; border-radius: var(--radius-sm); text-align: left; color: var(--color-ink); text-decoration: none; font-size: var(--text-md); }
.menu-item:hover, .menu-item.is-active, .menu-item.is-hover { background: var(--color-surface-2); text-decoration: none; }
.menu-item[aria-checked="true"] .check-i { visibility: visible; }
.menu-item .check-i { visibility: hidden; color: var(--color-accent); margin-left: auto; }
.menu-sep { height: 1px; background: var(--color-line); margin: var(--space-1) 0; }
.menu-label { padding: var(--space-2) var(--space-2) var(--space-1); font-size: var(--text-xs); font-weight: var(--weight-semibold); color: var(--color-ink-3); }
@media (prefers-reduced-motion: no-preference) { .menu, .drawer, .modal { animation: pop-in var(--dur-base) var(--ease-out); } }
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px); } }

/* Overlays */
.scrim { position: fixed; inset: 0; background: var(--color-scrim); z-index: var(--z-modal); display: flex; align-items: center; justify-content: center; padding: var(--space-4); }
.scrim.for-drawer { z-index: var(--z-drawer); background: rgba(22,24,29,.24); justify-content: flex-end; padding: 0; align-items: stretch; }
.modal { width: min(480px, 100%); background: var(--color-surface); border-radius: var(--radius-md); box-shadow: var(--shadow-3); display: flex; flex-direction: column; max-height: calc(100% - 32px); }
.modal-head { padding: var(--space-5) var(--space-5) 0; display: flex; gap: var(--space-3); align-items: flex-start; }
.modal-head h2 { font-size: var(--text-xl); }
.modal-body { padding: var(--space-4) var(--space-5); overflow: auto; display: flex; flex-direction: column; gap: var(--space-4); }
.modal-foot { padding: var(--space-4) var(--space-5) var(--space-5); display: flex; gap: var(--space-2); justify-content: flex-end; }
.drawer { width: min(480px, 100%); height: 100%; background: var(--color-surface); box-shadow: var(--shadow-3); display: flex; flex-direction: column; min-height: 0; }
.drawer-head { height: var(--pane-header-h); padding: 0 var(--space-3) 0 var(--space-5); display: flex; align-items: center; gap: var(--space-2); border-bottom: 1px solid var(--color-line); flex: none; }
.drawer-body { flex: 1; min-height: 0; overflow: auto; padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-5); }
.drawer-foot { flex: none; padding: var(--space-3) var(--space-5); border-top: 1px solid var(--color-line); display: flex; gap: var(--space-2); justify-content: flex-end; }
.sheet-handle { width: 36px; height: 4px; border-radius: 2px; background: var(--color-line-strong); margin: var(--space-2) auto 0; }

/* Skeletons */
.skel { background: linear-gradient(90deg, var(--color-surface-3) 0%, #d9dce2 50%, var(--color-surface-3) 100%); background-size: 200% 100%; border-radius: 4px; height: 12px; }
@media (prefers-reduced-motion: no-preference) { .skel { animation: shimmer 1.4s ease-in-out infinite; } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* Empty / error states (centred block inside a pane) */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--space-3); padding: var(--space-7) var(--space-5); margin: auto; max-width: 360px; }
.empty .empty-icon { width: 48px; height: 48px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--color-surface-2); color: var(--color-ink-2); }
.empty.is-error .empty-icon { background: var(--color-bad-bg); color: var(--color-bad); }
.empty h3 { font-size: var(--text-lg); }
.empty p { color: var(--color-ink-2); }

/* Table */
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--text-md); }
.table th { text-align: left; font-size: var(--text-xs); font-weight: var(--weight-semibold); color: var(--color-ink-3); padding: 0 var(--space-3); height: 36px; border-bottom: 1px solid var(--color-line); white-space: nowrap; background: var(--color-surface); position: sticky; top: 0; z-index: 1; }
.table td { padding: 0 var(--space-3); height: 52px; border-bottom: 1px solid var(--color-line); vertical-align: middle; }
.table tr.clickable { cursor: pointer; }
.table tbody tr:hover td { background: var(--color-surface-2); }
.table th:first-child, .table td:first-child { padding-left: var(--space-5); }
.table th:last-child, .table td:last-child { padding-right: var(--space-5); }
.table .r { text-align: right; }
.table .c2 { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

/* =====================================================================
   APP SHELL
   Desktop >=1200: sidebar 240. 768-1199: rail 76. <768: phone shell.
   The shell is pinned to screen edges (position:fixed; inset:0) at every
   width, per the mobile full-height app shell rule. Panes scroll inside.
   ===================================================================== */
.app { position: fixed; inset: 0; display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); background: var(--color-canvas); }
.sidebar { display: flex; flex-direction: column; min-height: 0; background: var(--color-canvas); border-right: 1px solid var(--color-line); padding: var(--space-3) var(--space-2); gap: var(--space-1); }
.ws-switch { display: flex; align-items: center; gap: var(--space-2); width: 100%; min-height: 44px; padding: var(--space-2); border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent; text-align: left; }
.ws-switch:hover { background: var(--color-surface-2); }
.ws-switch[aria-expanded="true"] { background: var(--color-surface); border-color: var(--color-line); }
.ws-switch .ws-name { font-weight: var(--weight-semibold); font-size: var(--text-md); line-height: var(--lh-md); }
.ws-switch .ws-sub { font-size: var(--text-xs); color: var(--color-ink-3); }
.side-search { display: flex; align-items: center; gap: var(--space-2); height: 36px; margin: var(--space-1) 0 var(--space-2); padding: 0 var(--space-2) 0 var(--space-3); border: 1px solid var(--color-line); border-radius: var(--radius-sm); background: var(--color-surface); color: var(--color-ink-3); font-size: var(--text-md); width: 100%; text-align: left; }
.side-search:hover { border-color: var(--color-line-strong); }
.side-search .kbd { margin-left: auto; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: var(--space-3); height: 36px; padding: 0 var(--space-2) 0 var(--space-3); border-radius: var(--radius-sm); color: var(--color-ink-2); font-weight: var(--weight-medium); text-decoration: none; position: relative; }
.nav a:hover { background: var(--color-surface-2); color: var(--color-ink); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--color-surface); color: var(--color-ink); box-shadow: inset 0 0 0 1px var(--color-line); }
.nav a .badge { margin-left: auto; }
.nav .nav-label { flex: 1; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--color-line); padding-top: var(--space-2); }
.phone-status { display: flex; align-items: center; gap: var(--space-3); min-height: 36px; padding: 0 var(--space-2) 0 var(--space-3); font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-ink-2); border-radius: var(--radius-sm); border: 0; background: none; width: 100%; text-align: left; }
.phone-status .ps-icon { position: relative; display: inline-flex; width: 18px; height: 18px; flex: none; }
.phone-status .ps-icon .dot { position: absolute; right: -3px; bottom: -2px; box-shadow: 0 0 0 2px var(--color-canvas); }
.phone-status:hover { background: var(--color-surface-2); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--color-good); flex: none; }
.dot.attn { background: #c77700; } .dot.bad { background: var(--color-bad); } .dot.off { background: var(--color-ink-3); }
.me { display: flex; align-items: center; gap: var(--space-3); min-height: 44px; padding: 0 var(--space-2) 0 9px; border-radius: var(--radius-sm); }
.me .me-name { font-size: var(--text-sm); font-weight: var(--weight-medium); }
.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; position: relative; }
.phone-head, .tabbar { display: none; }

/* Page scaffolding */
.page { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--color-surface); }
.page-head { height: var(--pane-header-h); flex: none; display: flex; align-items: center; gap: var(--space-3); padding: 0 var(--space-5); border-bottom: 1px solid var(--color-line); background: var(--color-surface); }
.page-head h1 { font-size: var(--text-xl); line-height: var(--lh-xl); }
.page-head .head-actions { margin-left: auto; display: flex; gap: var(--space-2); align-items: center; }
.page-body { flex: 1; min-height: 0; overflow: auto; }
.toolbar { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-3) var(--space-5); border-bottom: 1px solid var(--color-line); flex: none; flex-wrap: wrap; }
.search { position: relative; display: flex; align-items: center; min-width: 0; }
.search .i { position: absolute; left: 10px; color: var(--color-ink-3); pointer-events: none; }
.search .input { padding-left: 34px; }
.panes { flex: 1; min-height: 0; display: grid; }
.pane { min-height: 0; min-width: 0; display: flex; flex-direction: column; background: var(--color-surface); }
.pane + .pane { border-left: 1px solid var(--color-line); }
.pane-head { height: var(--pane-header-h); flex: none; display: flex; align-items: center; gap: var(--space-2); padding: 0 var(--space-4); border-bottom: 1px solid var(--color-line); min-width: 0; }
.pane-head h2 { font-size: var(--text-lg); line-height: var(--lh-lg); }
.pane-body { flex: 1; min-height: 0; overflow: auto; }
.back-btn { display: none; }

/* ---------------------------------------------------------------------
   Lists: conversation rows, contact rows
   --------------------------------------------------------------------- */
.list { list-style: none; margin: 0; padding: 0; }
.item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 2px var(--space-3); padding: 10px var(--space-4) 10px var(--space-5); border-bottom: 1px solid var(--color-line); text-decoration: none; color: inherit; position: relative; align-items: baseline; }
.item:hover, .item.is-hover { background: var(--color-surface-2); text-decoration: none; }
.item[aria-current="true"] { background: var(--color-surface-2); }
.item[aria-current="true"]::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--color-ink); }
.item .who { font-weight: var(--weight-semibold); font-size: var(--text-md); line-height: var(--lh-md); }
/* Unread has exactly one signal: the 8px dot at the row edge (screen readers get "Unread" text). */
.item.unread::after { content: ""; position: absolute; left: 8px; top: 18px; width: 8px; height: 8px; border-radius: 50%; background: var(--color-accent); }
.item .when { font-size: var(--text-xs); color: var(--color-ink-3); white-space: nowrap; line-height: var(--lh-md); }
.item .subj { grid-column: 2 / 4; font-size: var(--text-sm); line-height: var(--lh-sm); color: var(--color-ink); }
.item .snip { grid-column: 2 / 4; font-size: var(--text-sm); line-height: var(--lh-sm); color: var(--color-ink-3); }
.item .via { grid-column: 2 / 4; display: block; font-size: var(--text-xs); line-height: var(--lh-xs); color: var(--color-ink-3); margin-top: 2px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; min-width: 0; }
.item .lead { grid-row: 1 / 4; align-self: start; }
.unread-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--color-accent); display: inline-block; }

/* ---------------------------------------------------------------------
   Thread + composer
   --------------------------------------------------------------------- */
.thread { padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-4); max-width: 820px; width: 100%; margin: 0 auto; }
.msg { border: 1px solid var(--color-line); border-radius: var(--radius-md); background: var(--color-surface); }
.msg-head { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-3) var(--space-4); }
.msg-head .msg-from { font-weight: var(--weight-semibold); }
.msg-head .msg-addr { color: var(--color-ink-3); font-size: var(--text-sm); line-height: var(--lh-sm); overflow-wrap: break-word; }
.msg-body { padding: 0 var(--space-4) var(--space-4) calc(var(--space-4) + 32px + var(--space-3)); line-height: 1.55; max-width: 72ch; }
.msg-body p + p { margin-top: var(--space-3); }
.msg.out { background: var(--color-surface-2); border-color: var(--color-line); }
.msg.out .avatar { background: var(--color-surface); color: var(--color-ink-2); box-shadow: inset 0 0 0 1px var(--color-line); }
.msg-addr .to { white-space: nowrap; }
.msg-head .you { font-weight: var(--weight-regular); color: var(--color-ink-3); }
.msg .attach { display: inline-flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); border: 1px solid var(--color-line); border-radius: var(--radius-sm); font-size: var(--text-sm); margin-top: var(--space-3); background: var(--color-surface); }
.bubble-row { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.bubble-row.out { align-items: flex-end; }
.bubble { max-width: min(72%, 520px); padding: var(--space-2) var(--space-3); border-radius: 14px 14px 14px 4px; background: var(--color-surface-2); line-height: 1.45; }
.bubble-row.out .bubble { border-radius: 14px 14px 4px 14px; background: var(--color-ink); color: #fff; }
.event { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); border: 1px dashed var(--color-line-strong); font-size: var(--text-sm); color: var(--color-ink-2); }
.day-sep { display: flex; align-items: center; gap: var(--space-3); font-size: var(--text-xs); color: var(--color-ink-3); font-weight: var(--weight-semibold); }
.day-sep::before, .day-sep::after { content: ""; flex: 1; height: 1px; background: var(--color-line); }
.composer { flex: none; border-top: 1px solid var(--color-line); background: var(--color-surface); padding: var(--space-3) var(--space-5); box-shadow: 0 -4px 12px rgba(22,24,29,.04); position: relative; }
.composer-box { border: 1px solid var(--color-control-border); border-radius: var(--radius-md); background: var(--color-surface); max-width: 820px; margin: 0 auto; }
.composer-box:focus-within { border-color: var(--color-accent); box-shadow: 0 0 0 3px rgba(34,81,204,.14); }
.reply-as { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-2) var(--space-2) var(--space-3); border-bottom: 1px solid var(--color-line); font-size: var(--text-sm); min-width: 0; flex-wrap: wrap; }
.reply-as .ra-label { color: var(--color-ink-3); }
.from-btn { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 var(--space-2); border: 1px solid var(--color-line); border-radius: var(--radius-sm); background: var(--color-surface); font-size: var(--text-sm); font-weight: var(--weight-medium); max-width: 100%; min-width: 0; }
.from-btn:hover { background: var(--color-surface-2); }
.from-btn .addr { color: var(--color-ink-2); font-weight: var(--weight-regular); }
.from-btn .fb-text { display: inline-flex; gap: 6px; min-width: 0; align-items: baseline; }
.composer textarea { display: block; width: 100%; border: 0; resize: none; padding: var(--space-2) var(--space-3); min-height: 40px; transition: min-height var(--dur-base) var(--ease-out); font-size: var(--text-md); line-height: 1.5; background: transparent; }
.composer textarea:focus { outline: none; box-shadow: none; }
.composer-foot { display: flex; align-items: center; gap: var(--space-2); padding: 0 var(--space-2) var(--space-2) var(--space-3); }
.composer-foot .sig { font-size: var(--text-xs); color: var(--color-ink-3); }

/* Context panel (contact summary next to a thread) */
.ctx { padding: var(--space-5) var(--space-4); display: flex; flex-direction: column; gap: var(--space-5); }
.ctx-section { display: flex; flex-direction: column; gap: var(--space-2); }
.link-row { display: flex; align-items: center; gap: var(--space-2); min-height: 40px; padding: var(--space-2) var(--space-3); border: 1px solid var(--color-line); border-radius: var(--radius-sm); text-decoration: none; color: inherit; }
.link-row:hover { background: var(--color-surface-2); text-decoration: none; }

/* ---------------------------------------------------------------------
   Timeline (contact record)
   --------------------------------------------------------------------- */
.tl { list-style: none; margin: 0; padding: 0; position: relative; }
.tl::before { content: ""; position: absolute; left: 15px; top: 8px; bottom: 8px; width: 1px; background: var(--color-line); }
.tl-item { position: relative; display: grid; grid-template-columns: 32px minmax(0,1fr); gap: var(--space-3); padding: var(--space-2) 0 var(--space-4); }
.tl-icon { width: 32px; height: 32px; border-radius: 50%; background: var(--color-surface); border: 1px solid var(--color-line); display: inline-flex; align-items: center; justify-content: center; color: var(--color-ink-2); position: relative; z-index: 1; }
.tl-icon.good { background: var(--color-good-bg); border-color: transparent; color: var(--color-good); }
.tl-icon.bad { background: var(--color-bad-bg); border-color: transparent; color: var(--color-bad); }
.tl-icon.wait { background: var(--color-wait-bg); border-color: transparent; color: var(--color-wait); }
.tl-icon .i { width: 16px; height: 16px; }
.tl-head { display: flex; align-items: baseline; gap: var(--space-2); flex-wrap: wrap; padding-top: 6px; }
.tl-head .t { font-weight: var(--weight-medium); }
.tl-head .w { font-size: var(--text-xs); color: var(--color-ink-3); margin-left: auto; white-space: nowrap; }
.tl-card { margin-top: var(--space-2); padding: var(--space-3); border: 1px solid var(--color-line); border-radius: var(--radius-sm); background: var(--color-surface); font-size: var(--text-md); color: var(--color-ink-2); }
.tl-card.note { background: #fffbeb; border-color: #f3e3b5; color: var(--color-ink); }

/* ---------------------------------------------------------------------
   Deals board
   --------------------------------------------------------------------- */
.board { flex: 1; min-height: 0; overflow: auto; display: flex; gap: var(--space-3); padding: var(--space-4) var(--space-5); background: var(--color-canvas); align-items: flex-start; }
.col { flex: 0 0 272px; display: flex; flex-direction: column; max-height: 100%; min-height: 0; background: var(--color-surface-2); border-radius: var(--radius-md); }
.col-head { padding: var(--space-3) var(--space-3) var(--space-2); display: flex; flex-direction: column; gap: 2px; flex: none; }
.col-head .col-title { display: flex; align-items: center; gap: var(--space-2); font-weight: var(--weight-semibold); font-size: var(--text-md); }
.col-head .col-sum { font-size: var(--text-xs); color: var(--color-ink-3); }
.col-head .col-auto { font-size: var(--text-xs); color: var(--color-wait); display: flex; align-items: center; gap: 4px; margin-top: 2px; }
.col-cards { flex: 1; min-height: 0; overflow: auto; padding: 0 var(--space-2) var(--space-2); display: flex; flex-direction: column; gap: var(--space-2); }
.col.is-collapsed { flex-basis: 48px; background: transparent; border: 1px dashed var(--color-line-strong); }
.col.is-collapsed .col-head { writing-mode: vertical-rl; transform: rotate(180deg); padding: var(--space-3) var(--space-2); align-items: center; justify-content: flex-end; height: 100%; }
.dcard { display: block; background: var(--color-surface); border: 1px solid var(--color-line); border-radius: var(--radius-sm); padding: var(--space-3); text-decoration: none; color: inherit; transition: border-color var(--dur-fast), box-shadow var(--dur-fast); }
.dcard:hover { border-color: var(--color-line-strong); box-shadow: var(--shadow-1); text-decoration: none; }
.dcard.is-selected { border-color: var(--color-accent); box-shadow: 0 0 0 1px var(--color-accent); }
.dcard .dc-title { font-weight: var(--weight-semibold); font-size: var(--text-md); line-height: var(--lh-md); }
.dcard .dc-co { font-size: var(--text-sm); color: var(--color-ink-2); margin-top: 2px; }
.dcard .dc-foot { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-3); }
.dcard .dc-value { font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums; margin-left: auto; }
.dcard .dc-doc { margin-top: var(--space-2); display: flex; align-items: center; gap: 6px; font-size: var(--text-xs); color: var(--color-ink-2); }

/* Stage stepper (deal detail) */
.stepper { display: flex; gap: 2px; }
.stepper span { flex: 1; height: 6px; border-radius: 3px; background: var(--color-surface-3); }
.stepper span.done { background: var(--color-ink-2); }
.stepper span.now { background: var(--color-accent); }

/* ---------------------------------------------------------------------
   Document editor
   --------------------------------------------------------------------- */
.doc-wrap { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 340px; }
.doc-main { overflow: auto; min-height: 0; background: var(--color-canvas); padding: var(--space-5); }
.doc-sheet { max-width: 880px; margin: 0 auto; background: var(--color-surface); border: 1px solid var(--color-line); border-radius: var(--radius-md); }
.doc-sec { padding: var(--space-5); border-bottom: 1px solid var(--color-line); }
.doc-sec:last-child { border-bottom: 0; }
.doc-sec > h4 { margin-bottom: var(--space-3); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
.lines { width: 100%; border-collapse: collapse; }
.lines th { font-size: var(--text-xs); color: var(--color-ink-3); font-weight: var(--weight-semibold); text-align: left; padding: 0 var(--space-2) var(--space-2); white-space: nowrap; }
.lines td { padding: var(--space-1) var(--space-2); vertical-align: top; }
.lines tr.line td { border-top: 1px solid var(--color-line); padding-top: var(--space-2); padding-bottom: var(--space-2); }
.lines .input, .lines .select { height: 34px; }
.lines .r, .lines th.r { text-align: right; }
.lines .amt { padding-top: 15px; font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: var(--weight-medium); }
.lines .drag { color: var(--color-ink-3); padding-top: 14px; cursor: grab; }
.line-desc { font-size: var(--text-sm); color: var(--color-ink-2); margin-top: 4px; }
.totals { margin-left: auto; width: min(340px, 100%); display: grid; grid-template-columns: 1fr auto; gap: var(--space-2) var(--space-4); font-variant-numeric: tabular-nums; }
.totals .grand { font-size: var(--text-xl); line-height: var(--lh-xl); font-weight: var(--weight-bold); padding-top: var(--space-2); border-top: 1px solid var(--color-line); }
.doc-side { border-left: 1px solid var(--color-line); background: var(--color-surface); overflow: auto; min-height: 0; padding: var(--space-5) var(--space-4); display: flex; flex-direction: column; gap: var(--space-5); }
.sync-row { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); }
.doc-actions-phone { display: none; }

/* Branded document preview (what the customer receives) */
.paper { background: #fff; border: 1px solid var(--color-line); border-radius: 4px; box-shadow: var(--shadow-1); padding: 40px 44px; font-size: 12px; line-height: 1.5; color: #1f2329; }
.paper .p-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding-bottom: 20px; border-bottom: 2px solid var(--ws, #222); }
.paper .p-title { font-size: 22px; font-weight: 700; letter-spacing: .04em; }
.paper .p-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; padding: 20px 0; }
.paper table { width: 100%; border-collapse: collapse; }
.paper th { text-align: left; font-size: 11px; color: #5b616c; border-bottom: 1px solid #d8dbe0; padding: 6px 4px; }
.paper td { padding: 8px 4px; border-bottom: 1px solid #eceef1; vertical-align: top; }
.paper .r { text-align: right; }
.paper .p-pay { margin-top: 20px; padding: 14px; background: #f6f7f9; border-radius: 6px; display: flex; gap: 16px; align-items: center; }
.paper .paybtn { white-space: nowrap; flex: none; display: inline-flex; align-items: center; height: 36px; padding: 0 16px; border-radius: 6px; background: var(--ws, #222); color: #fff; font-weight: 600; font-size: 13px; }

/* ---------------------------------------------------------------------
   Calendar (bookings)
   --------------------------------------------------------------------- */
.cal { display: grid; grid-template-columns: 56px repeat(5, minmax(0, 1fr)); min-width: 720px; position: relative; }
.cal-dayhead { position: sticky; top: 0; z-index: 2; background: var(--color-surface); height: 52px; border-bottom: 1px solid var(--color-line); display: flex; flex-direction: column; justify-content: center; padding: 0 var(--space-3); }
.cal-dayhead .d { font-size: var(--text-xs); color: var(--color-ink-2); font-weight: var(--weight-semibold); }
.cal-dayhead .n { font-size: var(--text-lg); font-weight: var(--weight-semibold); }
.cal-dayhead.today .n { color: var(--color-accent); }
.cal-col { position: relative; border-left: 1px solid var(--color-line); background-image: repeating-linear-gradient(to bottom, transparent 0, transparent 63px, var(--color-line) 63px, var(--color-line) 64px); }
.cal-times { position: relative; }
.cal-times span { position: absolute; right: 8px; font-size: var(--text-xs); color: var(--color-ink-3); transform: translateY(-50%); }
.appt { position: absolute; left: 4px; right: 4px; border-radius: var(--radius-sm); padding: 3px 8px; font-size: var(--text-xs); line-height: var(--lh-xs); overflow: hidden; background: var(--color-accent-weak); border-left: 3px solid var(--color-accent); color: var(--color-accent-ink); text-decoration: none; }
.appt:hover { text-decoration: none; filter: brightness(.98); }
.appt .a-name { font-weight: var(--weight-semibold); color: var(--color-ink); font-size: var(--text-sm); line-height: var(--lh-sm); }
.appt.follow { background: #eef6f1; border-left-color: var(--color-good); color: var(--color-good); }
.appt.is-selected { box-shadow: 0 0 0 2px var(--color-accent); }
.appt.cancelled { background: var(--color-surface-2); border-left-color: var(--color-ink-3); color: var(--color-ink-3); }
.appt.cancelled .a-name { text-decoration: line-through; color: var(--color-ink-2); }
.travel { position: absolute; left: 4px; right: 4px; border-radius: 4px; background: repeating-linear-gradient(135deg, var(--color-surface-2) 0 4px, #fff 4px 10px); border: 1px dashed var(--color-line-strong); font-size: var(--text-xs); color: var(--color-ink-2); display: flex; align-items: center; justify-content: center; gap: 4px; }
.now-line { position: absolute; left: 0; right: 0; height: 2px; background: var(--color-bad); z-index: 1; }
.now-line::before { content: ""; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--color-bad); }
.agenda-day { padding: var(--space-2) var(--space-4); font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--color-ink); background: var(--color-surface-2); border-bottom: 1px solid var(--color-line); position: sticky; top: 0; z-index: 1; }
.agenda-item { display: grid; grid-template-columns: 56px minmax(0,1fr) auto; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-line); text-decoration: none; color: inherit; align-items: start; }
.agenda-item:hover { background: var(--color-surface-2); text-decoration: none; }
.agenda-item .t { font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums; }
.agenda-gap { display: flex; align-items: center; gap: var(--space-2); padding: 6px var(--space-4) 6px calc(var(--space-4) + 56px + var(--space-3)); font-size: var(--text-xs); color: var(--color-ink-2); border-bottom: 1px solid var(--color-line); background: var(--color-canvas); }
.slot-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-2); }
.slot { height: 40px; border: 1px solid var(--color-line-strong); border-radius: var(--radius-sm); background: var(--color-surface); font-variant-numeric: tabular-nums; font-weight: var(--weight-medium); }
.slot:hover { border-color: var(--color-accent); }
.slot[aria-pressed="true"] { background: var(--color-accent); border-color: var(--color-accent); color: #fff; }
.slot[disabled] { background: var(--color-surface-2); color: var(--color-ink-3); border-color: var(--color-line); text-decoration: line-through; cursor: not-allowed; }

/* ---------------------------------------------------------------------
   Calls
   --------------------------------------------------------------------- */
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-2); }
.key { height: 52px; border-radius: var(--radius-md); border: 1px solid var(--color-line); background: var(--color-surface); display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: var(--text-xl); font-weight: var(--weight-medium); line-height: 1; }
.key small { font-size: 10px; letter-spacing: .12em; color: var(--color-ink-3); margin-top: 3px; font-weight: var(--weight-semibold); }
.key:hover { background: var(--color-surface-2); }
.key:active { background: var(--color-surface-3); }
.dial-display { font-size: var(--text-2xl); line-height: var(--lh-2xl); font-weight: var(--weight-semibold); text-align: center; font-variant-numeric: tabular-nums; letter-spacing: .02em; min-height: 40px; border: 0; width: 100%; background: transparent; }
.from-select { display: flex; align-items: center; gap: var(--space-3); width: 100%; min-height: 52px; padding: var(--space-2) var(--space-3); border: 1px solid var(--color-control-border); border-radius: var(--radius-sm); background: var(--color-surface); text-align: left; }
.from-select:hover { border-color: var(--color-ink-3); }
.callcard { position: fixed; z-index: var(--z-call); right: var(--space-5); bottom: var(--space-5); width: 360px; background: #17191f; color: #fff; border-radius: var(--radius-md); box-shadow: var(--shadow-3); overflow: hidden; }
.callcard .cc-top { padding: var(--space-4); display: flex; gap: var(--space-3); align-items: center; }
.callcard .cc-line { font-size: var(--text-xs); color: #c3c8d2; display: flex; align-items: center; gap: 6px; }
.callcard .cc-name { font-size: var(--text-lg); font-weight: var(--weight-semibold); }
.callcard .cc-sub { font-size: var(--text-sm); color: #c3c8d2; }
.callcard .cc-actions { display: flex; gap: var(--space-2); padding: 0 var(--space-4) var(--space-4); }
.callcard .cc-actions .btn { flex: 1; }
.callcard .avatar { background: #2c3039; color: #fff; }
.callcard .cc-strip { background: rgba(255,255,255,.06); padding: var(--space-2) var(--space-4); font-size: var(--text-sm); color: #dfe3ea; display: flex; align-items: center; gap: var(--space-2); }
.callcard .cc-tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-2); padding: 0 var(--space-4) var(--space-3); }
.ctool { display: flex; flex-direction: column; align-items: center; gap: 4px; border: 0; background: rgba(255,255,255,.08); color: #fff; border-radius: var(--radius-md); height: 60px; justify-content: center; font-size: var(--text-xs); }
.ctool:hover { background: rgba(255,255,255,.14); }
.ctool[aria-pressed="true"] { background: #fff; color: #17191f; }
.btn-end { background: #d93a2b; border-color: #d93a2b; color: #fff; }
.btn-end:hover { background: #bf3124; }
.callscreen { display: none; }
.play { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3) var(--space-2) var(--space-2); border: 1px solid var(--color-line); border-radius: var(--radius-pill); background: var(--color-surface); }
.play .btn { border-radius: 50%; }
.wave { flex: 1; height: 24px; display: flex; align-items: center; gap: 2px; min-width: 80px; }
.wave i { flex: 1; background: var(--color-line-strong); border-radius: 1px; }
.wave i.on { background: var(--color-accent); }

/* ---------------------------------------------------------------------
   Settings
   --------------------------------------------------------------------- */
.settings { flex: 1; min-height: 0; display: grid; grid-template-columns: 248px minmax(0,1fr); }
.set-nav { border-right: 1px solid var(--color-line); padding: var(--space-4) var(--space-2); overflow: auto; background: var(--color-surface); }
.set-nav a { display: flex; align-items: center; gap: var(--space-3); height: 36px; padding: 0 var(--space-3); border-radius: var(--radius-sm); color: var(--color-ink-2); text-decoration: none; font-weight: var(--weight-medium); }
.set-nav a:hover { background: var(--color-surface-2); color: var(--color-ink); text-decoration: none; }
.set-nav a[aria-current="page"] { background: var(--color-surface-2); color: var(--color-ink); }
.set-nav .set-group { padding: var(--space-4) var(--space-3) var(--space-2); }
.set-body { overflow: auto; min-height: 0; background: var(--color-surface); }
.set-inner { max-width: 880px; padding: var(--space-6) var(--space-6) var(--space-8); display: flex; flex-direction: column; gap: var(--space-6); }
.set-title { display: flex; align-items: flex-start; gap: var(--space-3); }
.set-title p { color: var(--color-ink-2); margin-top: var(--space-1); max-width: 60ch; }
.set-section { display: flex; flex-direction: column; gap: var(--space-4); }
.set-section > h3 { font-size: var(--text-lg); }
.rule { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: var(--space-3); padding: var(--space-4); border: 1px solid var(--color-line); border-radius: var(--radius-md); align-items: start; }
.rule-line { display: flex; align-items: flex-start; gap: var(--space-2); flex-wrap: wrap; line-height: 28px; }
.rule-line .kw { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--color-ink-2); width: 44px; flex: none; }
.chip:has(.avatar) { display: inline-flex; align-items: center; gap: 6px; }
.chip { display: inline-block; min-height: 28px; padding: 4px var(--space-2); border-radius: var(--radius-sm); background: var(--color-surface-2); border: 1px solid var(--color-line); font-size: var(--text-sm); font-weight: var(--weight-medium); line-height: var(--lh-sm); }
.stage-row { display: grid; grid-template-columns: 20px minmax(0,1fr) 140px 36px; gap: var(--space-3); align-items: center; padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--color-line); }

/* Command / global search */
.cmdk { width: min(640px, 100%); background: var(--color-surface); border-radius: var(--radius-md); box-shadow: var(--shadow-3); overflow: hidden; align-self: flex-start; margin-top: 12vh; }
.cmdk-input { display: flex; align-items: center; gap: var(--space-3); padding: 0 var(--space-4); height: 56px; border-bottom: 1px solid var(--color-line); }
.cmdk-input input { border: 0; flex: 1; font-size: var(--text-lg); background: transparent; height: 100%; }
.cmdk-input input:focus { outline: none; box-shadow: none; }
mark { background: #fff1b8; color: inherit; border-radius: 2px; padding: 0 1px; }
.cmdk .menu-item { min-height: 52px; }

/* Index / styleguide documentation pages (not app chrome) */
.doc-page { max-width: 1200px; margin: 0 auto; padding: var(--space-7) var(--space-6) var(--space-8); }
.doc-page section { margin-top: var(--space-7); }
.sg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--space-4); margin-top: var(--space-4); }
.sg-cell { border: 1px solid var(--color-line); border-radius: var(--radius-md); padding: var(--space-4); background: var(--color-surface); display: flex; flex-direction: column; gap: var(--space-3); }
.sg-cell > .meta { font-family: var(--font-mono); }
.swatch { height: 56px; border-radius: var(--radius-sm); border: 1px solid var(--color-line); }

/* =====================================================================
   RESPONSIVE
   ===================================================================== */
/* Tablet + small laptop: icon rail with labels */
@media (max-width: 1199px) and (min-width: 768px) {
  .app { grid-template-columns: var(--rail-w) minmax(0, 1fr); }
  .sidebar { padding: var(--space-2) var(--space-1); align-items: stretch; }
  .ws-switch { flex-direction: column; justify-content: center; padding: var(--space-2) 0; gap: 0; }
  .ws-switch .ws-text, .ws-switch .chev, .side-search .kbd, .me .me-text, .phone-status .ps-text { display: none; }
  .side-search { flex-direction: column; gap: 4px; font-size: 11px; line-height: 13px; color: var(--color-ink-2); font-weight: var(--weight-medium); }
  .composer { padding: var(--space-3) var(--space-4) var(--space-4); }
  .msg-body { padding-left: var(--space-4); }
  .side-search { justify-content: center; padding: 0; border-color: transparent; background: transparent; height: 52px; }
  .nav a { flex-direction: column; height: auto; padding: var(--space-2) 0; gap: 4px; justify-content: center; font-size: 11px; line-height: 13px; text-align: center; }
  .nav a .nav-label { flex: none; }
  .nav a .badge { position: absolute; top: 2px; right: 10px; margin: 0; min-width: 18px; height: 18px; font-size: 11px; }
  .phone-status, .me { justify-content: center; padding: 0; }
  .doc-wrap { grid-template-columns: minmax(0,1fr); }
  .doc-side { display: none; }
  .settings { grid-template-columns: 228px minmax(0,1fr); }
  .set-nav a { white-space: nowrap; }
  .set-inner { padding: var(--space-5); }
}

/* Phone shell: header + content + bottom tabs, pinned to screen edges */
@media (max-width: 767px) {
  body { font-size: var(--text-lg); line-height: var(--lh-lg); }
  .app { display: flex; flex-direction: column; }
  .sidebar { display: none; }
  .phone-head { display: flex; flex: none; align-items: center; gap: var(--space-2); height: var(--phone-header-h); padding: 0 var(--space-2) 0 var(--space-4); background: var(--color-surface); border-bottom: 1px solid var(--color-line); padding-top: env(safe-area-inset-top); box-sizing: content-box; }
  .phone-head h1 { font-size: var(--text-xl); line-height: var(--lh-xl); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .phone-head .ws-btn { border: 0; background: none; padding: 0; width: var(--tap); height: var(--tap); display: inline-flex; align-items: center; justify-content: center; margin-left: -8px; }
  .phone-head .btn-icon { width: var(--tap); height: var(--tap); border-color: transparent; background: transparent; }
  .main { flex: 1; min-height: 0; }
  .tabbar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; flex: none; background: var(--color-surface); border-top: 1px solid var(--color-line); padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -6px 16px rgba(22, 24, 29, .06); position: relative; z-index: var(--z-sticky); }
  .tabbar a, .tabbar button { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; height: var(--tabbar-h); font-size: 11px; line-height: 13px; font-weight: var(--weight-medium); color: var(--color-ink-2); text-decoration: none; border: 0; background: none; }
  .tabbar a[aria-current="page"], .tabbar button[aria-current="page"] { color: var(--color-ink); font-weight: var(--weight-semibold); }
  .tabbar a[aria-current="page"] .i { stroke-width: 2.25; }
  .tabbar .ti { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 56px; height: 30px; border-radius: var(--radius-pill); transition: background var(--dur-fast); }
  .tabbar [aria-current="page"] .ti { background: var(--color-surface-3); }
  .tabbar .badge { position: absolute; top: -2px; left: 34px; min-width: 18px; height: 18px; font-size: 11px; box-shadow: 0 0 0 2px var(--color-surface); }
  .tabbar .i { width: 22px; height: 22px; }
  .is-detail .tabbar, .is-detail .phone-head.root { display: none; }
  .page-head { display: none; }
  .page-head.keep { display: flex; height: var(--phone-header-h); padding: 0 var(--space-2); }
  .toolbar { padding: var(--space-2) var(--space-4); }
  .btn { height: var(--control-h-touch); font-size: var(--text-lg); padding: 0 var(--space-4); }
  .btn-sm { height: 44px; font-size: var(--text-md); padding: 0 var(--space-3); }
  .btn-icon { width: var(--control-h-touch); padding: 0; }
  .input, .select { height: var(--control-h-touch); font-size: var(--text-lg); }
  .textarea { font-size: var(--text-lg); }
  .seg button, .seg a { height: 38px; font-size: var(--text-md); padding: 0 var(--space-3); }
  .tabs { padding: 0 var(--space-4); gap: var(--space-5); min-height: 48px; }
  .panes { display: block; position: relative; }
  .panes > .pane { position: absolute; inset: 0; }
  .panes > .pane + .pane { border-left: 0; }
  .item { padding: var(--space-3) var(--space-4); }
  .item .who { font-size: var(--text-lg); line-height: var(--lh-lg); }
  .item .subj, .item .snip { font-size: var(--text-md); line-height: var(--lh-md); }
  .back-btn { display: inline-flex; }
  .thread { padding: var(--space-4); gap: var(--space-3); }
  .msg-body { padding: 0 var(--space-4) var(--space-4); }
  .bubble { max-width: 84%; }
  .composer { padding: var(--space-2) var(--space-3) calc(var(--space-2) + env(safe-area-inset-bottom)); }
  .msg-head { padding: var(--space-3); } .msg-body { padding: 0 var(--space-3) var(--space-3); }
  .reply-as { min-height: 44px; }
  .from-btn { height: 44px; flex: 1; justify-content: flex-start; }
  .from-btn .fb-text { flex-direction: column; gap: 0; align-items: flex-start; line-height: 16px; flex: 1; }
  .from-btn .addr { font-size: var(--text-xs); }
  .thread-head .btn-sm, .composer-foot .btn-sm { height: 44px; min-width: 44px; }
  .composer-box .menu { left: 0 !important; right: 0; width: auto !important; }
  .composer textarea { min-height: 48px; font-size: var(--text-lg); }
  .board { padding: var(--space-3) var(--space-4); flex-direction: column; gap: var(--space-2); overflow-x: hidden; }
  .col { flex: none; width: 100%; background: transparent; max-height: none; }
  .col-cards { padding: 0; overflow: visible; }
  .doc-wrap { display: block; overflow: auto; }
  .doc-main { padding: 0; overflow: visible; background: var(--color-surface); }
  .doc-sheet { border: 0; border-radius: 0; }
  .doc-sec { padding: var(--space-4); }
  .doc-side { display: none; }
  .doc-actions-phone { display: flex; gap: var(--space-2); flex: none; padding: var(--space-2) var(--space-3) calc(var(--space-2) + env(safe-area-inset-bottom)); border-top: 1px solid var(--color-line); background: var(--color-surface); }
  .doc-actions-phone .btn { flex: 1; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; gap: var(--space-3); }
  .settings { display: block; overflow: auto; }
  .set-nav { border: 0; padding: var(--space-2) 0; }
  .set-nav a { height: 52px; border-radius: 0; padding: 0 var(--space-4); border-bottom: 1px solid var(--color-line); font-size: var(--text-lg); color: var(--color-ink); }
  .set-inner { padding: var(--space-4) var(--space-4) var(--space-7); gap: var(--space-5); }
  .rule { grid-template-columns: 1fr; }
  .modal { width: 100%; align-self: flex-end; border-radius: var(--radius-md) var(--radius-md) 0 0; max-height: 92%; padding-bottom: env(safe-area-inset-bottom); }
  .scrim { padding: 0; align-items: flex-end; }
  .modal-foot { flex-direction: column-reverse; }
  .modal-foot .btn { width: 100%; }
  .drawer { width: 100%; }
  .callcard { display: none; }
  .cmdk-scrim { padding: 0; align-items: stretch; }
  .cmdk { margin: 0; border-radius: 0; width: 100%; height: 100%; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); }
  .cmdk-input { height: 60px; padding: 0 var(--space-2) 0 var(--space-4); }
  .callscreen { display: flex; position: fixed; inset: 0; z-index: var(--z-call); background: #17191f; color: #fff; flex-direction: column; align-items: center; padding: calc(var(--space-6) + env(safe-area-inset-top)) var(--space-5) calc(var(--space-6) + env(safe-area-inset-bottom)); text-align: center; }
  .callscreen .cs-line { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-md); color: #c3c8d2; padding: 6px var(--space-3); border-radius: var(--radius-pill); background: rgba(255,255,255,.08); }
  .callscreen .cs-name { font-size: var(--text-display); line-height: var(--lh-display); font-weight: var(--weight-semibold); margin-top: var(--space-5); letter-spacing: -.01em; }
  .callscreen .cs-sub { font-size: var(--text-lg); color: #c3c8d2; margin-top: var(--space-1); }
  .callscreen .avatar { background: #2c3039; color: #fff; margin-top: var(--space-6); }
  .callscreen .cs-tools { display: grid; grid-template-columns: repeat(3, 76px); gap: var(--space-4) var(--space-5); margin-top: auto; }
  .callscreen .ctool { height: 76px; border-radius: 50%; width: 76px; font-size: 12px; }
  .callscreen .cs-bottom { display: flex; gap: var(--space-8); margin-top: var(--space-6); align-items: center; justify-content: center; }
  .round { width: 72px; height: 72px; border-radius: 50%; border: 0; display: inline-flex; align-items: center; justify-content: center; color: #fff; }
  .round .i { width: 30px; height: 30px; }
  .round.answer { background: var(--color-call); }
  .round.end { background: #d93a2b; }
  .round-label { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); font-size: var(--text-md); color: #dfe3ea; }
  .cal-scroll { display: none; }
  .dl { grid-template-columns: 1fr; gap: 2px; }
  .dl dd { margin-bottom: var(--space-3); }
  .table th:first-child, .table td:first-child { padding-left: var(--space-4); }
  .doc-page { padding: var(--space-5) var(--space-4) var(--space-7); }
  .paper .p-pay { flex-direction: column; align-items: flex-start; }
  .paper { padding: 20px; }
}
@media (min-width: 768px) { .only-phone { display: none !important; } }
@media (max-width: 767px) { .only-desk { display: none !important; } }
@media (max-width: 1199px) { .only-wide { display: none !important; } }

.nowrap { white-space: nowrap; }
.sw-pair { display: inline-flex; align-items: center; gap: var(--space-2); white-space: nowrap; }
.email { overflow-wrap: normal; word-break: normal; }
