/* inventory-jelly — fresh-pantry palette + proper app shell (sidebar on desktop, drawer on mobile) */

:root {
  --primary: #2F6F4E;
  --primary-ink: #1F4A35;
  --primary-dim: #3D8561;
  --primary-soft: #D8E5DC;
  --primary-surface: #EEF4EF;
  --accent: #E8A93A;
  --accent-ink: #96681A;
  --bg: #F4F0E6;
  --surface: #FFFFFF;
  --surface-2: #FBF8F1;
  --ink: #1F2A24;
  --ink-muted: #6B776F;
  --line: #E7E1D0;
  --line-strong: #CFC8B3;
  --success: #2F6F4E;
  --warn: #E8A93A;
  --danger: #B4452F;
  --info: #3D6A8C;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;
  --shadow-xs: 0 1px 2px rgba(31, 42, 36, 0.05);
  --shadow-sm: 0 1px 2px rgba(31, 42, 36, 0.06), 0 2px 8px rgba(31, 42, 36, 0.04);
  --shadow: 0 1px 2px rgba(31, 42, 36, 0.06), 0 6px 22px rgba(31, 42, 36, 0.07);
  --sidebar-w: 240px;
  --topbar-h: 60px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font-family: var(--font); -webkit-font-smoothing: antialiased; font-size: 15px; line-height: 1.45; }
body { min-height: 100dvh; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }

button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-ink); }

/* ============ APP SHELL LAYOUT ============ */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 100dvh;
  min-height: 100dvh;
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
}

/* --- sidebar --- */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  position: sticky;
  top: 0;
  height: 100dvh;
}
.sidebar .sb-brand {
  height: var(--topbar-h);
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.sidebar .sb-brand .logo {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dim) 100%);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 14px; letter-spacing: -0.3px;
  box-shadow: inset 0 -1px 2px rgba(0,0,0,0.15);
}
.sidebar .sb-brand .name { font-weight: 700; color: var(--primary-ink); font-size: 15px; line-height: 1.1; }
.sidebar .sb-brand .sub { display: block; color: var(--ink-muted); font-size: 10px; font-weight: 500; letter-spacing: 0.4px; text-transform: uppercase; line-height: 1.2; margin-top: 2px; }

.sidebar .sb-section { padding: 14px 12px 6px; font-size: 11px; font-weight: 600; color: var(--ink-muted); letter-spacing: 0.6px; text-transform: uppercase; }
.sidebar .sb-nav { padding: 4px 8px; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.sidebar .sb-nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-weight: 500;
  transition: background .12s ease, color .12s ease;
}
.sidebar .sb-nav a:hover { background: var(--primary-surface); color: var(--primary-ink); }
.sidebar .sb-nav a.active { background: var(--primary); color: #fff; font-weight: 600; box-shadow: var(--shadow-xs); }
.sidebar .sb-nav a.active .ic { opacity: 1; }
.sidebar .sb-nav a .ic {
  width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center;
  font-size: 15px; opacity: 0.75;
}
.sidebar .sb-foot {
  border-top: 1px solid var(--line);
  padding: 14px 16px;
  display: flex; align-items: center; gap: 10px;
}
.sidebar .sb-foot .avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-ink);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}
.sidebar .sb-foot .info { flex: 1; min-width: 0; }
.sidebar .sb-foot .info .name { font-weight: 600; font-size: 13px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar .sb-foot .info .role { font-size: 11px; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.4px; }
.sidebar .sb-foot .signout { font-size: 12px; color: var(--ink-muted); padding: 6px 10px; border-radius: 6px; }
.sidebar .sb-foot .signout:hover { background: #F9E2DC; color: var(--danger); }

/* mobile: sidebar becomes a top strip / drawer */
@media (max-width: 900px) {
  .sidebar { position: static; height: auto; }
  .sidebar .sb-nav { display: none; flex-direction: row; overflow-x: auto; padding: 8px; gap: 6px; }
  .sidebar .sb-section { display: none; }
  .sidebar.open .sb-nav { display: flex; flex-direction: column; }
  .sidebar.open .sb-section { display: block; }
  .sidebar .sb-foot { display: none; }
  .sidebar.open .sb-foot { display: flex; }
}

/* --- main content --- */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: var(--topbar-h);
  padding: 0 28px;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
  box-shadow: var(--shadow-xs);
}
.topbar .hamburger { display: none; width: 36px; height: 36px; border-radius: 8px; align-items: center; justify-content: center; font-size: 20px; color: var(--primary-ink); }
.topbar .hamburger:hover { background: var(--primary-surface); }
@media (max-width: 900px) { .topbar { padding: 0 16px; } .topbar .hamburger { display: inline-flex; } }

.topbar .tb-title { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--primary-ink); font-size: 16px; min-width: 0; }
.topbar .tb-title .crumb { color: var(--ink-muted); font-weight: 500; }
.topbar .tb-title .crumb::before { content: '/'; margin: 0 8px; color: var(--line-strong); }
.topbar .tb-actions { display: flex; align-items: center; gap: 12px; }
.topbar .branch-pill {
  padding: 6px 12px; border-radius: 999px;
  background: var(--primary-surface); color: var(--primary-ink);
  font-size: 12px; font-weight: 600; border: 1px solid var(--primary-soft);
}

/* Legacy topbar (worker-built views: po/grn/production/planner/indent/queue/transfer).
   They render <div class="topbar"><div class="brand">…</div><div class="meta">…</div></div>
   directly inside #app, without the sidebar. Style it so it looks deliberate. */
body > #app > .topbar {
  display: flex; align-items: center; justify-content: space-between;
  height: var(--topbar-h);
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-xs);
  position: sticky; top: 0; z-index: 20;
}
body > #app > .topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--primary-ink); font-size: 16px; }
body > #app > .topbar .brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); display: inline-block; }
body > #app > .topbar .brand a { color: inherit; }
body > #app > .topbar .meta { font-size: 13px; color: var(--ink-muted); }
body > #app > .topbar .meta a { color: var(--primary); font-weight: 500; }

.content { flex: 1; padding: 28px 32px 60px; overflow-x: hidden; }
@media (max-width: 900px) { .content { padding: 18px 16px 80px; } }

.content-inner { max-width: 1100px; margin: 0 auto; }

/* Legacy: `.app-shell` kept as alias so older views still work */
.app-shell { max-width: 1100px; margin: 0 auto; padding: 4px; }

/* --- cards --- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 18px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.card-head h1, .card-head h2 { margin: 0; }

/* Page header (big title + lede) */
.page-head { margin-bottom: 22px; }
.page-head h1 { margin: 0; font-size: 26px; font-weight: 700; color: var(--primary-ink); letter-spacing: -0.3px; }
.page-head .lede { color: var(--ink-muted); margin-top: 4px; font-size: 14px; }

/* --- KPI cards --- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 22px; }
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-xs);
  display: flex; flex-direction: column; gap: 4px;
}
.kpi .kpi-label { font-size: 12px; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.kpi .kpi-value { font-size: 28px; font-weight: 700; color: var(--primary-ink); letter-spacing: -0.5px; font-variant-numeric: tabular-nums; }
.kpi .kpi-sub { font-size: 12px; color: var(--ink-muted); }
.kpi.warn .kpi-value { color: var(--accent-ink); }
.kpi.danger .kpi-value { color: var(--danger); }

/* --- action tiles --- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.tile {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  min-height: 108px;
  text-align: left;
  display: flex; flex-direction: column; gap: 6px;
  box-shadow: var(--shadow-xs);
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
  cursor: pointer;
  color: inherit;
}
.tile:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.tile .tile-ic {
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--primary-surface); color: var(--primary);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px; margin-bottom: 4px;
}
.tile .title { font-weight: 700; color: var(--primary-ink); font-size: 15px; }
.tile .hint { color: var(--ink-muted); font-size: 13px; }
.tile .tile-badge { position: absolute; top: 14px; right: 14px; padding: 2px 8px; border-radius: 999px; background: var(--primary); color: #fff; font-size: 11px; font-weight: 700; }

/* --- buttons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--primary); color: #fff; font-weight: 600;
  min-height: 40px; transition: all .15s ease;
  cursor: pointer;
}
.btn:hover { background: var(--primary-ink); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--primary-ink); border-color: var(--line-strong); }
.btn.ghost:hover { background: var(--primary-surface); border-color: var(--primary); }
.btn.danger { background: var(--danger); }
.btn.accent { background: var(--accent); color: var(--accent-ink); }
.btn.sm { padding: 6px 12px; min-height: 32px; font-size: 13px; }

/* --- form --- */
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; color: var(--ink-muted); margin-bottom: 6px; font-weight: 500; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], select, textarea {
  width: 100%; padding: 10px 13px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: #fff; min-height: 40px; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }

/* Hide native number-spinner arrows on stepper inputs (use custom +/- buttons instead). */
input.no-spinner::-webkit-outer-spin-button,
input.no-spinner::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input.no-spinner { -moz-appearance: textfield; appearance: textfield; }
input::placeholder, textarea::placeholder { color: var(--ink-muted); opacity: 0.7; }
textarea { min-height: auto; padding: 10px 13px; font-family: inherit; }

/* --- typography --- */
h1 { font-size: 20px; margin: 0 0 10px; color: var(--primary-ink); font-weight: 700; letter-spacing: -0.2px; }
h2 { font-size: 16px; margin: 0 0 8px; color: var(--primary-ink); font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 6px; color: var(--primary-ink); font-weight: 600; }
.muted { color: var(--ink-muted); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; font-family: var(--mono); }

/* --- messages --- */
.msg { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 12px; font-size: 14px; }
.msg.error { background: #F9E2DC; color: var(--danger); border: 1px solid #EBB8A9; }
.msg.info { background: var(--primary-surface); color: var(--primary-ink); border: 1px solid var(--primary-soft); }
.msg.warn { background: #FBE8C2; color: var(--accent-ink); border: 1px solid #E8C97A; }

/* --- login --- */
.login-wrap { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; background: linear-gradient(160deg, var(--bg) 0%, var(--primary-surface) 100%); }
.login-card { width: 100%; max-width: 380px; }
.login-card .logo { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-bottom: 22px; text-align: center; }
.login-card .logo .mark {
  width: 54px; height: 54px; border-radius: 14px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dim) 100%);
  display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 22px;
  box-shadow: var(--shadow);
}
.login-card .logo .title { font-weight: 700; color: var(--primary-ink); font-size: 20px; }
.login-card .logo .subtitle { color: var(--ink-muted); font-size: 13px; }

/* --- chips --- */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--primary-surface); color: var(--primary-ink); font-size: 12px; font-weight: 600; }
.chip.accent { background: #FBE8C2; color: var(--accent-ink); }
.chip.muted { background: var(--surface-2); color: var(--ink-muted); border: 1px solid var(--line); }
.chip.warn { background: #FBE8C2; color: var(--accent-ink); }
.chip.danger { background: #F9E2DC; color: var(--danger); }

/* --- data tables --- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; color: var(--ink-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; padding: 12px 10px; border-bottom: 1px solid var(--line); }
.table td { padding: 12px 10px; border-bottom: 1px solid var(--line); }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--surface-2); }
.table .right { text-align: right; }

/* Indent / queue / transfer shared bits (kept from Worker C, lightly updated) */
.small { font-size: 12px; }

/* Pill filter group */
.pills { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 16px; }
.pill { padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line-strong); background: #fff; color: var(--ink-muted); font-size: 13px; min-height: 34px; font-weight: 500; cursor: pointer; }
.pill:hover { border-color: var(--primary); color: var(--primary-ink); }
.pill.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }

/* Search results (indent / issue / adjustments pages) */
.search-results { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; max-height: 360px; overflow-y: auto; }
.search-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; cursor: pointer; }
.search-row:hover { border-color: var(--primary); background: var(--primary-surface); }
.search-row-main { flex: 1; min-width: 0; }
.search-row-name { font-weight: 600; color: var(--ink); }
.search-row-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 4px; }

/* Cart rows */
.indent-cart { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.cart-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); }
.cart-row-main { flex: 1; min-width: 0; }
.cart-row-name { font-weight: 600; }
.cart-row-meta { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.cart-row-qty { width: 100px; }
.qty-input { width: 100%; min-height: 36px; padding: 8px 10px; }
.icon-btn { padding: 6px 10px; min-height: 32px; font-size: 16px; color: var(--ink-muted); }
.icon-btn:hover { color: var(--danger); background: #F9E2DC; border-radius: 6px; }
.indent-summary { font-size: 13px; margin-bottom: 8px; color: var(--ink-muted); }

/* List rows (e.g. #/indents) */
.list-row {
  display: flex; align-items: center;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  margin-bottom: 8px;
  color: inherit;
  transition: border-color .12s, box-shadow .12s;
  cursor: pointer;
}
.list-row:hover { border-color: var(--primary); box-shadow: var(--shadow-xs); }
.list-row-main { flex: 1; min-width: 0; }
.list-row-title { font-weight: 600; color: var(--ink); }
.list-row-meta { margin-top: 4px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.list-row-cta .chev { color: var(--ink-muted); font-size: 22px; padding-left: 8px; }

/* Generic line row inside cards */
.line-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.line-row:first-child { border-top: none; }
.line-main { flex: 1; min-width: 0; }
.line-name { font-weight: 600; }
.line-meta { margin-top: 2px; color: var(--ink-muted); font-size: 13px; }
.line-qty { width: 110px; display: flex; align-items: center; gap: 4px; }
.line-reason { width: 130px; }
.check-wrap { padding: 0 6px; }

/* Queue item-head (by-item card header) */
.item-head { display: flex; align-items: center; gap: 12px; }
.item-head-main { flex: 1; }
.item-head-title { font-weight: 700; color: var(--primary-ink); font-size: 16px; }
.expand { padding-top: 8px; border-top: 1px dashed var(--line); margin-top: 12px; }

/* Sticky submit bar */
.sticky-submit { position: sticky; bottom: 0; padding-top: 12px; padding-bottom: calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(180deg, rgba(247,244,236,0) 0%, var(--bg) 28%); z-index: 5; }

/* Subcards (transfers in detail view) */
.subcard { padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); margin-top: 10px; }

/* Actions row */
.actions-row { display: flex; flex-wrap: wrap; gap: 10px; }

/* Vertical timeline stepper */
.timeline { position: relative; padding-left: 16px; margin-top: 6px; }
.timeline::before { content: ''; position: absolute; left: 4px; top: 6px; bottom: 6px; width: 2px; background: var(--line); border-radius: 1px; }
.step { position: relative; padding: 8px 0 14px 16px; }
.step-dot { position: absolute; left: -16px; top: 12px; width: 12px; height: 12px; border-radius: 50%; background: var(--primary); border: 2px solid #fff; box-shadow: 0 0 0 2px var(--primary); }
.step.amber .step-dot { background: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.step-title { font-weight: 600; color: var(--primary-ink); }
.step.amber .step-title { color: var(--accent-ink); }
.step-sub { margin-top: 2px; color: var(--ink-muted); font-size: 13px; }
