/* ==========================================================================
   Order Center — design system
   1. Tokens (light / dark)   2. Base   3. Components   4. Layout
   5. Workspace   6. Dashboard / Orders / Setup   7. Dialogs   8. Responsive
   ========================================================================== */

/* 1. Tokens ---------------------------------------------------------------- */
:root {
  color-scheme: light;

  --font-sans: 'IBM Plex Sans Thai', 'Noto Sans Thai', 'Leelawadee UI', Tahoma, system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;

  /* Type scale (Thai needs ≥12px; 14px is the reading size) */
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 20px;
  --fs-2xl: 28px;
  --lh-tight: 1.35;
  --lh-body: 1.6;

  /* Spacing (4px grid) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-full: 999px;

  --ctl-sm: 30px;
  --ctl-md: 36px;
  --ctl-lg: 42px;

  /* Neutrals */
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #eff1f4;
  --border: #e2e6eb;
  --border-strong: #cbd2da;
  --text: #121821;
  --text-2: #464f5c;
  --text-3: #66707d;

  /* Brand */
  --brand: #0f766e;
  --brand-hover: #0c5f58;
  --brand-soft: #e5f3f1;
  --brand-softer: #f2f9f8;
  --brand-text: #0b5c55;
  --on-brand: #ffffff;
  --focus-ring: 0 0 0 3px rgba(15, 118, 110, .28);

  /* Semantic */
  --success: #15803d;
  --success-soft: #e7f6ec;
  --success-text: #166534;
  --warning: #b45309;
  --warning-soft: #fdf2df;
  --warning-text: #8a3c06;
  --danger: #b91c1c;
  --danger-soft: #fdeceb;
  --danger-text: #991b1b;
  --info: #1d4ed8;
  --info-soft: #e8eefd;
  --info-text: #1e40af;
  --violet: #6d28d9;
  --violet-soft: #f0eafd;
  --violet-text: #5b21b6;
  --neutral-soft: #eef0f3;
  --neutral-text: #3b4451;

  /* Chat */
  --bubble-in: #ffffff;
  --bubble-out: #e3f2ef;
  --bubble-out-border: #c4e3dc;
  --bubble-admin: #fff8ea;
  --bubble-admin-border: #f0d9a8;
  --chat-bg: #f6f7f9;

  --shadow-1: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-2: 0 4px 12px rgba(16, 24, 40, .08);
  --shadow-3: 0 24px 64px rgba(16, 24, 40, .18);
  --backdrop: rgba(17, 24, 33, .45);

  --sidebar-w: 248px;
  --topbar-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e1116;
    --surface: #151a21;
    --surface-2: #1a2029;
    --surface-3: #222a35;
    --border: #2a323d;
    --border-strong: #3b4552;
    --text: #e7eaef;
    --text-2: #b6bdc8;
    --text-3: #8e98a5;
    --brand: #2bb3a3;
    --brand-hover: #43c4b5;
    --brand-soft: rgba(43, 179, 163, .16);
    --brand-softer: rgba(43, 179, 163, .08);
    --brand-text: #6ad8ca;
    --on-brand: #04211d;
    --focus-ring: 0 0 0 3px rgba(43, 179, 163, .4);
    --success: #4ade80;
    --success-soft: rgba(74, 222, 128, .14);
    --success-text: #86efac;
    --warning: #fbbf24;
    --warning-soft: rgba(251, 191, 36, .14);
    --warning-text: #fcd34d;
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, .14);
    --danger-text: #fca5a5;
    --info: #7aa2fb;
    --info-soft: rgba(122, 162, 251, .15);
    --info-text: #a9c2fd;
    --violet: #b9a3fb;
    --violet-soft: rgba(185, 163, 251, .15);
    --violet-text: #cdbdfd;
    --neutral-soft: #242c37;
    --neutral-text: #c2c9d3;
    --bubble-in: #1d242e;
    --bubble-out: #173a36;
    --bubble-out-border: #23524c;
    --bubble-admin: #34291a;
    --bubble-admin-border: #5a4524;
    --chat-bg: #11161c;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-2: 0 4px 12px rgba(0, 0, 0, .35);
    --shadow-3: 0 24px 64px rgba(0, 0, 0, .55);
    --backdrop: rgba(0, 0, 0, .6);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1116;
  --surface: #151a21;
  --surface-2: #1a2029;
  --surface-3: #222a35;
  --border: #2a323d;
  --border-strong: #3b4552;
  --text: #e7eaef;
  --text-2: #b6bdc8;
  --text-3: #8e98a5;
  --brand: #2bb3a3;
  --brand-hover: #43c4b5;
  --brand-soft: rgba(43, 179, 163, .16);
  --brand-softer: rgba(43, 179, 163, .08);
  --brand-text: #6ad8ca;
  --on-brand: #04211d;
  --focus-ring: 0 0 0 3px rgba(43, 179, 163, .4);
  --success: #4ade80;
  --success-soft: rgba(74, 222, 128, .14);
  --success-text: #86efac;
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, .14);
  --warning-text: #fcd34d;
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, .14);
  --danger-text: #fca5a5;
  --info: #7aa2fb;
  --info-soft: rgba(122, 162, 251, .15);
  --info-text: #a9c2fd;
  --violet: #b9a3fb;
  --violet-soft: rgba(185, 163, 251, .15);
  --violet-text: #cdbdfd;
  --neutral-soft: #242c37;
  --neutral-text: #c2c9d3;
  --bubble-in: #1d242e;
  --bubble-out: #173a36;
  --bubble-out-border: #23524c;
  --bubble-admin: #34291a;
  --bubble-admin-border: #5a4524;
  --chat-bg: #11161c;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-2: 0 4px 12px rgba(0, 0, 0, .35);
  --shadow-3: 0 24px 64px rgba(0, 0, 0, .55);
  --backdrop: rgba(0, 0, 0, .6);
}

/* 2. Base ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { margin: 0; color: var(--text); line-height: var(--lh-tight); font-weight: 600; }
h1 { font-size: var(--fs-2xl); letter-spacing: -.01em; }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }
p { margin: 0; }
a { color: var(--brand-text); }

button, input, select, textarea { font: inherit; color: inherit; }

[hidden] { display: none !important; }

:focus-visible { outline: none; box-shadow: var(--focus-ring); }

::selection { background: var(--brand-soft); }

* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

.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;
}

.ic {
  width: 16px; height: 16px; flex-shrink: 0;
  fill: none; stroke: currentColor; stroke-width: 1.9;
  stroke-linecap: round; stroke-linejoin: round;
  vertical-align: -3px;
}
.ic-lg { width: 20px; height: 20px; }
.ic-xl { width: 28px; height: 28px; stroke-width: 1.6; }

.num { font-variant-numeric: tabular-nums; }

/* 3. Components ------------------------------------------------------------ */

/* Form controls */
input, select, textarea {
  display: block;
  width: 100%;
  min-height: var(--ctl-md);
  margin-top: 6px;
  padding: 7px 11px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  color: var(--text);
  font-size: var(--fs-md);
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
input:hover, select:hover, textarea:hover { border-color: var(--text-3); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus-ring); }
input[readonly] { background: var(--surface-2); color: var(--text-2); font-family: var(--font-mono); font-size: var(--fs-sm); }
input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; margin: 0; accent-color: var(--brand); }
input[type="search"] { padding-left: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2366707d' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: 11px 50%; }
select {
  appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2366707d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
textarea { resize: vertical; min-height: 64px; }

label { display: block; font-size: var(--fs-sm); font-weight: 500; color: var(--text-2); }
.field { margin-bottom: var(--sp-3); }
.field-hint { display: block; margin-top: 4px; font-size: var(--fs-xs); color: var(--text-3); font-weight: 400; }
.check-row { display: flex; align-items: center; gap: 10px; margin: var(--sp-4) 0; font-size: var(--fs-md); color: var(--text); cursor: pointer; }

fieldset { margin: var(--sp-4) 0 0; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; margin-bottom: var(--sp-3); font-size: var(--fs-md); font-weight: 600; color: var(--text); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }

/* Buttons */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--ctl-md);
  max-width: 100%;
  padding: 6px 14px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: transparent;
  font-size: var(--fs-md);
  font-weight: 500;
  line-height: 1.3;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s;
}
button:disabled { cursor: not-allowed; opacity: .45; }

.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--on-brand);
  font-weight: 600;
}
.primary:hover:not(:disabled) { background: var(--brand-hover); border-color: var(--brand-hover); }
.primary:disabled { opacity: 1; background: var(--surface-3); border-color: var(--surface-3); color: var(--text-3); }

.quiet,
.sidebar-toggle-btn,
.sidebar-expand-btn {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}
.quiet:hover:not(:disabled),
.sidebar-toggle-btn:hover,
.sidebar-expand-btn:hover { background: var(--surface-3); }

.btn-xs { min-height: var(--ctl-sm); padding: 4px 10px; font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn-xs.primary { color: var(--on-brand); }
.wide { width: 100%; min-height: var(--ctl-lg); font-size: var(--fs-md); }

.danger-btn,
.cart-row button {
  min-height: var(--ctl-sm);
  padding: 0 10px;
  font-size: var(--fs-sm);
  border-radius: var(--r-sm);
  background: transparent;
  border-color: transparent;
  color: var(--danger-text);
}
.danger-btn:hover:not(:disabled),
.cart-row button:hover { background: var(--danger-soft); }
.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.danger-solid:hover:not(:disabled) { filter: brightness(.92); }

/* Compact controls keep their label on one line */
.nav, .c-filter, .q-filter, .status-pill-btn, .staff-assign-btn, .media-btn, .icon-btn,
.add-button, .dialog-close, .sidebar-toggle-btn, .sidebar-expand-btn, .preview-chip button,
.btn-toggle-page, .composer .primary, .composer .quiet { white-space: nowrap; overflow-wrap: normal; }

.icon-btn {
  min-height: var(--ctl-md); width: var(--ctl-md); padding: 0;
  color: var(--text-2); border-radius: var(--r-md);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

/* Badges / pills (shared look) */
.pill, .role-badge, .queue-tag, .cust-status-badge, .staff-pill-badge,
.page-status-badge, .order-item .status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--r-full);
  background: var(--neutral-soft);
  color: var(--neutral-text);
  font-size: var(--fs-xs);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  border: 0;
}
.pill .ic, .role-badge .ic, .queue-tag .ic, .cust-status-badge .ic,
.staff-pill-badge .ic, .page-status-badge .ic { width: 13px; height: 13px; vertical-align: 0; }

.closing, .is-active { --tone: var(--success); --tone-soft: var(--success-soft); --tone-text: var(--success-text); }
.slip, .pending { --tone: var(--warning); --tone-soft: var(--warning-soft); --tone-text: var(--warning-text); }
.issue, .human, .urgent { --tone: var(--danger); --tone-soft: var(--danger-soft); --tone-text: var(--danger-text); }
.pending_shipment { --tone: var(--info); --tone-soft: var(--info-soft); --tone-text: var(--info-text); }
.completed, .not_buying { --tone: var(--text-3); --tone-soft: var(--neutral-soft); --tone-text: var(--neutral-text); }
.in_progress { --tone: var(--brand); --tone-soft: var(--brand-soft); --tone-text: var(--brand-text); }

.queue-tag.closing, .queue-tag.slip, .queue-tag.issue, .queue-tag.human,
.cust-status-badge.closing, .cust-status-badge.slip, .cust-status-badge.issue, .cust-status-badge.pending_shipment,
.cust-status-badge.completed, .cust-status-badge.not_buying,
.staff-pill-badge.urgent, .page-status-badge.is-active {
  background: var(--tone-soft);
  color: var(--tone-text);
}
.page-status-badge.is-disabled { background: var(--warning-soft); color: var(--warning-text); }

.role-badge.role-admin { background: var(--warning-soft); color: var(--warning-text); }
.role-badge.role-agent { background: var(--info-soft); color: var(--info-text); }

/* Status dot used inside badges */
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--tone, var(--text-3)); flex-shrink: 0; }

/* Segmented filters */
.segmented {
  display: flex;
  gap: 2px;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 3px;
  background: var(--surface-3);
  border-radius: var(--r-md);
}
.c-filter, .q-filter {
  flex-shrink: 0;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 7px;
  background: transparent;
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 500;
}
.c-filter { flex: 1; }
.c-filter:hover, .q-filter:hover { color: var(--text); }
.c-filter.active, .q-filter.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow-1), 0 0 0 1px var(--border);
}
.q-filter .count, .c-filter .count { color: var(--text-3); font-weight: 500; font-variant-numeric: tabular-nums; }

/* Chips (page staff assignment) */
.staff-assign-btn {
  min-height: 30px;
  padding: 0 12px;
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 500;
}
.staff-assign-btn:hover { border-color: var(--border-strong); color: var(--text); background: var(--surface-2); }
.staff-pill-badge { height: 20px; padding: 0 7px; }

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 56px;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.panel-head h2 { font-size: var(--fs-lg); }
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text);
}
.section-title span, .section-title .muted { font-size: var(--fs-xs); font-weight: 400; color: var(--text-3); }

.empty, .cart-empty {
  color: var(--text-3);
  text-align: center;
}
.empty { padding: 56px var(--sp-4); }
.empty .empty-symbol { display: grid; place-items: center; width: 56px; height: 56px; margin: 0 auto var(--sp-3); border-radius: 50%; background: var(--surface-3); color: var(--text-3); }
.empty h3 { font-size: var(--fs-md); font-weight: 600; color: var(--text-2); }
.empty p { font-size: var(--fs-sm); max-width: 300px; margin: 6px auto 0; }
.cart-empty { padding: var(--sp-4); font-size: var(--fs-sm); background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: var(--r-md); }

/* Toast */
#toast {
  position: fixed;
  inset: auto auto 24px 50%;
  margin: 0;
  border: 0;
  overflow: visible;
  left: 50%;
  bottom: 24px;
  z-index: 100;
  transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: var(--r-md);
  background: #1b2330;
  color: #f4f6f8;
  box-shadow: var(--shadow-3);
  font-size: var(--fs-md);
  font-weight: 500;
  animation: toast-in .2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* 4. App layout ------------------------------------------------------------ */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-w);
  padding: var(--sp-4) var(--sp-3);
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform .2s ease;
}
.brand-row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); padding: 0 var(--sp-1) var(--sp-4); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; font-size: var(--fs-lg); font-weight: 700; color: var(--text); line-height: 1.2; }
.brand small { display: block; margin-top: 2px; font-size: var(--fs-xs); font-weight: 500; color: var(--text-3); letter-spacing: .02em; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; flex-shrink: 0; border-radius: var(--r-md); background: var(--brand); color: var(--on-brand); }
.brand-mark .ic { width: 20px; height: 20px; }
.sidebar-toggle-btn { min-height: 32px; width: 32px; padding: 0; border-color: transparent; color: var(--text-3); background: transparent; }
.sidebar-toggle-btn:hover { color: var(--text); }
.sidebar-expand-btn { display: none; }
body.sidebar-collapsed .sidebar { transform: translateX(-100%); pointer-events: none; }
body.sidebar-collapsed main { margin-left: 0 !important; }
body.sidebar-collapsed .sidebar-expand-btn { display: inline-flex; }

.user-avatar { display: grid; place-items: center; width: 32px; height: 32px; flex-shrink: 0; border-radius: 50%; background: var(--brand-soft); color: var(--brand-text); font-weight: 600; }

.nav-label { margin: var(--sp-2) var(--sp-2) 6px; font-size: var(--fs-xs); font-weight: 600; color: var(--text-3); }
.main-nav { display: flex; flex-direction: column; gap: 2px; }
.nav {
  justify-content: flex-start;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border-radius: var(--r-md);
  background: none;
  color: var(--text-2);
  font-weight: 500;
  text-align: left;
}
.nav .ic { width: 18px; height: 18px; color: var(--text-3); }
.nav:hover { background: var(--surface-3); color: var(--text); }
.nav.active { background: var(--brand-soft); color: var(--brand-text); font-weight: 600; }
.nav.active .ic { color: var(--brand-text); }
.nav span { flex: 1; }
.nav b {
  min-width: 22px; height: 20px; padding: 0 6px;
  display: inline-grid; place-items: center;
  border-radius: var(--r-full);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.nav b.has-alert { background: var(--danger); color: #fff; }
.nav b[data-zero] { display: none; }
.nav.active b { background: var(--brand); color: var(--on-brand); }


main {
  margin-left: var(--sidebar-w);
  height: 100vh;
  height: 100dvh;
  padding: var(--sp-3) var(--sp-4);
  overflow-y: auto;
  transition: margin-left .2s ease;
}

/* Top bar: page title on the left, profile on the right */
.app-topbar {
  position: sticky;
  top: calc(-1 * var(--sp-3));
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  min-height: var(--topbar-h);
  margin: calc(-1 * var(--sp-3)) calc(-1 * var(--sp-4)) var(--sp-3);
  padding: var(--sp-2) var(--sp-4);
  background: var(--bg);
}
.topbar-left { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.topbar-brand { display: none; }
.topbar-title { min-width: 0; }
.topbar-title h1 { font-size: var(--fs-xl); line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-title p { font-size: var(--fs-sm); color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: var(--sp-2); flex-shrink: 0; }

.profile-btn {
  gap: 10px;
  min-height: 44px;
  padding: 4px 10px 4px 4px;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  white-space: nowrap;
}
.profile-btn:hover { border-color: var(--border-strong); background: var(--surface-2); }
.profile-btn .user-avatar { width: 34px; height: 34px; }
.profile-text { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 0; }
.profile-text strong { max-width: 200px; font-size: var(--fs-sm); font-weight: 600; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; }
.profile-btn .chev { color: var(--text-3); transition: transform .15s; }
.profile-btn[aria-expanded="true"] .chev { transform: rotate(180deg); }

.profile-menu {
  position: fixed;
  inset: auto;
  margin: 0;
  min-width: 240px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-3);
}
.profile-menu:popover-open { display: flex; flex-direction: column; gap: 2px; animation: dialog-in .12s ease-out; }
.profile-menu-head { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.profile-menu-head strong { font-size: var(--fs-md); font-weight: 600; }
.profile-menu-head #current-user-meta { font-size: var(--fs-xs); color: var(--text-3); }
.profile-menu-head .role-badge { margin-top: 4px; align-self: flex-start; }
.profile-menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.menu-item { justify-content: flex-start; gap: 10px; width: 100%; min-height: 38px; padding: 6px 10px; border-radius: var(--r-md); color: var(--text); text-align: left; }
.menu-item .ic { color: var(--text-3); }
.menu-item:hover { background: var(--surface-3); }
.menu-item.danger, .menu-item.danger .ic { color: var(--danger-text); }
.menu-item.danger:hover { background: var(--danger-soft); }

/* Staff & pages page */

.staff-view .staff-admin-section { margin: 0 0 var(--sp-4); padding: var(--sp-5); }
.staff-view .staff-users-list, .staff-view .staff-pages-list { max-height: none; }

/* Demo-only UI is hidden outside the local environment */

/* 5. Workspace ------------------------------------------------------------- */
.workspace-top-flush { display: flex; flex-direction: column; height: calc(100dvh - var(--topbar-h) - 24px); }

/* Filters + page cards sit directly on the page background so white cards stand out */
.page-tabs-shell { flex-shrink: 0; margin-bottom: var(--sp-3); }
.page-tabs-row { display: flex; align-items: flex-start; gap: var(--sp-2); min-width: 0; }
.page-tabs-row { --page-card-h: 60px; }
.page-tabs-row .page-tabs-bar { flex: 1; min-width: 0; }

/* Staff filter dropdown: first item in the page-card row, same height as a card */
.staff-filter { flex-shrink: 0; padding: 2px 0 0 2px; }
.staff-filter-btn {
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  position: relative;
  width: 168px;
  height: var(--page-card-h);
  min-height: 0;
  padding: 8px 34px 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface-3);
  color: var(--text);
  text-align: left;
  white-space: nowrap;
}
.staff-filter-btn:hover:not(:disabled) { border-color: var(--text-3); }
.staff-filter-btn:disabled { opacity: 1; cursor: default; }
.staff-filter-label { font-size: var(--fs-xs); color: var(--text-3); }
.staff-filter-value { display: flex; align-items: center; gap: 6px; max-width: 100%; min-width: 0; }
.staff-filter-value strong { min-width: 0; font-size: var(--fs-md); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.staff-filter-btn .chev { position: absolute; right: 10px; top: 50%; margin-top: -8px; color: var(--text-3); transition: transform .15s; }
.staff-filter-btn[aria-expanded="true"] .chev { transform: rotate(180deg); }
.staff-filter-btn.is-locked .chev { display: none; }

.dropdown-menu {
  position: fixed;
  inset: auto;
  margin: 0;
  width: 260px;
  max-height: min(60vh, 420px);
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-3);
}
.dropdown-menu:popover-open { display: flex; flex-direction: column; gap: 2px; animation: dialog-in .12s ease-out; }
.dropdown-item { justify-content: flex-start; gap: 10px; width: 100%; min-height: 44px; padding: 6px 10px; border-radius: var(--r-md); color: var(--text); text-align: left; white-space: nowrap; }
.dropdown-item:hover { background: var(--surface-3); }
.dropdown-item.active { background: var(--brand-soft); }
.dropdown-item > .ic { color: var(--brand-text); }
.dropdown-item-text { display: flex; flex-direction: column; flex: 1; min-width: 0; line-height: 1.3; }
.dropdown-item-text strong { font-size: var(--fs-md); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.dropdown-item-text small { font-size: var(--fs-xs); color: var(--text-3); }

.page-tabs-bar { display: flex; gap: var(--sp-2); overflow-x: auto; padding: 2px 2px 8px; scroll-snap-type: x proximity; }
.page-tab-btn {
  position: relative;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  width: 176px;
  height: var(--page-card-h, 60px);
  min-height: 0;
  justify-content: center;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  white-space: normal;
  box-shadow: var(--shadow-1);
  scroll-snap-align: start;
  transition: border-color .15s, box-shadow .15s, background-color .15s;
}
.page-tab-btn:hover { border-color: var(--text-3); box-shadow: var(--shadow-2); }
.page-tab-btn.active {
  border-color: var(--brand);
  background: var(--brand-soft);
  box-shadow: inset 0 0 0 1px var(--brand), var(--shadow-1);
}
.page-tab-btn.active .page-tab-name { color: var(--brand-text); }
.page-tab-toprow { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); min-width: 0; }
.page-tab-name { min-width: 0; font-size: var(--fs-md); font-weight: 600; line-height: 1.35; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-tab-alert {
  display: inline-grid; place-items: center;
  min-width: 20px; height: 20px; padding: 0 6px; flex-shrink: 0;
  border-radius: var(--r-full);
  background: var(--success); color: var(--surface);
  font-size: var(--fs-xs); font-weight: 700; font-variant-numeric: tabular-nums;
}
.page-tab-meta { font-size: var(--fs-xs); color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-tab-meta.quiet-meta { color: var(--text-3); }

.workspace-grid.three-col {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 340px;
  gap: var(--sp-3);
  flex: 1;
  min-height: 0;
  align-items: stretch;
}
.workspace-top-flush .customer-list-panel,
.workspace-top-flush .chat-panel,
.workspace-top-flush .order-panel { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }

/* Customer list */
.customer-list-head { padding: var(--sp-3) var(--sp-3) var(--sp-3); border-bottom: 1px solid var(--border); }
.customer-list-title-row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); margin-bottom: var(--sp-3); min-height: 30px; }
.customer-list-title-row h2 { min-width: 0; font-size: var(--fs-lg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.customer-list-filters { display: flex; }
.page-customer-list { flex: 1; overflow-y: auto; padding: var(--sp-2); display: flex; flex-direction: column; gap: 2px; }
.cust-section-divider {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-2) var(--sp-1);
  font-size: var(--fs-xs); font-weight: 600; color: var(--text-3);
}
.cust-section-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.cust-row {
  position: relative;
  flex-direction: column;
  align-items: stretch;
  gap: 3px;
  width: 100%;
  min-height: 0;
  padding: 10px 12px 10px 15px;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text);
  text-align: left;
  white-space: normal;
}
.cust-row::before {
  content: "";
  position: absolute; left: 5px; top: 12px; bottom: 12px;
  width: 3px; border-radius: 3px;
  background: var(--tone, transparent);
}
.cust-row:hover { background: var(--surface-2); }
.cust-row.active { background: var(--brand-soft); }
.cust-row.status-in_progress { --tone: var(--brand); }
.cust-row.status-completed::before, .cust-row.status-not_buying::before { background: var(--border-strong); }
.cust-row.status-completed .cust-row-name, .cust-row.status-not_buying .cust-row-name { color: var(--text-2); }
.cust-row-top { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); min-width: 0; }
.cust-row-name { font-size: var(--fs-md); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cust-row-sub { font-size: var(--fs-xs); font-weight: 500; line-height: 1.45; color: var(--tone-text, var(--brand-text)); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cust-row-msg { font-size: var(--fs-sm); color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cust-row.status-closing { --tone: var(--success); --tone-text: var(--success-text); }
.cust-row.status-slip { --tone: var(--warning); --tone-text: var(--warning-text); }
.cust-row.status-issue { --tone: var(--danger); --tone-text: var(--danger-text); }
.cust-row.status-pending_shipment { --tone: var(--info); --tone-text: var(--info-text); }

/* Chat */
.chat-panel { container-type: inline-size; container-name: chat; }
.chat-panel .panel-head { flex-wrap: wrap; row-gap: var(--sp-2); }
.chat-identity { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; flex: 1 1 220px; }
.chat-identity h2 { font-size: var(--fs-lg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-identity #chat-page { display: block; font-size: var(--fs-sm); color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-identity > div { min-width: 0; }
.chat-head-actions { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; margin-left: auto; }
.avatar {
  display: grid; place-items: center;
  width: 40px; height: 40px; flex-shrink: 0;
  border-radius: 50%;
  background: var(--info-soft); color: var(--info-text);
  font-weight: 600; font-size: var(--fs-lg);
}
.staff-owner-pill { cursor: pointer; background: var(--violet-soft); color: var(--violet-text); }
/* Who answers this customer: one icon, click to switch (bot = pulsing, person = staff) */
.mode-toggle {
  position: relative;
  width: 48px;
  min-height: 48px;
  padding: 0;
  border-radius: 14px;
  border: 2px solid transparent;
  flex-shrink: 0;
}
.mode-toggle .mode-icon { width: 28px; height: 28px; stroke-width: 1.8; }
.mode-toggle.is-bot { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.mode-toggle.is-bot::after {
  content: "";
  position: absolute; inset: -6px;
  border-radius: 18px;
  border: 2px solid var(--brand);
  animation: bot-ring 1.6s ease-out infinite;
}
.mode-toggle.is-bot .mode-icon { animation: bot-blink 1.6s ease-in-out infinite; }
.mode-toggle.is-human { background: var(--warning); border-color: var(--warning); color: var(--surface); }
.mode-toggle:hover { filter: brightness(1.06); }
.mode-toggle:disabled { opacity: .6; }
@keyframes bot-blink { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
@keyframes bot-ring { 0% { opacity: .7; transform: scale(.9); } 100% { opacity: 0; transform: scale(1.15); } }

/* Chat lock (claim) */
.claim-btn { width: 48px; min-height: 48px; padding: 0; border-radius: 14px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-3); flex-shrink: 0; }
.claim-btn:hover:not(:disabled) { color: var(--text); border-color: var(--text-3); }
.claim-btn.is-mine { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-text); }
.claim-btn.is-other { background: var(--warning-soft); border-color: var(--warning); color: var(--warning-text); }
.claim-btn:disabled { opacity: 1; cursor: not-allowed; }
.claim-menu { width: 280px; }
.claim-banner {
  display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap;
  padding: var(--sp-2) var(--sp-4);
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-sm);
}
.claim-banner .ic { flex-shrink: 0; }
.claim-banner span { flex: 1 1 220px; }
.claim-banner.is-mine { background: var(--brand-softer); color: var(--brand-text); }
.claim-banner.is-other { background: var(--warning-soft); color: var(--warning-text); font-weight: 500; }
.claim-banner button { min-height: 28px; }
/* Someone else holds this chat: everything that would change it is inert (the server refuses too) */
.chat-locked .order-panel button, .chat-locked .lifecycle-bar button { pointer-events: none; opacity: .45; }
.claim-tag { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); font-weight: 600; color: var(--warning-text); }
.claim-tag .ic { width: 12px; height: 12px; vertical-align: 0; }

/* Alerts bell */
.alerts-btn { position: relative; width: 44px; min-height: 44px; border-radius: 50%; color: var(--text-2); }
.alerts-count {
  position: absolute; top: 4px; right: 2px;
  min-width: 18px; height: 18px; padding: 0 5px;
  display: inline-grid; place-items: center;
  border-radius: var(--r-full);
  background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 1;
  box-shadow: 0 0 0 2px var(--bg);
}
.alerts-btn.has-alerts { color: var(--danger-text); animation: bell-shake 1.2s ease-in-out infinite; }
@keyframes bell-shake { 0%, 70%, 100% { transform: rotate(0); } 75% { transform: rotate(-12deg); } 85% { transform: rotate(10deg); } 95% { transform: rotate(-6deg); } }
.alerts-menu { width: min(320px, calc(100vw - 16px)); }
.alerts-head { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.alerts-head strong { font-size: var(--fs-md); font-weight: 600; }
.alerts-head span { font-size: var(--fs-xs); color: var(--text-3); }
.alerts-list { display: flex; flex-direction: column; gap: 2px; }
.alert-item { flex-direction: column; align-items: stretch; gap: 2px; width: 100%; min-height: 0; padding: 8px 10px; border-radius: var(--r-md); text-align: left; white-space: normal; color: var(--text); border-left: 3px solid var(--danger); }
.alert-item:hover { background: var(--surface-3); }
.alert-item-top { display: flex; justify-content: space-between; gap: 8px; font-size: var(--fs-sm); }
.alert-item-top strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alert-item-top span { color: var(--danger-text); font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.alert-item small { font-size: var(--fs-xs); color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alerts-empty { padding: 16px 10px; font-size: var(--fs-sm); color: var(--text-3); text-align: center; }
/* AI settings card spans the Settings grid */
.ai-card { grid-column: 1 / -1; }
.ai-card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; }
.ai-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: var(--sp-5); }
.ai-form > .check-row, .ai-form > .ai-instructions, .ai-form > .form-error, .ai-form > .ai-test-result, .ai-form > .ai-actions { grid-column: 1 / -1; }
.ai-form > .check-row { margin-top: 0; font-weight: 600; }
.ai-actions { display: flex; justify-content: flex-end; align-items: center; gap: var(--sp-2); flex-wrap: wrap; margin-top: var(--sp-2); }
.ai-actions .danger-btn { margin-right: auto; }
.ai-test-result { margin-bottom: var(--sp-3); padding: 10px 12px; border-radius: var(--r-md); background: var(--success-soft); color: var(--success-text); font-size: var(--fs-sm); }
.ai-test-result strong { display: block; margin-bottom: 2px; }
.line-status { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; margin-bottom: var(--sp-2); }

.lifecycle-bar {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  overflow-x: auto;
}
.lifecycle-label { font-size: var(--fs-sm); color: var(--text-3); white-space: nowrap; }
.lifecycle-bar .segmented { flex-shrink: 0; }
.status-pill-btn {
  gap: 5px;
  min-height: 28px;
  padding: 0 9px;
  border-radius: 7px;
  background: transparent;
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 500;
}
.status-pill-btn .dot { width: 8px; height: 8px; }
.status-pill-btn:hover { color: var(--text); }
.status-pill-btn.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow-1), 0 0 0 1px var(--border); }

.messages { flex: 1; min-height: 0; overflow-y: auto; padding: var(--sp-5) var(--sp-5) var(--sp-3); background: var(--chat-bg); }
.bubble {
  width: fit-content;
  max-width: min(78%, 560px);
  margin-bottom: var(--sp-3);
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: 16px 16px 16px 4px;
  background: var(--bubble-in);
  color: var(--text);
  font-size: var(--fs-md);
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: var(--shadow-1);
}
.bubble .sender { display: flex; align-items: center; gap: 5px; margin-bottom: 3px; font-size: var(--fs-xs); font-weight: 600; color: var(--text-3); }
.bubble .sender .ic { width: 13px; height: 13px; vertical-align: 0; }
/* Customer = incoming (left); page side = outgoing (right) */
.bubble.customer { margin-right: auto; }
.bubble.assistant, .bubble.admin {
  margin-left: auto;
  border-radius: 16px 16px 4px 16px;
}
.bubble.assistant { background: var(--bubble-out); border-color: var(--bubble-out-border); }
.bubble.admin { background: var(--bubble-admin); border-color: var(--bubble-admin-border); }
.bubble.system {
  max-width: 100%;
  margin: var(--sp-2) auto var(--sp-4);
  padding: 6px 12px;
  border: 0;
  border-radius: var(--r-full);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: var(--fs-xs);
  text-align: center;
  box-shadow: none;
}
.bubble.system .sender { display: none; }
/* Notes between the bot and the team: staff only, never sent to the customer */
.bubble.bot_note, .bubble.staff_note {
  max-width: min(92%, 520px);
  margin-left: auto;
  border: 1px dashed color-mix(in srgb, var(--warning) 45%, transparent);
  border-radius: 12px;
  background: var(--warning-soft);
  box-shadow: none;
  font-size: var(--fs-sm);
}
.bubble.staff_note { border-color: var(--border-strong, var(--border)); background: var(--surface-2); }
.bubble-attachments { display: flex; flex-direction: column; gap: var(--sp-2); margin-top: 6px; }
.chat-image-link { display: inline-block; max-width: 260px; border-radius: var(--r-md); overflow: hidden; border: 1px solid var(--border); }
.chat-image { display: block; max-width: 100%; max-height: 220px; object-fit: cover; }
.chat-audio-wrap { display: flex; flex-direction: column; gap: 4px; padding: 8px 10px; border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--border); }
.chat-audio-label { display: flex; align-items: center; gap: 5px; font-size: var(--fs-xs); color: var(--text-2); font-weight: 500; }
.chat-audio { height: 34px; max-width: 260px; }
.chat-video { max-width: 260px; max-height: 200px; border-radius: var(--r-md); border: 1px solid var(--border); }
.chat-file-chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 11px; border-radius: var(--r-md); border: 1px solid var(--border); background: var(--surface-2); color: var(--brand-text); font-size: var(--fs-sm); font-weight: 500; text-decoration: none; }
.chat-file-chip:hover { background: var(--brand-soft); }

/* Composer */
.composer-wrap { border-top: 1px solid var(--border); background: var(--surface); }
.attachments-preview { display: flex; flex-wrap: wrap; gap: 6px; padding: var(--sp-2) var(--sp-3) 0; }
.preview-chip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 4px 0 10px; border-radius: var(--r-full); background: var(--brand-soft); color: var(--brand-text); font-size: var(--fs-xs); font-weight: 500; }
.preview-chip button { min-height: 22px; width: 22px; padding: 0; border-radius: 50%; color: var(--danger-text); font-size: 15px; }
.preview-chip button:hover { background: var(--danger-soft); }
.composer { display: flex; align-items: center; gap: 6px; padding: var(--sp-3); }
.composer input:not([type]),
.composer input[type="text"] { flex: 1; min-width: 0; margin: 0; min-height: var(--ctl-lg); border-radius: var(--r-full); padding: 0 16px; background: var(--surface-2); }
.composer input:not([type]):focus, .composer input[type="text"]:focus { background: var(--surface); }
.composer .primary, .composer .quiet { min-height: var(--ctl-lg); border-radius: var(--r-full); padding: 0 18px; }
.composer-tag { display: none; }
.media-btn { min-height: var(--ctl-lg); width: var(--ctl-lg); padding: 0; border-radius: 50%; color: var(--text-2); background: transparent; }
.media-btn:hover { background: var(--surface-3); color: var(--text); }
.media-btn.recording { width: auto; padding: 0 12px; border-radius: var(--r-full); background: var(--danger-soft); color: var(--danger-text); font-size: var(--fs-sm); font-weight: 600; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .6; } }
.composer-sub { display: flex; align-items: center; justify-content: flex-end; gap: var(--sp-2); padding: 0 var(--sp-3) var(--sp-3); margin-top: -4px; }
.composer-sub .hint { margin-right: auto; font-size: var(--fs-xs); color: var(--text-3); }

@container chat (max-width: 480px) {
  #admin-submit-btn span { display: none; }
  #admin-submit-btn { width: var(--ctl-lg); padding: 0; }
  .composer-sub .hint { display: none; }
  .chat-head-actions .pill { display: none; }
  .mode-toggle, .claim-btn { width: 42px; min-height: 42px; }
  .lifecycle-label { display: none; }
}

/* Order panel */
.order-content { flex: 1; min-height: 0; overflow-y: auto; padding: var(--sp-4); }
.order-section + .order-section { margin-top: var(--sp-5); padding-top: var(--sp-5); border-top: 1px solid var(--border); }
.matched-box { margin-bottom: var(--sp-4); padding: var(--sp-3); border-radius: var(--r-md); background: var(--brand-softer); border: 1px solid var(--brand-soft); }
.matched-title { color: var(--brand-text); }
.product-search-wrap input { margin-top: 0; }
.products-scroll { max-height: 280px; overflow-y: auto; margin-top: var(--sp-2); }
.product { display: flex; align-items: center; gap: var(--sp-3); padding: 10px 2px; border-bottom: 1px solid var(--border); }
.product:last-child { border-bottom: 0; }
.product-icon { display: grid; place-items: center; width: 40px; height: 40px; flex-shrink: 0; border-radius: var(--r-md); background: var(--surface-3); color: var(--text-2); font-size: 18px; }
.product-body { flex: 1; min-width: 0; }
.product-name { font-size: var(--fs-md); font-weight: 500; color: var(--text); line-height: 1.4; }
.product-meta { margin-top: 2px; font-size: var(--fs-xs); color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.product-stock { font-size: var(--fs-xs); color: var(--success-text); font-weight: 500; }
.product-stock.low { color: var(--warning-text); }
.product-stock.out { color: var(--text-3); font-weight: 400; }
.product-price { display: flex; flex-direction: column; align-items: flex-end; font-size: var(--fs-md); font-weight: 600; color: var(--text); white-space: nowrap; font-variant-numeric: tabular-nums; line-height: 1.25; }
.product-list-price { font-size: var(--fs-xs); font-weight: 400; color: var(--text-3); }
/* Book covers are portrait: give them a 3:4 frame */
.product-icon.has-cover { width: 40px; height: 54px; overflow: hidden; padding: 0; background: var(--surface-3); }
.product-cover { width: 100%; height: 100%; object-fit: cover; display: block; }
.product-name { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.add-button { min-height: 32px; width: 32px; padding: 0; border-radius: var(--r-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--brand-text); }
.add-button:hover:not(:disabled) { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.cart-row { display: flex; align-items: center; gap: var(--sp-2); padding: 8px 0; border-bottom: 1px solid var(--border); font-size: var(--fs-md); color: var(--text); }
.cart-row:last-child { border-bottom: 0; }
.cart-row > span:first-child { flex: 1; min-width: 0; }
.cart-row strong { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.cart-total { display: flex; justify-content: space-between; align-items: baseline; padding-top: var(--sp-3); margin-top: var(--sp-1); border-top: 1px solid var(--border); font-size: var(--fs-md); font-weight: 600; }
.cart-total strong { font-size: var(--fs-lg); font-variant-numeric: tabular-nums; }
.order-content label { margin-bottom: var(--sp-3); }
.order-section fieldset { margin: 0; }
.title-with-icon, .matched-label { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm) !important; font-weight: 600 !important; color: inherit !important; }
.order-submit { position: sticky; bottom: calc(-1 * var(--sp-4)); margin: var(--sp-4) calc(-1 * var(--sp-4)) calc(-1 * var(--sp-4)); padding: var(--sp-3) var(--sp-4) var(--sp-4); background: linear-gradient(to bottom, transparent, var(--surface) 30%); }

/* 6. Dashboard / Orders / Setup ------------------------------------------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-3); margin: 0 0 var(--sp-5); }
.stats > div { padding: var(--sp-4) var(--sp-5); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-1); }
.stats span { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--text-3); }
.stats strong { display: block; margin-top: var(--sp-2); font-size: var(--fs-2xl); font-weight: 600; line-height: 1.1; color: var(--text); font-variant-numeric: tabular-nums; }
.stats small { font-size: var(--fs-sm); font-weight: 400; color: var(--text-3); }

.queue-panel { padding: var(--sp-4) var(--sp-5); margin-bottom: var(--sp-4); }
.queue-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; margin-bottom: var(--sp-4); }
.queue-head strong { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-lg); font-weight: 600; color: var(--text); }
.queue-head .muted { font-size: var(--fs-sm); font-weight: 400; color: var(--text-3); }
.queue-controls { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; min-width: 0; max-width: 100%; }
.queue-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--sp-3); }
.queue-card {
  position: relative;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  min-height: 0;
  padding: var(--sp-3) var(--sp-4) var(--sp-3) calc(var(--sp-4) + 4px);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  white-space: normal;
  overflow: hidden;
}
.queue-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--tone, var(--border-strong)); }
.queue-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-2); }
.queue-card.active { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.queue-card-top { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); font-size: var(--fs-xs); color: var(--text-3); }
.queue-card-top > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-card-cust { font-size: var(--fs-md); font-weight: 600; color: var(--text); }
.queue-card-msg { font-size: var(--fs-sm); color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.staff-overview-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--sp-3); }
.staff-card {
  flex-direction: column; align-items: stretch; gap: 6px;
  min-height: 0;
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  white-space: normal;
}
.staff-card:hover { border-color: var(--border-strong); background: var(--surface-2); }
.staff-card.active { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); background: var(--brand-softer); }
.staff-card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); font-size: var(--fs-md); font-weight: 600; }
.staff-card-pages { font-size: var(--fs-sm); color: var(--text-2); }
.staff-card-sub { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: var(--fs-xs); color: var(--text-3); }
.staff-card-sub .stat { display: inline-flex; align-items: center; gap: 5px; }

/* Orders */
.orders-table { width: 100%; border-collapse: collapse; }
.order-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}
.order-item:last-child { border-bottom: 0; }
.order-item:hover { background: var(--surface-2); }
.order-item h3 { font-family: var(--font-mono); font-size: var(--fs-md); font-weight: 600; }
.order-item p { margin-top: 3px; font-size: var(--fs-sm); color: var(--text-2); }
.order-item p + p { color: var(--text-3); }
.order-item > div:last-child { display: flex; flex-direction: column; align-items: flex-end; gap: var(--sp-2); }
.order-item .total { font-size: var(--fs-lg); font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.order-item .status { background: var(--warning-soft); color: var(--warning-text); }
.order-item .status.cancelled { background: var(--neutral-soft); color: var(--text-3); }
.order-item .status.shipped { background: var(--success-soft); color: var(--success-text); }
.order-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; justify-content: flex-end; }

/* Setup */
.setup-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-4); align-items: start; }
.setup-col { display: flex; flex-direction: column; gap: var(--sp-4); min-width: 0; }
.setup-card { padding: var(--sp-6); }
.setup-card h2 { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-1); }
.setup-card .card-desc { margin-bottom: var(--sp-5); font-size: var(--fs-sm); color: var(--text-3); }
.setup-card hr { border: 0; border-top: 1px solid var(--border); margin: var(--sp-6) 0; }
.copy-field { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
.copy-field input { margin: 0; }
.pages-status-list { max-height: 320px; overflow: auto; border: 1px solid var(--border); border-radius: var(--r-md); padding: 0 var(--sp-3); }
.page-row-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.pages-status-list .cart-row { flex-wrap: wrap; }
.pages-status-list .cart-row > span:first-child { flex: 1 1 180px; overflow-wrap: anywhere; }

/* 7. Dialogs --------------------------------------------------------------- */
dialog {
  width: calc(100% - 32px);
  max-width: 480px;
  max-height: calc(100dvh - 48px);
  padding: var(--sp-6);
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-3);
  overflow-y: auto;
}
dialog[open] { animation: dialog-in .18s ease-out; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
dialog::backdrop { background: var(--backdrop); backdrop-filter: blur(2px); }
dialog h2 { font-size: var(--fs-xl); margin: 0 40px var(--sp-1) 0; }
dialog .dialog-desc { margin-bottom: var(--sp-5); font-size: var(--fs-sm); color: var(--text-3); }
dialog p { font-size: var(--fs-md); color: var(--text-2); }
.dialog-close {
  position: absolute; top: 14px; right: 14px;
  min-height: 34px; width: 34px; padding: 0;
  border-radius: 50%;
  color: var(--text-3);
  font-size: 22px; font-weight: 400;
}
.dialog-close:hover { background: var(--surface-3); color: var(--text); }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); margin-top: var(--sp-5); }

.quote-line { display: flex; justify-content: space-between; gap: var(--sp-3); padding: 7px 0; font-size: var(--fs-md); color: var(--text); }
.quote-line span:last-child { font-variant-numeric: tabular-nums; white-space: nowrap; }
.quote-line:first-child { font-size: var(--fs-sm); color: var(--text-3); border-bottom: 1px solid var(--border); padding-bottom: var(--sp-3); margin-bottom: var(--sp-1); }
.quote-total { margin-top: var(--sp-2); padding-top: var(--sp-3); border-top: 1px solid var(--border); font-size: var(--fs-xl); font-weight: 600; color: var(--text); }
.quote-address { margin: var(--sp-4) 0 0; padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); font-size: var(--fs-sm); white-space: pre-wrap; }

.staff-dialog { max-width: 820px; }
.staff-admin-section { margin-top: var(--sp-5); }
.staff-admin-section h3 { margin-bottom: var(--sp-3); font-size: var(--fs-lg); }
.create-staff-form { padding: var(--sp-4); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2); }
.staff-form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: var(--sp-3); }
.staff-form-grid label { display: block; }
.staff-form-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); margin-top: var(--sp-3); }
.staff-users-list, .staff-pages-list { max-height: 300px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--r-md); }
.staff-user-row, .staff-assign-row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); }
.staff-user-row:last-child, .staff-assign-row:last-child { border-bottom: 0; }
.staff-user-info, .staff-assign-page { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.staff-user-title, .staff-assign-page-head { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; font-size: var(--fs-md); }
.staff-user-code { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-3); }
.staff-user-info small, .staff-assign-page span:not(.page-status-badge) { font-size: var(--fs-sm); color: var(--text-3); }
.staff-user-controls { display: flex; align-items: center; gap: 6px; }
.staff-role-select { width: auto; min-height: var(--ctl-sm); margin: 0; padding: 0 30px 0 10px; font-size: var(--fs-sm); }
.staff-assign-row.is-disabled { background: var(--surface-2); }
.staff-assign-row.is-disabled strong { color: var(--text-3); }
.staff-assign-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.page-lifecycle-actions { display: flex; align-items: center; gap: 4px; margin-left: var(--sp-1); padding-left: var(--sp-2); border-left: 1px solid var(--border); }
.btn-toggle-page { min-height: var(--ctl-sm); padding: 0 10px; border-radius: var(--r-sm); font-size: var(--fs-sm); color: var(--text-2); }
.btn-toggle-page:hover { background: var(--surface-3); color: var(--text); }
.btn-toggle-page.enable { color: var(--success-text); }
.staff-preset-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: var(--sp-3) 0; font-size: var(--fs-sm); color: var(--text-3); }
.staff-modal-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--sp-2); margin-bottom: var(--sp-3); }
.staff-summary-chip { display: flex; flex-direction: column; gap: 2px; padding: var(--sp-2) var(--sp-3); border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--border); }
.staff-summary-chip strong { font-size: var(--fs-sm); font-weight: 600; color: var(--text); }
.staff-summary-chip span { font-size: var(--fs-xs); color: var(--text-3); }

/* Sign-in page (/login) */
.login-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(var(--sp-4) + env(safe-area-inset-top)) var(--sp-4) calc(var(--sp-4) + env(safe-area-inset-bottom));
}
.login-card {
  width: 100%;
  max-width: 400px;
  padding: var(--sp-6);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
}
.login-card .login-brand { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-5); }
.login-card .login-brand .brand-mark { width: 44px; height: 44px; border-radius: 12px; flex: none; }
.login-card .login-brand h1 { margin: 0; font-size: 1.25rem; }
.login-card .login-brand .dialog-desc { margin: 2px 0 0; }
.login-back { display: block; margin-top: var(--sp-4); text-align: center; font-size: .875rem; }
.login-form { margin-top: var(--sp-2); }
.login-form label { margin-bottom: var(--sp-3); }
.login-form .form-row { grid-template-columns: 1fr; gap: 0; }

.delete-page-dialog, .confirm-dialog { max-width: 420px; }
.confirm-icon.success { background: var(--success-soft); color: var(--success); }
.confirm-icon.neutral { background: var(--brand-soft); color: var(--brand-text); }
.confirm-icon { display: grid; place-items: center; width: 44px; height: 44px; margin-bottom: var(--sp-4); border-radius: 50%; background: var(--danger-soft); color: var(--danger); }
.danger-text { color: var(--danger-text); font-weight: 600; }

.form-error {
  display: flex; align-items: flex-start; gap: 8px;
  margin: 0 0 var(--sp-3);
  padding: 10px 12px;
  border-radius: var(--r-md);
  background: var(--danger-soft);
  color: var(--danger-text);
  font-size: var(--fs-sm);
  font-weight: 500;
}
.notice-box {
  display: flex; align-items: flex-start; gap: 8px;
  margin-top: var(--sp-3);
  padding: 10px 12px;
  border-radius: var(--r-md);
  background: var(--warning-soft);
  color: var(--warning-text) !important;
  font-size: var(--fs-sm) !important;
}
.notice-box .ic { margin-top: 2px; }
.edit-staff-dialog, .new-password-dialog { max-width: 440px; }
.password-box {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap;
  margin-top: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
}
.password-box { flex-direction: column; align-items: stretch; }
.password-box-head { display: flex; flex-direction: column; gap: 2px; }
.password-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.password-actions .btn-xs[aria-expanded="true"] { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-text); }
.custom-password-fields { display: grid; gap: var(--sp-3); padding-top: var(--sp-3); border-top: 1px dashed var(--border-strong); }
.custom-password-fields[hidden] { display: none; }
.check-row.compact { margin: 0; font-size: var(--fs-sm); color: var(--text-2); }
.custom-password-submit { display: flex; justify-content: flex-end; }

/* Multi-select staff (a page can have several) */
.staff-checks { margin: 0; }
.staff-checks legend { display: flex; align-items: baseline; gap: 6px; margin-bottom: 6px; font-size: var(--fs-sm); font-weight: 500; color: var(--text-2); }
.staff-checks legend .field-hint { margin: 0; }
.check-list { display: flex; flex-wrap: wrap; gap: 6px; }
.check-list .check-chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 32px; padding: 0 12px 0 8px;
  border: 1px solid var(--border); border-radius: var(--r-full);
  background: var(--surface); color: var(--text-2);
  font-size: var(--fs-sm); font-weight: 500; cursor: pointer;
}
.check-list .check-chip input { width: 16px; height: 16px; margin: 0; }
.check-chip:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-text); }
.check-list .empty-note { font-size: var(--fs-sm); color: var(--text-3); }
.staff-assign-btn .ic { width: 14px; height: 14px; }
.staff-assign-btn[aria-pressed="true"] { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-text); }
.staff-assign-btn[aria-pressed="false"] { border-style: dashed; color: var(--text-3); }
.unassigned { color: var(--warning-text); font-weight: 500; }
.staff-owner-pill { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.password-box strong { font-size: var(--fs-md); font-weight: 600; }
.password-box .field-hint { margin-top: 0; }
input.password-reveal { font-family: var(--font-mono); font-size: var(--fs-lg); letter-spacing: .06em; color: var(--text); background: var(--surface-2); }
.staff-user-controls .btn-xs .ic { width: 14px; height: 14px; }

/* 8. Responsive ------------------------------------------------------------ */
/* Products page ------------------------------------------------------------ */
.catalog-panel { padding: var(--sp-4) var(--sp-5) var(--sp-3); overflow: visible; }
.catalog-toolbar { display: flex; gap: var(--sp-3); align-items: center; margin-bottom: var(--sp-3); }
.catalog-toolbar input[type="search"] { flex: 1; min-width: 0; }
.catalog-toolbar .primary { flex-shrink: 0; white-space: nowrap; }
.catalog-filters { margin-bottom: var(--sp-3); }

.catalog-head, .catalog-row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 110px 90px 118px 84px;
  column-gap: var(--sp-4);
  align-items: center;
}
.catalog-head {
  padding: 0 var(--sp-3) var(--sp-2);
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-3);
}
.catalog-head span:first-child { grid-column: 1 / 3; }
.catalog-head span:nth-child(2), .catalog-head span:nth-child(3) { text-align: right; }

.catalog-list { min-height: 120px; }
.catalog-list[aria-busy="true"] { opacity: .55; transition: opacity .15s; }
.catalog-row { padding: var(--sp-3); border-bottom: 1px solid var(--border); }
.catalog-row:hover { background: var(--surface-2); }
.catalog-row.is-off .catalog-cover, .catalog-row.is-off .catalog-info,
.catalog-row.is-deleted .catalog-cover, .catalog-row.is-deleted .catalog-info { opacity: .55; }

.catalog-cover, .product-cover-preview {
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--surface-3);
  color: var(--text-3);
  border: 1px solid var(--border);
}
.catalog-cover { width: 48px; height: 64px; border-radius: var(--r-sm); }
.catalog-cover img, .product-cover-preview img { width: 100%; height: 100%; object-fit: cover; }

.catalog-info { min-width: 0; }
.catalog-name {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text);
  line-height: var(--lh-tight);
  text-align: left;
  overflow-wrap: anywhere;
}
button.catalog-name:hover { color: var(--brand-text); text-decoration: underline; }
.catalog-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 4px; font-size: var(--fs-xs); color: var(--text-3); }
.catalog-meta .mono { font-family: var(--font-mono); }
.catalog-meta .pill { height: 20px; }

.catalog-price, .catalog-stock { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.catalog-price strong, .catalog-stock strong { font-size: var(--fs-md); font-weight: 600; color: var(--text); }
.catalog-price s { font-size: var(--fs-xs); color: var(--text-3); }
.catalog-stock small { font-size: var(--fs-xs); color: var(--text-3); }
.catalog-stock.low strong { color: var(--warning-text); }
.catalog-stock.out strong { color: var(--danger-text); }

.catalog-actions { display: flex; justify-content: flex-end; gap: 2px; }
.danger-icon:hover { background: var(--danger-soft); color: var(--danger); }

.catalog-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: var(--sp-8) var(--sp-4); text-align: center; color: var(--text-3); font-size: var(--fs-sm); }
.catalog-empty strong { color: var(--text); font-size: var(--fs-md); }
.catalog-empty .ic-lg { width: 28px; height: 28px; margin-bottom: var(--sp-1); }

.catalog-pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3) 0 var(--sp-1); font-size: var(--fs-sm); color: var(--text-3); }
.catalog-pager-nav { display: flex; align-items: center; gap: var(--sp-2); }
.catalog-page-no { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Category filters and groups */
.catalog-facets { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.catalog-facets select { flex: 1 1 180px; max-width: 280px; min-height: var(--ctl-sm); padding-top: 4px; padding-bottom: 4px; font-size: var(--fs-sm); }
.catalog-facets select.is-set { border-color: var(--brand); background-color: var(--brand-softer); color: var(--brand-text); font-weight: 600; }
.catalog-groups { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin-top: 6px; }
.catalog-category { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-xs); font-weight: 500; color: var(--text-2); }
.tag-chip { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: var(--r-full); background: var(--brand-soft); color: var(--brand-text); font-size: var(--fs-xs); font-weight: 500; white-space: nowrap; }
.tag-chip.more { background: var(--neutral-soft); color: var(--neutral-text); cursor: default; }

.product-tags-field { margin: var(--sp-1) 0 var(--sp-3); }
.product-tags-field legend { font-size: var(--fs-sm); font-weight: 500; color: var(--text-2); margin-bottom: var(--sp-2); }
.product-tags-field legend .field-hint { display: inline; margin: 0 0 0 4px; }
.tag-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-option { position: relative; display: inline-flex; cursor: pointer; }
.tag-option input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.tag-option span {
  display: inline-flex; align-items: center; min-height: 30px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: var(--r-full);
  background: var(--surface); color: var(--text-2); font-size: var(--fs-sm); white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s;
}
.tag-option:hover span { border-color: var(--text-3); color: var(--text); }
.tag-option input:checked + span { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-text); font-weight: 600; }
.tag-option input:focus-visible + span { box-shadow: var(--focus-ring); }

/* Live sync with the shop's stock system */
.sync-bar { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-3); padding: 6px 6px 6px var(--sp-3); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2); font-size: var(--fs-sm); color: var(--text-2); }
.sync-bar .sync-text { flex: 1; min-width: 0; }
.sync-bar .btn-xs { flex-shrink: 0; }
.sync-bar.is-ok { --tone: var(--success); }
.sync-bar.is-warning { --tone: var(--warning); background: var(--warning-soft); color: var(--warning-text); border-color: transparent; }
.sync-bar.is-error { --tone: var(--danger); background: var(--danger-soft); color: var(--danger-text); border-color: transparent; }
.sync-bar.is-off { --tone: var(--text-3); }
.page-status-badge.is-error { background: var(--danger-soft); color: var(--danger-text); }
.sync-details { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px var(--sp-4); margin: 0 0 var(--sp-3); font-size: var(--fs-sm); }
.sync-details dt { color: var(--text-3); }
.sync-details dd { margin: 0; color: var(--text); overflow-wrap: anywhere; }
.setup-howto { margin-top: var(--sp-3); font-size: var(--fs-sm); color: var(--text-2); }
.setup-howto summary { cursor: pointer; font-weight: 600; color: var(--text); }
.setup-howto p { margin: var(--sp-2) 0; font-size: var(--fs-sm); }
.setup-howto pre { margin: 0 0 var(--sp-2); padding: var(--sp-2) var(--sp-3); border-radius: var(--r-sm); background: var(--surface-3); font-family: var(--font-mono); font-size: var(--fs-xs); white-space: pre-wrap; overflow-wrap: anywhere; }
.synced-note { margin: 0 0 var(--sp-4); }
#product-form input:disabled, #product-form select:disabled { background: var(--surface-2); color: var(--text-2); cursor: not-allowed; }
.tag-option input:disabled + span { cursor: not-allowed; opacity: .75; }

/* Held product sync: review dialog and alert */
.sync-hold-dialog { max-width: 560px; }
.confirm-icon.warning { background: var(--warning-soft); color: var(--warning); }
.sync-hold-reasons { margin: 0 0 var(--sp-4); padding-left: 20px; font-size: var(--fs-md); font-weight: 600; color: var(--text); }
.sync-hold-reasons li + li { margin-top: 4px; }
.sync-hold-list { margin-bottom: var(--sp-4); }
.sync-hold-list ul { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--r-md); }
.sync-hold-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: var(--sp-3); align-items: center; padding: 6px var(--sp-3); border-top: 1px solid var(--border); font-size: var(--fs-sm); }
.sync-hold-list li:first-child { border-top: 0; }
.sync-hold-list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.sync-hold-list .mono { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-3); }
.sync-hold-list .value { font-variant-numeric: tabular-nums; color: var(--danger-text); font-weight: 600; white-space: nowrap; }
.sync-hold-list small { display: block; margin-top: 4px; color: var(--text-3); font-size: var(--fs-xs); }
.alert-item.alert-sync { background: var(--warning-soft); }
.alert-item.alert-sync strong { color: var(--warning-text); }
.sync-bar .primary.btn-xs { flex-shrink: 0; }

/* Install entry: bottom of the sidebar (computers) and an icon in the top bar (phones) */
.side-bottom { margin-top: auto; padding-top: var(--sp-4); }
.sidebar > .side-app-btn { margin-top: var(--sp-3); }

/* Signed-in person at the bottom of the sidebar */
.side-profile { border-top: 1px solid var(--border); }
.side-profile .profile-btn { width: 100%; justify-content: flex-start; border-radius: var(--r-md); }
.side-profile .profile-text { flex: 1; min-width: 0; }
.side-profile .profile-text strong { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-profile .chev { transform: rotate(180deg); }
.side-profile .profile-btn[aria-expanded="true"] .chev { transform: none; }
.side-app-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  min-height: 0; padding: 10px 12px;
  border: 1px dashed var(--border-strong); border-radius: var(--r-md);
  background: transparent; color: var(--text-2); text-align: left;
}
.side-app-btn:hover { border-color: var(--brand); background: var(--brand-softer); color: var(--brand-text); }
.side-app-btn .ic { flex-shrink: 0; width: 20px; height: 20px; }
.side-app-btn span { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.side-app-btn strong { font-size: var(--fs-sm); font-weight: 600; color: inherit; }
.side-app-btn small { font-size: var(--fs-xs); color: var(--text-3); white-space: normal; }
.topbar-app-btn { display: none; }

/* Installed app and phone notifications */
.app-dialog { max-width: 460px; }
.app-dialog-head { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.app-dialog-head img { border-radius: 14px; flex-shrink: 0; }
.app-dialog-head h2 { margin-right: 32px; }
.app-dialog-head .dialog-desc { margin: 2px 0 0; }
.app-section { padding: var(--sp-4); margin-bottom: var(--sp-3); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2); }
.app-section h3 { display: flex; align-items: center; gap: var(--sp-2); margin: 0 0 var(--sp-3); font-size: var(--fs-md); }
.app-step-no { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--brand); color: var(--on-brand); font-size: var(--fs-xs); font-weight: 700; }
.app-steps { margin: 0; padding-left: 20px; font-size: var(--fs-sm); color: var(--text-2); line-height: 1.7; }
.app-state { display: flex; align-items: center; gap: 6px; margin: 0 0 var(--sp-2); font-size: var(--fs-sm); color: var(--text-2); }
.app-state.ok { color: var(--success-text); font-weight: 600; }
.app-state.warn { color: var(--warning-text); }
.app-notify-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
#app-notify-what { margin: 0 0 var(--sp-3); }

/* AI provider and WaveSpeed model picker */
.ai-provider-row { grid-column: 1 / -1; display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.ai-provider-label { font-size: var(--fs-sm); font-weight: 500; color: var(--text-2); }
.ai-provider-fields { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: var(--sp-5); }
.ai-provider-fields[hidden] { display: none; }
.ai-provider-fields[data-provider-fields="wavespeed"] > .field { grid-column: 1 / 2; }
.ws-picker { grid-column: 1 / -1; margin-bottom: var(--sp-3); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2); }
.ws-picker-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--sp-2); padding: var(--sp-3) var(--sp-3) 0; font-size: var(--fs-sm); color: var(--text-2); }
.ws-picker-head b { color: var(--text); overflow-wrap: anywhere; }
.ws-picker-head .field-hint { margin: 0; }
.ws-picker-tools { display: flex; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); }
.ws-picker-tools input { flex: 1; min-width: 0; }
.ws-picker-tools select { width: auto; flex-shrink: 0; }
.ws-models { max-height: 380px; overflow-y: auto; border-top: 1px solid var(--border); background: var(--surface); }
.ws-model {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--sp-3); align-items: center;
  width: 100%; min-height: 0; padding: 10px var(--sp-3);
  border: 0; border-bottom: 1px solid var(--border); border-radius: 0;
  background: var(--surface); text-align: left; color: var(--text);
}
.ws-model:hover { background: var(--surface-2); }
.ws-model.selected { background: var(--brand-softer); box-shadow: inset 3px 0 0 var(--brand); }
.ws-model-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ws-model-name { font-weight: 600; font-size: var(--fs-md); overflow-wrap: anywhere; }
.ws-model-id { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-3); overflow-wrap: anywhere; }
.ws-model-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.ws-model-tags .pill { height: 18px; font-size: 11px; }
.ws-model-tags .pill.warn { background: var(--warning-soft); color: var(--warning-text); }
.ws-model-price { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ws-per-reply { font-weight: 700; font-size: var(--fs-md); color: var(--text); }
.ws-thb { font-size: var(--fs-xs); color: var(--text-2); }
.ws-per-m { font-size: 11px; color: var(--text-3); }
#ws-note { margin: 0; padding: var(--sp-2) var(--sp-3) var(--sp-3); }
.ai-effort-field { grid-column: 1 / 2; }
.ai-usage { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 2px; margin-bottom: var(--sp-3); padding: 10px 12px; border-radius: var(--r-md); background: var(--info-soft); color: var(--info-text); font-size: var(--fs-sm); }
.ai-usage strong { color: var(--text); }
@media (max-width: 760px) {
  .ai-provider-fields { grid-template-columns: 1fr; }
  .ai-provider-fields[data-provider-fields="wavespeed"] > .field, .ai-effort-field { grid-column: 1 / -1; }
  .ws-picker-tools { flex-wrap: wrap; }
  .ws-model { grid-template-columns: 1fr; }
  .ws-model-price { align-items: flex-start; flex-direction: row; flex-wrap: wrap; gap: 4px 8px; }
}

/* Facebook connection checklist and guide */
.meta-checklist { list-style: none; margin: 0 0 var(--sp-3); padding: 0; display: flex; flex-direction: column; gap: 6px; }
.meta-checklist li { display: grid; grid-template-columns: 18px minmax(0, 1fr); column-gap: 8px; align-items: start; font-size: var(--fs-sm); color: var(--text); }
.meta-checklist li .ic { width: 16px; height: 16px; margin-top: 3px; }
.meta-checklist li.ok .ic { color: var(--success); }
.meta-checklist li.missing .ic { color: var(--danger); }
.meta-checklist li.warn .ic { color: var(--warning); }
.meta-checklist li small { grid-column: 2; font-size: var(--fs-xs); color: var(--text-3); }
.section-title .icon-btn { min-height: 28px; width: 28px; }
.howto-steps { margin: var(--sp-3) 0 0; padding-left: 22px; }
.howto-steps li { margin-bottom: var(--sp-3); }
.howto-steps li strong { display: block; color: var(--text); font-size: var(--fs-sm); }
.howto-steps li p { margin: 4px 0; }
.howto-steps code { font-family: var(--font-mono); font-size: var(--fs-xs); padding: 1px 5px; border-radius: 4px; background: var(--surface-3); }
.page-fb-state { margin-top: 2px; font-size: var(--fs-xs); }
.page-fb-state.ok { color: var(--success-text); }
.page-fb-state.warn { color: var(--warning-text); }
.page-fb-state.missing { color: var(--danger-text); }

/* On/off switch (a styled checkbox) */
.switch-row { position: relative; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.switch-row input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.switch {
  position: relative;
  flex-shrink: 0;
  width: 38px;
  height: 22px;
  border-radius: var(--r-full);
  background: var(--border-strong);
  transition: background-color .15s;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
  transition: transform .15s;
}
.switch-row input:checked + .switch { background: var(--brand); }
.switch-row input:checked + .switch::after { transform: translateX(16px); }
.switch-row input:focus-visible + .switch { box-shadow: var(--focus-ring); }
.switch-row input:disabled + .switch { opacity: .5; }
.switch-label { font-size: var(--fs-sm); color: var(--text-2); white-space: nowrap; }
.switch-text { display: flex; flex-direction: column; gap: 2px; }
.switch-text strong { font-size: var(--fs-md); color: var(--text); }
.switch-text small { font-size: var(--fs-xs); color: var(--text-3); font-weight: 400; }

/* Product form */
.product-dialog { max-width: 760px; }
.product-form-layout { display: grid; grid-template-columns: 168px minmax(0, 1fr); gap: var(--sp-5); }
.product-cover-field { display: flex; flex-direction: column; gap: var(--sp-2); }
.product-cover-preview { width: 168px; aspect-ratio: 3 / 4; border-radius: var(--r-md); }
.product-cover-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: var(--fs-sm); }
.product-cover-empty .ic { width: 26px; height: 26px; }
.product-cover-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.file-btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border-strong); cursor: pointer; font-weight: 500; color: var(--text); }
.file-btn:hover { background: var(--surface-3); }
#product-image:focus-visible + .product-cover-actions .file-btn { box-shadow: var(--focus-ring); }
.product-fields .field { margin-bottom: var(--sp-3); }
.product-fields .switch-row { margin-top: var(--sp-1); padding: var(--sp-3); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2); }
.req { color: var(--danger); }

.product-pages { margin-top: var(--sp-4); border: 1px solid var(--border); border-radius: var(--r-md); }
.product-pages summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  cursor: pointer;
  font-size: var(--fs-md);
  font-weight: 600;
  list-style: none;
}
.product-pages summary::-webkit-details-marker { display: none; }
.product-pages summary::after {
  content: '';
  width: 8px;
  height: 8px;
  margin-left: auto;
  border-right: 2px solid var(--text-3);
  border-bottom: 2px solid var(--text-3);
  transform: rotate(45deg);
  transition: transform .15s;
}
.product-pages[open] summary::after { transform: rotate(-135deg); }
.product-pages summary small { font-size: var(--fs-xs); font-weight: 500; color: var(--text-3); }
.product-pages > .field-hint { margin: 0; padding: 0 var(--sp-4) var(--sp-2); }
.product-pages-list { max-height: 260px; overflow-y: auto; padding: 0 var(--sp-4) var(--sp-3); }
.product-page-row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: 6px 0; border-top: 1px solid var(--border); }
.product-page-row .check-row { flex: 1; min-width: 0; }
.product-page-name { overflow-wrap: anywhere; }
.product-page-name small { color: var(--text-3); }
.product-page-price { width: 120px; flex-shrink: 0; min-height: var(--ctl-sm); text-align: right; font-variant-numeric: tabular-nums; }
.product-page-price:disabled { opacity: .5; }

@media (max-width: 1000px) {
  .catalog-head { display: none; }
  .catalog-row {
    grid-template-columns: 48px minmax(0, 1fr) auto;
    grid-template-areas:
      "cover info info"
      "cover price stock"
      "cover state actions";
    row-gap: var(--sp-2);
    align-items: start;
  }
  .catalog-cover { grid-area: cover; }
  .catalog-info { grid-area: info; }
  .catalog-price { grid-area: price; flex-direction: row; align-items: baseline; justify-content: flex-start; gap: 6px; }
  .catalog-stock { grid-area: stock; flex-direction: row; align-items: baseline; gap: 6px; }
  .catalog-stock strong::before { content: 'คงเหลือ '; font-weight: 400; color: var(--text-3); font-size: var(--fs-sm); }
  .catalog-stock.out strong::before { content: ''; }
  .catalog-state { grid-area: state; align-self: center; }
  .catalog-actions { grid-area: actions; }
}
@media (max-width: 760px) {
  .catalog-panel { padding: var(--sp-3); }
  .catalog-toolbar .primary { padding: 6px 12px; }
  .product-form-layout { grid-template-columns: 1fr; }
  .product-cover-field { flex-direction: row; flex-wrap: wrap; align-items: flex-end; }
  .product-cover-preview { width: 96px; }
  .product-cover-field .field-hint { flex-basis: 100%; }
  .product-page-price { width: 100px; }
}

/* Larger cover shown while hovering a product thumbnail */
.cover-zoom {
  position: fixed;
  z-index: 60;
  width: 260px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-3);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: scale(.96);
  transition: opacity .12s ease-out, transform .12s ease-out, visibility 0s linear .12s;
}
.cover-zoom.open { opacity: 1; visibility: visible; transform: none; transition: opacity .12s ease-out, transform .12s ease-out; }
.cover-zoom img { display: block; width: 100%; max-height: min(380px, calc(100vh - 32px)); object-fit: contain; border-radius: var(--r-md); }
.catalog-cover img, .product-icon.has-cover img { cursor: zoom-in; }

@media (min-width: 1600px) {
  .workspace-grid.three-col { grid-template-columns: 310px minmax(0, 1fr) 380px; }
}

@media (max-width: 1360px) {
  .workspace-grid.three-col { grid-template-columns: 260px minmax(0, 1fr) 320px; }
}

@media (max-width: 1180px) {
  :root { --sidebar-w: 220px; }
  .workspace-top-flush { height: auto; }
  .workspace-grid.three-col { grid-template-columns: 280px minmax(0, 1fr); }
  .workspace-grid.three-col .customer-list-panel,
  .workspace-grid.three-col .chat-panel { height: calc(100dvh - 190px - var(--topbar-h)); min-height: 520px; }
  .workspace-grid.three-col .order-panel { grid-column: 1 / -1; }
  .order-content { overflow: visible; }
  .order-submit { position: static; margin: var(--sp-4) 0 0; padding: 0; background: none; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .setup-grid { grid-template-columns: 1fr; }
}

@media (max-width: 1000px) {
  /* Stacked inbox: customers as a horizontal strip, then chat, then order */
  .workspace-grid.three-col { grid-template-columns: minmax(0, 1fr); gap: var(--sp-3); }
  .workspace-grid.three-col .customer-list-panel { height: auto; min-height: 0; order: 1; }
  .workspace-grid.three-col .chat-panel { order: 2; height: 72dvh; min-height: 460px; }
  .workspace-grid.three-col .order-panel { order: 3; grid-column: auto; }
  .customer-list-head { padding: var(--sp-3) var(--sp-3) var(--sp-2); border-bottom: 0; }
  .page-customer-list { flex-direction: row; overflow-x: auto; overflow-y: hidden; padding: 0 var(--sp-3) var(--sp-3); gap: var(--sp-2); scroll-snap-type: x proximity; }
  .cust-section-divider { display: none; }
  .cust-row { flex: 0 0 230px; border: 1px solid var(--border); scroll-snap-align: start; }
  .cust-row.active { border-color: var(--brand); }

}

@media (max-width: 760px) {
  main {
    margin-left: 0 !important;
    height: auto;
    min-height: 100dvh;
    padding: var(--sp-3) var(--sp-3) calc(76px + env(safe-area-inset-bottom));
    overflow: visible;
  }

  /* Sidebar becomes only the fixed bottom tab bar; brand + profile sit in the top bar */
  .sidebar { display: contents; }
  .brand-row, .sidebar-expand-btn, .nav-label { display: none !important; }
  .sidebar > .side-app-btn { display: none !important; }
  .side-profile { position: fixed; top: calc(8px + env(safe-area-inset-top)); right: var(--sp-3); z-index: 31; margin: 0; padding: 0; border: 0; }
  .side-profile .profile-btn { width: auto; border-radius: var(--r-full); }
  .side-profile .chev { transform: none; }
  .app-topbar .topbar-right { margin-right: 84px; }
  .app-topbar .topbar-app-btn { display: inline-flex; }
  .nav-long { display: none; }

  .app-topbar { margin: calc(-1 * var(--sp-3)) calc(-1 * var(--sp-3)) var(--sp-3); padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--border); background: var(--surface); }
  .topbar-brand { display: grid; width: 32px; height: 32px; }
  .topbar-title h1 { font-size: var(--fs-lg); }
  .topbar-title p { display: none; }
  .profile-text { display: none; }
  .profile-btn { padding: 3px 8px 3px 3px; min-height: 40px; }


  .main-nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 50;
    flex-direction: row;
    gap: 0;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 16px rgba(16, 24, 40, .06);
  }
  .nav {
    position: relative;
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    min-height: 54px;
    padding: 4px 2px;
    font-size: var(--fs-xs);
    text-align: center;
  }
  .nav span { flex: 0; white-space: nowrap; }
  .nav .ic { width: 22px; height: 22px; }
  .nav.active { background: none; }
  .nav b { position: absolute; top: 2px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; font-size: 11px; }

  .staff-filter-btn { width: 124px; }
  .staff-filter-btn .staff-pill-badge { display: none; }
  .page-tab-btn { width: 156px; }

  .chat-panel .panel-head { padding: var(--sp-3); gap: var(--sp-2); }
  .lifecycle-bar { padding: var(--sp-2) var(--sp-3); }
  .messages { padding: var(--sp-4) var(--sp-3) var(--sp-2); }
  .bubble { max-width: 86%; }
  .composer { padding: var(--sp-2); gap: 4px; }

  .stats { gap: var(--sp-2); }
  .stats > div { padding: var(--sp-3) var(--sp-4); }
  .stats strong { font-size: var(--fs-xl); }
  .queue-panel { padding: var(--sp-4); }
  .queue-list { grid-template-columns: 1fr; }
  .order-item { grid-template-columns: 1fr; padding: var(--sp-4); }
  .order-item > div:last-child { align-items: flex-start; }
  .order-actions { justify-content: flex-start; }
  .setup-card { padding: var(--sp-4); }
  .form-row { grid-template-columns: 1fr; gap: 0; }
  .ai-form { grid-template-columns: 1fr; }
  .staff-user-row, .staff-assign-row { flex-direction: column; align-items: stretch; }
  .staff-assign-actions { justify-content: flex-start; }
  .page-lifecycle-actions { margin-left: 0; padding-left: 0; border-left: 0; }

  dialog { padding: var(--sp-5); border-radius: 16px; }
  #toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
}

/* ---- Phones: list → full-screen chat → order ---------------------------- */
.m-only { display: none !important; }
@media (max-width: 760px) {
  .m-only { display: inline-flex !important; }
  .m-only[hidden] { display: none !important; }

  .app-topbar { padding-top: calc(var(--sp-2) + env(safe-area-inset-top)); }

  body[data-mview="list"] #workspace .chat-panel,
  body[data-mview="list"] #workspace .order-panel,
  body[data-mview="chat"] #workspace .order-panel,
  body[data-mview="order"] #workspace .chat-panel { display: none; }

  /* Chat and order fill the phone screen, above the tab bar */
  body[data-mview="chat"] #workspace .chat-panel,
  body[data-mview="order"] #workspace .order-panel {
    position: fixed;
    inset: 0;
    z-index: 45;
    height: auto;
    min-height: 0;
    margin: 0;
    border: 0;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface);
  }
  body[data-mview="chat"], body[data-mview="order"] { overflow: hidden; }
  body[data-mview="chat"] .main-nav, body[data-mview="order"] .main-nav { display: none; }

  body[data-mview="chat"] .chat-panel .panel-head { flex-wrap: nowrap; gap: var(--sp-1); padding: var(--sp-2) var(--sp-2) var(--sp-2) var(--sp-1); }
  body[data-mview="chat"] .chat-identity { flex: 1; min-width: 0; }
  body[data-mview="chat"] .chat-identity h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  body[data-mview="chat"] .chat-head-actions { flex-shrink: 0; gap: 2px; }
  body[data-mview="chat"] .lifecycle-bar { padding: 6px var(--sp-2); }
  body[data-mview="chat"] .lifecycle-label { display: none; }
  body[data-mview="chat"] .messages { flex: 1; min-height: 0; }
  body[data-mview="chat"] .composer-wrap { padding-bottom: 2px; }

  body[data-mview="order"] .order-panel .panel-head { gap: var(--sp-1); padding: var(--sp-2) var(--sp-3) var(--sp-2) var(--sp-1); }
  body[data-mview="order"] .order-content { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  /* One scroll for the whole order screen, no box scrolling inside it */
  body[data-mview="order"] .products-scroll { max-height: none; overflow: visible; }

  .back-btn { width: 40px; min-height: 40px; color: var(--text); flex-shrink: 0; }
  .order-for { margin-left: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-sm); color: var(--text-3); }
  .chat-order-btn { position: relative; }
  .chat-cart-badge {
    position: absolute; top: 2px; right: 0;
    min-width: 18px; height: 18px; padding: 0 5px;
    border-radius: var(--r-full); background: var(--danger); color: #fff;
    font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Chat page on computers: no page title, more room for the chat */
@media (min-width: 761px) {
  main { position: relative; }
  body[data-view="workspace"] .topbar-title { display: none; }
  body[data-view="workspace"] .app-topbar {
    position: absolute;
    top: var(--sp-3);
    left: var(--sp-4);
    right: var(--sp-4);
    min-height: 0;
    margin: 0;
    padding: 0;
    background: transparent;
    pointer-events: none;
  }
  body[data-view="workspace"] .app-topbar > * { pointer-events: auto; }
  body[data-view="workspace"] .page-tabs-shell { padding-right: 52px; }
  body.sidebar-collapsed[data-view="workspace"] .page-tabs-shell { padding-left: 48px; }
  body[data-view="workspace"] .workspace-top-flush { height: calc(100dvh - 24px); }
}

/* The bot asks the team (above the reply box) */
.bot-ask {
  margin: 0 var(--sp-3) var(--sp-2);
  padding: var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface-2);
}
.bot-ask.is-question { border-color: color-mix(in srgb, var(--warning) 45%, transparent); background: var(--warning-soft); }
.bot-ask-head { display: flex; align-items: flex-start; gap: var(--sp-2); }
.bot-ask-icon { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--surface); border: 1px solid var(--border); flex: none; }
.bot-ask-body { flex: 1; min-width: 0; }
.bot-ask-body strong { display: block; font-size: var(--fs-xs); color: var(--text-2); }
.bot-ask-body p { margin-top: 2px; font-size: var(--fs-sm); color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }
.bot-ask-head .icon-btn { width: 28px; height: 28px; }
.bot-ask-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: var(--sp-2); }
.bot-ask-actions .btn-xs { background: var(--surface); }
.bot-advise { display: flex; align-items: flex-end; gap: var(--sp-2); margin-top: var(--sp-2); }
.bot-advise textarea { flex: 1; min-width: 0; min-height: 40px; max-height: 140px; resize: vertical; font: inherit; font-size: var(--fs-sm); }
.bot-advise .btn-xs { flex: none; }
.bot-ask-hint { margin-top: 6px; font-size: var(--fs-xs); color: var(--text-3); }
.composer-sub { display: flex; align-items: center; gap: var(--sp-2); }
.composer-sub .hint { flex: 1; min-width: 0; }
.link-btn { padding: 2px 4px; border: 0; background: none; color: var(--brand-text); cursor: pointer; font: inherit; }
.link-btn:hover { text-decoration: underline; }
#bot-advise-open { display: inline-flex; align-items: center; gap: 4px; flex: none; font-size: var(--fs-xs); }
#bot-advise-open[hidden] { display: none; }
.workspace-grid.chat-locked .bot-ask, .workspace-grid.chat-locked #bot-advise-open { display: none; }
.alert-item.alert-consult small { color: var(--text); }
