/*
 * Van Damik OS — module design system (Inventory & Purchase, POS).
 * Same brand tokens as the Portal: brand = exact logo colour, 600/700 for
 * buttons and links (white text on them meets WCAG AA).
 * Mobile-first: every layout starts at phone width and grows.
 */
:root {
  --brand: #f93903;
  --brand-50: #fff4ef;
  --brand-100: #ffe4d8;
  --brand-200: #ffc7b0;
  --brand-600: #e03302;
  --brand-700: #c22c02;
  --brand-800: #9a2302;

  --ink: #1f2328;
  --ink-muted: #565c66;
  --ink-subtle: #7d838d;
  --canvas: #faf9f7;
  --surface: #ffffff;
  --surface-2: #f4f2ef;
  --line: #e8e5e0;
  --line-strong: #d6d2cb;

  --success: #15803d;
  --success-50: #ecfdf3;
  --warning: #a15c07;
  --warning-50: #fff8eb;
  --danger: #c81e1e;
  --danger-50: #fef2f2;
  --info: #1d4ed8;
  --info-50: #eff6ff;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 1px 2px rgb(31 35 40 / 0.05), 0 1px 0 rgb(31 35 40 / 0.02);
  --shadow-pop: 0 10px 30px -12px rgb(31 35 40 / 0.25), 0 2px 6px rgb(31 35 40 / 0.06);
  --touch: 48px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: "Plus Jakarta Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
img { max-width: 100%; display: block; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 22px; font-weight: 750; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 16px; font-weight: 700; }
p { margin: 0; }
a { color: var(--brand-700); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
/* 16px inputs stop iOS Safari from zooming in on focus. */
input, select, textarea { font-size: 16px; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
::selection { background: var(--brand-100); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--ink-muted); }
.subtle { color: var(--ink-subtle); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-sm { display: flex; flex-direction: column; gap: 6px; }
.stack-lg { display: flex; flex-direction: column; gap: 20px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
@media (max-width: 380px) { .grid-2.collapse { grid-template-columns: 1fr; } }

/* ------------------------------------------------------------------ boot / full-page states */
.boot { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--ink-muted); padding: 16px; text-align: center; }
.boot-logo { width: 80px; height: 80px; border-radius: 22%; box-shadow: var(--shadow-card); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.state-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.state-card { width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 28px 22px; text-align: center; box-shadow: var(--shadow-card); }
.state-card .logo-lg { width: 72px; height: 72px; margin: 0 auto 14px; border-radius: 22%; }
.state-card h1 { font-size: 20px; margin-bottom: 8px; }
.state-card p { color: var(--ink-muted); margin-bottom: 18px; }

/* ------------------------------------------------------------------ app shell */
.shell { min-height: 100vh; display: flex; }
.sidebar { display: none; }
.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  min-height: 56px; padding: 8px 16px;
  background: rgb(255 255 255 / .92); backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar .logo { width: 36px; height: 36px; border-radius: 22%; flex: none; }
.topbar .title { font-weight: 750; font-size: 16px; line-height: 1.2; }
.topbar .title small { display: block; font-weight: 500; font-size: 12px; color: var(--ink-subtle); }
.content { width: 100%; max-width: 1100px; margin: 0 auto; padding: 16px 16px calc(var(--nav-h) + 24px + var(--safe-b)); }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head p { color: var(--ink-muted); margin-top: 4px; font-size: 14px; }
.back { display: inline-flex; align-items: center; gap: 4px; min-height: 40px; color: var(--ink-muted); font-weight: 600; font-size: 14px; margin: -6px 0 6px -4px; padding: 0 4px; background: none; border: 0; cursor: pointer; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--surface); border-top: 1px solid var(--line);
}
.bottom-nav a, .bottom-nav button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--ink-subtle); font-size: 11.5px; font-weight: 600; text-decoration: none;
  background: none; border: 0; cursor: pointer; padding: 6px 2px;
}
.bottom-nav .active { color: var(--brand-700); }
.bottom-nav .icon { width: 24px; height: 24px; }
.bottom-nav .fab { color: #fff; }
.bottom-nav .fab .fab-dot { width: 46px; height: 46px; margin-top: -18px; border-radius: 50%; background: var(--brand-600); display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow-pop); }
.bottom-nav .fab span:last-child { color: var(--brand-700); }

@media (min-width: 960px) {
  .sidebar {
    display: flex; flex-direction: column; gap: 4px;
    position: sticky; top: 0; height: 100vh; width: 248px; flex: none;
    padding: 16px 12px; background: var(--surface); border-right: 1px solid var(--line); overflow-y: auto;
  }
  .sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
  .sidebar .brand img { width: 40px; height: 40px; border-radius: 22%; }
  .sidebar .brand b { display: block; font-size: 14px; line-height: 1.2; }
  .sidebar .brand small { color: var(--ink-subtle); font-size: 12px; }
  .sidebar .group { margin: 12px 10px 4px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-subtle); }
  .sidebar a { display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 0 12px; border-radius: 10px; color: var(--ink-muted); font-weight: 600; font-size: 14px; text-decoration: none; }
  .sidebar a:hover { background: var(--surface-2); }
  .sidebar a.active { background: var(--brand-50); color: var(--brand-800); }
  .sidebar .icon { width: 20px; height: 20px; flex: none; }
  .bottom-nav { display: none; }
  .topbar .logo, .topbar .title { display: none; }
  .content { padding: 24px 28px 40px; }
}

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--touch); padding: 0 18px; border-radius: 12px;
  font-weight: 700; font-size: 15px; line-height: 1; white-space: nowrap;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  cursor: pointer; user-select: none; text-decoration: none;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn .icon { width: 20px; height: 20px; flex: none; }
.btn-primary { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
.btn-primary:hover { background: var(--brand-700); border-color: var(--brand-700); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: #126c33; }
.btn-danger { background: var(--surface); border-color: #f3c4c4; color: var(--danger); }
.btn-danger:hover { background: var(--danger-50); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-muted); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-block { width: 100%; }
.btn-lg { min-height: 56px; font-size: 16.5px; border-radius: 14px; }
.btn-sm { min-height: 38px; padding: 0 12px; font-size: 13.5px; border-radius: 10px; }
.btn-icon { width: var(--touch); padding: 0; }
.btn-icon.btn-sm { width: 38px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-row > .btn { flex: 1 1 auto; }

/* ------------------------------------------------------------------ cards, lists */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-card); }
.card-pad { padding: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.card-body { padding: 14px 16px; }
.card-foot { padding: 12px 16px; border-top: 1px solid var(--line); }
.section-title { font-size: 13px; font-weight: 700; color: var(--ink-subtle); text-transform: uppercase; letter-spacing: .05em; margin: 4px 0 8px; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li + li { border-top: 1px solid var(--line); }
.list-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 60px; padding: 12px 16px; text-align: left;
  background: none; border: 0; color: inherit; text-decoration: none; cursor: pointer;
}
a.list-item:hover, button.list-item:hover { background: var(--surface-2); text-decoration: none; }
.list-item .title { font-weight: 650; }
.list-item .meta { color: var(--ink-subtle); font-size: 13px; }
.list-item .chev { color: var(--line-strong); width: 18px; height: 18px; flex: none; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--ink-subtle); }
.kv dd { margin: 0; text-align: right; font-weight: 600; overflow-wrap: anywhere; }
.stat { padding: 14px 16px; }
.stat .label { color: var(--ink-subtle); font-size: 13px; font-weight: 600; }
.stat .value { font-size: 24px; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat.warn .value { color: var(--warning); }
.stat.bad .value { color: var(--danger); }
.stat.good .value { color: var(--success); }
a.stat { display: block; color: inherit; text-decoration: none; }
a.stat:hover { background: var(--surface-2); }
.big-number { font-size: 40px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.05; }
.big-number small { font-size: 18px; font-weight: 700; color: var(--ink-muted); margin-left: 6px; }

/* ------------------------------------------------------------------ badges, alerts */
.badge { display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 10px; border-radius: 999px; font-size: 12.5px; font-weight: 700; white-space: nowrap; background: var(--surface-2); color: var(--ink-muted); }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge.plain::before { display: none; }
.badge-safe, .badge-success { background: var(--success-50); color: var(--success); }
.badge-low, .badge-warning { background: var(--warning-50); color: var(--warning); }
.badge-out, .badge-danger { background: var(--danger-50); color: var(--danger); }
.badge-info { background: var(--info-50); color: var(--info); }
.badge-brand { background: var(--brand-50); color: var(--brand-800); }
.alert { display: flex; gap: 10px; padding: 12px 14px; border-radius: 12px; font-size: 14px; border: 1px solid; }
.alert .icon { width: 20px; height: 20px; flex: none; margin-top: 1px; }
.alert-info { background: var(--info-50); border-color: #cfe0ff; color: #1e3a8a; }
.alert-warning { background: var(--warning-50); border-color: #f4dfb6; color: #7a4504; }
.alert-danger { background: var(--danger-50); border-color: #f6caca; color: #9b1c1c; }
.alert-success { background: var(--success-50); border-color: #bfe8cf; color: #14532d; }
.alert b { font-weight: 700; }

/* ------------------------------------------------------------------ forms */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-weight: 650; font-size: 14px; }
.field .hint { color: var(--ink-subtle); font-size: 13px; }
.field .error { color: var(--danger); font-size: 13px; font-weight: 600; }
.input, .select, .textarea {
  width: 100%; min-height: var(--touch); padding: 10px 14px;
  border: 1px solid var(--line-strong); border-radius: 12px; background: var(--surface);
  outline: none; transition: border-color .12s, box-shadow .12s;
}
.textarea { min-height: 84px; resize: vertical; line-height: 1.45; }
.select { appearance: none; padding-right: 40px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23565c66' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; background-size: 18px; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-100); }
.input.invalid, .select.invalid, .textarea.invalid { border-color: var(--danger); }
.input[readonly] { background: var(--surface-2); }
.input-group { display: flex; align-items: stretch; }
.input-group .input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group .addon { display: flex; align-items: center; padding: 0 12px; border: 1px solid var(--line-strong); border-left: 0; border-radius: 0 12px 12px 0; background: var(--surface-2); color: var(--ink-muted); font-weight: 600; white-space: nowrap; }
.input-group .addon.left { border-radius: 12px 0 0 12px; border-left: 1px solid var(--line-strong); border-right: 0; }
.input-group .addon.left + .input { border-radius: 0 12px 12px 0; }
.check { display: flex; align-items: center; gap: 10px; min-height: var(--touch); cursor: pointer; font-weight: 600; }
.check input { width: 22px; height: 22px; accent-color: var(--brand-600); flex: none; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line-strong); transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .2); transition: transform .15s; }
.switch input:checked + span { background: var(--success); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); font-weight: 650; font-size: 14px; color: var(--ink-muted); cursor: pointer; white-space: nowrap; }
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip .count { font-size: 12px; opacity: .8; }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.segmented button { min-height: 42px; border: 0; border-radius: 9px; background: transparent; font-weight: 700; color: var(--ink-muted); cursor: pointer; padding: 0 8px; }
.segmented button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-card); }
.search { position: relative; }
.search .input { padding-left: 42px; }
.search .icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; color: var(--ink-subtle); pointer-events: none; }
.toolbar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.sticky-tools { position: sticky; top: 56px; z-index: 10; background: var(--canvas); padding: 8px 0 10px; margin-top: -8px; }
@media (min-width: 960px) { .sticky-tools { top: 0; } }

/* ------------------------------------------------------------------ sheet / modal */
.overlay { position: fixed; inset: 0; z-index: 60; background: rgb(31 35 40 / .45); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease-out; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-height: calc(100vh - 32px); max-height: calc(100dvh - 24px); display: flex; flex-direction: column;
  background: var(--surface); border-radius: 20px 20px 0 0; box-shadow: var(--shadow-pop);
  animation: up .2s cubic-bezier(.2,.8,.2,1); padding-bottom: var(--safe-b);
}
@keyframes up { from { transform: translateY(24px); opacity: .6; } }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px 12px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { flex: 1; font-size: 17px; }
.sheet-body { padding: 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet-foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; }
.sheet-foot .btn { flex: 1; }
@media (min-width: 720px) {
  .overlay { align-items: center; padding: 24px; }
  .sheet { max-width: 560px; border-radius: 20px; max-height: calc(100vh - 48px); }
  .sheet.wide { max-width: 860px; }
}

/* ------------------------------------------------------------------ toast */
.toasts { position: fixed; z-index: 80; left: 12px; right: 12px; bottom: calc(var(--nav-h) + 12px + var(--safe-b)); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
@media (min-width: 960px) { .toasts { bottom: 20px; left: auto; right: 20px; align-items: flex-end; } }
.toast { pointer-events: auto; max-width: 440px; width: 100%; display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; background: var(--ink); color: #fff; box-shadow: var(--shadow-pop); font-size: 14px; font-weight: 600; animation: up .18s ease-out; }
.toast.error { background: #8f1414; }
.toast.success { background: #14532d; }
.toast .icon { width: 20px; height: 20px; flex: none; }

/* ------------------------------------------------------------------ misc */
.empty { text-align: center; padding: 36px 16px; color: var(--ink-muted); }
.empty .icon { width: 44px; height: 44px; margin: 0 auto 10px; color: var(--line-strong); }
.empty b { display: block; color: var(--ink); margin-bottom: 4px; font-size: 16px; }
.skeleton { background: linear-gradient(90deg, var(--surface-2), #ece9e4, var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 10px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.spinner { width: 20px; height: 20px; border: 2.5px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.divider { height: 1px; background: var(--line); margin: 4px 0; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; font-size: 14px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--brand); }
.timeline li::after { content: ""; position: absolute; left: 8px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-subtle); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; }
.sticky-foot {
  position: sticky; bottom: calc(var(--nav-h) + var(--safe-b)); z-index: 15;
  margin: 16px -16px 0; padding: 12px 16px; background: rgb(255 255 255 / .96); backdrop-filter: blur(6px);
  border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px;
}
@media (min-width: 960px) { .sticky-foot { bottom: 0; margin: 16px 0 0; border: 1px solid var(--line); border-radius: var(--radius); } }
.photo-thumb { width: 100%; max-height: 360px; object-fit: contain; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.line-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--surface); }
.line-card.invalid { border-color: var(--danger); }
.dev-banner { position: fixed; z-index: 100; top: 6px; left: 50%; transform: translateX(-50%); max-width: calc(100vw - 24px); background: rgb(31 35 40 / .9); color: #fff; font-size: 12px; padding: 4px 10px; border-radius: 999px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dev-banner select { margin-left: 8px; font-size: 13px; border-radius: 6px; padding: 2px 4px; color: #1f2328; }

@media print {
  .sidebar, .bottom-nav, .topbar, .toasts, .no-print { display: none !important; }
  body { background: #fff; }
  .content { padding: 0; max-width: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
