/* ============================================================
   SITE BILLING — industrial ledger
   ink #1B1E1C · concrete #EFF0EC · amber #F0A400 · green #1F7A44
   ============================================================ */
:root {
  --ink: #1b1e1c;
  --ink-soft: #3c423e;
  --muted: #6d746e;
  --paper: #eff0ec;
  --surface: #ffffff;
  --line: #d8dad2;
  --amber: #f0a400;
  --amber-dark: #c78800;
  --green: #1f7a44;
  --red: #be3d2a;
  --display: 'Saira Condensed', 'Arial Narrow', sans-serif;
  --body: 'IBM Plex Sans', system-ui, sans-serif;
  --radius: 6px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--body);
  font-size: 15px;
  color: var(--ink);
  background: var(--paper);
  font-variant-numeric: tabular-nums;
}

.hidden { display: none !important; }

h1, h2, h3 { font-family: var(--display); text-transform: uppercase; letter-spacing: 0.02em; }

button { font-family: var(--body); cursor: pointer; }
input, select, textarea { font-family: var(--body); font-size: 15px; color: var(--ink); }

a { color: inherit; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background:
    repeating-linear-gradient(-45deg, transparent 0 26px, rgba(240,164,0,.06) 26px 52px),
    var(--ink);
}
.login-card {
  width: min(360px, 90vw);
  background: var(--surface);
  border-top: 6px solid var(--amber);
  padding: 36px 32px 28px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,.45);
}
.login-mark, .brand {
  font-family: var(--display);
  font-weight: 700; font-size: 26px; letter-spacing: .04em;
}
.login-mark span, .brand span { color: var(--amber-dark); }
.login-sub { color: var(--muted); margin: 6px 0 22px; font-size: 14px; }
#login-pin {
  width: 100%; text-align: center; font-size: 28px; letter-spacing: .5em;
  padding: 10px 0 10px .5em; border: 1px solid var(--line); border-radius: var(--radius);
  margin-bottom: 14px;
}
.login-error { color: var(--red); font-size: 13px; min-height: 18px; margin-top: 10px; }
.login-hint { color: var(--muted); font-size: 12px; margin-top: 12px; }

/* ---------- Shell ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 200px; flex-shrink: 0;
  background: var(--ink); color: #e8eae6;
  display: flex; flex-direction: column;
  padding: 22px 0 14px;
  position: sticky; top: 0; height: 100vh;
}
.brand { padding: 0 20px 22px; color: #fff; }
.brand span { color: var(--amber); }

.nav-link {
  display: block; padding: 11px 20px;
  text-decoration: none;
  font-family: var(--display); font-weight: 600; font-size: 16px;
  text-transform: uppercase; letter-spacing: .05em;
  color: #b9bfb8;
  border-left: 4px solid transparent;
}
.nav-link:hover { color: #fff; }
.nav-link.active { color: #fff; border-left-color: var(--amber); background: rgba(255,255,255,.05); }
.nav-star { color: var(--amber); }
.nav-star.active, .nav-star:hover { color: var(--amber); }
.sidebar-foot { margin-top: auto; padding: 0 20px; }

.main { flex: 1; padding: 28px 32px 120px; max-width: 1200px; }

.page-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 30px; }
.page-sub { color: var(--muted); font-size: 13px; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid transparent; border-radius: var(--radius);
  padding: 9px 18px; font-size: 14px; font-weight: 600;
  background: var(--surface); color: var(--ink);
  border-color: var(--line);
}
.btn:hover { border-color: var(--ink-soft); }
.btn-primary { background: var(--amber); border-color: var(--amber); color: var(--ink); }
.btn-primary:hover { background: var(--amber-dark); border-color: var(--amber-dark); }
.btn-dark { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-dark:hover { background: #000; }
.btn-danger { color: var(--red); }
.btn-ghost { background: transparent; color: #b9bfb8; border-color: #4a4f4b; }
.btn-ghost:hover { color: #fff; border-color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Cards & stats ---------- */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px 14px;
}
.stat .label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.stat .value { font-family: var(--display); font-weight: 700; font-size: 32px; margin-top: 2px; }
.stat.amber { border-top: 4px solid var(--amber); }
.stat.green .value { color: var(--green); }
.stat.red .value { color: var(--red); }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; margin-bottom: 20px;
}
.card h2 { font-size: 20px; margin-bottom: 14px; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); padding: 8px 10px; border-bottom: 2px solid var(--ink);
  font-weight: 700;
}
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f7f7f3; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 99px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
}
.badge.paid { background: #e2f2e8; color: var(--green); }
.badge.pending { background: #fae4df; color: var(--red); }
.badge.mode { background: #eef0ec; color: var(--ink-soft); }

.empty { color: var(--muted); padding: 20px 10px; text-align: center; font-size: 14px; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.field label {
  display: block; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 5px;
}
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius);
  background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus,
.btn:focus-visible, .nav-link:focus-visible {
  outline: 2px solid var(--amber); outline-offset: 1px;
}
.field textarea { resize: vertical; min-height: 70px; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input, .toolbar select { padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius); }
.toolbar input[type="search"] { min-width: 240px; }

/* ---------- New Bill ---------- */
.bill-layout { display: grid; grid-template-columns: 1fr 320px; gap: 20px; align-items: start; }

.item-row {
  display: grid; grid-template-columns: 1fr 90px 110px 70px 110px 34px;
  gap: 8px; align-items: center; margin-bottom: 8px;
}
.item-row input, .item-row select { padding: 8px 9px; border: 1px solid var(--line); border-radius: var(--radius); width: 100%; }
.item-row .ro { background: #f4f5f1; color: var(--ink-soft); }
.item-head { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.item-del { border: none; background: none; color: var(--muted); font-size: 18px; line-height: 1; }
.item-del:hover { color: var(--red); }

.summary-card { position: sticky; top: 20px; }
.sum-line { display: flex; justify-content: space-between; padding: 7px 0; font-size: 14px; }
.sum-line.total {
  border-top: 2px solid var(--ink); margin-top: 8px; padding-top: 12px;
  font-family: var(--display); font-weight: 700; font-size: 22px;
}
.sum-line .lbl { color: var(--muted); }
.sum-line.total .lbl { color: var(--ink); }

/* signature: weighbridge-style running total */
.totalbar {
  position: fixed; bottom: 0; left: 200px; right: 0;
  background: var(--ink); color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 32px; z-index: 40;
  border-top: 4px solid var(--amber);
}
.totalbar .tb-label { font-family: var(--display); text-transform: uppercase; letter-spacing: .1em; font-size: 14px; color: #b9bfb8; }
.totalbar .tb-value {
  font-family: var(--display); font-weight: 700; font-size: 40px; letter-spacing: .03em;
  color: var(--amber);
}
.totalbar .tb-actions { display: flex; gap: 10px; }

/* ---------- Reports ---------- */
.bar-chart { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding-top: 10px; }
.bar-chart .bar { flex: 1; background: var(--amber); min-height: 2px; border-radius: 2px 2px 0 0; position: relative; }
.bar-chart .bar:hover { background: var(--amber-dark); }
.bar-chart .bar .tip {
  display: none; position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; font-size: 11px; padding: 3px 8px; border-radius: 4px;
  white-space: nowrap; margin-bottom: 4px;
}
.bar-chart .bar:hover .tip { display: block; }

.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .report-grid { grid-template-columns: 1fr; } }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 100;
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: var(--radius);
  border-left: 4px solid var(--amber);
  opacity: 0; transform: translateY(10px); pointer-events: none;
  transition: opacity .2s, transform .2s;
  font-size: 14px; max-width: 320px;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { border-left-color: var(--red); }

/* ---------- Invoice (screen preview + print) ---------- */
.invoice-print { display: none; }

.invoice {
  background: #fff; color: #111; max-width: 820px;
  padding: 40px 44px; font-size: 13px; margin: 0 auto;
  border: 1px solid var(--line);
}
.inv-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 3px solid #111; padding-bottom: 16px; }
.inv-biz h1 { font-size: 26px; margin-bottom: 4px; }
.inv-biz p { color: #444; line-height: 1.45; white-space: pre-line; }
.inv-logo img { max-height: 70px; max-width: 160px; object-fit: contain; }
.inv-title { text-align: right; }
.inv-title .t { font-family: var(--display); font-size: 22px; font-weight: 700; letter-spacing: .1em; }
.inv-title .n { font-size: 16px; font-weight: 700; margin-top: 2px; }
.inv-title .d { color: #444; margin-top: 2px; }

.inv-meta { display: flex; justify-content: space-between; gap: 20px; padding: 14px 0; border-bottom: 1px solid #ccc; }
.inv-meta h3 { font-size: 12px; letter-spacing: .08em; color: #666; margin-bottom: 4px; }
.inv-meta p { line-height: 1.5; }

.invoice table { margin: 14px 0 6px; }
.invoice th { border-bottom: 2px solid #111; color: #333; }
.invoice td { border-bottom: 1px solid #ddd; }

.inv-totals { display: flex; justify-content: flex-end; margin-top: 8px; }
.inv-totals .box { width: 280px; }
.inv-totals .row { display: flex; justify-content: space-between; padding: 4px 0; }
.inv-totals .grand {
  border-top: 2px solid #111; margin-top: 6px; padding-top: 8px;
  font-family: var(--display); font-size: 20px; font-weight: 700;
}
.inv-foot { display: flex; justify-content: space-between; gap: 24px; margin-top: 28px; padding-top: 14px; border-top: 1px solid #ccc; }
.inv-foot .pay { font-size: 12px; color: #333; line-height: 1.55; white-space: pre-line; }
.inv-foot .pay h3, .inv-sign h3 { font-size: 11px; letter-spacing: .08em; color: #666; margin-bottom: 4px; }
.inv-foot .qr img { max-width: 110px; max-height: 110px; }
.inv-sign { text-align: center; align-self: flex-end; }
.inv-sign .line { border-top: 1px solid #111; width: 180px; margin-top: 48px; padding-top: 5px; font-size: 12px; }

.invoice-actions { max-width: 820px; margin: 0 auto 16px; display: flex; gap: 10px; justify-content: space-between; flex-wrap: wrap; }
.invoice-actions .right { display: flex; gap: 10px; }

/* ---------- Print ---------- */
@media print {
  body { background: #fff; }
  .app, .toast, .login-screen { display: none !important; }
  .invoice-print { display: block !important; }
  .invoice { border: none; max-width: none; padding: 10mm 6mm; }
  .invoice-actions { display: none !important; }
}

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 12px; gap: 2px; }
  .brand { padding: 0 12px 0 4px; font-size: 20px; }
  .nav-link { padding: 8px 10px; font-size: 14px; border-left: none; border-bottom: 3px solid transparent; }
  .nav-link.active { border-left: none; border-bottom-color: var(--amber); }
  .sidebar-foot { margin: 0 0 0 auto; padding: 0; }
  .main { padding: 18px 14px 130px; }
  .bill-layout { grid-template-columns: 1fr; }
  .summary-card { position: static; }
  .totalbar { left: 0; padding: 10px 14px; }
  .totalbar .tb-value { font-size: 30px; }
  .item-row { grid-template-columns: 1fr 70px 90px 60px 90px 30px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
