:root {
  --bg: #f6f7f3;
  --card: #ffffff;
  --text: #1d2b20;
  --muted: #6b7a6e;
  --border: #e4e8e1;
  --green-900: #1e2f22;
  --green-800: #27402c;
  --green-700: #33553a;
  --green: #4f7a3f;
  --lime: #a8c94e;
  --lime-soft: #e7f0cf;
  --red: #c94a3d;
  --red-soft: #f8e3e0;
  --amber: #b98413;
  --amber-soft: #f7edd6;
  --chart-sales: #27402c;
  --shadow: 0 1px 3px rgba(20, 35, 25, .07);
  --radius: 14px;
  --sidebar-text: #cfd8cc;
}
[data-theme="dark"] {
  --bg: #141a15;
  --card: #1d251e;
  --text: #e6ece4;
  --muted: #93a295;
  --border: #2b352c;
  --lime-soft: #2c3a1e;
  --red-soft: #3d2320;
  --amber-soft: #3a3118;
  --chart-sales: #9fd08a;
  --shadow: 0 1px 3px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.app { display: flex; min-height: 100vh; }
.hidden { display: none !important; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 232px; flex-shrink: 0;
  background: linear-gradient(180deg, var(--green-900), var(--green-800));
  color: var(--sidebar-text);
  display: flex; flex-direction: column;
  padding: 18px 12px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: rgba(255,255,255,.12);
  display: grid; place-items: center; font-size: 20px;
}
.brand-name { font-weight: 700; color: #fff; line-height: 1.15; font-size: 13px; }
.brand-name span { font-weight: 500; color: var(--sidebar-text); }
.menu-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; opacity: .55; padding: 4px 10px 8px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  background: none; border: 0; color: inherit; font: inherit;
  padding: 10px 12px; border-radius: 10px; cursor: pointer; text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: var(--lime); color: var(--green-900); font-weight: 600; }
.nav-ico { width: 20px; text-align: center; }
.sidebar-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.user-row {
  display: flex; align-items: center; gap: 8px;
  border-top: 1px solid rgba(255,255,255,.1); padding-top: 12px; margin-top: 4px;
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--lime); color: var(--green-900);
  display: grid; place-items: center; font-weight: 700;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; flex: 1; }
.user-meta strong { color: #fff; font-size: 13px; }
.user-meta span { font-size: 11px; opacity: .6; }
.signout { background: none; border: 0; color: var(--sidebar-text); font-size: 11px; cursor: pointer; opacity: .7; }
.signout:hover { opacity: 1; text-decoration: underline; }

/* ---------- Main ---------- */
.main { flex: 1; padding: 26px 30px 40px; min-width: 0; }
.view-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 16px; flex-wrap: wrap; margin-bottom: 20px;
}
h1 { margin: 0 0 4px; font-size: 22px; }
h3 { margin: 0; font-size: 15px; }
.sub { margin: 0; color: var(--muted); font-size: 12.5px; }
.head-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* segmented control */
.seg { display: flex; background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.seg button {
  border: 0; background: none; color: var(--muted); font: inherit; font-size: 12.5px;
  padding: 6px 12px; border-radius: 8px; cursor: pointer;
}
.seg button.active { background: var(--green-800); color: #fff; }
.seg-sm button { padding: 4px 9px; font-size: 11.5px; }

/* cards */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.link-btn { background: none; border: 0; color: var(--green); font: inherit; font-size: 12.5px; cursor: pointer; font-weight: 600; }
.link-btn:hover { text-decoration: underline; }

/* ---------- Overview grid ---------- */
.grid-overview {
  display: grid; gap: 16px;
  grid-template-columns: repeat(3, minmax(0, 1fr)) 300px;
  grid-template-areas:
    "s1 s2 s3 top"
    "tr tr tr top"
    "tr tr tr al";
}
#statSales { grid-area: s1; } #statIncome { grid-area: s2; } #statTx { grid-area: s3; }
.top-products { grid-area: top; }
.trend { grid-area: tr; }
.alerts { grid-area: al; }
@media (max-width: 1100px) {
  .grid-overview { grid-template-columns: 1fr 1fr; grid-template-areas: "s1 s2" "s3 top" "tr tr" "al al"; }
}

.stat-title { color: var(--muted); font-size: 12.5px; }
.stat-period { float: right; font-size: 11px; opacity: .8; }
.stat-value { font-size: 26px; font-weight: 700; margin: 6px 0 4px; }
.stat-delta { font-size: 12px; font-weight: 600; }
.stat-delta.up { color: var(--green); }
.stat-delta.down { color: var(--red); }
.stat-delta small { color: var(--muted); font-weight: 400; }
.spark { margin-top: 10px; height: 42px; }
.spark svg { width: 100%; height: 42px; display: block; }

/* donut */
.donut-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; }
#donut svg { width: 160px; height: 160px; }
.donut-center-total { font-size: 15px; font-weight: 700; fill: var(--text); }
.donut-center-label { font-size: 10px; fill: var(--muted); }
.legend { list-style: none; margin: 0; padding: 0; width: 100%; display: flex; flex-direction: column; gap: 8px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.legend .amt { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

/* trend */
.legend-inline { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.legend-inline .dot { margin-right: 5px; }
.dot-sales { background: var(--chart-sales); }
.dot-income { background: var(--lime); }
.trend-chart svg { width: 100%; height: 260px; display: block; }
.axis-label { font-size: 10px; fill: var(--muted); }
.grid-line { stroke: var(--border); stroke-width: 1; }

/* alerts */
.alert-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.alert-list li { display: flex; align-items: center; gap: 10px; }
.alert-ico { font-size: 16px; }
.alert-meta { flex: 1; line-height: 1.25; }
.alert-meta strong { display: block; font-size: 13px; }
.alert-meta span { font-size: 11.5px; color: var(--muted); }
.badge { font-size: 10.5px; font-weight: 700; padding: 3px 8px; border-radius: 20px; }
.badge.critical { background: var(--red-soft); color: var(--red); }
.badge.low { background: var(--amber-soft); color: var(--amber); }
.badge.ok { background: var(--lime-soft); color: var(--green); }
.alert-empty { color: var(--muted); font-size: 12.5px; }

/* ---------- POS ---------- */
.pos-layout { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .pos-layout { grid-template-columns: 1fr; } }
.pos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.pos-item {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; cursor: pointer; text-align: left; font: inherit; color: inherit;
  box-shadow: var(--shadow); transition: transform .06s;
}
.pos-item:hover { transform: translateY(-2px); border-color: var(--lime); }
.pos-item:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.pos-item .p-name { font-weight: 600; font-size: 13px; display: block; margin-bottom: 4px; }
.pos-item .p-price { color: var(--green); font-weight: 700; }
.pos-item .p-stock { display: block; font-size: 11px; color: var(--muted); margin-top: 4px; }
.cart { position: sticky; top: 20px; }
.cart h3 { margin-bottom: 10px; }
.cart-list { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 300px; overflow: auto; }
.cart-list .empty { color: var(--muted); font-size: 12.5px; }
.cart-line { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.cart-line .c-name { flex: 1; }
.qty-btn {
  width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--border);
  background: none; color: inherit; cursor: pointer; line-height: 1;
}
.c-qty { min-width: 18px; text-align: center; font-weight: 600; }
.c-amt { min-width: 70px; text-align: right; font-variant-numeric: tabular-nums; }
.cart-total, .cart-change {
  display: flex; justify-content: space-between; padding: 10px 0;
  border-top: 1px solid var(--border); font-size: 14px;
}
.cart-total strong { font-size: 18px; }
.cart-actions { display: flex; gap: 8px; margin-top: 10px; }
.cart-actions .btn { flex: 1; }

/* ---------- forms / buttons ---------- */
.btn {
  border: 0; border-radius: 10px; padding: 10px 16px; font: inherit;
  font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--green-800); color: #fff; }
.btn.primary:hover { background: var(--green-700); }
.btn.primary:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: none; border: 1px solid var(--border); color: var(--text); }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn.danger-ghost { background: none; border: 1px solid var(--border); color: var(--red); }
.search, .field input, .field select, .field-inline input {
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 9px 12px; font: inherit; outline: none;
}
.search:focus, .field input:focus, .field select:focus { border-color: var(--lime); }
.search { width: 240px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); margin-bottom: 12px; }
.field input, .field select { color: var(--text); }
.field-inline { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }

/* ---------- tables ---------- */
.table-card { padding: 6px 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; }
.muted { color: var(--muted); }

/* ---------- restock/report ---------- */
.restock-layout { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .restock-layout { grid-template-columns: 1fr; } }
.restock-form h3 { margin-bottom: 14px; }
.report-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
@media (max-width: 900px) { .report-cards { grid-template-columns: 1fr 1fr; } }
.card.mini { display: flex; flex-direction: column; gap: 6px; }
.card.mini span { color: var(--muted); font-size: 12px; }
.card.mini strong { font-size: 20px; }

/* ---------- modal & toast ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 20, 12, .45);
  display: grid; place-items: center; z-index: 50;
}
.modal { width: 420px; max-width: calc(100vw - 32px); }
.modal h3 { margin-bottom: 16px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
/* ---------- auth ---------- */
.auth {
  position: fixed; inset: 0; z-index: 70;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--green-900) 0%, var(--green-700) 100%);
  padding: 20px;
}
.auth-card { width: 400px; max-width: 100%; padding: 28px; text-align: left; }
.auth-logo {
  width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 12px;
  background: var(--lime-soft); display: grid; place-items: center; font-size: 30px;
}
.auth-card h2 { margin: 0; text-align: center; font-size: 19px; }
.auth-sub { text-align: center; margin-bottom: 18px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); margin-bottom: 12px; cursor: pointer; }
.form-error { color: var(--red); font-size: 12.5px; margin: 0 0 10px; }
.btn.wide { width: 100%; margin-top: 4px; }
.btn.ghost.wide { margin-top: 8px; }
.license-line { font-size: 11px; opacity: .65; padding: 0 10px 4px; }
.license-line.warn { color: #f0c46a; opacity: 1; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--green-900); color: #fff; padding: 11px 20px;
  border-radius: 10px; font-size: 13px; z-index: 60; box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
