/* Harmain Sanitary — design system */
:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #0e7490;
  --primary-600: #0891b2;
  --primary-dark: #155e75;
  --primary-soft: #ecfeff;
  --success: #15803d;
  --success-soft: #f0fdf4;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warning: #b45309;
  --warning-soft: #fffbeb;
  --sidebar: #0f172a;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .16);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
h1, h2, h3, h4 { margin: 0; font-weight: 700; }

/* ---------- layout shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 224px; flex: 0 0 224px;
  background: var(--sidebar); color: #cbd5e1;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  padding: 18px 12px;
  gap: 4px;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  color: #fff; font-weight: 800; font-size: 17px;
  padding: 4px 10px 16px;
}
.brand-icon {
  width: 34px; height: 34px; border-radius: 8px; background: var(--primary-600);
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 34px;
}
.brand-icon svg { width: 20px; height: 20px; fill: #fff; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px;
  color: #cbd5e1; text-decoration: none; font-weight: 600; font-size: 14px;
  border: 0; background: transparent; cursor: pointer; width: 100%; text-align: left;
}
.nav-item svg { width: 18px; height: 18px; fill: currentColor; opacity: .85; flex: 0 0 18px; }
.nav-item:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.nav-item.active { background: var(--primary-600); color: #fff; }
.nav-item .pill {
  margin-left: auto; background: var(--danger); color: #fff;
  border-radius: 99px; padding: 0 7px; font-size: 11.5px; font-weight: 700; line-height: 18px;
}
.sidebar .spacer { flex: 1; }
.sidebar-foot { font-size: 11.5px; color: #475569; padding: 8px 10px; }

.main { flex: 1; min-width: 0; padding: 22px 26px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 21px; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* mobile bottom nav */
.bottom-nav { display: none; }

/* ---------- cards & stats ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px;
}
.card h3 { font-size: 14px; color: var(--muted); font-weight: 600; margin-bottom: 12px; text-transform: uppercase; letter-spacing: .3px; }
.card + .card { margin-top: 0; }

.grid { display: grid; gap: 14px; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.mt { margin-top: 14px; }

.stat { display: flex; flex-direction: column; gap: 4px; }
.stat .label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 23px; font-weight: 800; letter-spacing: -.3px; }
.stat .hint { font-size: 12px; color: var(--muted); }
.stat.accent { border-left: 4px solid var(--primary-600); }
.stat.green { border-left: 4px solid var(--success); }
.stat.red { border-left: 4px solid var(--danger); }
.stat.amber { border-left: 4px solid #d97706; }
.stat.gold { background: linear-gradient(135deg, #155e75, #0e7490); color: #fff; border: none; }
.stat.gold .label, .stat.gold .hint { color: #cffafe; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border-radius: 8px; border: 1px solid transparent;
  padding: 8px 14px; font-weight: 700; font-size: 13.5px;
  cursor: pointer; background: var(--primary); color: #fff;
  transition: background .12s, transform .05s;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--primary-dark); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 15px; height: 15px; fill: currentColor; }
.btn.ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #b91c1c; }
.btn.success { background: var(--success); }
.btn.success:hover { background: #166534; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn.icon { padding: 6px 8px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- forms ---------- */
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
label.field input, label.field select, label.field textarea,
.input, .select {
  background: var(--surface); border: 1px solid #cbd5e1; border-radius: 8px;
  padding: 8px 11px; font-size: 14px; color: var(--text); width: 100%;
}
label.field input:focus, label.field select:focus, .input:focus, .select:focus {
  outline: 2px solid var(--primary-600); outline-offset: -1px; border-color: var(--primary-600);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.form-error { color: var(--danger); font-size: 13px; font-weight: 600; min-height: 18px; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); background: var(--surface-2);
  padding: 9px 12px; border-bottom: 1px solid var(--border);
  white-space: nowrap; user-select: none;
}
.tbl th.sortable { cursor: pointer; }
.tbl th.sortable:hover { color: var(--text); }
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: #f8fafc; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .actions { display: flex; gap: 5px; justify-content: flex-end; }
.row-low td { background: var(--danger-soft); }
.row-low .qty-cell { color: var(--danger); font-weight: 800; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 700; }

.empty { padding: 34px 16px; text-align: center; color: var(--muted); }
.empty svg { width: 38px; height: 38px; fill: #cbd5e1; margin-bottom: 8px; }

/* ---------- badges ---------- */
.badge { display: inline-block; border-radius: 99px; padding: 2px 9px; font-size: 11.5px; font-weight: 700; }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.green { background: var(--success-soft); color: var(--success); }
.badge.amber { background: var(--warning-soft); color: var(--warning); }
.badge.gray { background: #f1f5f9; color: var(--muted); }
.badge.blue { background: var(--primary-soft); color: var(--primary-dark); }

/* ---------- toolbar ---------- */
.toolbar { display: flex; gap: 9px; margin-bottom: 13px; flex-wrap: wrap; align-items: center; }
.toolbar .search { flex: 1; min-width: 180px; position: relative; }
.toolbar .search input { padding-left: 34px; }
.toolbar .search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; fill: var(--muted); }
.toolbar select { width: auto; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 14px 14px; z-index: 100; overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; animation: pop .14s ease-out;
}
.modal.wide { max-width: 780px; }
@keyframes pop { from { transform: scale(.97) translateY(6px); opacity: 0; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 15px 18px 0; }
.modal-head h2 { font-size: 17px; }
.modal-close { border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 21px; line-height: 1; padding: 4px; }
.modal-body { padding: 14px 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 18px 16px; flex-wrap: wrap; }

/* ---------- toast ---------- */
#toast-root { position: fixed; bottom: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #0f172a; color: #fff; border-radius: 10px; padding: 11px 16px;
  font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow-lg);
  animation: slide-in .18s ease-out; max-width: 340px;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes slide-in { from { transform: translateX(30px); opacity: 0; } }

/* ---------- login ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 18px; background: linear-gradient(145deg, #0c4a6e, #155e75 55%, #0e7490); }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 16px; padding: 30px 28px; box-shadow: var(--shadow-lg); }
.auth-card .logo { width: 54px; height: 54px; border-radius: 14px; background: var(--primary-600); display: flex; align-items: center; justify-content: center; margin: 0 auto 14px; }
.auth-card .logo svg { width: 30px; height: 30px; fill: #fff; }
.auth-card h1 { text-align: center; font-size: 20px; }
.auth-card .sub { text-align: center; color: var(--muted); font-size: 13px; margin: 4px 0 18px; }
.pass-wrap { position: relative; }
.pass-wrap .toggle { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); border: 0; background: transparent; color: var(--primary); font-weight: 700; font-size: 12px; cursor: pointer; padding: 4px 6px; }

/* ---------- billing ---------- */
.bill-grid { display: grid; grid-template-columns: 1fr 340px; gap: 14px; align-items: start; }
.item-picker { position: relative; }
.item-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 50;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-lg); max-height: 320px; overflow-y: auto;
}
.item-results .res { padding: 9px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.item-results .res:hover, .item-results .res.sel { background: var(--primary-soft); }
.item-results .res .stock { font-size: 12px; color: var(--muted); white-space: nowrap; }
.item-results .res .stock.low { color: var(--danger); font-weight: 700; }
.cart-line input.qty-in { width: 64px; text-align: center; }
.cart-line input.price-in { width: 90px; text-align: right; }
.totals { display: flex; flex-direction: column; gap: 7px; font-size: 14px; }
.totals .row { display: flex; justify-content: space-between; }
.totals .grand { font-size: 20px; font-weight: 800; border-top: 2px solid var(--text); padding-top: 9px; margin-top: 4px; }
.totals input.discount-in { width: 110px; text-align: right; }

/* ---------- charts ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart .bar { fill: #0891b2; }
.chart .bar:hover { fill: #155e75; }
.chart .axis { stroke: #e2e8f0; stroke-width: 1; }
.chart text { font-size: 10px; fill: #64748b; }

/* ---------- misc ---------- */
.card h3 svg { width: 15px; height: 15px; fill: currentColor; vertical-align: -2px; margin-right: 5px; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip { background: var(--danger-soft); color: var(--danger); border-radius: 8px; padding: 5px 10px; font-size: 12.5px; font-weight: 600; }
.kv { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px dashed var(--border); font-size: 14px; }
.kv:last-child { border-bottom: 0; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--primary);
  animation: spin .7s linear infinite; margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { color: var(--muted); text-align: center; padding: 60px 0; }

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  .sidebar { display: none; }
  .main { padding: 16px 14px 90px; }
  .grid.cols-3 { grid-template-columns: 1fr; }
  .bill-grid { grid-template-columns: 1fr; }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 90;
    background: var(--sidebar); padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
  }
  .bottom-nav a, .bottom-nav button {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    color: #94a3b8; text-decoration: none; font-size: 10.5px; font-weight: 700;
    padding: 6px 2px; border-radius: 8px; background: transparent; border: 0; cursor: pointer;
  }
  .bottom-nav svg { width: 20px; height: 20px; fill: currentColor; }
  .bottom-nav .active { color: #fff; background: rgba(255, 255, 255, .09); }
  .grid.cols-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .hide-sm { display: none !important; }
}
@media (max-width: 520px) {
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .stat .value { font-size: 19px; }
}

/* ---------- print ---------- */
#print-root { display: none; }
@media print {
  body { background: #fff; }
  #app, #modal-root, #toast-root, .bottom-nav { display: none !important; }
  #print-root { display: block; }
}

/* thermal 80mm */
#print-root.thermal { width: 72mm; margin: 0 auto; font-size: 12px; }
#print-root.thermal .t-shop { text-align: center; font-weight: 800; font-size: 16px; }
#print-root.thermal .t-center { text-align: center; }
#print-root.thermal table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
#print-root.thermal th, #print-root.thermal td { padding: 2px 3px; vertical-align: top; }
#print-root.thermal thead th { border-top: 1px dashed #000; border-bottom: 1px dashed #000; text-align: left; }
#print-root.thermal .t-num { text-align: right; white-space: nowrap; }
#print-root.thermal .t-tot { border-top: 1px dashed #000; padding-top: 4px; margin-top: 4px; }
#print-root.thermal .t-grand { font-weight: 800; font-size: 14px; }

/* A4 invoice */
#print-root.a4 { width: 100%; padding: 10px; color: #000; }
#print-root.a4 .inv-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 3px solid #000; padding-bottom: 12px; }
#print-root.a4 .inv-shop { font-size: 26px; font-weight: 800; }
#print-root.a4 .inv-meta { text-align: right; font-size: 13px; }
#print-root.a4 .inv-title { font-size: 15px; font-weight: 700; text-transform: uppercase; letter-spacing: 2px; }
#print-root.a4 table.items { width: 100%; border-collapse: collapse; margin-top: 18px; font-size: 13px; }
#print-root.a4 table.items th, #print-root.a4 table.items td { border: 1px solid #000; padding: 6px 9px; text-align: left; }
#print-root.a4 table.items th { background: #f0f0f0; }
#print-root.a4 .inv-totals { margin-top: 14px; margin-left: auto; width: 290px; font-size: 13.5px; }
#print-root.a4 .inv-totals .grand { font-size: 17px; font-weight: 800; border-top: 2px solid #000; }
#print-root.a4 .inv-foot { margin-top: 26px; text-align: center; font-size: 12px; color: #333; }
@page { margin: 12mm; }
