:root {
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f1f5f9;
  --card: #ffffff;
  --brand: #1e293b;
  --accent: #2563eb;
  --danger: #b91c1c;
  --ok: #15803d;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Sinhala", "Noto Sans Tamil", sans-serif;
}

h1, h2 { margin: 0 0 12px; line-height: 1.2; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
a { color: var(--accent); }

/* ---------- layout ---------- */
.bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--brand); color: #fff; padding: 10px 16px;
}
.bar .brand { font-weight: 700; font-size: 18px; margin-right: auto; }
.bar a, .bar button.link { color: #cbd5e1; text-decoration: none; padding: 8px 10px; border-radius: 8px; background: none; border: 0; font: inherit; cursor: pointer; }
.bar a.active, .bar a:hover, .bar button.link:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.bar .who { color: #94a3b8; font-size: 14px; }

main { max-width: 960px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }

/* ---------- forms ---------- */
label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 8px 10px; font: inherit; color: var(--ink);
  background: #fff; border: 1px solid #cbd5e1; border-radius: 8px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
textarea { min-height: 70px; resize: vertical; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.field { margin-bottom: 12px; }

button.btn, a.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 18px; font: inherit; font-weight: 600; text-decoration: none;
  color: #fff; background: var(--accent); border: 0; border-radius: 8px; cursor: pointer;
}
button.btn:hover, a.btn:hover { filter: brightness(1.08); }
button.btn:disabled { opacity: .55; cursor: default; }
.btn.secondary { background: #fff; color: var(--ink); border: 1px solid #cbd5e1; }
.btn.danger { background: var(--danger); }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.error { color: var(--danger); margin: 8px 0 0; min-height: 1.2em; }
.muted { color: var(--muted); }

/* ---------- login ---------- */
.login { max-width: 380px; margin: 8vh auto 0; }
.login .brand { text-align: center; font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.login .sub { text-align: center; color: var(--muted); margin-bottom: 16px; }

/* ---------- invoice list ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 13px; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; }
td.act { text-align: right; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.tag.paid { background: #dcfce7; color: var(--ok); }
.tag.due { background: #fee2e2; color: var(--danger); }
.empty { text-align: center; padding: 28px 0; color: var(--muted); }

/* ---------- new invoice ---------- */
.items { display: grid; gap: 8px; }
.item-row { display: grid; gap: 8px; grid-template-columns: 1fr 80px 110px 100px 44px; align-items: end; }
.item-row .line { text-align: right; padding-bottom: 10px; font-variant-numeric: tabular-nums; }
.item-head { font-size: 13px; color: var(--muted); }
@media (max-width: 640px) {
  .item-row { grid-template-columns: 1fr 1fr; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .item-row .desc { grid-column: 1 / -1; }
  .item-head { display: none; }
}
.totals { margin-left: auto; max-width: 320px; font-variant-numeric: tabular-nums; }
.totals div { display: flex; justify-content: space-between; padding: 3px 0; }
.totals .grand { font-size: 20px; font-weight: 700; border-top: 2px solid var(--ink); margin-top: 4px; padding-top: 6px; }

/* ---------- receipt preview ---------- */
.preview-wrap { background: #cbd5e1; border-radius: 12px; padding: 20px 8px; overflow-x: auto; }
.paper { margin: 0 auto; background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, .25); }
.paper-80 { width: 384px; }
.paper-58 { width: 256px; }
.seg { display: inline-flex; border: 1px solid #cbd5e1; border-radius: 8px; overflow: hidden; }
.seg button { min-height: 44px; padding: 0 14px; font: inherit; background: #fff; border: 0; cursor: pointer; }
.seg button.on { background: var(--brand); color: #fff; }
.status { min-height: 1.4em; margin-top: 8px; }
.status.ok { color: var(--ok); }
.status.err { color: var(--danger); }

/* ---------- toast + modal ---------- */
#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--brand); color: #fff; padding: 10px 18px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; z-index: 60;
}
#toast.show { opacity: .96; }
.modal-back { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: 12px; padding: 20px; max-width: 380px; width: 100%; }
.modal p { margin: 0 0 16px; }
.modal .actions { justify-content: flex-end; }

/* ---------- browser printing (not used inside the tablet app) ---------- */
@media print {
  body { background: #fff; }
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area { position: absolute; left: 0; top: 0; width: 100%; box-shadow: none; }
}
