:root {
  --bg: #f4f6fb; --panel: #ffffff; --ink: #16213a; --muted: #64748b;
  --line: #e2e8f0; --accent: #3b4bd8; --accent-ink: #ffffff;
  --good: #15803d; --warn: #b45309; --bad: #b91c1c;
  --chip-draft: #fef3c7; --chip-final: #dcfce7;
}
* { box-sizing: border-box; margin: 0; }
body {
  font: 14px/1.5 -apple-system, "Segoe UI", "Noto Sans", "Noto Sans Devanagari", sans-serif;
  background: var(--bg); color: var(--ink);
}
#app { display: flex; min-height: 100vh; }

.sidebar {
  width: 210px; background: #101733; color: #cbd5e1; padding: 18px 0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { font-size: 20px; font-weight: 800; color: #fff; padding: 0 20px 16px; }
.sidebar nav { display: flex; flex-direction: column; }
.sidebar a {
  color: #cbd5e1; text-decoration: none; padding: 10px 20px; font-weight: 500;
  border-left: 3px solid transparent;
}
.sidebar a:hover { background: #1a2447; color: #fff; }
.sidebar a.active { background: #1a2447; color: #fff; border-left-color: #8ea2ff; }
.sidebar-foot { margin-top: auto; padding: 14px 20px 0; font-size: 11px; color: #64748b; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 24px;
  position: sticky; top: 0; z-index: 5;
}
.topbar-right { color: var(--muted); font-size: 12px; }
main { padding: 24px; max-width: 1150px; width: 100%; margin: 0 auto; }

h2 { font-size: 20px; margin-bottom: 4px; }
.sub { color: var(--muted); margin-bottom: 18px; font-size: 13px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
        padding: 16px 18px; margin-bottom: 16px; overflow-x: auto; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
         gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.stat .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.stat .v { font-size: 22px; font-weight: 800; margin-top: 2px; }
.stat .v.good { color: var(--good); } .stat .v.bad { color: var(--bad); }

table { width: 100%; border-collapse: collapse; background: var(--panel); }
.card table { margin: 0 -18px; width: calc(100% + 36px); }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted);
     background: #f8fafc; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; } tr.clickable:hover { background: #f8faff; }
tr.total td { font-weight: 800; background: #f8fafc; }

.chip { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 11px;
        font-weight: 700; }
.chip.draft { background: var(--chip-draft); color: #92400e; }
.chip.final { background: var(--chip-final); color: #166534; }
.chip.reversed, .chip.cancelled { background: #fee2e2; color: #991b1b; }
.chip.posted { background: var(--chip-final); color: #166534; }
.chip.msme { background: #fee2e2; color: #991b1b; }
.chip.type { background: #e0e7ff; color: #3730a3; }

button, .btn {
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px;
  padding: 8px 16px; font-size: 13px; font-weight: 600; cursor: pointer;
  text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { filter: brightness(1.1); }
button.secondary, .btn.secondary { background: #eef1fb; color: var(--accent); }
button.danger { background: #fee2e2; color: var(--bad); }
button.small { padding: 4px 10px; font-size: 12px; }

form.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); }
label.wide { grid-column: 1 / -1; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; margin-top: 3px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #c7d2fe; border-color: var(--accent); }
.form-actions { grid-column: 1 / -1; display: flex; gap: 10px; align-items: center; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px;
         color: var(--ink); margin-top: 20px; }
.check input { width: auto; margin: 0; }

.lines-table input, .lines-table select { margin: 0; padding: 6px 8px; }
.lines-table td { padding: 5px 6px; }
.totals-preview { display: flex; gap: 24px; justify-content: flex-end; padding: 10px 4px;
                  font-variant-numeric: tabular-nums; flex-wrap: wrap; }
.totals-preview b { font-size: 16px; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs button { background: #eef1fb; color: var(--accent); }
.tabs button.active { background: var(--accent); color: #fff; }

.empty { color: var(--muted); text-align: center; padding: 48px 0; }
.alert { border-left: 4px solid var(--bad); background: #fef2f2; color: #7f1d1d;
         padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; }
.note { border-left: 4px solid var(--accent); background: #eef2ff; color: #312e81;
        padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; font-size: 13px; }

#toast { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column;
         gap: 8px; z-index: 50; }
.toast-msg { background: #16213a; color: #fff; padding: 10px 16px; border-radius: 8px;
             box-shadow: 0 6px 18px rgba(0,0,0,.25); font-size: 13px; }
.toast-msg.err { background: var(--bad); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
/* ── desktop-only chrome ── */
.menu-btn, .brand-mobile, .bottom-nav, .scrim { display: none; }
.net-status { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d;
  border-radius: 6px; padding: 3px 10px; font-size: 12px; font-weight: 600; }

/* ── tablet: icon rail ── */
@media (max-width: 900px) and (min-width: 641px) {
  .two-col { grid-template-columns: 1fr; }
  .sidebar { width: 56px; }
  .sidebar a { padding: 12px 0; text-align: center; font-size: 18px; border-left-width: 0; }
  .sidebar a .lbl, .brand, .sidebar-foot { display: none; }
}

/* ── phone: bottom nav + drawer ── */
@media (max-width: 640px) {
  .two-col, .cards { grid-template-columns: 1fr; }
  form.grid { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 30% 0 0; z-index: 40; width: auto;
    transform: translateX(-105%); transition: transform .22s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,.35); }
  .sidebar.open { transform: translateX(0); }
  .scrim.show { display: block; position: fixed; inset: 0; z-index: 39;
    background: rgba(10,14,30,.5); }
  .menu-btn { display: inline-flex; align-items: center; justify-content: center;
    border: 0; background: transparent; font-size: 22px; padding: 4px 10px 4px 0;
    cursor: pointer; color: var(--ink, #1a2447); }
  .brand-mobile { display: block; font-weight: 800; font-size: 16px; }
  .brand-mobile .wm { color: #14213d; }
  .brand-mobile .wm > span { color: #0a8c33; }  /* exact logo green on white */
  .topbar { position: sticky; top: 0; z-index: 30; background: #fff; gap: 8px;
    padding: 10px 12px; flex-wrap: wrap; }
  .topbar-right { display: none; }
  main#view { padding: 12px; padding-bottom: 76px; }
  .bottom-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0;
    z-index: 35; background: #121836; padding: 4px 0 max(4px, env(safe-area-inset-bottom));
    justify-content: space-around; }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center;
    gap: 1px; color: #93a0c8; text-decoration: none; font-size: 10.5px;
    padding: 4px 10px; border-radius: 8px; min-width: 56px; }
  .bottom-nav a span { font-size: 19px; }
  .bottom-nav a.active { color: #fff; background: #1a2447; }
  /* tables scroll sideways instead of breaking the page */
  .card { overflow-x: auto; }
  table { min-width: 560px; }
  .lines-table { min-width: 720px; }
  /* touch targets */
  button, .btn { padding: 10px 16px; min-height: 42px; }
  input, select, textarea { min-height: 40px; font-size: 16px; } /* no iOS zoom */
  .form-actions { position: sticky; bottom: 64px; background: #fff;
    padding: 8px 0; display: flex; gap: 8px; flex-wrap: wrap; }
  h2 { font-size: 20px; }
  .page-head { flex-wrap: wrap; gap: 8px; }
}
select.firm-select { font-weight: 700; min-width: 220px; }
.muted { color: var(--muted); }

/* brand: mark + wordmark + tagline (must fit 210px sidebar untruncated) */
.brand-logo { display: block; padding: 2px 12px 12px; }
.brand-row { display: flex; align-items: center; gap: 8px;
  font-size: 18px; white-space: nowrap; }
.brand-row img { width: 32px; height: 32px; background: #fff;
  border-radius: 7px; padding: 2px; flex: none; }
/* wordmark: tight like the logo, "Books" in the logo's true green */
.wm { color: #fff; }
.wm > span { color: #12a844; }          /* logo green, lifted a touch for dark bg */
.brand-tagline { font-size: 7.9px; font-weight: 600; letter-spacing: .3px;
  text-transform: uppercase; color: #8b98bd; margin-top: 5px;
  white-space: nowrap; }
.brand-mobile img { height: 26px; width: 26px; vertical-align: -6px;
  margin-right: 6px; border-radius: 6px; }

/* ── auth screen ── */
body.auth-mode .sidebar, body.auth-mode .topbar, body.auth-mode .bottom-nav,
body.auth-mode .scrim { display: none !important; }
body.auth-mode main#view { padding: 0; }
.auth-wrap { min-height: 100vh; display: flex; align-items: center;
  justify-content: center; background: linear-gradient(160deg, #101733 0%, #1b2650 100%);
  padding: 20px; }
.auth-card { background: #fff; border-radius: 14px; padding: 28px 26px;
  width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.auth-brand img { width: 46px; height: 46px; border-radius: 10px;
  border: 1px solid #e5e9f2; padding: 3px; }
.auth-brand .wm { color: #14213d; font-weight: 800; }
.auth-brand .wm > span { color: #0a8c33; }
.auth-tag { font-size: 8.5px; font-weight: 600; letter-spacing: .4px;
  text-transform: uppercase; color: #8b93a8; margin-top: 2px; }
.auth-card h3 { margin: 0 0 6px; }
.auth-card label { display: block; margin: 10px 0; font-size: 13px;
  color: #3b4256; }
.auth-card input { width: 100%; margin-top: 4px; }
.auth-card button { width: 100%; margin-top: 14px; padding: 11px;
  font-size: 15px; }
.auth-links { display: flex; justify-content: space-between; margin-top: 14px;
  font-size: 13px; flex-wrap: wrap; gap: 6px; }
.auth-foot { text-align: center; font-size: 11px; color: #8b93a8;
  margin-top: 18px; border-top: 1px solid #eef1f6; padding-top: 12px; }

/* invoice detail totals strip (all screens) */
.tot-strip .trow { display: flex; justify-content: space-between;
  padding: 7px 4px; border-bottom: 1px solid var(--line, #e5e9f2);
  font-variant-numeric: tabular-nums; }
.tot-strip .trow span { color: #5b6472; }
.tot-strip .trow.grand { border-bottom: 0; font-size: 17px; font-weight: 800; }
.tot-strip .trow.grand span { color: inherit; }

@media (max-width: 640px) {
  /* line entry becomes cards: every field visible, no sideways scroll */
  .lines-table { min-width: 0 !important; display: block; }
  .lines-table tr:first-child { display: none; }          /* header row */
  .lines-table tr { display: grid; grid-template-columns: 1fr 1fr;
    gap: 8px; padding: 12px; margin-bottom: 10px; border: 1px solid #dbe3ec;
    border-radius: 10px; background: #fff; position: relative; }
  .lines-table td { display: block; border: 0 !important; padding: 0 !important; }
  .lines-table td::before { content: attr(data-l); display: block;
    font-size: 10.5px; font-weight: 700; color: #5b6472; margin-bottom: 2px;
    text-transform: uppercase; letter-spacing: .3px; }
  .lines-table td[data-l="Item"], .lines-table td[data-l="Description"] {
    grid-column: 1 / -1; }
  .lines-table td input, .lines-table td select { width: 100%; margin: 0; }
  .lines-table td.f-taxable { font-weight: 800; font-size: 15px;
    align-self: center; }
  .lines-table td.f-del-cell { position: absolute; top: 8px; right: 8px; }
  .lines-table td.f-del-cell::before { content: none; }
  /* invoice detail: line items table stays scrollable, page header wraps */
  .page-head > div:last-child { width: 100%; }
  .page-head .btn, .page-head button { flex: 1; text-align: center; }
}

/* uniform invoice action bar — all buttons identical, professional */
.act-bar { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px;
  margin: 4px 0 14px; }
.act { display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 10px 4px; border: 1px solid #dbe3ec; border-radius: 10px;
  background: #fff; color: #14213d; font-weight: 600; font-size: 12.5px;
  text-decoration: none; cursor: pointer; font-family: inherit; }
.act i { font-style: normal; font-size: 18px; line-height: 1; }
.act:hover { border-color: #6172f3; }
.act.act-danger { color: #b91c1c; border-color: #fecaca; background: #fff7f7; }
@media (max-width: 640px) {
  .act-bar { grid-template-columns: repeat(3, 1fr); }
}
