﻿/* Blueno - mobile-first UI */

:root {
  --bg: #f6faf7;
  --fg: #232a25;
  --card: #ffffff;
  --muted: #68756c;
  --border: #e3eae5;
  --primary: #2f9e63;
  --primary-dark: #268552;
  --primary-fg: #ffffff;
  --accent: #e4f3ea;
  --accent-fg: #1e6b43;
  --secondary: #f0f4f1;
  --destructive: #d84343;
  --destructive-bg: #fbeaea;
  --amber: #b45309;
  --amber-bg: #fdf3e3;
  --topbar-bg: rgba(246, 250, 247, 0.92);
  --nav-bg: rgba(255, 255, 255, 0.95);
  --bar-bg: #232a25;
  --bar-fg: #ffffff;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 1px 2px rgba(20, 40, 30, 0.05);
  --nav-h: 62px;
  --topbar-h: 58px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, monospace;
}

/* Dark palette - shared by the manual toggle and the system-preference fallback */
:root[data-theme="dark"] {
  --bg: #10140f;
  --fg: #e7eee8;
  --card: #191f1a;
  --muted: #8a978d;
  --border: #2a322b;
  --primary: #35a76a;
  --primary-dark: #2f9e63;
  --primary-fg: #ffffff;
  --accent: #17301f;
  --accent-fg: #7fd3a4;
  --secondary: #212a23;
  --destructive: #f0736f;
  --destructive-bg: #34201f;
  --amber: #e0a24c;
  --amber-bg: #322817;
  --topbar-bg: rgba(16, 20, 15, 0.9);
  --nav-bg: rgba(21, 27, 22, 0.95);
  --bar-bg: #2a352d;
  --bar-fg: #e7eee8;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #10140f;
    --fg: #e7eee8;
    --card: #191f1a;
    --muted: #8a978d;
    --border: #2a322b;
    --primary: #3caf73;
    --primary-dark: #2f9e63;
    --primary-fg: #06130c;
    --accent: #17301f;
    --accent-fg: #7fd3a4;
    --secondary: #212a23;
    --destructive: #f0736f;
    --destructive-bg: #34201f;
    --amber: #e0a24c;
    --amber-bg: #322817;
    --topbar-bg: rgba(16, 20, 15, 0.9);
    --nav-bg: rgba(21, 27, 22, 0.95);
    --bar-bg: #2a352d;
    --bar-fg: #e7eee8;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
/* The `hidden` attribute must always win over class-based display rules
   (e.g. .sheet-backdrop{display:flex}), so sheets/modals start closed. */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--fg);
  background: var(--bg);
  min-height: 100dvh;
}
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; letter-spacing: -0.02em; }
h2 { font-size: 16px; }
small { font-size: 12px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.text-danger { color: var(--destructive); }
.text-primary { color: var(--primary); }
.text-right { text-align: right; }

.skip-link {
  position: absolute; top: -40px; left: 8px; z-index: 100;
  padding: 10px 16px; border-radius: var(--radius);
  background: var(--primary); color: var(--primary-fg);
  font-size: 14px; font-weight: 600; text-decoration: none;
  transition: top 0.15s;
}
.skip-link:focus { top: 8px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  height: var(--topbar-h);
  padding: 0 16px;
  padding-top: env(safe-area-inset-top);
  background: var(--topbar-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 11px;
  background: #fff; color: var(--primary-fg);
  border: 1px solid var(--border); overflow: hidden;
  font-weight: 700; font-family: var(--mono); font-size: 15px; flex-shrink: 0;
}
.brand-mark img { width: 100%; height: 100%; object-fit: cover; transform: scale(1.28); }
.brand-text { line-height: 1.15; }
.brand-text strong { font-size: 14px; display: block; }
.brand-text small { color: var(--muted); font-size: 11px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--card); color: var(--muted);
}
.icon-btn:active { background: var(--secondary); }
/* Theme toggle: show moon in light, sun in dark (system mode follows prefers-color-scheme) */
#theme-toggle .theme-icon-light, #theme-toggle .theme-icon-dark { display: inline-flex; }
#theme-toggle .theme-icon-dark { display: none; }
:root[data-theme="dark"] #theme-toggle .theme-icon-dark { display: inline-flex; }
:root[data-theme="dark"] #theme-toggle .theme-icon-light { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #theme-toggle .theme-icon-dark { display: inline-flex; }
  :root:not([data-theme="light"]) #theme-toggle .theme-icon-light { display: none; }
}
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 50%; overflow: hidden;
  background: var(--accent); color: var(--accent-fg);
  font-size: 13px; font-weight: 600;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-lg { width: 48px; height: 48px; font-size: 15px; }

/* ---------- Page ---------- */
.page {
  max-width: 680px;
  margin: 0 auto;
  padding: 20px 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px);
}
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head p { margin-top: 2px; font-size: 13px; color: var(--muted); }
.section-gap > * + * { margin-top: 16px; }

/* ---------- Bottom nav (mobile) ---------- */
.bottom-nav {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 40;
  display: flex;
  background: var(--nav-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
.bottom-nav-item {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; font-weight: 500; color: var(--muted);
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav-item.is-active { color: var(--primary); }

/* ---------- Bottom sheets ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(20, 30, 24, 0.4);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 680px;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 8px 20px calc(20px + env(safe-area-inset-bottom));
  animation: sheet-up 0.22s ease;
  max-height: 85dvh; overflow-y: auto;
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0.4; } to { transform: none; opacity: 1; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 6px auto 14px; }
.sheet-user { display: flex; align-items: center; gap: 12px; padding-bottom: 14px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.sheet-link { display: flex; align-items: center; gap: 10px; padding: 13px 4px; font-weight: 500; }
.sheet-link svg { color: var(--muted); }
.sheet-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.sheet-tile {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 16px 8px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg);
  font-size: 12px; font-weight: 500; text-align: center;
}
.sheet-tile svg { color: var(--primary); }
.sheet-tile.is-active { border-color: var(--primary); background: var(--accent); }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: 14px; }
.card-head small { display: block; color: var(--muted); }
.card-body { padding: 16px; }
.card-link { font-size: 12px; font-weight: 600; color: var(--primary); display: inline-flex; align-items: center; gap: 4px; }

/* ---------- Stat cards ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat-card { padding: 14px; border-radius: var(--radius-lg); background: var(--card); border: 1px solid var(--border); box-shadow: var(--shadow); }
.stat-card.is-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-fg); }
.stat-card.is-primary .muted, .stat-card.is-primary .stat-label { color: rgba(255,255,255,0.75); }
.stat-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.stat-label { font-size: 12px; font-weight: 500; color: var(--muted); }
.stat-icon { color: var(--muted); opacity: 0.7; }
.stat-card.is-primary .stat-icon { color: var(--primary-fg); }
.stat-value { font-family: var(--mono); font-size: 19px; font-weight: 700; letter-spacing: -0.01em; }
.stat-sub { margin-top: 3px; font-size: 11px; color: var(--muted); }
.stat-delta-up { color: var(--primary); font-weight: 600; }
.stat-card.is-primary .stat-delta-up { color: var(--primary-fg); }
.stat-delta-down { color: var(--destructive); font-weight: 600; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border-radius: var(--radius);
  font-size: 14px; font-weight: 600;
  background: var(--primary); color: var(--primary-fg);
  border: 1px solid transparent;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s;
}
.btn:active { opacity: 0.85; }
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn-outline { background: var(--card); color: var(--fg); border-color: var(--border); }
.btn-outline:active { background: var(--secondary); }
.btn-danger { background: var(--destructive); }
.btn-ghost-danger { background: var(--destructive-bg); color: var(--destructive); }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn-block { width: 100%; }
.btn.is-loading { opacity: 0.75; pointer-events: none; }
.spinner {
  display: inline-block; width: 14px; height: 14px; flex-shrink: 0;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 1.5s; } }
@keyframes spin { to { transform: rotate(360deg); } }
.fab-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px;
  padding: 10px 13px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card);
  font-size: 15px;
  outline: none;
}
textarea.input { min-height: 72px; resize: vertical; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47, 158, 99, 0.15); }
.input-search { padding-left: 40px; }
.search-wrap { position: relative; }
.search-wrap > svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-hint { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* Searchable dropdown (combobox) */
.combo { position: relative; }
.combo-menu {
  margin-top: 6px;
  max-height: 240px; overflow-y: auto;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 4px;
}
.combo-menu[hidden] { display: none; }
.combo-option {
  display: flex; gap: 8px; align-items: baseline; width: 100%; text-align: left;
  padding: 11px 12px; border-radius: 9px; font-size: 14px;
}
.combo-option:hover, .combo-option.is-active { background: var(--secondary); }
.combo-option[hidden] { display: none; }
.combo-option strong { font-family: var(--mono); }
.combo-add { color: var(--accent-fg); font-weight: 600; }
.combo-empty { padding: 11px 12px; font-size: 13px; color: var(--muted); }

/* Segmented control */
.segmented { display: inline-flex; padding: 3px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--secondary); gap: 2px; }
.segmented button, .segmented a {
  min-height: 36px; padding: 0 14px; border-radius: 9px;
  font-size: 13px; font-weight: 600; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  white-space: nowrap;
}
.segmented .is-active { background: var(--card); color: var(--fg); box-shadow: var(--shadow); }
.segmented-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.segmented-scroll::-webkit-scrollbar { display: none; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
  border: 1px solid var(--border); color: var(--muted); background: var(--card);
}
.badge-green { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
.badge-red { background: var(--destructive-bg); color: var(--destructive); border-color: transparent; }
.badge-amber { background: var(--amber-bg); color: var(--amber); border-color: transparent; }

/* ---------- Lists ---------- */
.list { list-style: none; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }
.list-thumb {
  width: 46px; height: 46px; border-radius: 11px; flex-shrink: 0;
  background: var(--secondary); object-fit: cover;
  display: flex; align-items: center; justify-content: center; color: var(--muted);
}
.list-main { flex: 1; min-width: 0; }
.list-main p { font-weight: 500; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-main small { color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-end { text-align: right; flex-shrink: 0; }
.list-end .mono { font-weight: 600; font-size: 14px; }
.list-end small { color: var(--muted); font-size: 11px; }
a.list-item-link:active { background: var(--secondary); }

/* ---------- POS ---------- */
.pos-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.pos-product {
  text-align: left; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  overflow: hidden; position: relative;
  -webkit-tap-highlight-color: transparent;
}
.pos-product:active { border-color: var(--primary); }
.pos-product.is-out { opacity: 0.45; pointer-events: none; }
.pos-product img { aspect-ratio: 1; width: 100%; object-fit: cover; background: var(--secondary); }
.pos-product-info { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; }
.pos-product-info p { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pos-product-info .mono { color: var(--primary); font-weight: 700; font-size: 14px; }
.pos-product-stock { position: absolute; top: 8px; right: 8px; }
.pos-qty-bubble {
  position: absolute; top: 8px; left: 8px;
  min-width: 26px; height: 26px; padding: 0 7px;
  border-radius: 999px; background: var(--primary); color: var(--primary-fg);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; font-family: var(--mono);
}

/* Cart bar (mobile sticky) */
.cart-bar {
  position: fixed; z-index: 50;
  inset-inline: 12px;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 10px);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--bar-bg); color: var(--bar-fg);
  border-radius: 14px; padding: 12px 16px;
  box-shadow: 0 8px 24px rgba(20, 40, 30, 0.25);
}
.cart-bar .mono { font-weight: 700; }
.cart-bar-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 24px; height: 24px; padding: 0 7px; border-radius: 999px;
  background: var(--primary); font-size: 12px; font-weight: 700;
}

/* Qty stepper */
.stepper { display: inline-flex; align-items: center; gap: 2px; }
.stepper button {
  width: 34px; height: 34px; border-radius: 9px;
  border: 1px solid var(--border); color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--card);
}
.stepper button:active { background: var(--secondary); }
.stepper span { min-width: 30px; text-align: center; font-family: var(--mono); font-weight: 600; }

/* Totals block */
.totals { padding: 14px 16px; background: var(--secondary); border-top: 1px solid var(--border); }
.totals-row { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); padding: 3px 0; }
.totals-row.is-total { color: var(--fg); font-weight: 700; font-size: 16px; border-top: 1px solid var(--border); margin-top: 8px; padding-top: 10px; }

/* Payment method picker */
.pay-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pay-option {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 12px 6px; border-radius: var(--radius);
  border: 1px solid var(--border); color: var(--muted);
  font-size: 12px; font-weight: 600; background: var(--card);
}
.pay-option.is-active { border-color: var(--primary); background: var(--accent); color: var(--accent-fg); }

/* ---------- Tables (mobile: horizontal scroll) ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 560px; }
.table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); font-weight: 600;
  padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--secondary);
  white-space: nowrap;
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- CSS bar charts ---------- */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding: 4px 2px 0; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; min-width: 0; }
.bar-stack { width: 100%; max-width: 34px; display: flex; flex-direction: column-reverse; gap: 2px; height: 100%; justify-content: flex-start; }
.bar { width: 100%; border-radius: 4px 4px 2px 2px; min-height: 2px; }
.bar-revenue { background: #5fba8c; }
.bar-profit { background: var(--primary); }
.bar-group { display: flex; gap: 2px; align-items: flex-end; height: 100%; width: 100%; max-width: 40px; justify-content: center; }
.bar-group .bar { flex: 1; max-width: 18px; }
.bar-label { font-size: 10px; color: var(--muted); white-space: nowrap; }
.hbar-row { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; align-items: center; gap: 10px; padding: 7px 0; }
.hbar-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { height: 8px; border-radius: 4px; background: var(--secondary); overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 4px; background: var(--primary); }
.hbar-val { font-family: var(--mono); font-size: 12px; font-weight: 600; }
.legend { display: flex; gap: 14px; font-size: 11px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ---------- Progress ---------- */
.progress { height: 6px; border-radius: 3px; background: var(--secondary); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--primary); border-radius: 3px; }
.progress.is-low > i { background: var(--destructive); }

/* PO lifecycle stepper (Created -> Raised -> Received) */
.po-steps { display: flex; margin: 14px 0 4px; }
.po-step { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; position: relative; }
.po-step:not(:last-child)::after {
  content: ''; position: absolute; top: 12px; left: 50%; width: 100%; height: 2px;
  background: var(--border); z-index: 0;
}
.po-step.is-done:not(:last-child)::after { background: var(--primary); }
.po-step-dot {
  position: relative; z-index: 1;
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--card); border: 2px solid var(--border); color: var(--muted);
  font-size: 12px; font-weight: 700;
}
.po-step.is-done .po-step-dot { background: var(--primary); border-color: var(--primary); color: #fff; }
.po-step.is-current .po-step-dot { border-color: var(--primary); color: var(--primary); background: var(--accent); }
.po-step-label { font-size: 11px; font-weight: 500; color: var(--muted); }
.po-step.is-done .po-step-label, .po-step.is-current .po-step-label { color: var(--fg); }

/* ---------- Toast / empty ---------- */
.toast {
  display: flex; align-items: center; gap: 8px;
  background: var(--accent); color: var(--accent-fg);
  border: 1px solid rgba(47, 158, 99, 0.3);
  border-radius: var(--radius); padding: 12px 14px;
  font-size: 13px; font-weight: 500; margin-bottom: 14px;
  animation: sheet-up 0.25s ease;
}
/* Floating JS toasts */
.toast-stack {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + 16px); z-index: 90;
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 0 16px; pointer-events: none;
}
.toast-stack .toast { margin: 0; width: fit-content; max-width: 460px; pointer-events: auto; box-shadow: 0 8px 24px -8px rgba(16, 40, 28, 0.3); }
.toast.toast-error { background: var(--destructive-bg); color: var(--destructive); border-color: transparent; }
.toast.is-out { opacity: 0; transform: translateY(8px); transition: opacity 0.3s ease, transform 0.3s ease; }

/* App confirmation dialog */
.confirm-backdrop {
  position: fixed; inset: 0; z-index: 95; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: rgba(20, 30, 24, 0.5); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  animation: confirm-fade 0.15s ease;
}
@keyframes confirm-fade { from { opacity: 0; } to { opacity: 1; } }
.confirm-box {
  width: 100%; max-width: 360px; background: var(--card); border-radius: var(--radius-lg); padding: 22px;
  box-shadow: 0 24px 60px -20px rgba(16, 40, 28, 0.45); animation: sheet-up 0.2s ease;
}
.confirm-icon {
  width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--primary); margin-bottom: 14px;
}
.confirm-icon.is-danger { background: var(--destructive-bg); color: var(--destructive); }
.confirm-box h3 { font-size: 17px; margin-bottom: 6px; }
.confirm-box p { font-size: 13.5px; color: var(--muted); line-height: 1.5; }
.confirm-actions { display: flex; gap: 8px; margin-top: 20px; }
.confirm-actions .btn { flex: 1; }

.empty-state { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 40px 20px; text-align: center; }
.empty-state svg { color: var(--muted); opacity: 0.4; }
.empty-title { font-weight: 600; }

/* ---------- Login ---------- */
/* ---------- Auth / login (gradient + translucent panel) ---------- */
.lg {
  min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 30px 20px;
  background: linear-gradient(150deg, #40b6d8 0%, #2c9a92 47%, #9fb15f 100%);
}
.lg-brand { text-align: center; margin-bottom: 20px; }
.lg-logo {
  width: 88px; height: 88px; border-radius: 50%; background: #fff; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 22px -8px rgba(0, 0, 0, 0.35);
}
.lg-logo img { width: 100%; height: 100%; object-fit: cover; transform: scale(1.28); }
.lg-name { color: #fff; font-size: 22px; font-weight: 700; letter-spacing: 0.01em; margin-top: 14px; }
.lg-form { width: 100%; max-width: 420px; display: flex; flex-direction: column; }
.lg-panel { background: rgba(16, 112, 106, 0.42); padding: 30px 26px; }
.lg-field {
  display: flex; align-items: center; gap: 12px; padding: 8px 2px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.55); transition: border-color 0.15s ease;
}
.lg-field + .lg-field { margin-top: 24px; }
.lg-field:focus-within { border-bottom-color: #fff; }
.lg-ico { color: #fff; opacity: 0.9; display: flex; flex-shrink: 0; }
.lg-input {
  flex: 1; min-width: 0; background: transparent; border: none; outline: none;
  color: #fff; font-size: 15px; padding: 4px 0;
}
.lg-input::placeholder { color: rgba(255, 255, 255, 0.82); }
.lg-input:-webkit-autofill { -webkit-text-fill-color: #fff; transition: background-color 9999s ease-in-out 0s; }

.lg-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 16px 4px 0; color: #fff; }
.lg-check { display: flex; align-items: center; gap: 9px; font-size: 13px; cursor: pointer; user-select: none; }
.lg-check input { position: absolute; opacity: 0; width: 0; height: 0; }
.lg-box { width: 18px; height: 18px; border: 1.5px solid rgba(255, 255, 255, 0.85); border-radius: 4px; position: relative; flex-shrink: 0; }
.lg-check input:checked + .lg-box { background: #fff; border-color: #fff; }
.lg-check input:checked + .lg-box::after {
  content: ""; position: absolute; left: 5px; top: 1px; width: 5px; height: 9px;
  border: solid #17867b; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.lg-check input:focus-visible + .lg-box { box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.4); }
.lg-forgot { font-size: 13px; font-style: italic; color: #fff; opacity: 0.92; }
.lg-forgot:hover { text-decoration: underline; }

.lg-btn {
  margin-top: 22px; height: 52px; border: none; cursor: pointer;
  background: #17867b; color: #fff; font-size: 14px; font-weight: 600;
  letter-spacing: 0.2em; text-transform: uppercase;
  transition: background 0.18s ease, transform 0.1s ease;
}
.lg-btn:hover { background: #12736a; }
.lg-btn:active { transform: translateY(1px); }
.lg-hint { color: #fff; font-size: 12px; text-align: center; margin-top: 12px; opacity: 0.92; }
.lg-alert {
  display: flex; align-items: center; gap: 8px; font-size: 13px; color: #fff;
  padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; background: rgba(214, 69, 69, 0.95);
}
.lg-alert.is-notice { background: rgba(20, 120, 92, 0.92); }

/* ---------- Modal (centered, for confirms) ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 70; background: rgba(20,30,24,0.45); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { width: 100%; max-width: 380px; background: var(--card); border-radius: var(--radius-lg); padding: 20px; animation: sheet-up 0.2s ease; max-height: 85dvh; overflow-y: auto; }
.modal h3 { font-size: 16px; margin-bottom: 6px; }

/* Toggle switch */
.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  position: relative; width: 46px; height: 27px; border-radius: 999px;
  background: var(--border); flex-shrink: 0; transition: background 0.18s ease;
}
.switch-thumb {
  position: absolute; top: 3px; left: 3px; width: 21px; height: 21px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28); transition: transform 0.18s ease;
}
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(19px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 30%, transparent); }
.switch-label { font-size: 14px; font-weight: 500; }

/* ---------- Receipt ---------- */
.receipt { max-width: 420px; margin: 0 auto; }
.receipt-paper { background: var(--card); border: 1px dashed var(--border); border-radius: var(--radius-lg); padding: 22px; }
.receipt-head { text-align: center; padding-bottom: 14px; border-bottom: 1px dashed var(--border); margin-bottom: 14px; }
.receipt-items { list-style: none; }
.receipt-items li { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; font-size: 14px; }
.receipt-total { border-top: 1px dashed var(--border); margin-top: 12px; padding-top: 12px; }
.receipt-footer-note { text-align: center; font-size: 12px; color: var(--muted); margin-top: 14px; }

/* ---------- Document (PO / invoice - printable, always light "paper") ---------- */
.doc {
  max-width: 820px; margin: 0 auto; background: #ffffff; color: #1f2620;
  border: 1px solid #e4eae6; border-radius: 14px; box-shadow: 0 1px 3px rgba(20, 40, 30, 0.06);
  padding: 34px; font-size: 14px; line-height: 1.5;
}
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; padding-bottom: 20px; border-bottom: 2px solid var(--primary); }
.doc-brand { display: flex; align-items: center; gap: 12px; }
.doc-logo { display: flex; align-items: center; justify-content: center; width: 52px; height: 52px; border-radius: 13px; background: #fff; border: 1px solid #e4eae6; overflow: hidden; flex-shrink: 0; }
.doc-logo img { width: 100%; height: 100%; object-fit: cover; transform: scale(1.28); }
.doc-brand-text strong { display: block; font-size: 18px; color: #1f2620; }
.doc-brand-text span { display: block; font-size: 12px; color: #6b776f; }
.doc-brand-note { margin-top: 4px; line-height: 1.4; color: #7d8880 !important; }
.doc-title { text-align: right; }
.doc-title h1 { font-size: 14px; letter-spacing: 0.16em; text-transform: uppercase; color: #6b776f; font-weight: 600; }
.doc-number { font-family: var(--mono); font-size: 22px; font-weight: 700; color: var(--primary); margin: 2px 0 8px; }
.doc-meta { display: flex; justify-content: space-between; gap: 24px; margin: 24px 0; }
.doc-meta > div { display: flex; flex-direction: column; gap: 2px; }
.doc-meta-right { align-items: flex-end; text-align: right; }
.doc-meta-right > div { display: flex; gap: 12px; }
.doc-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: #98a29a; font-weight: 700; }
.doc-meta strong { font-size: 15px; color: #1f2620; }
.doc-meta span { font-size: 13px; color: #4a544d; }
.doc-table { width: 100%; border-collapse: collapse; margin-top: 4px; }
.doc-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: #6b776f; font-weight: 700; padding: 9px 10px; border-bottom: 1.5px solid #d7ded9; background: #f6f9f7; }
.doc-table td { padding: 11px 10px; border-bottom: 1px solid #eef2ef; vertical-align: top; }
.doc-table .num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.doc-item-name { font-weight: 600; color: #1f2620; }
.doc-item-sub { font-size: 12px; color: #98a29a; margin-top: 2px; }
.doc-table .muted { color: #98a29a; }
.doc-summary { display: flex; justify-content: flex-end; margin-top: 18px; }
.doc-summary-box { min-width: 270px; }
.doc-sum-row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 14px; color: #4a544d; }
.doc-sum-row span:last-child { font-family: var(--mono); }
.doc-sum-total { border-top: 1.5px solid #d7ded9; margin-top: 4px; padding-top: 10px; font-weight: 700; font-size: 17px; color: #1f2620; }
.doc-sum-mvr { color: var(--primary); font-weight: 600; }
.doc-notes { margin-top: 22px; }
.doc-notes p { margin-top: 4px; font-size: 13px; color: #4a544d; }
.doc-footer { margin-top: 30px; padding-top: 14px; border-top: 1px solid #eef2ef; text-align: center; font-size: 11px; color: #98a29a; }
/* Status badges (Paid, Refunded, Created…) keep their light-mode colors here too — the
   document is always "paper", so nothing on it should shift when the app theme changes. */
.doc .badge { border-color: transparent; }
.doc .badge-green { background: #e4f3ea; color: #1e6b43; }
.doc .badge-red { background: #fbeaea; color: #d84343; }
.doc .badge-amber { background: #fdf3e3; color: #b45309; }
.doc .badge:not(.badge-green):not(.badge-red):not(.badge-amber) { background: #f6f9f7; color: #6b776f; border-color: #e4eae6; }
@media (max-width: 640px) {
  .doc { padding: 20px; }
  .doc-head { flex-direction: column; gap: 12px; }
  .doc-title { text-align: left; }
  .doc-meta { flex-direction: column; gap: 16px; }
  .doc-meta-right { align-items: flex-start; text-align: left; }
  .doc-table { display: block; overflow-x: auto; white-space: nowrap; }
}

/* ---------- Printable report header + per-section pagination ---------- */
.print-head { display: none; margin-bottom: 24px; }
.doc-title-sub { display: block; font-size: 11px; color: #6b776f; margin-top: 2px; }
.print-section > * + * { margin-top: 16px; }

/* ---------- Report filter chips ---------- */
.report-filter-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.report-filter-scroll::-webkit-scrollbar { display: none; }
.report-filter { display: flex; gap: 8px; padding-bottom: 2px; }
/* Desktop: wrap onto multiple rows (mouse can't drag a hidden-scrollbar strip) */
@media (min-width: 700px) {
  .report-filter-scroll { overflow-x: visible; }
  .report-filter { flex-wrap: wrap; }
}
.report-chip {
  flex-shrink: 0; display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--card); color: var(--muted); font-size: 12.5px; font-weight: 600;
  cursor: pointer; white-space: nowrap; -webkit-tap-highlight-color: transparent; user-select: none;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.report-chip:active { transform: scale(0.96); }
.report-chip.is-active { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.report-chip .chip-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.4; transition: opacity 0.15s ease; }
.report-chip.is-active .chip-dot { opacity: 1; }

/* ---------- Per-report print-in-isolation icon button (inside card-head, left of title) ---------- */
.card-head-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.report-print-icon-btn {
  flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--card); color: var(--muted); cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.report-print-icon-btn:hover { color: var(--primary); border-color: var(--primary); background: var(--accent); }

/* ---------- Categories: toolbar + card grid ---------- */
.cat-toolbar { display: flex; gap: 8px; align-items: center; }
.cat-toolbar .search-wrap { flex: 1; min-width: 0; }
.cat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 560px) { .cat-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 860px) { .cat-grid { grid-template-columns: repeat(4, 1fr); } }
.cat-card {
  display: flex; flex-direction: column; gap: 3px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 14px; box-shadow: var(--shadow);
}
.cat-card-top { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 6px; }
.cat-card-badge {
  width: 34px; height: 34px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--primary); flex-shrink: 0;
}
.cat-card-actions { display: flex; gap: 4px; }
.icon-btn.cat-mini { width: 30px; height: 30px; }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.cat-card-name { font-size: 14.5px; font-weight: 600; line-height: 1.3; }
.cat-card-count { font-size: 12px; color: var(--muted); }
.cat-card-view {
  margin-top: 10px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; border-radius: 10px; border: 1px solid var(--border); background: var(--secondary);
  color: var(--fg); font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.cat-card-view:hover { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
.cat-card-view:active { transform: scale(0.98); }

/* ---------- Category → products popup (card grid) ---------- */
.cat-sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.cat-sheet-head h2 { font-size: 16px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-pgrid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
  max-height: 62dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.cat-pcard {
  display: flex; flex-direction: column; gap: 4px;
  border: 1px solid var(--border); border-radius: var(--radius); padding: 10px;
  background: var(--card); color: var(--fg);
  animation: cat-pcard-in 0.26s ease both;
}
.cat-pcard:active { background: var(--secondary); }
.cat-pcard-img {
  width: 100%; aspect-ratio: 1 / 1; border-radius: 9px; object-fit: cover;
  background: var(--secondary); margin-bottom: 4px;
}
.cat-pcard-ph { display: flex; align-items: center; justify-content: center; color: var(--muted); }
.cat-pcard-name { font-size: 13px; font-weight: 600; line-height: 1.3; }
.cat-pcard-sku { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.cat-pcard-foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 2px; }
.cat-pcard-price { font-size: 13px; font-weight: 700; color: var(--primary); }
.cat-pcard-stock { font-size: 11px; color: var(--muted); }
@keyframes cat-pcard-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}
@media (min-width: 620px) { .cat-pgrid { grid-template-columns: repeat(3, 1fr); } }

/* ---------- PO search result pop-in ---------- */
.po-card.po-pop { animation: po-pop 0.28s ease both; }
@keyframes po-pop {
  from { opacity: 0; transform: translateY(6px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

/* ---------- Report reorder ("bring to front") animation ---------- */
/* Hidden = display:none, used only for single-report print isolation. */
.report-block.is-hidden { display: none !important; }
/* Light highlight wash on the card that was just promoted to the top. */
.card.is-promoted { animation: report-promote 0.85s ease; }
@keyframes report-promote {
  0%   { background: var(--accent); }
  100% { background: var(--card); }
}

@media print {
  @page { size: A4; margin: 14mm 12mm; }
  :root, :root[data-theme="dark"] {
    --bg: #ffffff; --fg: #1f2620; --card: #ffffff; --muted: #6b776f;
    --border: #e4eae6; --secondary: #f0f4f1; --shadow: none;
  }
  .topbar, .bottom-nav, .no-print, .toast, .cart-bar { display: none !important; }
  body { background: #fff; color: #1f2620; }
  .page { padding: 0; max-width: none; }
  .page-head { display: none; }
  .card, .receipt-paper { border: none; box-shadow: none; }
  .doc { border: none; box-shadow: none; border-radius: 0; max-width: none; padding: 0; }

  .print-head { display: block; }
  .print-head .doc-head { width: 100%; }
  /* Force chart/bar/badge colors to render (browsers drop backgrounds in print by default) */
  .bar, .bar-revenue, .bar-profit, .hbar-track, .hbar-fill, .legend i, .badge, .doc-table th, .stat-card.is-primary {
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .print-section { break-before: page; }
  /* The first section always shares page 1 with the header (P&L uses this;
     Reports overrides it per-section via JS-added .is-print-first below) */
  .print-section:first-of-type { break-before: avoid; }
  .report-block.is-print-first { break-before: avoid !important; }
  .report-block { transform: none !important; }
  .card.is-promoted { animation: none !important; }
  .card, .stat-grid, table.table tr, .doc-table tr { break-inside: avoid; }
}

/* ---------- Larger screens ---------- */
@media (min-width: 700px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .pos-grid { grid-template-columns: repeat(3, 1fr); }
  .form-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
}

@media (min-width: 1024px) {
  :root { --nav-h: 0px; }
  .page { max-width: 960px; padding-bottom: 40px; }
  .bottom-nav {
    inset: 0 auto 0 0; top: 0; width: 200px; height: 100dvh;
    flex-direction: column; justify-content: flex-start;
    border-top: 0; border-right: 1px solid var(--border);
    padding: calc(var(--topbar-h) + 16px) 10px 16px;
    gap: 2px;
  }
  .bottom-nav-item {
    flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 12px;
    width: 100%; padding: 11px 14px; border-radius: var(--radius);
    font-size: 14px;
  }
  .bottom-nav-item.is-active { background: var(--primary); color: var(--primary-fg); }
  .topbar { padding-left: 216px; }
  .page, main.page { margin-left: calc(200px + (100vw - 200px - 960px) / 2); }
  @media (max-width: 1380px) { .page, main.page { margin-left: 220px; margin-right: 20px; } }
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 20px; max-width: 480px; }
  .pos-grid { grid-template-columns: repeat(4, 1fr); }
  .pos-layout { display: grid; grid-template-columns: 1.5fr 1fr; gap: 20px; align-items: start; }
  .pos-cart-card { position: sticky; top: calc(var(--topbar-h) + 20px); }
  .cart-bar { display: none; }
}

