/* ============================================================
   Ambrosia Admin — standalone B2B back-office styles.
   Self-contained: tokens mirrored from the main app's visual
   system (plain, boring, correct). Do not import styles.css.
   ============================================================ */

:root {
  --bg:            #FAFAF9;
  --surface:       #FFFFFF;
  --surface-2:     #F4F4F5;
  --surface-3:     #E9E9EB;
  --border:        #E4E4E7;
  --border-strong: #D4D4D8;
  --text:          #18181B;
  --text-muted:    #71717A;
  --text-soft:     #A1A1AA;
  --accent:        #16A34A;
  --accent-700:    #15803D;
  --accent-bg:     #DCFCE7;
  --info:          #2563EB;
  --info-bg:       #DBEAFE;
  --danger:        #DC2626;
  --danger-bg:     #FEE2E2;
  --warn:          #F59E0B;
  --warn-bg:       #FEF3C7;
  --warn-strong:   #B45309;
  --disabled:      #D4D4D8;
  --scrim:         rgba(0,0,0,0.5);
  --scrim-soft:    rgba(0,0,0,0.4);
  --shadow-card:   0 4px 12px rgba(0,0,0,0.04);
  --shadow-modal:  0 10px 30px rgba(0,0,0,0.15);
  --shadow-detail: 0 12px 40px rgba(0,0,0,0.25);

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Consolas, monospace;
}

:root[data-theme="dark"] {
  --bg:            #0F0F11;
  --surface:       #18181B;
  --surface-2:     #1F1F23;
  --surface-3:     #2A2A30;
  --border:        #2E2E34;
  --border-strong: #3F3F46;
  --text:          #FAFAFA;
  --text-muted:    #A1A1AA;
  --text-soft:     #71717A;
  --accent:        #22C55E;
  --accent-700:    #16A34A;
  --accent-bg:     rgba(34, 197, 94, 0.18);
  --info:          #60A5FA;
  --info-bg:       rgba(96, 165, 250, 0.18);
  --danger:        #F87171;
  --danger-bg:     rgba(248, 113, 113, 0.18);
  --warn:          #FBBF24;
  --warn-bg:       rgba(251, 191, 36, 0.16);
  --warn-strong:   #FCD34D;
  --disabled:      #3F3F46;
  color-scheme: dark;
}

/* ----- base ----- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}
body.drawer-open { overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { cursor: default; opacity: 0.55; }
input, textarea, select { font: inherit; color: inherit; }
input::placeholder, textarea::placeholder { color: var(--text-soft); }
h1, h2, h3, p { margin: 0; }
.mono { font-family: var(--mono); }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface);
  font-size: 13px; font-weight: 600;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn.primary {
  background: var(--accent); border-color: var(--accent-700); color: #fff;
}
.btn.primary:hover:not(:disabled) { background: var(--accent-700); }
.btn.danger {
  background: var(--danger); border-color: var(--danger); color: #fff;
}
.btn.danger:hover:not(:disabled) { filter: brightness(0.92); }
.btn.danger-ghost { color: var(--danger); border-color: var(--border); }
.btn.danger-ghost:hover:not(:disabled) { background: var(--danger-bg); border-color: var(--danger); }
.btn.ghost { border-color: transparent; color: var(--text-muted); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn.sm { padding: 4px 10px; font-size: 12px; border-radius: 7px; }
.btn.block { width: 100%; }
.btn.busy { opacity: 0.6; pointer-events: none; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  flex: 0 0 auto;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.subtle { border-color: transparent; background: transparent; width: 26px; height: 26px; }
.icon-btn.subtle:hover { background: var(--surface-2); }

/* theme toggle: show moon in light mode, sun in dark mode */
.theme-toggle .ic.sun { display: none; }
:root[data-theme="dark"] .theme-toggle .ic.moon { display: none; }
:root[data-theme="dark"] .theme-toggle .ic.sun { display: inline-block; }

/* ============================================================
   Form fields
   ============================================================ */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted);
  display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface);
  font-size: 13.5px;
}
:root[data-theme="dark"] .field input,
:root[data-theme="dark"] .field select,
:root[data-theme="dark"] .field textarea { background: var(--surface-2); border-color: var(--border); }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}
.field textarea { resize: vertical; min-height: 48px; }
.hint-inline { font-style: normal; font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--text-soft); font-size: 11px; }
.hint { font-size: 12px; color: var(--text-muted); margin-top: 8px; }
.form-error {
  background: var(--danger-bg); color: var(--danger);
  border-radius: 8px; padding: 8px 10px;
  font-size: 12.5px; font-weight: 600;
}
.sep { border: 0; border-top: 1px solid var(--border); margin: 2px 0; }

.check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; min-width: 0; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; flex: 0 0 auto; margin: 0; }
.check.master { font-weight: 700; margin-bottom: 4px; }

/* switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .knob {
  width: 38px; height: 22px; border-radius: 999px;
  background: var(--surface-3); border: 1px solid var(--border-strong);
  position: relative; flex: 0 0 auto;
  transition: background 0.15s, border-color 0.15s;
}
.switch .knob::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,0.25);
  transition: left 0.15s;
}
.switch input:checked + .knob { background: var(--accent); border-color: var(--accent-700); }
.switch input:checked + .knob::after { left: 18px; }
.switch input:focus-visible + .knob { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch .switch-label { font-size: 12px; font-weight: 600; color: var(--text-muted); }

/* ============================================================
   Chips / callouts
   ============================================================ */
.chip {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.02em;
  white-space: nowrap;
}
.chip.ok   { background: var(--accent-bg); color: var(--accent-700); }
.chip.bad  { background: var(--danger-bg); color: var(--danger); }
.chip.warnc{ background: var(--warn-bg); color: var(--warn-strong); }
.chip.muted{ background: var(--surface-2); color: var(--text-muted); }
.chip.sm   { padding: 1px 7px; font-size: 10px; }
:root[data-theme="dark"] .chip.ok { color: var(--accent); }

.callout {
  border-radius: 8px; padding: 8px 10px;
  font-size: 12.5px; margin-bottom: 10px;
}
.callout.danger { background: var(--danger-bg); color: var(--danger); font-weight: 600; }
.callout.warn { background: var(--warn-bg); color: var(--warn-strong); font-weight: 600; }

/* ============================================================
   Login view
   ============================================================ */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-theme { position: fixed; top: 16px; right: 16px; }
.login-card {
  width: min(360px, 100%);
  background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow-card);
  padding: 28px 26px;
  display: flex; flex-direction: column; gap: 14px;
}
.login-mark { font-size: 20px; font-weight: 800; letter-spacing: -0.01em; }
.login-mark span { color: var(--accent); }
.login-sub { font-size: 12.5px; color: var(--text-muted); margin-top: -8px; }

/* ============================================================
   Top bar + layout
   ============================================================ */
.topbar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 12px;
  height: 54px; padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-size: 15px; font-weight: 800; letter-spacing: -0.01em; white-space: nowrap; }
.brand span { color: var(--accent); }
.topbar-title {
  font-size: 13px; color: var(--text-muted);
  padding-left: 12px; border-left: 1px solid var(--border);
}
.spacer { flex: 1; }
.acct-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 10px 4px 4px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface);
}
.acct-btn:hover { background: var(--surface-2); }
.acct-btn .avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; flex: 0 0 auto;
}
.acct-btn .acct-meta { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.acct-btn .name { font-size: 13px; font-weight: 700; }
.acct-btn .kind {
  font-size: 9px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--text-muted);
}

.content { max-width: 1080px; margin: 0 auto; padding: 24px 20px 48px; }
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  margin-bottom: 18px;
}
.page-head h1 { font-size: 22px; font-weight: 800; letter-spacing: -0.01em; }
.page-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.page-actions { display: flex; align-items: center; gap: 10px; }
.search {
  width: 220px; padding: 7px 12px;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface); font-size: 13px;
}
:root[data-theme="dark"] .search { background: var(--surface-2); border-color: var(--border); }
.search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ============================================================
   Clients table
   ============================================================ */
.table-scroll {
  background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-card);
  overflow-x: auto;
}
table.clients { width: 100%; border-collapse: collapse; }
.clients th {
  text-align: left;
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.clients td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.clients tbody tr { cursor: pointer; transition: background 0.1s; }
.clients tbody tr:hover { background: var(--surface-2); }
.clients tbody tr:last-child td { border-bottom: 0; }
.clients tr.is-suspended .cname { color: var(--text-muted); text-decoration: line-through; text-decoration-color: var(--text-soft); }
.cname { font-weight: 700; font-size: 14px; }
.clogin { font-size: 12px; color: var(--text-muted); font-family: var(--mono); margin-top: 1px; }
.tmuted { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; }
td .chip + .chip { margin-left: 4px; }
.overdue { color: var(--danger); font-weight: 700; }

/* placeholders / empty states */
.placeholder {
  padding: 32px 20px; text-align: center;
  color: var(--text-muted); font-size: 13px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
}
.placeholder.small { padding: 14px; background: none; border: 0; text-align: left; }
.placeholder.error { color: var(--danger); }
.placeholder .btn { margin-left: 8px; }
.empty-state {
  padding: 56px 20px; text-align: center;
  background: var(--surface); border: 1px dashed var(--border-strong); border-radius: 12px;
}
.empty-state h2 { font-size: 17px; font-weight: 800; margin-bottom: 6px; }
.empty-state p { color: var(--text-muted); font-size: 13px; margin-bottom: 16px; }

.spinner {
  display: inline-block; width: 13px; height: 13px;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  border-radius: 50%; vertical-align: -2px; margin-right: 6px;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   Client detail drawer
   ============================================================ */
.drawer-scrim { position: fixed; inset: 0; background: var(--scrim-soft); z-index: 200; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(580px, 100vw);
  background: var(--bg);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-detail);
  z-index: 201;
  display: flex; flex-direction: column;
  animation: drawer-in 0.16s ease-out;
}
@keyframes drawer-in { from { transform: translateX(28px); opacity: 0.4; } to { transform: none; opacity: 1; } }

.drawer-head {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.dh-main { flex: 1; min-width: 0; }
.dh-name-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.dh-name-row h2 {
  font-size: 18px; font-weight: 800; letter-spacing: -0.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  cursor: text;
}
.dh-name-input {
  font-size: 18px; font-weight: 800; letter-spacing: -0.01em;
  padding: 2px 8px; margin-left: -9px;
  border: 1px solid var(--accent); border-radius: 8px;
  background: var(--surface); width: 100%; max-width: 320px;
}
.dh-name-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.dh-sub { font-size: 12px; color: var(--text-muted); margin-top: 3px; font-family: var(--mono); }
.dh-chips { margin-top: 8px; display: flex; gap: 4px; flex-wrap: wrap; }

/* "Not saving" explanation — staff terms, under the chips it belongs to. */
.dh-health {
  margin-top: 8px; padding: 8px 10px;
  border: 1px solid var(--danger); border-radius: 8px;
  background: var(--danger-bg); color: var(--text);
  font-size: 12px; line-height: 1.45;
}
.dh-health strong { color: var(--danger); }
.dh-health-detail {
  margin-top: 6px; font-size: 11px; color: var(--text-muted);
  word-break: break-word;
}
.dh-suspend { display: flex; flex-direction: column; align-items: center; gap: 4px; padding-top: 2px; }

.drawer-body {
  flex: 1; overflow-y: auto;
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}

/* cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow-card);
}
.card h3 {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-head h3 { margin-bottom: 10px; }
.card-form { display: flex; flex-direction: column; gap: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.row-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 2px; }
.field-toggle { justify-content: flex-end; padding-bottom: 4px; }

/* entitlements */
.module-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 6px 12px;
  margin: 2px 0 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: 8px;
}
.module-grid.disabled { opacity: 0.45; pointer-events: none; }
.limits { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.limit .used { font-style: normal; font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--text-soft); font-size: 11px; }
.cap-note { font-style: normal; font-size: 11.5px; color: var(--warn-strong); }

/* devices */
.device-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.device-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.device-list li:last-child { border-bottom: 0; }
.device-list li.revoked { opacity: 0.6; }
.dev-main { flex: 1; min-width: 0; }
/* The impersonation label carries who and when, so it is long and must wrap
   rather than push the Revoke button off the card. */
.dev-label { font-size: 13.5px; font-weight: 600; display: flex; align-items: center; flex-wrap: wrap; gap: 6px; overflow-wrap: anywhere; }
.dev-meta { font-size: 11.5px; color: var(--text-muted); margin-top: 1px; }
/* On a tenant we have been testing against, every row says "Admin test
   session" — the age, the timestamps and the token fingerprint are the only
   parts that tell them apart, so they get the contrast. */
.dev-seen strong { color: var(--text); font-weight: 700; }
.dev-never { font-style: italic; }
.dev-count { margin-left: 8px; font-weight: 600; }
/* Revoked devices are kept, never purged — folded away, one click from open. */
.revoked-box { margin-top: 12px; }
.revoked-box .more-body { padding: 0 12px; }

/* danger zone */
.card.danger-zone { border-color: var(--danger); }
.card.danger-zone h3 { color: var(--danger); }
.dz-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.dz-row strong { font-size: 13.5px; }
.dz-row .hint { margin-top: 2px; }

/* ============================================================
   Modals
   ============================================================ */
.modal-scrim {
  position: fixed; inset: 0; z-index: 300;
  background: var(--scrim);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal {
  width: min(440px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow-modal);
  padding: 20px 22px;
  animation: modal-in 0.14s ease-out;
}
@keyframes modal-in { from { transform: translateY(8px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }
.modal h2 { font-size: 17px; font-weight: 800; margin-bottom: 6px; }
.modal-sub { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
.modal-sub strong { color: var(--text); }
.modal-form { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.confirm-name { margin-top: 12px; }
.confirm-name strong { color: var(--text); }

.pw-reveal {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; margin: 12px 0;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong); border-radius: 10px;
}
.pw-reveal code {
  flex: 1; font-family: var(--mono);
  font-size: 16px; font-weight: 700; letter-spacing: 0.03em;
  word-break: break-all;
}

.modal.modal-wide { width: min(560px, 100%); }

/* ============================================================
   Topbar nav (Clients / Plans & contacts)
   ============================================================ */
.topbar-nav { display: flex; gap: 4px; padding-left: 12px; margin-left: 4px; border-left: 1px solid var(--border); }
.nav-tab {
  border: 0; background: none; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--text-muted);
  padding: 6px 10px; border-radius: 8px;
}
.nav-tab:hover { color: var(--text); background: var(--surface-2); }
.nav-tab.active { color: var(--accent-700); background: var(--accent-bg); }
:root[data-theme="dark"] .nav-tab.active { color: var(--accent); }

/* ============================================================
   Plans & contacts (catalog view)
   ============================================================ */
.catalog-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.catalog-col { display: flex; flex-direction: column; }
.cat-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.cat-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2);
}
.cat-main { flex: 1; min-width: 0; }
.cat-name { font-size: 14px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.cat-sub { font-size: 12px; margin-top: 2px; }
.cat-meta { font-size: 11.5px; margin-top: 2px; }
.cat-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* Read-only entitlements summary (client on a preset) */
.ent-summary {
  padding: 12px 14px; margin: 4px 0 2px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
}
.ent-summary .es-mods { font-size: 13px; font-weight: 700; }
.ent-summary .es-caps { font-size: 12px; margin-top: 4px; }
.linklike {
  border: 0; background: none; padding: 0; cursor: pointer;
  color: var(--accent-700); font: inherit; font-weight: 600; text-decoration: underline;
}
:root[data-theme="dark"] .linklike { color: var(--accent); }

/* ============================================================
   Toasts
   ============================================================ */
.toasts {
  position: fixed; right: 16px; bottom: 16px; z-index: 400;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-modal);
  max-width: 340px;
  opacity: 0; transform: translateY(6px);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { border-left-color: var(--danger); }

/* ============================================================
   Responsive (desktop-first; collapse under 720px)
   ============================================================ */
@media (max-width: 720px) {
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar-title, .acct-btn .acct-meta { display: none; }
  /* Six tabs never fit beside the brand on a phone. Squeezed into the leftover
     space they became a 20px window onto 560px of tabs — Leads was physically
     untappable — and they shoved Log out off the right edge, scrolling the whole
     page sideways. Give the row its own full-width line under the brand and let
     it scroll there. */
  .topbar { flex-wrap: wrap; height: auto; padding: 0 12px; }
  .topbar > :not(.topbar-nav) { height: 54px; display: flex; align-items: center; }
  /* `.topbar .topbar-nav`, not `.topbar-nav`: the base class is declared twice
     in this file and the LATER copy (further down, outside any media query)
     would otherwise win on source order and put its margin back. */
  .topbar .topbar-nav {
    order: 10; flex: 1 0 100%; width: 100%; min-width: 0;
    margin: 0; padding: 6px 0;
    border-left: 0; border-top: 1px solid var(--border);
    overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .topbar .topbar-nav::-webkit-scrollbar { display: none; }
  .topbar .nav-tab { flex: 0 0 auto; white-space: nowrap; min-height: 40px; }
  .content { padding: 16px 12px 40px; }
  .page-head { flex-direction: column; align-items: stretch; }
  .page-actions { flex-direction: column; align-items: stretch; }
  .search { width: 100%; }
  .clients th:nth-child(3), .clients td:nth-child(3),
  .clients th:nth-child(4), .clients td:nth-child(4),
  .clients th:nth-child(5), .clients td:nth-child(5) { display: none; }
  .drawer { width: 100vw; border-left: 0; }
  .grid2, .limits, .catalog-grid { grid-template-columns: 1fr; }
  .module-grid { grid-template-columns: 1fr 1fr; }
  .dz-row { flex-direction: column; align-items: flex-start; }
}

/* Translations view */
.tr-cards { display: flex; flex-direction: column; gap: 16px; max-width: 720px; }
.tr-steps { margin: 4px 0 14px; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; font-size: 13px; color: var(--text); }
.tr-steps li::marker { color: var(--text-muted); font-weight: 600; }
#btnTrImportLabel { cursor: pointer; }

/* Topbar view tabs (Clients / Plans & contacts / Translations) */
.topbar-nav { display: flex; gap: 4px; margin-left: 18px; }
.nav-tab {
  padding: 6px 12px; border: 0; border-radius: 8px;
  background: transparent; color: var(--text-muted);
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.nav-tab:hover { color: var(--text); background: var(--surface-2); }
.nav-tab.active { color: var(--text); background: var(--surface-2); }

/* ----- billing escalation + messages ----- */
.esc-head { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.esc-head h4 { margin: 0; font-size: 13px; }
.row-tools { text-align: right; white-space: nowrap; }
.btn.sm.danger { color: var(--danger); border-color: var(--danger); }
.btn.sm.danger:hover { background: var(--danger-bg, rgba(220,60,60,0.12)); }
.msg-table tbody tr { cursor: default; }
.msg-table tbody tr:hover { background: transparent; }

/* ============================================================
   Leads (sales pipeline)
   Built thumb-first: this screen is used on a phone, standing in
   front of the restaurant owner. Tap targets grow to 40px under
   720px and the filter bar turns into a horizontal scroller.
   ============================================================ */

/* overdue follow-ups, surfaced on the nav tab itself */
.nav-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 17px; height: 17px; padding: 0 5px; margin-left: 5px;
  border-radius: 999px;
  background: var(--danger); color: #fff;
  font-size: 10.5px; font-weight: 800;
}

/* ----- shared small controls ----- */
.fchip {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 32px; padding: 4px 12px;
  border: 1px solid var(--border-strong); border-radius: 999px;
  background: var(--surface); color: var(--text-muted);
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.fchip:hover { background: var(--surface-2); color: var(--text); }
.fchip.active { background: var(--accent-bg); border-color: var(--accent); color: var(--accent-700); }
:root[data-theme="dark"] .fchip { background: var(--surface-2); border-color: var(--border); }
:root[data-theme="dark"] .fchip.active { color: var(--accent); background: var(--accent-bg); }

.seg {
  display: inline-flex; flex: 0 0 auto;
  border: 1px solid var(--border-strong); border-radius: 999px;
  background: var(--surface); overflow: hidden;
}
.seg-btn {
  min-height: 32px; padding: 4px 14px;
  font-size: 12.5px; font-weight: 600; color: var(--text-muted); white-space: nowrap;
}
.seg-btn:hover { background: var(--surface-2); color: var(--text); }
.seg-btn.active { background: var(--accent); color: #fff; }
:root[data-theme="dark"] .seg { background: var(--surface-2); border-color: var(--border); }

/* ----- filter bar (sticky under the topbar) ----- */
.lead-filters {
  position: sticky; top: 54px; z-index: 60;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.lf-search { width: 200px; }
.lf-stages { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.lf-select {
  min-height: 32px; padding: 5px 10px;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface); font-size: 12.5px;
}
:root[data-theme="dark"] .lf-select { background: var(--surface-2); border-color: var(--border); }
.lf-select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ----- the card list (a table cannot carry this on a phone) ----- */
.lead-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 14px; }
@media (min-width: 900px) { .lead-grid { grid-template-columns: 1fr 1fr; } }

.lead-card {
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px 14px; cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-card);
  transition: background 0.12s, border-color 0.12s;
}
.lead-card:hover { background: var(--surface-2); border-color: var(--border-strong); }
.lead-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.lead-card.is-archived { opacity: 0.62; }
.lc-top { display: flex; align-items: flex-start; gap: 10px; }
.lc-name { flex: 1; min-width: 0; font-size: 15px; font-weight: 700; word-break: break-word; }
.lc-owner {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%; flex: 0 0 auto;
  background: var(--accent-bg); color: var(--accent-700);
  font-size: 11px; font-weight: 800;
}
:root[data-theme="dark"] .lc-owner { color: var(--accent); }
.lc-owner.none { background: var(--surface-2); color: var(--text-soft); }
.lc-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.lc-meta { font-size: 12px; color: var(--text-muted); }
.lc-next {
  font-size: 12.5px; padding: 6px 8px; border-radius: 8px;
  background: var(--surface-2); color: var(--text);
}
.lc-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.lc-act { min-height: 34px; text-decoration: none; }

/* stage + product chips: the whole point is reading this without opening it */
.chip.lead-stage { background: var(--surface-3); color: var(--text-muted); }
.chip.lead-stage[data-stage="contacted"] { background: var(--info-bg); color: var(--info); }
.chip.lead-stage[data-stage="meeting"]   { background: var(--warn-bg); color: var(--warn-strong); }
.chip.lead-stage[data-stage="proposal"]  { background: var(--accent-bg); color: var(--accent-700); }
.chip.lead-stage[data-stage="won"]       { background: var(--accent); color: #fff; }
.chip.lead-stage[data-stage="lost"]      { background: var(--danger-bg); color: var(--danger); }
:root[data-theme="dark"] .chip.lead-stage[data-stage="proposal"] { color: var(--accent); }
:root[data-theme="dark"] .chip.lead-stage[data-stage="won"] { color: #0F0F11; }

.chip.lead-prod { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.chip.lead-prod.bad { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.chip.lead-prod.ok { background: var(--accent-bg); color: var(--accent-700); border-color: transparent; }
:root[data-theme="dark"] .chip.lead-prod.ok { color: var(--accent); }
.chip .pdot { width: 7px; height: 7px; margin-right: 5px; }
.pdot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }

/* floating "+" — mobile only, see the media query below */
.lead-fab { display: none; }

/* ----- lead drawer ----- */
.lead-head { flex-direction: column; align-items: stretch; gap: 10px; }
.lh-top { display: flex; align-items: flex-start; gap: 12px; }
.lh-stages { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.lead-assign-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
.lead-acts { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.lead-acts .btn { min-height: 34px; text-decoration: none; }

/* products: the "which one did they reject?" answer */
.lead-prods { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.lead-prods li {
  padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2);
}
.lead-prods li.is-rejected { border-color: var(--danger); }
.lead-prods li.is-won { border-color: var(--accent); }
.lp-head { display: flex; align-items: center; gap: 8px; }
.lp-name { flex: 1; min-width: 0; font-size: 13.5px; font-weight: 700; }
.lp-status {
  min-height: 34px; max-width: 50%; padding: 5px 8px;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface); font-size: 12.5px;
}
.lp-note {
  width: 100%; margin-top: 8px; padding: 7px 10px;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface); font-size: 13px;
}
.lp-note:disabled { opacity: 0.5; }
.lp-when { font-size: 11px; margin-top: 4px; }
.lead-prods.compact li { background: var(--surface); }

/* notes + activity */
#leadNotes {
  width: 100%; min-height: 92px; padding: 9px 11px; resize: vertical;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface); font-size: 13.5px;
}
.lead-log { display: flex; flex-direction: column; gap: 8px; }
.lead-log-kinds { display: flex; gap: 6px; flex-wrap: wrap; }
.lead-log-row { display: flex; gap: 8px; }
.lead-log-row input {
  flex: 1; min-width: 0; min-height: 36px; padding: 8px 10px;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface); font-size: 13.5px;
}
.lead-log-row .btn { min-height: 36px; }
.lead-timeline { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; }
.lead-timeline li { padding: 9px 0; border-bottom: 1px solid var(--border); }
.lead-timeline li:last-child { border-bottom: 0; }
.lt-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.lt-who { font-size: 12.5px; font-weight: 700; }
.lt-when { font-size: 11.5px; }
.lt-body { font-size: 13px; margin-top: 4px; white-space: pre-wrap; word-break: break-word; }

:root[data-theme="dark"] .lp-status,
:root[data-theme="dark"] .lp-note,
:root[data-theme="dark"] .lead-log-row input,
:root[data-theme="dark"] #leadNotes { background: var(--surface); border-color: var(--border-strong); }
.lp-status:focus, .lp-note:focus, .lead-log-row input:focus, #leadNotes:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}

/* ----- new-lead modal: duplicate hints + the "More details" expander ----- */
.lead-dupes {
  padding: 10px 12px;
  border: 1px solid var(--warn); border-radius: 10px;
  background: var(--warn-bg);
}
.ld-title {
  font-size: 11px; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--warn-strong);
}
.lead-dupes ul { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.lead-dupes li { display: flex; align-items: center; gap: 10px; }
.lead-dupes .hint { color: var(--warn-strong); margin-top: 8px; }
.ld-main { flex: 1; min-width: 0; }
.ld-name { font-size: 13.5px; font-weight: 700; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ld-why { font-size: 11.5px; margin-top: 2px; white-space: normal; }

.more-details {
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2);
}
.more-details > summary {
  display: flex; align-items: center; min-height: 40px;
  padding: 8px 12px; cursor: pointer; list-style: none;
  font-size: 13px; font-weight: 700; color: var(--text-muted);
}
.more-details > summary::-webkit-details-marker { display: none; }
.more-details > summary::after { content: '▾'; margin-left: auto; transition: transform 0.15s; }
.more-details[open] > summary { border-bottom: 1px solid var(--border); }
.more-details[open] > summary::after { transform: rotate(180deg); }
.more-body { padding: 12px; display: flex; flex-direction: column; gap: 12px; }

/* Archived clients — collapsed under the live table; the whole of the undo. */
.archived-box { margin-top: 16px; }
.archived-box .cat-list { margin-top: 0; }
.archived-box .cat-list li { background: var(--surface); }

/* ----- products manager (owner only) ----- */
.lp-admin { list-style: none; margin: 12px 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.lp-admin li { display: flex; align-items: center; gap: 8px; }
.lp-color, .lp-new input[type="color"] {
  width: 40px; height: 34px; padding: 2px; flex: 0 0 auto;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface);
}
.lp-name-input, .lp-new input[name="name"] {
  flex: 1; min-width: 0; min-height: 34px; padding: 7px 10px;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface); font-size: 13.5px;
}
:root[data-theme="dark"] .lp-name-input,
:root[data-theme="dark"] .lp-new input[name="name"] { background: var(--surface-2); border-color: var(--border); }
.lp-new { display: flex; align-items: center; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }

/* ============================================================
   Leads — list layout, keyboard hints, product editor
   ============================================================ */

/* Keyboard affordance printed on the button that the shortcut triggers. */
.kbd-hint {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 16px; margin-left: 7px; padding: 1px 5px;
  border: 1px solid currentColor; border-radius: 4px;
  font-family: var(--mono); font-size: 10px; line-height: 1.4;
  opacity: 0.65;
}
@media (max-width: 720px) { .kbd-hint { display: none; } }  /* no keyboard to hint at */

/* The dense alternative to the card grid. Rows carry the same chips, so the
   product verdict still reads without opening anything. */
.lead-rows { display: flex; flex-direction: column; gap: 6px; }
.lead-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface);
  cursor: pointer; transition: background 0.1s, border-color 0.1s;
}
.lead-row:hover { background: var(--surface-2); border-color: var(--border-strong); }
.lead-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }
.lead-row.is-archived { opacity: 0.6; }
.lr-main { flex: 1; min-width: 0; }
.lr-top { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; }
.lr-name { font-size: 14px; font-weight: 700; margin-right: 2px; }
.lr-meta { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }
.lr-actions { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }

/* Colour swatch + name on one line in the product editor. */
.prod-name-row { display: flex; gap: 10px; align-items: flex-end; }
.prod-name-row .field.grow { flex: 1; }
.prod-name-row input[type="color"] { width: 44px; height: 34px; padding: 2px; cursor: pointer; }
.cat-name .pdot { margin-right: 7px; }

/* ============================================================
   Leads — phone layout (thumb reach, 40px targets, FAB)
   ============================================================ */
@media (max-width: 720px) {
  .leads .page-actions { flex-direction: row; flex-wrap: wrap; }
  .leads .page-actions .btn { flex: 1 1 auto; min-height: 40px; }
  #btnNewLead { display: none; }        /* the FAB replaces it */
  /* The phone layout is cards, full stop — so the choice isn't offered here.
     leadLayout() already forces cards below this breakpoint; these rules are
     the belt-and-braces path for a browser without matchMedia, so a row at
     least stacks instead of scrolling sideways. */
  .lead-layout-toggle { display: none; }
  .lead-rows { display: flex; flex-direction: column; gap: 10px; }
  .lead-row { flex-wrap: wrap; align-items: flex-start; padding: 14px; }
  .lr-main { flex: 1 1 100%; }
  .lr-name { font-size: 16px; }
  .lr-actions { flex: 1 1 100%; margin-top: 10px; }
  .lr-actions .btn { min-height: 40px; padding: 8px 14px; }
  .lead-fab {
    display: flex; align-items: center; justify-content: center;
    position: fixed; right: 16px; bottom: 16px; z-index: 150;
    width: 56px; height: 56px; border-radius: 50%;
    background: var(--accent); color: #fff;
    font-size: 30px; line-height: 1;
    box-shadow: var(--shadow-modal);
  }
  .lead-filters { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .lead-filters::-webkit-scrollbar { display: none; }
  .lead-filters > * { flex: 0 0 auto; }
  .lf-stages { flex-wrap: nowrap; }
  .lf-search { width: 58vw; max-width: 260px; }
  .fchip, .seg-btn, .lf-select { min-height: 40px; }
  .lc-act, .lead-acts .btn { min-height: 40px; padding: 8px 14px; }
  .lead-card { padding: 14px; }
  .lc-name { font-size: 16px; }
  .lp-status, .lead-log-row input, .lead-log-row .btn { min-height: 40px; }
  .lp-status { max-width: 55%; }
  .lp-admin li { flex-wrap: wrap; }
  .lead-assign-row { flex-wrap: wrap; }
}

/* performance profiling
   ---------------------
   A card that is usually one row of buttons and a list of nothing. The live
   state is deliberately loud: somebody's till is instrumented while it shows,
   and the countdown is the reassurance that it will stop on its own. */
.perf-start { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.perf-live {
  display: flex; flex-direction: column; gap: 2px;
  padding: 9px 10px; margin-bottom: 8px;
  border: 1px solid var(--border); border-left: 3px solid var(--warn, #c98a00);
  border-radius: 6px;
  background: color-mix(in srgb, var(--warn, #c98a00) 7%, transparent);
  font-size: 13px;
}
.perf-reports { margin-top: 10px; }
.perf-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.perf-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.perf-list li:last-child { border-bottom: 0; }
.pf-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
/* The summary line carries five numbers; it wraps rather than pushing Download
   off the card on a narrow window. `.tmuted` cannot be used for any of this —
   it is globally white-space: nowrap, which is right for a count chip and wrong
   for a sentence, and using it here clipped the card's own hint text. */
.pf-meta { font-size: 11.5px; color: var(--text-muted); overflow-wrap: anywhere; }
/* Inside the amber banner the flex gap already spaces the lines. */
.perf-live .pf-hint { margin-top: 2px; }
.pf-when { font-size: 13.5px; font-weight: 600; }
