/* ===========================================================================
   Design tokens
   HSL triplets without the hsl() wrapper, so any colour can be used with an
   alpha channel: hsl(var(--primary) / 0.12). Dark theme is a class on <html>,
   set before first paint by the inline script in index.html.
   ========================================================================= */

:root {
  --background: 210 40% 98%;
  --foreground: 222 47% 11%;

  --card: 0 0% 100%;
  --card-foreground: 222 47% 11%;

  --primary: 221 83% 53%;
  --primary-foreground: 210 40% 98%;

  --secondary: 210 40% 96%;
  --secondary-foreground: 222 47% 11%;

  --muted: 210 40% 96%;
  --muted-foreground: 215 16% 47%;

  --accent: 221 83% 96%;
  --accent-foreground: 221 83% 40%;

  --destructive: 0 72% 51%;
  --destructive-foreground: 0 0% 100%;

  --success: 142 71% 40%;
  --warning: 32 95% 44%;

  --border: 214 32% 91%;
  --input: 214 32% 91%;
  --ring: 221 83% 53%;

  --sidebar: 222 47% 11%;
  --sidebar-foreground: 215 20% 75%;
  --sidebar-active: 221 83% 53%;
  --sidebar-border: 217 33% 20%;

  --radius: 0.625rem;
  --sidebar-width: 248px;
  --topbar-height: 68px;

  --shadow-sm: 0 1px 2px 0 hsl(222 47% 11% / 0.05);
  --shadow-md: 0 1px 3px 0 hsl(222 47% 11% / 0.08), 0 1px 2px -1px hsl(222 47% 11% / 0.06);
  --shadow-lg: 0 10px 30px -10px hsl(222 47% 11% / 0.25);
}

.dark {
  --background: 222 47% 9%;
  --foreground: 210 40% 96%;

  --card: 222 40% 13%;
  --card-foreground: 210 40% 96%;

  --primary: 217 91% 60%;
  --primary-foreground: 222 47% 11%;

  --secondary: 217 33% 18%;
  --secondary-foreground: 210 40% 96%;

  --muted: 217 33% 18%;
  --muted-foreground: 215 20% 65%;

  --accent: 217 44% 20%;
  --accent-foreground: 213 94% 78%;

  --destructive: 0 63% 50%;
  --destructive-foreground: 0 0% 100%;

  --success: 142 64% 52%;
  --warning: 38 92% 58%;

  --border: 217 33% 20%;
  --input: 217 33% 22%;
  --ring: 217 91% 60%;

  --sidebar: 222 47% 7%;
  --sidebar-foreground: 215 20% 70%;
  --sidebar-active: 217 91% 60%;
  --sidebar-border: 217 33% 16%;

  --shadow-sm: 0 1px 2px 0 hsl(0 0% 0% / 0.3);
  --shadow-md: 0 1px 3px 0 hsl(0 0% 0% / 0.4), 0 1px 2px -1px hsl(0 0% 0% / 0.3);
  --shadow-lg: 0 10px 30px -10px hsl(0 0% 0% / 0.6);
}

/* ===========================================================================
   Base
   ========================================================================= */

* { box-sizing: border-box; }

/* Component rules below set display on .btn, .toast and friends, which would
   otherwise win over the user-agent's [hidden] rule and keep hidden elements on
   screen. Author styles beat the UA sheet, so the attribute has to be enforced. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font: 14px/1.5 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
        Roboto, "Helvetica Neue", Arial, "Noto Sans TC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }
svg { width: 1em; height: 1em; }

:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
  border-radius: 4px;
}

/* ===========================================================================
   Layout shell
   ========================================================================= */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 14px 14px;
  background: hsl(var(--sidebar));
  color: hsl(var(--sidebar-foreground));
  border-right: 1px solid hsl(var(--sidebar-border));
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 20px; }

.brand-mark {
  width: 36px; height: 36px;
  flex: none;
  display: grid; place-items: center;
  border-radius: 9px;
  background: hsl(var(--sidebar-active));
  color: hsl(var(--primary-foreground));
  font-size: 19px;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong { color: #fff; font-size: 14.5px; font-weight: 650; }
.brand-text small { font-size: 11.5px; opacity: 0.65; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }

.nav-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  opacity: 0.45;
  padding: 16px 10px 6px;
}
.nav-label:first-child { padding-top: 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 11px;
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
}
.nav-item svg { font-size: 17px; opacity: 0.8; flex: none; }
.nav-item:hover { background: hsl(0 0% 100% / 0.07); color: #fff; }
.nav-item.active { background: hsl(var(--sidebar-active)); color: #fff; box-shadow: var(--shadow-md); }
.nav-item.active svg { opacity: 1; }

.nav-count {
  margin-left: auto;
  font-size: 11.5px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  background: hsl(0 0% 100% / 0.1);
}
.nav-item.active .nav-count { background: hsl(0 0% 100% / 0.22); }

.sidebar-status {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 11px 12px;
  border-radius: 9px;
  border: 1px solid hsl(var(--sidebar-border));
  background: hsl(0 0% 100% / 0.03);
  color: inherit;
  text-decoration: none;
}
.sidebar-status:hover { background: hsl(0 0% 100% / 0.07); }
.sidebar-status-text { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.sidebar-status-text strong { font-size: 12.5px; color: #fff; font-weight: 600; }
.sidebar-status-text small { font-size: 11px; opacity: 0.6; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dot {
  width: 8px; height: 8px; flex: none;
  border-radius: 50%;
  background: hsl(var(--warning));
  box-shadow: 0 0 0 3px hsl(var(--warning) / 0.18);
}
.dot.ok { background: hsl(var(--success)); box-shadow: 0 0 0 3px hsl(var(--success) / 0.18); }
.dot.warn { background: hsl(var(--destructive)); box-shadow: 0 0 0 3px hsl(var(--destructive) / 0.18); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-height);
  flex: none;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  background: hsl(var(--card) / 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid hsl(var(--border));
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-titles { flex: 1; min-width: 0; }
.topbar-titles h1 { font-size: 18px; }
.topbar-sub {
  font-size: 12.5px;
  color: hsl(var(--muted-foreground));
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-actions { display: flex; align-items: center; gap: 9px; }

.content {
  flex: 1;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 1500px;
  width: 100%;
}

.view { display: flex; flex-direction: column; gap: 20px; }
.view[hidden] { display: none; }

.topbar .menu-btn { display: none; }
.scrim { display: none; }

/* ===========================================================================
   KPI cards
   ========================================================================= */

.kpi-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

.kpi {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 17px 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.kpi-label {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: hsl(var(--muted-foreground));
}

.kpi-icon {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 9px;
  font-size: 17px;
  background: hsl(var(--accent));
  color: hsl(var(--accent-foreground));
}
.kpi-icon.green { background: hsl(var(--success) / 0.13); color: hsl(var(--success)); }
.kpi-icon.amber { background: hsl(var(--warning) / 0.14); color: hsl(var(--warning)); }
.kpi-icon.violet { background: hsl(262 83% 58% / 0.13); color: hsl(262 83% 58%); }

.kpi-value {
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.kpi-sub { font-size: 12px; color: hsl(var(--muted-foreground)); }

/* ===========================================================================
   Card
   ========================================================================= */

.card {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-start;
  justify-content: space-between;
  padding: 17px 20px;
  border-bottom: 1px solid hsl(var(--border));
}
.card-head h2 { font-size: 15.5px; }
.card-head p {
  font-size: 12.5px;
  color: hsl(var(--muted-foreground));
  margin-top: 3px;
  max-width: 74ch;
}

.card-body { padding: 20px; }

.card-note {
  padding: 13px 20px;
  border-top: 1px solid hsl(var(--border));
  background: hsl(var(--muted) / 0.5);
  font-size: 12.5px;
  color: hsl(var(--muted-foreground));
}

.rule { border: none; border-top: 1px solid hsl(var(--border)); margin: 18px 0; }
.btn-row { display: flex; gap: 9px; flex-wrap: wrap; }

/* ===========================================================================
   Controls
   ========================================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
}
.btn svg { font-size: 15px; }
.btn:hover { background: hsl(var(--muted)); }

.btn.primary {
  background: hsl(var(--primary));
  border-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  box-shadow: var(--shadow-sm);
}
.btn.primary:hover { background: hsl(var(--primary) / 0.9); }

.btn.ghost { background: transparent; }
.btn.ghost:hover { background: hsl(var(--muted)); }

.btn.danger { color: hsl(var(--destructive)); border-color: hsl(var(--destructive) / 0.35); }
.btn.danger:hover { background: hsl(var(--destructive) / 0.08); }

.btn:disabled { opacity: 0.45; cursor: default; }

.btn.link {
  border: none; background: none; padding: 3px 6px;
  color: hsl(var(--primary)); font-size: 12.5px; font-weight: 550;
}
.btn.link:hover { background: hsl(var(--accent)); }
.btn.link.danger { color: hsl(var(--destructive)); }

.icon-btn {
  width: 36px; height: 36px;
  display: inline-grid; place-items: center;
  border-radius: 8px;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  font: inherit; font-size: 16px;
  cursor: pointer;
  transition: background 0.12s;
}
.icon-btn:hover { background: hsl(var(--muted)); }
.icon-btn:disabled { opacity: 0.4; cursor: default; }
.icon-btn.sm { width: 30px; height: 30px; font-size: 15px; }

.icon-moon { display: none; }
.dark .icon-sun { display: none; }
.dark .icon-moon { display: block; }

input[type="text"], input[type="search"], input[type="number"], select {
  padding: 8px 11px;
  border-radius: 8px;
  border: 1px solid hsl(var(--input));
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  font: inherit;
  font-size: 13px;
}
input::placeholder { color: hsl(var(--muted-foreground)); }
select { cursor: pointer; }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form input { min-width: 190px; }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 13px 20px;
  border-bottom: 1px solid hsl(var(--border));
}
.filter-bar.sub { background: hsl(var(--muted) / 0.45); font-size: 12.5px; }
.bulk-label { color: hsl(var(--muted-foreground)); }
.filter-bar #bulk-shipping { width: 108px; }

.search-field { position: relative; flex: 1 1 300px; min-width: 220px; }
.search-field svg {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  font-size: 15px; color: hsl(var(--muted-foreground)); pointer-events: none;
}
.search-field input { width: 100%; padding-left: 33px; }

.switch { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; }
.switch input { width: 15px; height: 15px; accent-color: hsl(var(--primary)); cursor: pointer; }

/* ===========================================================================
   Import by address
   ========================================================================= */

.url-import { display: flex; flex-direction: column; gap: 7px; }

.url-import-label {
  font-size: 13px;
  font-weight: 600;
  color: hsl(var(--foreground));
}

.url-import-row { display: flex; gap: 10px; }

.url-import-row input {
  flex: 1;
  min-width: 0;
  /* An order address is long and its tail is the part that matters, so the text
     must be able to scroll rather than be squeezed. */
  text-overflow: ellipsis;
}

.url-import-row input:disabled { opacity: 0.6; cursor: progress; }

/* A rule with the word sitting in a gap in it, so the two import routes read as
   alternatives rather than steps. */
.url-import-or {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0;
  color: hsl(var(--muted-foreground));
  font-size: 12.5px;
}

.url-import-or::before,
.url-import-or::after {
  content: "";
  flex: 1;
  height: 1px;
  background: hsl(var(--border));
}

@media (max-width: 560px) {
  .url-import-row { flex-direction: column; }
}

/* ===========================================================================
   Dropzone + log
   ========================================================================= */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 44px 20px;
  border: 1.5px dashed hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--muted) / 0.4);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.12s, background 0.12s;
}
.dropzone:hover, .dropzone.dragover {
  border-color: hsl(var(--primary));
  background: hsl(var(--accent));
}
.dropzone strong { font-size: 14.5px; }
.dropzone span { font-size: 12.5px; color: hsl(var(--muted-foreground)); }
.dropzone-icon {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  color: hsl(var(--primary));
  font-size: 23px;
  margin-bottom: 4px;
}

.dropzone-note {
  margin-top: 10px;
  font-size: 12.5px;
  color: hsl(var(--muted-foreground));
}
.dropzone-note strong { color: hsl(var(--foreground)); font-weight: 600; }

.log {
  margin-top: 16px;
  border: 1px solid hsl(var(--border));
  border-radius: 8px;
  overflow: hidden;
  font-size: 12.5px;
}
.log div {
  padding: 9px 13px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
  border-bottom: 1px solid hsl(var(--border));
}
.log div:last-child { border-bottom: none; }
.log .ok { background: hsl(var(--success) / 0.07); }
.log .err { background: hsl(var(--destructive) / 0.07); }
.log .warn { background: hsl(var(--warning) / 0.09); }
.log .ok::before { content: "\2713"; color: hsl(var(--success)); font-weight: 700; }
.log .err::before { content: "\2715"; color: hsl(var(--destructive)); font-weight: 700; }
.log .warn::before { content: "\26A0"; color: hsl(var(--warning)); }

/* ===========================================================================
   Tables
   ========================================================================= */

.table-scroll { overflow-x: auto; }

table { border-collapse: collapse; width: 100%; }

th, td {
  padding: 11px 16px;
  text-align: left;
  border-bottom: 1px solid hsl(var(--border));
  vertical-align: middle;
}

thead th {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.055em;
  text-transform: uppercase;
  color: hsl(var(--muted-foreground));
  background: hsl(var(--muted) / 0.55);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: hsl(var(--foreground)); }
th[data-sort]::after { content: " \2195"; opacity: 0.3; }
th.asc::after { content: " \2191"; opacity: 1; color: hsl(var(--primary)); }
th.desc::after { content: " \2193"; opacity: 1; color: hsl(var(--primary)); }

tbody tr { transition: background 0.1s; }
tbody tr:hover { background: hsl(var(--muted) / 0.5); }
tbody tr:last-child td { border-bottom: none; }

tfoot td {
  border-top: 2px solid hsl(var(--border));
  border-bottom: none;
  font-weight: 650;
  background: hsl(var(--muted) / 0.55);
}

.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.img-col { width: 64px; }
.actions-col { width: 1%; white-space: nowrap; text-align: right; }

#items-table { min-width: 1020px; }

/* Scoped to tbody: the footer's first cell spans four columns, so an unscoped
   nth-child(2) would land on the Qty column and stretch it. */
#items-table tbody td:nth-child(2),
#items-table thead th:nth-child(2) { min-width: 215px; }

/* Let the longest header wrap instead of forcing the table wider. */
#items-table thead th:last-child { white-space: normal; min-width: 104px; line-height: 1.3; }
#uploads-table, #groups-table { min-width: 880px; }

.thumb {
  width: 44px; height: 56px;
  object-fit: cover;
  border-radius: 7px;
  background: hsl(var(--muted));
  border: 1px solid hsl(var(--border));
  display: block;
}

.name { font-weight: 550; }
.name a { color: inherit; text-decoration: none; }
.name a:hover { color: hsl(var(--primary)); text-decoration: underline; }
.meta { color: hsl(var(--muted-foreground)); font-size: 11.5px; margin-top: 3px; }
.strike { color: hsl(var(--muted-foreground)); text-decoration: line-through; font-size: 11.5px; }
.discount { color: hsl(var(--destructive)); font-size: 11.5px; }
.final { font-weight: 650; }
/* The selling side of the table: the same weight as the cost total, tinted so the
   two totals can be told apart at a glance. */
.sell { font-weight: 650; color: hsl(var(--success)); }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: hsl(var(--muted));
  padding: 1.5px 6px;
  border-radius: 5px;
}
code + code { margin-left: 5px; }

.ship-input, .retail-input {
  width: 86px;
  text-align: right;
  padding: 5px 9px;
  font-size: 12.5px;
}
.ship-input.set, .retail-input.set {
  border-color: hsl(var(--primary));
  background: hsl(var(--accent));
}

/* A figure that has not been filled in yet, rather than a real zero. */
.cell-dash { color: hsl(var(--muted-foreground)); }

/* A line the retailer dropped. It stays in the table but must not read as
   something that was bought, so it is dimmed and its name is struck through. */
tbody tr.cancelled { background: hsl(var(--muted) / 0.35); }
tbody tr.cancelled:hover { background: hsl(var(--muted) / 0.55); }
tbody tr.cancelled td { color: hsl(var(--muted-foreground)); }
tbody tr.cancelled .name a,
tbody tr.cancelled .name { text-decoration: line-through; font-weight: 450; }
tbody tr.cancelled .thumb { opacity: 0.45; }

.tag-cancelled {
  display: inline-block;
  margin-left: 7px;
  padding: 1px 8px;
  border-radius: 999px;
  background: hsl(var(--destructive) / 0.12);
  color: hsl(var(--destructive));
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  /* The row is struck through; the badge explaining why must not be. */
  text-decoration: none;
  white-space: nowrap;
  vertical-align: middle;
}

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: hsl(var(--muted));
  color: hsl(var(--muted-foreground));
  white-space: nowrap;
}
.badge.green { background: hsl(var(--success) / 0.13); color: hsl(var(--success)); }
.badge.amber { background: hsl(var(--warning) / 0.14); color: hsl(var(--warning)); }
.badge.blue  { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }

.group-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: hsl(var(--accent));
  color: hsl(var(--accent-foreground));
  font-size: 12px;
  font-weight: 600;
}
.group-pill.none { background: hsl(var(--muted)); color: hsl(var(--muted-foreground)); }

.empty { padding: 44px 20px; color: hsl(var(--muted-foreground)); text-align: center; }

/* ===========================================================================
   Pager
   ========================================================================= */

.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 13px 20px;
  border-top: 1px solid hsl(var(--border));
  font-size: 12.5px;
  color: hsl(var(--muted-foreground));
}
.pager label { display: inline-flex; align-items: center; gap: 8px; }
.pager select { padding: 5px 9px; font-size: 12.5px; }
.pager-nav { display: flex; align-items: center; gap: 6px; }
#page-info { min-width: 164px; text-align: center; font-variant-numeric: tabular-nums; }

/* ===========================================================================
   Toast
   ========================================================================= */

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: 360px;
  background: hsl(var(--foreground));
  color: hsl(var(--background));
  padding: 11px 17px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 60;
}
.toast.err { background: hsl(var(--destructive)); color: hsl(var(--destructive-foreground)); }

/* ===========================================================================
   Modals
   ========================================================================= */

/* No `display` is set on the dialog itself: the user-agent sheet hides it while
   closed, and overriding that would leave it on screen permanently. */
.modal {
  border: none;
  padding: 0;
  background: transparent;
  max-width: min(560px, calc(100vw - 32px));
  width: 100%;
  max-height: calc(100vh - 48px);
}
.modal::backdrop { background: hsl(222 47% 11% / 0.55); backdrop-filter: blur(2px); }

.modal-form {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 48px);
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) + 2px);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid hsl(var(--border));
}
.modal-head h2 { font-size: 15.5px; flex: 1; }
.modal-body { padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 15px; }
.modal-foot {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 14px 18px;
  border-top: 1px solid hsl(var(--border));
  background: hsl(var(--muted) / 0.4);
}
.modal-spacer { flex: 1; }
.modal-hint { flex: 1; font-size: 12px; color: hsl(var(--muted-foreground)); }
.modal.wide { max-width: min(620px, calc(100vw - 32px)); }

.field-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.field-head label { font-size: 12.5px; font-weight: 600; color: hsl(var(--muted-foreground)); }
.btn.sm { padding: 4px 9px; font-size: 12px; }

.check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 2px 10px;
}
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 7px;
  border-radius: 7px;
  font-size: 13px;
  cursor: pointer;
}
.check:hover { background: hsl(var(--muted)); }
.check input[type="checkbox"] {
  width: 15px; height: 15px;
  flex: none;
  accent-color: hsl(var(--primary));
  cursor: pointer;
}
.check > span { white-space: nowrap; }
.check.standalone {
  align-items: flex-start;
  padding: 11px 13px;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--muted) / 0.4);
}
.check.standalone input { margin-top: 2px; }
.check.standalone > span { display: flex; flex-direction: column; gap: 2px; white-space: normal; }
.check.standalone small { font-size: 11.5px; color: hsl(var(--muted-foreground)); }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 12.5px; font-weight: 600; color: hsl(var(--muted-foreground)); }
.field input, .field textarea {
  padding: 8px 11px;
  border-radius: 8px;
  border: 1px solid hsl(var(--input));
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font: inherit;
  font-size: 13px;
  width: 100%;
}
.field textarea { resize: vertical; min-height: 68px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.field-row .field.narrow { flex: 0 0 110px; }

.photo-row { display: flex; gap: 14px; align-items: flex-start; }
.photo-preview {
  width: 108px; height: 108px;
  flex: none;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--muted));
  overflow: hidden;
}
.photo-preview img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.photo-actions { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.photo-actions small { font-size: 11.5px; color: hsl(var(--muted-foreground)); line-height: 1.45; }

.form-error { font-size: 12.5px; color: hsl(var(--destructive)); font-weight: 500; }
.form-error:empty { display: none; }

.btn.danger.armed {
  background: hsl(var(--destructive));
  border-color: hsl(var(--destructive));
  color: hsl(var(--destructive-foreground));
}

/* ===========================================================================
   Responsive: sidebar becomes a drawer
   ========================================================================= */

@media (max-width: 1000px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-lg);
  }
  .layout.nav-open .sidebar { transform: translateX(0); }
  .topbar .menu-btn { display: inline-grid; }
  .scrim {
    position: fixed; inset: 0;
    background: hsl(222 47% 11% / 0.5);
    z-index: 25;
  }
  .layout.nav-open .scrim { display: block; }
}

@media (max-width: 680px) {
  .content { padding: 16px; gap: 16px; }
  .topbar { padding: 0 16px; }
  .topbar-sub { display: none; }
  .card-head { padding: 15px 16px; }
  .card-body, .filter-bar, .pager { padding-left: 16px; padding-right: 16px; }
  #topbar-import span { display: none; }
  .photo-row { flex-direction: column; }
  .field-row { flex-direction: column; }
  .field-row .field.narrow { flex: 1; }
}

/* ===========================================================================
   Hand-written order editor

   A wider modal than the rest, because it carries a table: the order header on
   top, its lines below, and a running total in the footer.
   ========================================================================= */

.modal.wider { max-width: min(1040px, calc(100vw - 32px)); }

.table-scroll.compact {
  border: 1px solid hsl(var(--border));
  border-radius: 9px;
  max-height: 290px;
  overflow-y: auto;
  /* The modal body is a column flex container, so this would otherwise be squeezed
     to nothing once the dialog's content is taller than the screen. It scrolls the
     body, not the table. */
  flex: none;
}
.table-scroll.compact table { font-size: 12.5px; }
.table-scroll.compact th,
.table-scroll.compact td { padding: 6px 10px; }
.table-scroll.compact thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: hsl(var(--card));
}
.table-scroll.compact .empty { padding: 26px 12px; font-size: 12.5px; }
.table-scroll.compact tr.editing { background: hsl(var(--accent)); }

/* An input sized to sit inside a table cell without changing the row height. */
.cell-input {
  width: 72px;
  padding: 3px 6px;
  text-align: right;
  font: inherit;
  font-variant-numeric: tabular-nums;
  border: 1px solid hsl(var(--input));
  border-radius: 6px;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
}
.cell-input:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: -1px; }

/* The add-a-line form. It mirrors the table's columns, so a line is typed in
   roughly where it will appear. */
.line-form {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  flex-wrap: wrap;
  padding: 12px;
  border: 1px solid hsl(var(--border));
  border-radius: 9px;
  background: hsl(var(--muted) / 0.4);
}
.line-form .field { flex: 0 1 120px; }
.line-form .field.grow { flex: 1 1 220px; }
.line-form .field.narrow { flex: 0 0 78px; }
.line-form .btn { flex: none; }

.more > summary {
  cursor: pointer;
  font-size: 12.5px;
  color: hsl(var(--muted-foreground));
  padding: 2px 0;
}
.more > summary:hover { color: hsl(var(--foreground)); }
.more > .field-row { padding-top: 10px; }

.modal-totals {
  font-size: 12.5px;
  color: hsl(var(--muted-foreground));
  font-variant-numeric: tabular-nums;
}
.modal-totals strong { color: hsl(var(--foreground)); }

@media (max-width: 820px) {
  .line-form .field,
  .line-form .field.grow,
  .line-form .field.narrow { flex: 1 1 100%; }
  /* The footer is a nowrap flex row by default, so the totals cannot take a line
     of their own until wrapping is allowed here. */
  .modal-foot { flex-wrap: wrap; }
  .modal-totals { flex: 1 1 100%; order: -1; padding-bottom: 6px; font-size: 12px; }
}

/* A line in the order editor carries a thumbnail beside its name, so a picture can
   be checked against the product without opening the line. */
.line-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.line-thumb {
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 5px;
  object-fit: cover;
  background: hsl(var(--muted));
  border: 1px solid hsl(var(--border));
}
.line-name .name { min-width: 0; }

/* ===========================================================================
   Sign-in gate
   Covers the whole viewport instead of living inside the shell, so no sidebar,
   topbar or data is painted before there is a session that is allowed to see it.
   The shell is hidden by `body.booting` until the session has been checked, which
   is what stops a signed-out reload from flashing the last-rendered page.
   ========================================================================= */

body.booting .layout { display: none; }

.gate {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: auto;
  background:
    radial-gradient(1100px 520px at 15% -10%, hsl(var(--primary) / 0.14), transparent 70%),
    radial-gradient(900px 480px at 100% 110%, hsl(var(--primary) / 0.10), transparent 70%),
    hsl(var(--background));
}

.gate[hidden] { display: none; }

.gate-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 380px;
  padding: 28px;
  border-radius: calc(var(--radius) + 4px);
  border: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  box-shadow: var(--shadow-lg);
}

.gate-brand { display: flex; align-items: center; gap: 13px; margin-bottom: 4px; }

.gate-mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 11px;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}
.gate-mark svg { width: 22px; height: 22px; }

.gate-brand h1 { font-size: 17px; font-weight: 680; letter-spacing: -0.01em; }
.gate-brand p { margin-top: 2px; font-size: 12.5px; color: hsl(var(--muted-foreground)); }

/* Sized for a touch target, because this is the one screen that is as likely to be
   met on a phone as at a desk. */
.gate-card .field input { padding: 10px 12px; font-size: 14px; }

.gate-error {
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid hsl(var(--destructive) / 0.35);
  background: hsl(var(--destructive) / 0.08);
  color: hsl(var(--destructive));
  font-size: 12.5px;
}
.gate-error[hidden] { display: none; }

.gate-note {
  text-align: center;
  font-size: 12px;
  color: hsl(var(--muted-foreground));
}

.btn.block { width: 100%; justify-content: center; padding: 10px 14px; font-size: 14px; }

/* -- the account in the topbar --------------------------------------------- */

.account {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-left: 10px;
  margin-left: 2px;
  border-left: 1px solid hsl(var(--border));
}
.account[hidden] { display: none; }

/* The address is the only confirmation of which account is signed in, so it is
   kept rather than dropped on narrow screens - truncated instead. */
.account-email {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
  font-weight: 550;
  color: hsl(var(--muted-foreground));
}

@media (max-width: 720px) {
  .account-email { display: none; }
  .account { padding-left: 4px; border-left: 0; }
}

/* A log that sits between a card head and a full-bleed table, where the card
   itself has no padding to inherit. */
.log-inset { margin: 14px 20px 2px; }
