/* ==========================================================================
   Tokens
   ========================================================================== */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --surface-hover: #f3f4f6;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-2: #374151;
  --muted: #6b7280;
  --faint: #9ca3af;

  --primary: #111827;
  --primary-hover: #1f2937;
  --on-primary: #ffffff;
  --accent: #2563eb;
  --focus: rgba(37, 99, 235, 0.35);

  --success: #15803d;
  --success-bg: #f0fdf4;
  --success-border: #bbf7d0;
  --warning: #b45309;
  --warning-bg: #fffbeb;
  --warning-border: #fde68a;
  --danger: #b91c1c;
  --danger-solid: #dc2626;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;
  --info: #1d4ed8;
  --info-bg: #eff6ff;
  --info-border: #bfdbfe;

  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 20px 40px rgba(16, 24, 40, 0.16);

  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0b0d;
    --surface: #121316;
    --surface-2: #17181c;
    --surface-hover: #1c1e22;
    --border: #25272c;
    --border-strong: #33363c;
    --text: #ececee;
    --text-2: #c4c6cc;
    --muted: #8d9099;
    --faint: #62656d;
    --primary: #ececee;
    --primary-hover: #ffffff;
    --on-primary: #0a0b0d;
    --accent: #6ea8fe;
    --focus: rgba(110, 168, 254, 0.4);
    --success: #4ade80;
    --success-bg: rgba(34, 197, 94, 0.1);
    --success-border: rgba(34, 197, 94, 0.25);
    --warning: #fbbf24;
    --warning-bg: rgba(245, 158, 11, 0.1);
    --warning-border: rgba(245, 158, 11, 0.25);
    --danger: #f87171;
    --danger-solid: #dc2626;
    --danger-bg: rgba(239, 68, 68, 0.1);
    --danger-border: rgba(239, 68, 68, 0.3);
    --info: #93c5fd;
    --info-bg: rgba(59, 130, 246, 0.1);
    --info-border: rgba(59, 130, 246, 0.28);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.55);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0a0b0d;
  --surface: #121316;
  --surface-2: #17181c;
  --surface-hover: #1c1e22;
  --border: #25272c;
  --border-strong: #33363c;
  --text: #ececee;
  --text-2: #c4c6cc;
  --muted: #8d9099;
  --faint: #62656d;
  --primary: #ececee;
  --primary-hover: #ffffff;
  --on-primary: #0a0b0d;
  --accent: #6ea8fe;
  --focus: rgba(110, 168, 254, 0.4);
  --success: #4ade80;
  --success-bg: rgba(34, 197, 94, 0.1);
  --success-border: rgba(34, 197, 94, 0.25);
  --warning: #fbbf24;
  --warning-bg: rgba(245, 158, 11, 0.1);
  --warning-border: rgba(245, 158, 11, 0.25);
  --danger: #f87171;
  --danger-solid: #dc2626;
  --danger-bg: rgba(239, 68, 68, 0.1);
  --danger-border: rgba(239, 68, 68, 0.3);
  --info: #93c5fd;
  --info-bg: rgba(59, 130, 246, 0.1);
  --info-border: rgba(59, 130, 246, 0.28);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

/* ==========================================================================
   Base
   ========================================================================== */

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.3; font-weight: 600; letter-spacing: -0.011em; }
h1 { font-size: 22px; letter-spacing: -0.02em; }
h2 { font-size: 15px; }
h3 { font-size: 14px; }
p { margin: 0; }
strong { font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 0.92em; letter-spacing: 0.01em; }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

.icon {
  width: 16px; height: 16px; flex-shrink: 0;
  fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
  vertical-align: -3px;
}
.icon-sm { width: 14px; height: 14px; vertical-align: -2px; }
.icon-lg { width: 20px; height: 20px; }
[data-icon] { display: inline-flex; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ==========================================================================
   App shell
   ========================================================================== */

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 24px;
  height: 56px; display: flex; align-items: center; gap: 32px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 600; letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.brand-logo {
  width: 28px; height: 28px; border-radius: 7px;
  display: grid; place-items: center;
  background: var(--primary); color: var(--on-primary);
}
.brand-logo .icon { width: 16px; height: 16px; }

.nav { display: flex; gap: 4px; flex: 1; align-self: stretch; }
.nav a {
  position: relative; display: flex; align-items: center; gap: 8px;
  padding: 0 12px; color: var(--muted); font-weight: 500;
}
.nav a:hover { color: var(--text); text-decoration: none; }
.nav a.active { color: var(--text); }
.nav a.active::after {
  content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px;
  height: 2px; border-radius: 2px; background: var(--text);
}
.nav-count {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  display: inline-grid; place-items: center;
  background: var(--surface-hover); color: var(--text-2);
  font-size: 11.5px; font-weight: 600; font-variant-numeric: tabular-nums;
}

.topbar-right { display: flex; align-items: center; gap: 12px; }

.theme-switch {
  display: inline-flex; padding: 2px; gap: 2px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
}
.theme-switch button {
  width: 28px; height: 26px; border: 0; border-radius: 6px;
  display: grid; place-items: center;
  background: transparent; color: var(--muted); cursor: pointer;
}
.theme-switch button:hover { color: var(--text); }
.theme-switch button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.user-menu { position: relative; }
.user-btn {
  display: flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 8px 0 4px;
  border: 1px solid transparent; border-radius: var(--radius);
  background: transparent; color: var(--text); font: inherit; font-weight: 500; cursor: pointer;
}
.user-btn:hover, .user-btn[aria-expanded="true"] { background: var(--surface-hover); }
.user-btn .icon { color: var(--muted); }
.avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-hover); border: 1px solid var(--border);
  font-size: 11px; font-weight: 600; color: var(--text-2); text-transform: uppercase;
}
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30;
  min-width: 200px; padding: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}
.menu button {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.menu button:hover { background: var(--surface-hover); }
.menu button .icon { color: var(--muted); }

.demo-banner {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 16px;
  background: var(--warning-bg); color: var(--warning);
  border-bottom: 1px solid var(--warning-border);
  font-size: 13px; font-weight: 500;
}

.container { max-width: 1200px; margin: 0 auto; padding: 28px 24px 80px; }

/* ==========================================================================
   Page structure
   ========================================================================== */

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-head p { margin-top: 4px; color: var(--muted); }
.page-actions { display: flex; gap: 8px; }
.crumbs { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--text); text-decoration: none; }
.crumbs .icon { width: 14px; height: 14px; color: var(--faint); }
.title-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 6px; color: var(--muted); font-size: 13px; }
.meta span { display: inline-flex; align-items: center; gap: 6px; }

.layout-2 { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 20px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ==========================================================================
   Surfaces
   ========================================================================== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
}
.card-head p { margin-top: 2px; color: var(--muted); font-size: 13px; }
.card-body { padding: 20px; }
.card-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  padding: 12px 20px; border-top: 1px solid var(--border); background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; white-space: nowrap; cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.12s, border-color 0.12s, color 0.12s, opacity 0.12s;
}
.btn:hover:not(:disabled) { background: var(--surface-hover); text-decoration: none; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger-solid); border-color: var(--danger-solid); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; border-color: #b91c1c; }
.btn-ghost { border-color: transparent; background: transparent; box-shadow: none; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-lg { height: 40px; padding: 0 18px; }
.btn-block { width: 100%; }
.btn-icon { width: 34px; padding: 0; }

/* ==========================================================================
   Forms
   ========================================================================== */

.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; font-weight: 500; color: var(--text); display: flex; align-items: center; gap: 8px; }
.field-hint { font-size: 12.5px; color: var(--muted); }
input[type="text"], input[type="password"], input[type="search"], input[type="url"], select {
  width: 100%; height: 36px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font: inherit; box-shadow: var(--shadow-sm);
  transition: border-color 0.12s, box-shadow 0.12s;
}
select {
  appearance: none; padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' 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; background-size: 16px;
}
input::placeholder { color: var(--faint); }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
input.mono { font-family: var(--mono); font-size: 13.5px; letter-spacing: 0.04em; }
input.is-ok { border-color: var(--success); }
input.is-bad { border-color: var(--danger); }
.input-icon { position: relative; }
.input-icon .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.input-icon input { padding-left: 34px; }

.check {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); cursor: pointer;
  transition: border-color 0.12s, background-color 0.12s;
}
.check:hover { border-color: var(--border-strong); }
.check input { width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--primary); flex-shrink: 0; }
.check.checked { border-color: var(--success-border); background: var(--success-bg); }
.check-title { font-weight: 500; }
.check-desc { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

.form-error { display: flex; gap: 8px; align-items: flex-start; color: var(--danger); font-size: 13px; }


/* ==========================================================================
   Badges & callouts
   ========================================================================== */

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 22px; padding: 0 8px; border-radius: 6px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
  background: var(--surface-hover); color: var(--text-2);
  border: 1px solid var(--border);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.8; }
.badge.no-dot::before { display: none; }
.badge .icon { width: 12px; height: 12px; }
.badge-success { background: var(--success-bg); color: var(--success); border-color: var(--success-border); }
.badge-warning { background: var(--warning-bg); color: var(--warning); border-color: var(--warning-border); }
.badge-danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-border); }
.badge-info { background: var(--info-bg); color: var(--info); border-color: var(--info-border); }

.callout {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2);
  font-size: 13px;
}
.callout > .icon { margin-top: 1px; }
.callout strong { color: inherit; }
.callout-info { background: var(--info-bg); border-color: var(--info-border); color: var(--info); }
.callout-warning { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning); }
.callout-danger { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger); }
.callout-success { background: var(--success-bg); border-color: var(--success-border); color: var(--success); }

/* ==========================================================================
   Tables
   ========================================================================== */

.toolbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.toolbar .input-icon { flex: 1; max-width: 360px; }
.toolbar .count { margin-left: auto; color: var(--muted); font-size: 13px; }

.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th {
  height: 38px; padding: 0 16px; text-align: left;
  font-size: 12px; font-weight: 500; color: var(--muted);
  background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-hover); }
.table .right { text-align: right; }
.table .order-link { font-weight: 600; color: var(--text); }
.table .sub { color: var(--muted); font-size: 12.5px; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions .btn + .btn { margin-left: 4px; }
.cell-truncate { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty { padding: 56px 24px; text-align: center; color: var(--muted); }
.empty .empty-icon {
  width: 44px; height: 44px; margin: 0 auto 14px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--surface-hover); color: var(--muted);
}
.empty h2 { color: var(--text); margin-bottom: 4px; }

/* ==========================================================================
   Order detail
   ========================================================================== */

.items { width: 100%; border-collapse: collapse; }
.items td { padding: 14px 20px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.items tr:last-child td { border-bottom: 0; }
.item-cell { display: flex; gap: 12px; align-items: center; }
.thumb {
  width: 44px; height: 44px; border-radius: var(--radius); flex-shrink: 0; overflow: hidden;
  display: grid; place-items: center;
  background: var(--surface-hover); border: 1px solid var(--border); color: var(--faint);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.item-title { font-weight: 500; }
.item-meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.qty { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.qty strong { font-size: 15px; }
.qty span { color: var(--muted); margin-right: 4px; }

.address { font-style: normal; line-height: 1.6; color: var(--text-2); }
.address strong { display: block; color: var(--text); font-size: 14.5px; margin-bottom: 2px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; color: var(--text); min-width: 0; overflow-wrap: anywhere; }
.divider { height: 1px; background: var(--border); margin: 4px 0; }

.summary { padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.tracking-big { font-family: var(--mono); font-size: 15px; font-weight: 500; letter-spacing: 0.06em; }

/* Stepper */
.stepper { display: flex; align-items: center; gap: 8px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.step { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 500; white-space: nowrap; }
.step-dot {
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  border: 1px solid var(--border-strong); background: var(--surface);
  font-size: 11.5px; font-weight: 600; color: var(--muted);
}
.step-dot .icon { width: 12px; height: 12px; stroke-width: 2.5; }
.step.active { color: var(--text); }
.step.active .step-dot { border-color: var(--primary); background: var(--primary); color: var(--on-primary); }
.step.done { color: var(--text-2); }
.step.done .step-dot { border-color: var(--success); background: var(--success); color: #fff; }
.step-line { flex: 1; height: 1px; background: var(--border); min-width: 12px; }

.locked-panel { padding: 20px; }
.locked-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.locked-icon {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: var(--success-bg); color: var(--success); border: 1px solid var(--success-border);
}

/* ==========================================================================
   Auth
   ========================================================================== */

.auth-wrap { min-height: calc(100vh - 170px); min-height: calc(100dvh - 170px); display: grid; place-items: center; padding: 24px 0; }
.auth-card { width: 100%; max-width: 380px; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 24px; text-align: center; }
.auth-brand .brand-logo { width: 40px; height: 40px; border-radius: 10px; }
.auth-brand .brand-logo .icon { width: 22px; height: 22px; }
.auth-brand p { color: var(--muted); }
.auth-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 20px; color: var(--muted); font-size: 12.5px; }

/* ==========================================================================
   Modal & toast
   ========================================================================== */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 16px;
  background: rgba(8, 10, 14, 0.55);
  animation: fade 0.12s ease-out;
}
.modal {
  width: 100%; max-width: 460px; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow: auto;
  overscroll-behavior: contain;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: pop 0.14s ease-out;
}
.modal .card-body { display: flex; flex-direction: column; gap: 16px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(0.98); } }

.toast {
  position: fixed; right: 24px; bottom: 24px; z-index: 60;
  display: flex; align-items: center; gap: 10px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 16px; border-radius: var(--radius);
  background: var(--primary); color: var(--on-primary);
  box-shadow: var(--shadow-lg); font-weight: 500;
  opacity: 0; transform: translateY(8px); pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
}
.toast.show { opacity: 1; transform: none; }
@keyframes sheet { from { transform: translateY(100%); } }
.toast.error { background: var(--danger-solid); color: #fff; }

.spinner {
  width: 22px; height: 22px; margin: 80px auto; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--text);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 960px) {
  .layout-2 { grid-template-columns: 1fr; }
  .hide-md { display: none; }
}
@media (max-width: 680px) {
  .topbar-inner {
    height: auto; flex-wrap: wrap; gap: 0 12px;
    padding: 10px max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  }
  .brand { flex: 1; height: 36px; min-width: 0; }
  .nav { order: 3; width: 100%; flex: none; height: 44px; margin: 0 -12px; }
  .nav a { flex: 0 0 auto; }
  .topbar-right { gap: 8px; }
  .user-btn { padding: 0 4px; }
  .user-name { display: none; }
  .demo-banner { justify-content: flex-start; padding: 8px 16px; font-size: 12.5px; }
  .container {
    padding: 20px max(16px, env(safe-area-inset-right)) 64px max(16px, env(safe-area-inset-left));
  }
  h1 { font-size: 20px; }
  .page-head { margin-bottom: 16px; }
  .page-head > div:first-child { flex: 1 1 100%; }
  .hide-sm { display: none; }
  .card-head, .card-body { padding-left: 16px; padding-right: 16px; }
  .card-head { flex-wrap: wrap; }
  .card-foot { padding-left: 16px; padding-right: 16px; flex-wrap: wrap; }
  .card-foot > .btn { flex: 1 1 auto; }
  .card-foot .spacer { display: none; }
  .items td { padding: 12px 16px; }
  .item-cell { gap: 10px; }
  .item-title { overflow-wrap: anywhere; }
  .table td, .table th { padding-left: 12px; padding-right: 12px; }
  .stepper { padding: 14px 16px; }
  .step-label { display: none; }
  .step.active .step-label { display: inline; }
  .toast { left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); }
  .toolbar { padding: 12px; }
  .toolbar .count { display: none; }
  .toolbar .input-icon { max-width: none; }
  .tracking-big { overflow-wrap: anywhere; }
  .locked-panel { padding: 16px; }

  /* Modals become bottom sheets, within thumb reach. */
  .modal-backdrop { place-items: end stretch; padding: 0; }
  .modal {
    max-width: none; max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px);
    border-radius: 16px 16px 0 0; border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom);
    animation: sheet 0.2s ease-out;
  }
  .modal .card-foot { border-radius: 0; }
  .modal .card-foot > .btn { flex: 1; }

  /* Tables that turn each row into a compact card. */
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody { display: block; }
  .table-stack tr {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px;
    padding: 12px 16px; border-bottom: 1px solid var(--border);
  }
  .table-stack tbody tr:last-child { border-bottom: 0; }
  .table-stack td { display: block; padding: 0; border: 0; min-width: 0; }
  .table-stack td.hide-sm, .table-stack td.hide-md { display: none; }
  .table-stack td.st-show { display: block; }
  .table-stack td:empty { display: none; }
  .table-stack tr.clickable:hover td { background: none; }
  .table-stack tr.clickable:active { background: var(--surface-hover); }

  .shipped-table td:first-child { flex: 1; }
  .shipped-table .st-status { order: 1; }
  .shipped-table .st-customer { order: 2; flex: 1 1 100%; }
  .shipped-table .st-customer > div { display: inline; }
  .shipped-table .st-customer .sub::before { content: " · "; }
  .shipped-table .st-carrier { order: 3; color: var(--muted); font-size: 13px; }
  .shipped-table .st-tracking { order: 4; white-space: normal; overflow-wrap: anywhere; }
  .shipped-table .st-date { order: 5; flex: 1 1 100%; color: var(--muted); font-size: 12.5px; white-space: normal; }
  .shipped-table .st-date > div { display: inline; }
  .shipped-table .st-date .sub::before { content: " · "; }

  .staff-table .st-user { flex: 1 1 100%; }
  .staff-table td.actions { flex: 1 1 100%; display: flex; flex-wrap: wrap; gap: 6px; text-align: left; white-space: normal; margin-top: 4px; }
  .staff-table td.actions .btn + .btn { margin-left: 0; }

  .activity-table .st-event { order: 1; flex: 1; }
  .activity-table .st-date { order: 2; font-size: 12.5px; }
  .activity-table .st-user { order: 3; flex: 1 1 100%; color: var(--muted); font-size: 12.5px; }
  .activity-table .st-order { order: 4; font-size: 12.5px; font-weight: 500; }
  .activity-table .st-details { order: 5; flex: 1; overflow-wrap: anywhere; }
}

/* Touch screens: larger tap targets, and 16px inputs so iOS doesn't zoom on focus. */
@media (pointer: coarse) {
  .btn { height: 42px; padding: 0 16px; }
  .btn-sm { height: 36px; padding: 0 12px; }
  .btn-lg { height: 46px; }
  .btn-icon { width: 42px; }
  input[type="text"], input[type="password"], input[type="search"], input[type="url"], select { height: 44px; font-size: 16px; }
  input.mono { font-size: 16px; }
  .check { padding: 14px; }
  .check input { width: 20px; height: 20px; margin-top: 0; }
  .theme-switch button { width: 34px; height: 32px; }
  .user-btn { height: 40px; }
  .menu button { padding: 12px; }
  .nav a { padding: 0 14px; }
  .table tr.clickable:hover td { background: none; }
  .table tr.clickable:active td { background: var(--surface-hover); }
}

.empty-actions { display: flex; justify-content: center; padding: 0 24px 32px; }
.card-foot.start { justify-content: flex-start; }

/* Footer */
body { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
#app { flex: 1; width: 100%; }
.site-footer { border-top: 1px solid var(--border); color: var(--muted); font-size: 12.5px; }
.site-footer-inner {
  max-width: 1200px; margin: 0 auto; padding: 16px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px 24px; flex-wrap: wrap;
}
.site-footer strong { color: var(--text-2); font-weight: 600; }
@media (max-width: 680px) {
  .site-footer-inner {
    padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
    flex-direction: column; align-items: flex-start; gap: 4px;
  }
}
