:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #1d4ed8;
  --brand-ink: #ffffff;
  --brand-soft: #e8efff;
  --side: #0b1f4d;
  --side-ink: #c7d2fe;
  --green: #047857;
  --green-soft: #e7f7ef;
  --red: #b91c1c;
  --red-soft: #fdecec;
  --amber: #a16207;
  --amber-soft: #fef6e0;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .04);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px; color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 10px; }

/* ---------- layout ---------- */
.side {
  position: fixed; inset: 0 auto 0 0; width: 250px; background: var(--side); color: var(--side-ink);
  overflow-y: auto; z-index: 30; padding-bottom: 24px;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px; color: #fff; text-decoration: none !important; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand b { display: block; font-size: 13.5px; line-height: 1.25; }
.brand small { color: #93a4d8; font-size: 11.5px; }
.logo { flex: 0 0 38px; height: 38px; border-radius: 10px; background: linear-gradient(135deg, #3b82f6, #1d4ed8); display: grid; place-items: center; font-weight: 700; color: #fff; }
.side nav { padding: 8px 10px; }
.navhead { font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: #7f8fc4; padding: 14px 10px 6px; font-weight: 600; }
.side nav a { display: flex; gap: 10px; align-items: center; color: var(--side-ink); padding: 8px 10px; border-radius: 8px; font-size: 13.5px; text-decoration: none; }
.side nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side nav a.on { background: #1d4ed8; color: #fff; }
.side nav a svg { flex: 0 0 18px; opacity: .9; }

.main { margin-left: 250px; min-height: 100vh; }
.top { position: sticky; top: 0; z-index: 20; background: rgba(244,246,251,.92); backdrop-filter: blur(6px); display: flex; align-items: center; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--line); }
.top h1 { font-size: 18px; margin: 0; flex: 1; }
.top-right { display: flex; gap: 10px; align-items: center; }
.who { color: var(--muted); font-size: 13px; }
.menu-btn { display: none; background: none; border: 0; padding: 4px; color: var(--ink); cursor: pointer; }
.content { padding: 20px 24px 60px; max-width: 1280px; }
.scrim { display: none; }

@media (max-width: 900px) {
  .side { transform: translateX(-100%); transition: transform .2s; }
  body.menu .side { transform: none; }
  body.menu .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }
  .main { margin-left: 0; }
  .menu-btn { display: block; }
  .top { padding: 10px 16px; }
  .content { padding: 16px 16px 60px; }
  .who { display: none; }
}

/* ---------- components ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-head h2 { margin: 0; }
.help { background: var(--brand-soft); color: #1e3a8a; border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; font-size: 13px; line-height: 1.5; }
.help b { color: #1e3a8a; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }

.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat .lbl { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.stat .val { font-size: 22px; font-weight: 700; margin-top: 6px; letter-spacing: -.01em; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.stat.blue { border-top: 3px solid #2563eb; }
.stat.green { border-top: 3px solid #059669; }
.stat.red { border-top: 3px solid #dc2626; }
.stat.amber { border-top: 3px solid #d97706; }

.quick { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.quick a { display: flex; gap: 10px; align-items: center; padding: 14px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); color: var(--ink); font-weight: 600; text-decoration: none; box-shadow: var(--shadow); }
.quick a:hover { border-color: var(--brand); color: var(--brand); }
.quick a span.ic { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); font-size: 18px; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink); padding: 9px 16px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none !important; white-space: nowrap; }
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--brand); color: var(--brand); }
.btn.danger { background: #fff; color: var(--red); border-color: #f3c4c4; }
.btn.green { background: var(--green); border-color: var(--green); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn.lg { padding: 12px 22px; font-size: 15px; }
form.inline { display: inline; }

label { display: block; font-size: 12.5px; font-weight: 600; color: #334155; margin-bottom: 5px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: #fff; border: 1px solid #cbd5e1; border-radius: 8px; padding: 9px 11px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--brand); }
input[readonly] { background: #f8fafc; }
.field { margin-bottom: 12px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { margin: 0; min-width: 150px; }
.filters .field.wide { min-width: 240px; }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.tbl th { background: #f8fafc; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: #475569; font-weight: 600; white-space: nowrap; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl tr:hover td { background: #fafcff; }
.tbl tfoot td, .tbl tr.total td { font-weight: 700; background: #f8fafc; border-top: 2px solid #cbd5e1; }
.tbl tr.group td { background: #eef2ff; font-weight: 700; color: #1e3a8a; }
.tbl tr.sub td { font-weight: 600; background: #fbfcfe; }
.tbl td.indent { padding-left: 28px; }
.tbl .empty { text-align: center; color: var(--muted); padding: 30px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: #f1f5f9; color: #334155; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.blue { background: var(--brand-soft); color: var(--brand); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 4px; vertical-align: -1px; margin-right: 6px; border: 1px solid rgba(0,0,0,.15); }
.pos { color: var(--green); }
.neg { color: var(--red); }

.alert { padding: 11px 14px; border-radius: 10px; margin-bottom: 14px; font-weight: 500; }
.alert.ok { background: var(--green-soft); color: var(--green); }
.alert.err { background: var(--red-soft); color: var(--red); }
.alert.warn { background: var(--amber-soft); color: var(--amber); }

/* ---------- invoice entry ---------- */
.lines th { white-space: nowrap; }
.lines td { padding: 6px 6px; }
.lines input, .lines select { padding: 8px 8px; }
.lines .c-item { min-width: 190px; }
.lines .c-color { min-width: 130px; }
.lines .c-w, .lines .c-r { width: 120px; }
.lines .c-amt { width: 130px; }
.lines .c-x { width: 40px; }
.lines .stockhint { font-size: 11px; color: var(--muted); margin-top: 3px; min-height: 13px; }
.xbtn { border: 0; background: none; color: #94a3b8; font-size: 20px; cursor: pointer; line-height: 1; }
.xbtn:hover { color: var(--red); }
.totals { margin-left: auto; max-width: 380px; }
.totals .t { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 0; }
.totals .t input { width: 150px; text-align: right; }
.totals .t.big { font-size: 18px; font-weight: 700; border-top: 2px solid var(--line); padding-top: 10px; }
.entry-grid { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 900px) { .entry-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .entry-grid { grid-template-columns: 1fr; } }

/* ---------- printable invoice ---------- */
.paper { background: #fff; max-width: 820px; margin: 0 auto; border: 1px solid var(--line); border-radius: 12px; padding: 28px; box-shadow: var(--shadow); }
.inv-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 3px solid #1d4ed8; padding-bottom: 14px; }
.inv-head .co { font-size: 24px; font-weight: 800; color: #1e3a8a; letter-spacing: -.01em; }
.inv-head .tag { display: inline-block; margin-top: 6px; background: #1d4ed8; color: #fff; padding: 3px 10px; border-radius: 6px; font-size: 12px; }
.inv-head .contact { text-align: right; font-size: 12.5px; color: #334155; line-height: 1.6; }
.inv-title { text-align: center; margin: 14px 0; }
.inv-title span { background: #1d4ed8; color: #fff; padding: 6px 18px; border-radius: 8px; font-weight: 700; letter-spacing: .04em; }
.inv-meta { display: grid; grid-template-columns: 1fr auto; gap: 6px 30px; margin-bottom: 14px; font-size: 13.5px; }
.inv-meta b { color: #1e3a8a; }
.paper .tbl th { background: #eef2ff; color: #1e3a8a; }
.paper .tbl td, .paper .tbl th { border: 1px solid #c7d2fe; }
.inv-foot { display: grid; grid-template-columns: 1fr 320px; gap: 20px; margin-top: 16px; }
.inv-sum .t { display: flex; justify-content: space-between; padding: 5px 10px; border-bottom: 1px solid var(--line); }
.inv-sum .t.big { background: #1d4ed8; color: #fff; font-weight: 700; border-radius: 6px; border: 0; }
.sign { margin-top: 50px; display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); }
.sign div { border-top: 1px solid #94a3b8; padding-top: 6px; min-width: 180px; text-align: center; }
@media (max-width: 640px) {
  .paper { padding: 16px; }
  .inv-head { flex-direction: column; }
  .inv-head .contact { text-align: left; }
  .inv-foot { grid-template-columns: 1fr; }
}

/* ---------- login ---------- */
body.bare .main { margin: 0; }
body.bare .content { padding: 0; max-width: none; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(circle at 20% 10%, #dbe6ff, transparent 50%), var(--bg); }
.login { width: 100%; max-width: 400px; background: #fff; border-radius: 16px; padding: 30px; box-shadow: 0 10px 40px rgba(15,23,42,.12); }
.login .logo { width: 48px; height: 48px; margin-bottom: 14px; font-size: 18px; }
.login h1 { font-size: 20px; margin: 0 0 4px; }
.demo-box { margin-top: 16px; background: #f8fafc; border: 1px dashed #cbd5e1; border-radius: 10px; padding: 10px 12px; font-size: 12.5px; color: #334155; }

/* ---------- print ---------- */
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  .side, .top, .no-print, .scrim, .alert { display: none !important; }
  .main { margin: 0; }
  .content { padding: 0; max-width: none; }
  .card, .paper, .stat { box-shadow: none; border-color: #ccc; }
  .paper { border: 0; padding: 0; }
  .print-only { display: block !important; }
  a { color: inherit; }
  .tbl th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .inv-title span, .inv-sum .t.big, .inv-head .tag { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
.print-only { display: none; }
.report-head { text-align: center; margin-bottom: 14px; }
.report-head .co { font-size: 18px; font-weight: 800; color: #1e3a8a; }

/* ---------- plain business look (overrides) ---------- */
body { font-size: 14px; letter-spacing: 0; color: #1f2937; }
h1, h2, h3, .top h1 { font-weight: 600; letter-spacing: 0; }
.top h1 { font-size: 17px; }
.card, .stat, .quick a, .paper { border-radius: 6px; box-shadow: none; border-color: #dde2ea; }
.stat { border-top: 0 !important; padding: 14px 16px; }
.stat .lbl { font-size: 12.5px; color: #6b7280; font-weight: 400; }
.stat .val { font-size: 20px; font-weight: 600; letter-spacing: 0; margin-top: 4px; }
.stat .sub { font-size: 12px; }
.quick a { font-weight: 500; padding: 12px 14px; }
.quick a span.ic { border-radius: 4px; width: 30px; height: 30px; font-size: 15px; }
.btn { border-radius: 5px; font-weight: 500; }
.btn.sm { border-radius: 4px; }
input, select, textarea { border-radius: 5px; }
.badge { border-radius: 3px; font-weight: 500; }
.tbl th { text-transform: none; letter-spacing: 0; font-size: 12.5px; font-weight: 600; color: #374151; background: #f6f7f9; }
.tbl td { font-variant-numeric: tabular-nums; }
.logo { border-radius: 6px; background: #1d4ed8; }
.side nav a { border-radius: 4px; }
.side nav a.on { background: #23408f; }
.navhead { letter-spacing: .04em; }
.help { border-radius: 5px; background: #eef3fb; border-left: 3px solid #1d4ed8; }
.inv-head .co { font-weight: 700; letter-spacing: 0; }
.login { border-radius: 8px; box-shadow: 0 2px 12px rgba(15,23,42,.08); }
.login-wrap { background: #eef1f6; }

/* ---------- layout helpers ---------- */
.split { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); align-items: start; }
.top-align { align-items: start; }

/* sidebar scrollbar: thin and dark, no white strip */
.side { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.18) transparent; }
.side::-webkit-scrollbar { width: 6px; }
.side::-webkit-scrollbar-track { background: transparent; }
.side::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); border-radius: 3px; }

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
  body.menu .side { box-shadow: 4px 0 18px rgba(0,0,0,.25); }
}

/* ---------- phones ---------- */
@media (max-width: 640px) {
  body { font-size: 13.5px; }
  .content { padding: 12px 12px 70px; }
  .top { padding: 8px 12px; gap: 8px; }
  .top h1 { font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .card { padding: 14px; margin-bottom: 12px; }
  .card-head { padding: 12px 14px; }
  .help { font-size: 12.5px; padding: 9px 11px; margin-bottom: 12px; }

  /* dashboard */
  .quick { grid-template-columns: 1fr 1fr; gap: 8px; }
  .quick a { padding: 10px; font-size: 13px; gap: 8px; }
  .quick a span.ic { width: 26px; height: 26px; flex: 0 0 26px; font-size: 13px; }
  .g4, .g3 { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat { padding: 11px 12px; }
  .stat .val { font-size: 16.5px; }
  .stat .lbl, .stat .sub { font-size: 11.5px; }

  /* filters: two per row, buttons full row */
  .filters { gap: 8px; }
  .filters .field, .filters .field.wide { min-width: 0; flex: 1 1 calc(50% - 8px); }
  .filters .field.wide { flex-basis: 100%; }
  .filters .spacer { display: none; }

  /* tables */
  .tbl th, .tbl td { padding: 7px 8px; font-size: 12.5px; }
  .tbl .btn.sm { padding: 4px 8px; font-size: 12px; }
  .tbl td.indent { padding-left: 16px; }

  /* bill entry: each line becomes a small card */
  .inv-lines thead { display: none; }
  .inv-lines, .inv-lines tbody { display: block; width: 100%; }
  .inv-lines tbody tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) 30px; gap: 6px 8px; padding: 12px; border-bottom: 1px solid var(--line); }
  .inv-lines tbody tr:nth-child(even) { background: #fafbfc; }
  .inv-lines td { display: block; padding: 0; border: 0; min-width: 0; }
  .inv-lines input, .inv-lines select { width: 100%; min-width: 0; }
  .hide-sm { display: none !important; }
  .inv-lines td.rn { display: none; }
  .inv-lines td.l-item { grid-column: 1 / 4; }
  .inv-lines td.l-x { grid-column: 4; grid-row: 1; align-self: start; text-align: right; }
  .inv-lines td.l-color { grid-column: 1 / 4; }
  .inv-lines td.l-w { grid-column: 1; }
  .inv-lines td.l-r { grid-column: 2; }
  .inv-lines td.l-amt { grid-column: 3; }
  .inv-lines.norate td.l-w { grid-column: 1 / 4; }
  .entry-grid { grid-template-columns: 1fr 1fr; gap: 0 10px; }
  .entry-grid > .field:first-child { grid-column: 1 / -1; }
  .inv-lines td.l-w::before, .inv-lines td.l-r::before, .inv-lines td.l-amt::before { display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
  .inv-lines td.l-w::before { content: 'Weight (kg)'; }
  .inv-lines td.l-r::before { content: 'Rate / kg'; }
  .inv-lines td.l-amt::before { content: 'Amount'; }
  .inv-lines input, .inv-lines select { font-size: 15px; padding: 9px 8px; }
  .inv-lines tr:hover td { background: transparent; }
  .totals { max-width: none; min-width: 0 !important; flex: 1 1 100% !important; }
  .totals .t input, .totals .t select { width: 140px !important; }
  .row .btn.lg { flex: 1 1 auto; justify-content: center; padding: 11px 14px; font-size: 14px; }

  /* printed bill on a phone */
  .paper { padding: 14px; border-radius: 6px; }
  .inv-head .co { font-size: 19px; }
  .inv-meta { grid-template-columns: 1fr; font-size: 13px; }
  .inv-meta .right { text-align: left; }
  .paper .tbl th, .paper .tbl td { padding: 6px 5px; font-size: 12px; }
  .paper .c-code { display: none; }
  .sign div { min-width: 120px; }

  .login { padding: 22px; }
}
@media (max-width: 380px) {
  .quick a { font-size: 12.5px; }
  .stat .val { font-size: 15px; }
}
