/* ==========================================================================
   GST Billing — styles
   ========================================================================== */

:root {
  --ink: #111827;
  --ink-2: #374151;
  --muted: #6b7280;
  --muted-2: #9ca3af;
  --line: #e5e7eb;
  --line-2: #f1f2f4;
  --bg: #f7f8fa;
  --card: #ffffff;
  --accent: #4338ca;
  --accent-hover: #3730a3;
  --accent-soft: #eef2ff;
  --green: #047857;      --green-bg: #ecfdf5;
  --amber: #b45309;      --amber-bg: #fffbeb;
  --red: #b91c1c;        --red-bg: #fef2f2;
  --blue: #1d4ed8;       --blue-bg: #eff6ff;
  --gray: #4b5563;       --gray-bg: #f3f4f6;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 10px 30px rgba(16, 24, 40, .10), 0 2px 8px rgba(16, 24, 40, .05);
}

* { box-sizing: border-box; }

/* nothing in this app scrolls sideways — wide content shrinks or wraps */
html, body { overflow-x: hidden; max-width: 100%; }
input, select, textarea { min-width: 0; max-width: 100%; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
input, select, textarea, button { font: inherit; color: inherit; }
.boot { padding: 80px; text-align: center; color: var(--muted); }

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

.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--card);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 16px;
  border-bottom: 1px solid var(--line-2);
}
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(140deg, #4f46e5, #4338ca);
  color: #fff; font-weight: 700; font-size: 17px;
  display: grid; place-items: center;
  flex: 0 0 32px;
}
.brand-name { font-weight: 650; font-size: 14px; line-height: 1.2; }
.brand-sub { font-size: 11.5px; color: var(--muted); line-height: 1.3; }

.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border-radius: 9px;
  color: var(--ink-2); font-weight: 500; text-decoration: none;
}
.nav a:hover { background: var(--line-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .ico { width: 17px; height: 17px; flex: 0 0 17px; opacity: .85; }
.nav .count { margin-left: auto; font-size: 11px; color: var(--muted); background: var(--line-2); padding: 1px 7px; border-radius: 20px; }

.side-foot { margin-top: auto; padding: 12px; border-top: 1px solid var(--line-2); }
.who { font-size: 12px; color: var(--muted); margin-bottom: 8px; word-break: break-all; }
.demo-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--amber-bg); color: var(--amber);
  border: 1px solid #fde68a; border-radius: 20px;
  padding: 3px 9px; font-size: 11.5px; font-weight: 600; margin-bottom: 8px;
}
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.main { flex: 1; min-width: 0; padding: 26px 30px 24px; }
.wrap { max-width: 1120px; margin: 0 auto; }
.wrap-wide { max-width: 1240px; margin: 0 auto; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-title { font-size: 21px; }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- buttons ------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 13px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--card);
  color: var(--ink-2); font-weight: 550; font-size: 13px;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .12s, border-color .12s, box-shadow .12s;
}
.btn:hover { background: #fafafa; border-color: #d8dbe0; text-decoration: none; }
.btn:active { transform: translateY(.5px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(67,56,202,.25); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--red); border-color: #f3d0d0; background: #fff; }
.btn-danger:hover { background: var(--red-bg); border-color: #f0b8b8; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--line-2); color: var(--ink); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-icon { padding: 6px; width: 30px; height: 30px; }
.btn svg { width: 15px; height: 15px; flex: 0 0 15px; }

/* ---------- cards & stats ------------------------------------------------ */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { padding: 14px 16px; border-bottom: 1px solid var(--line-2); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-title { font-size: 13.5px; font-weight: 650; }
.card-body { padding: 16px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 16px; box-shadow: var(--shadow); }
.stat-lbl { font-size: 12px; color: var(--muted); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.stat-val { font-size: 22px; font-weight: 650; margin-top: 6px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-val.sm { font-size: 18px; }
.stat-sub { font-size: 12px; color: var(--muted-2); margin-top: 2px; }

.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; align-items: start; }

/* ---------- tables ------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 600; padding: 9px 14px;
  border-bottom: 1px solid var(--line); background: #fcfcfd; white-space: nowrap;
}
table.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.tbl tbody tr:last-child td { border-bottom: 0; }
table.tbl tbody tr:hover { background: #fcfcfd; }
table.tbl tr.clickable { cursor: pointer; }
table.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.strong { font-weight: 600; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.nowrap { white-space: nowrap; }

/* ---------- badges ------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600; padding: 2.5px 8px; border-radius: 20px;
  border: 1px solid transparent; white-space: nowrap; text-transform: capitalize;
}
.b-draft     { background: var(--gray-bg);  color: var(--gray);  border-color: #e5e7eb; }
.b-sent      { background: var(--blue-bg);  color: var(--blue);  border-color: #dbeafe; }
.b-partial   { background: var(--amber-bg); color: var(--amber); border-color: #fde68a; }
.b-paid      { background: var(--green-bg); color: var(--green); border-color: #a7f3d0; }
.b-overdue   { background: var(--red-bg);   color: var(--red);   border-color: #fecaca; }
.b-cancelled { background: var(--gray-bg);  color: var(--muted-2); border-color: #e5e7eb; text-decoration: line-through; }

/* ---------- forms -------------------------------------------------------- */
.field { margin-bottom: 14px; }
.field label, .lbl { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
.field .hint { font-size: 11.5px; color: var(--muted-2); margin-top: 4px; }
/* bare <input> has no type attribute, so the [type=text] selector below
   never matched it and it fell back to the browser's default width */
input:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=range]),
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date],
input[type=tel], input[type=url], select, textarea {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 8px;
  background: #fff; outline: none; font-size: 13.5px;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus { border-color: #a5b4fc; box-shadow: 0 0 0 3px rgba(99,102,241,.13); }
input::placeholder, textarea::placeholder { color: var(--muted-2); }
textarea { resize: vertical; min-height: 62px; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 9px center; padding-right: 28px; }
.row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 14px; }
.row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
.inline-check { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink-2); }
input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--accent); }

/* ---------- toolbar / filters ------------------------------------------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.search { position: relative; flex: 1; min-width: 200px; max-width: 320px; }
.search input { padding-left: 32px; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--muted-2); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 5px 11px; border-radius: 20px; border: 1px solid var(--line);
  background: #fff; font-size: 12.5px; font-weight: 550; color: var(--muted);
  cursor: pointer;
}
.chip:hover { border-color: #d5d8dd; }
.chip.on { background: var(--accent-soft); border-color: #c7d2fe; color: var(--accent); }

/* ---------- empty state -------------------------------------------------- */
.empty { padding: 46px 20px; text-align: center; color: var(--muted); }
.empty h3 { font-size: 14px; color: var(--ink); margin-bottom: 4px; }
.empty p { margin: 0 0 14px; font-size: 13px; }

/* ---------- login -------------------------------------------------------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; background:
  radial-gradient(1000px 500px at 50% -10%, #eef2ff 0%, transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 372px; background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 28px; }
.auth-head { text-align: center; margin-bottom: 22px; }
.auth-head .brand-mark { margin: 0 auto 12px; width: 40px; height: 40px; font-size: 21px; border-radius: 11px; }
.auth-head h1 { font-size: 18px; }
.auth-head p { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
.auth-note { font-size: 12px; color: var(--muted); text-align: center; margin-top: 16px; line-height: 1.5; }
.auth-company { font-size: 11px; color: var(--muted-2); }
.about {
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line-2);
  font-size: 11.5px; line-height: 1.6; color: var(--muted-2);
}

/* ---------- invoice editor ---------------------------------------------- */
/* ---------- invoice editor: everything on one screen -------------------- */
.ed { display: grid; grid-template-columns: minmax(0, 1fr) 284px; gap: 14px; align-items: stretch; }
.ed-main { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.ed-side { position: sticky; top: 10px; }
.ed-head { margin-bottom: 14px; }
.ed-head .page-title { font-size: 19px; }
.ed-head .page-sub { margin-top: 1px; }

.ed-card { padding: 12px 14px; }
.ed-card .field, .ed-side .field { margin-bottom: 0; }
.ed-card label, .ed-side label { font-size: 11px; margin-bottom: 4px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.ed-card input, .ed-card select, .ed-card textarea,
.ed-side input, .ed-side select { padding: 6px 9px; font-size: 13px; border-radius: 7px; }
.ed-fields { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 150px) minmax(0, 140px); gap: 10px; margin-bottom: 10px; }
.ed-fields-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; margin-bottom: 10px; }
.ed-fields > .field, .ed-fields-2 > .field { min-width: 0; }
.ed-side, .ed-sum, .ed-main, .ed { min-width: 0; }
.ed-side { overflow-x: hidden; }
input[type=date] { width: 100%; min-width: 0; }
.input-sm { height: 34px; min-height: 34px; padding: 6px 9px; resize: none; }
/* the billing address grows with its content instead of clipping */
#f-address { height: auto; overflow: hidden; line-height: 1.45; }

.ed-items { display: flex; flex-direction: column; }
.ed-items .card-body { padding: 0; display: flex; flex-direction: column; min-height: 0; }
.ed-items .card-head { padding: 9px 12px; }
/* grows with the lines, then scrolls inside — the page itself never scrolls */
.ed-items .table-wrap { overflow: auto; max-height: calc(100vh - 420px); min-height: 0; }
.ed-items .items-table { min-width: 0; }
.ed-items .items-table .c-hsn { width: 74px; }
.ed-items .items-table .c-qty { width: 62px; }
.ed-items .items-table .c-unit { width: 76px; }
.ed-items .items-table .c-rate { width: 92px; }
.ed-items .items-table .c-disc { width: 62px; }
.ed-items .items-table .c-gst { width: 68px; }
.ed-items .items-table .c-taxable, .ed-items .items-table .c-tax { width: 74px; }
.ed-items .items-table .c-amt { width: 84px; }
.ed-items .items-table .row-del { width: 28px; }

/* the per-line taxable/tax pair is the first thing to go when space is tight */
@media (max-width: 1420px) {
  .ed-items .items-table .c-taxable, .ed-items .items-table .c-tax { display: none; }
}
@media (max-width: 1180px) {
  .ed-items .items-table .c-disc { display: none; }
}
.ed-items .items-table th {
  position: sticky; top: 0; z-index: 2; background: #fcfcfd;
  padding: 7px 6px; font-size: 10.5px;
}
.ed-items .items-table td { padding: 3px 4px; }
.ed-items .items-table input, .ed-items .items-table select { padding: 5px 7px; font-size: 12.5px; border-radius: 6px; }
.ed-items .items-table .cell { padding: 8px 6px; }

/* notes + terms live in a dialog so the page keeps its one-screen shape */
.ed-notes {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 11px 14px; text-align: left; cursor: pointer;
  color: var(--ink-2); background: var(--card);
}
.ed-notes:hover { border-color: #d8dbe0; }
.ed-notes:hover svg { color: var(--accent); }
.ed-notes svg { width: 15px; height: 15px; color: var(--muted-2); flex: 0 0 15px; }
.ed-notes-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ed-notes-lbl { font-size: 12.5px; font-weight: 650; }
.ed-notes-preview {
  font-size: 12px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ed-notes-preview.empty { color: var(--muted-2); font-style: italic; }

.count-pill {
  display: inline-block; min-width: 18px; padding: 0 6px; margin-left: 4px;
  font-size: 11px; font-weight: 600; line-height: 17px; text-align: center;
  color: var(--accent); background: var(--accent-soft); border-radius: 20px;
}

.words-line {
  font-size: 11.5px; color: var(--muted); line-height: 1.45;
  margin-top: 10px; padding-top: 9px; border-top: 1px dashed var(--line);
}
.words-line:empty { display: none; }
.ed-savenew { width: 100%; justify-content: center; margin-top: 12px; }
.kbd-hint { margin-top: 8px; text-align: center; font-size: 11px; color: var(--muted-2); }
.kbd-hint kbd { font-size: 10px; }

/* the row you are editing gets a quiet highlight */
.ed-items .items-table tbody tr:focus-within { background: #fbfbff; box-shadow: inset 3px 0 0 var(--accent); }
.ed-items .items-table tbody tr { transition: background .12s, box-shadow .12s; }

.ed-sum { padding: 12px 14px; }
.ed-sum .tax-mode { margin: 10px 0 12px; }
.ed-sum .totals { gap: 6px; }
.ed-sum .totals .grand { padding-top: 9px; }
.ed-sum .totals .grand .v { font-size: 18px; }

/* ---------- short windows (laptops at 125% scaling, ~590px tall) --------- */
@media (max-height: 780px) {
  .main { padding: 16px 24px 16px; }
  .ed-head { margin-bottom: 10px; }
  .ed-head .page-title { font-size: 17px; }
  .ed-card { padding: 10px 12px; }
  .ed-fields { gap: 8px; margin-bottom: 8px; }
  .ed-sum { padding: 10px 12px; }
  .ed-sum .totals { gap: 4px; }
  .ed-sum .totals .grand { padding-top: 7px; margin-top: 2px; }
  .ed-sum .tax-mode { margin: 8px 0 9px; }
  .ed-notes { padding: 9px 12px; }
  .kbd-hint { display: none; }
  .ed-savenew { margin-top: 9px; }
  .words-line { margin-top: 8px; padding-top: 7px; }
  .ed-items .table-wrap { max-height: calc(100vh - 350px); }
  .ed-items .items-table td { padding: 2px 4px; }
}

@media (max-height: 700px) {
  /* the rail is the tallest block on a short screen: cap it rather than let it
     push the page, and drop the decorative rows */
  .ed-side { position: static; max-height: calc(100vh - 96px); overflow-y: auto; }
  .ed-items .table-wrap { max-height: calc(100vh - 400px); }
  .ed-sum .totals .line { font-size: 12px; padding: 1px 0; }
  .ed-sum .totals .grand .v { font-size: 16px; }
  .ed-sum .tax-mode { padding: 4px 8px; font-size: 11px; margin: 6px 0 8px; }
  .ed-side .field label { font-size: 10px; }
}

@media (max-height: 640px) {
  .main { padding: 12px 20px 12px; }
  .ed-head .page-sub { display: none; }
  .words-line { display: none; }
  .ed-card label, .ed-side label { margin-bottom: 2px; }
  .ed-card input, .ed-card select, .ed-side input, .ed-side select { padding: 5px 8px; }
  .ed-items .table-wrap { max-height: calc(100vh - 380px); }
}

/* ---------- phones and tablets: essentials stay on screen ---------------- */
.mob-bar { display: none; }

@media (max-width: 900px) {
  .mob-bar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
    background: rgba(255, 255, 255, .97);
    border-top: 1px solid var(--line);
    box-shadow: 0 -4px 16px rgba(16, 24, 39, .06);
  }
  .mob-bar .mob-total { font-size: 17px; font-weight: 700; letter-spacing: -0.02em; }
  .mob-bar .mob-lbl { font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
  .main { padding-bottom: 86px; padding-top: 16px; }
  .ed-main { gap: 10px; }
  .ed-head { margin-bottom: 10px; }
  .ed-side { position: static; max-height: none; overflow: visible; }

  /* the phone bar owns saving; the header keeps just Cancel */
  .ed-head .page-actions #btn-draft,
  .ed-head .page-actions #btn-save { display: none; }
  .ed-head .page-actions { flex: 0 0 auto; }

  /* rarely-changed fields fold away behind one tap */
  .mob-more {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    width: 100%; margin: 8px 0 0; padding: 7px 10px;
    background: var(--line-2); border: 1px solid transparent; border-radius: 8px;
    font-size: 12.5px; font-weight: 600; color: var(--ink-2); cursor: pointer;
  }
  .mob-more svg { width: 14px; height: 14px; color: var(--muted); }
  .mob-more.open { margin-bottom: 8px; }
  .cust-extra, .ed-extra { display: none; }
  .cust-extra.open, .ed-extra.open { display: block; }
  .mob-bar-actions { display: flex; gap: 8px; }
}

@media (min-width: 901px) {
  .mob-more { display: none; }
}


/* ---------- tablets and phones: line items become cards ---------- */
@media (max-width: 900px) {
  /* each line becomes a compact two-column card */
  .items-table tr {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 2px 10px;
    border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
    margin-bottom: 10px; background: #fff;
  }
  .items-table td { display: flex; flex-direction: column; align-items: stretch; gap: 2px; padding: 2px 0; border: 0; }
  .items-table td::before { content: attr(data-label); font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); flex: none; }
  .items-table td input, .items-table td select { max-width: 100%; width: 100%; padding: 4px 7px; font-size: 12.5px; }
  .items-table td::before { font-size: 9.5px; }
  .items-table tr { padding: 7px 9px; margin-bottom: 8px; }
  .items-table td.c-item { grid-column: 1 / -1; }
  .items-table td.c-amt { grid-column: 1 / 2; flex-direction: row; align-items: baseline; justify-content: space-between; }
  .items-table td.row-del { grid-column: 2 / 3; justify-self: end; align-items: flex-end; padding-top: 0; }
  .items-table td.c-disc { display: none; }
  .items-table td.row-del { align-items: flex-end; padding-top: 4px; }
  .items-table td.row-del::before { content: ''; }
  /* the summary rail loses what the sticky bar already says */
  .ed-sum .tax-mode { display: none; }
  .words-line { display: none; }
  .ed-savenew { display: none; }
}

/* ---------- typeahead ---------------------------------------------------- */
.ta-list {
  position: fixed; z-index: 95; background: #fff;
  border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow-lg); padding: 4px; max-height: 260px; overflow: auto;
}
.ta-list[hidden] { display: none; }
.ta-item {
  display: flex; align-items: baseline; gap: 8px; width: 100%;
  padding: 7px 9px; border: 0; background: transparent; border-radius: 7px;
  cursor: pointer; text-align: left;
}
.ta-item:hover, .ta-item.on { background: var(--accent-soft); }
.ta-label { font-weight: 600; font-size: 13px; }
.ta-sub { font-size: 11.5px; color: var(--muted); margin-left: auto; text-align: right; }
.ta-item[data-new="1"] .ta-label, .ta-item[data-new="1"] .ta-sub { color: var(--accent); }
.items-table { width: 100%; border-collapse: collapse; min-width: 860px; }
.items-table th {
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  font-weight: 600; text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.items-table th.num, .items-table td.num { text-align: right; }
.items-table td { padding: 5px 4px; border-bottom: 1px solid var(--line-2); }
.items-table input, .items-table select { padding: 6px 8px; font-size: 13px; border-radius: 7px; }
.items-table td.num input { text-align: right; }
.items-table .cell { padding: 10px 6px; font-variant-numeric: tabular-nums; color: var(--ink-2); white-space: nowrap; }
.items-table .del {
  border: 0; background: transparent; color: var(--muted-2); cursor: pointer;
  width: 26px; height: 26px; border-radius: 6px; font-size: 16px; line-height: 1;
}
.items-table .del:hover { background: var(--red-bg); color: var(--red); }
.items-table tr:last-child td { border-bottom: 0; }

.totals { display: flex; flex-direction: column; gap: 8px; }
.totals .line { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-2); }
.totals .line .v { font-variant-numeric: tabular-nums; }
.totals .grand {
  display: flex; justify-content: space-between; align-items: baseline;
  border-top: 1px solid var(--line); margin-top: 4px; padding-top: 10px;
  font-size: 15px; font-weight: 650;
}
.totals .grand .v { font-size: 19px; letter-spacing: -0.02em; }
.tax-mode { font-size: 12px; color: var(--muted); background: var(--line-2); padding: 6px 9px; border-radius: 8px; }
.tax-mode.igst { background: var(--blue-bg); color: var(--blue); }

/* ---------- invoice sheet ------------------------------------------------ */
.sheet-scroll { overflow-x: auto; }
.sheet {
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 34px 36px 28px; box-shadow: var(--shadow);
  max-width: 820px; margin: 0 auto; color: #111827;
}
.sheet-head { display: flex; justify-content: space-between; gap: 28px; align-items: flex-start; }
.biz-name { font-size: 19px; font-weight: 700; letter-spacing: -0.02em; }
.biz-meta { font-size: 12px; color: #4b5563; line-height: 1.55; margin-top: 5px; white-space: pre-line; }
.doc-title { font-size: 13px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; text-align: right; color: var(--accent); }
.doc-meta { border-collapse: collapse; margin-top: 8px; font-size: 12px; }
.doc-meta td { padding: 2px 0 2px 12px; }
.doc-meta td:first-child { color: #6b7280; padding-left: 0; white-space: nowrap; }
.doc-meta td:last-child { text-align: right; font-weight: 600; }

.sheet-parties { display: flex; justify-content: space-between; gap: 24px; margin-top: 26px; padding-top: 18px; border-top: 1px solid #e5e7eb; }
.sheet-parties .lbl { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: #6b7280; font-weight: 600; margin-bottom: 5px; }
.cust-name { font-weight: 650; font-size: 14px; }
.cust-meta { font-size: 12px; color: #4b5563; line-height: 1.55; margin-top: 3px; white-space: pre-line; }
.sheet-badge { text-align: right; }

table.sheet-items { width: 100%; border-collapse: collapse; margin-top: 22px; font-size: 12.5px; }
table.sheet-items th {
  background: #f9fafb; border-top: 1px solid #e5e7eb; border-bottom: 1px solid #e5e7eb;
  padding: 8px 8px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em;
  color: #4b5563; font-weight: 650; text-align: left; white-space: nowrap;
}
table.sheet-items th.num, table.sheet-items td.num { text-align: right; }
table.sheet-items td { padding: 8px 8px; border-bottom: 1px solid #f1f2f4; vertical-align: top; }
table.sheet-items td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
table.sheet-items .desc { font-weight: 550; }
table.sheet-items .sub { font-size: 11px; color: #6b7280; }

.sheet-foot { display: grid; grid-template-columns: 1fr 268px; gap: 26px; margin-top: 20px; }
.foot-block { margin-bottom: 14px; }
.foot-block .lbl { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: #6b7280; font-weight: 650; margin-bottom: 5px; }
.words { font-size: 12px; color: #374151; line-height: 1.5; }
table.tax-sum { width: 100%; border-collapse: collapse; font-size: 11.5px; }
table.tax-sum th, table.tax-sum td { border: 1px solid #e5e7eb; padding: 4px 7px; text-align: right; font-variant-numeric: tabular-nums; }
table.tax-sum th { background: #f9fafb; font-weight: 600; color: #4b5563; text-align: right; }
table.tax-sum td:first-child, table.tax-sum th:first-child { text-align: left; }

.tot-box { font-size: 12.5px; }
.tot-box .line { display: flex; justify-content: space-between; padding: 5px 0; color: #374151; }
.tot-box .line .v { font-variant-numeric: tabular-nums; }
.tot-box .grand {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-top: 6px; padding: 10px 12px; background: #f5f6f8; border-radius: 8px;
  font-weight: 700; font-size: 14px;
}
.tot-box .grand .v { font-size: 18px; letter-spacing: -0.02em; }
.tot-box .paid { color: var(--green); }
.tot-box .due { color: var(--red); font-weight: 650; }

.pay-box { display: flex; gap: 12px; align-items: center; margin-top: 6px; }
.qr { width: 84px; height: 84px; flex: 0 0 84px; border: 1px solid #e5e7eb; border-radius: 8px; padding: 3px; background: #fff; }
.qr svg { width: 100%; height: 100%; display: block; }
.pay-text { font-size: 11.5px; color: #4b5563; line-height: 1.5; }
.pay-text .vpa { font-weight: 650; color: #111827; }

.sheet-sign { margin-top: 30px; padding-top: 14px; border-top: 1px solid #e5e7eb; display: flex; justify-content: space-between; align-items: flex-end; font-size: 11.5px; color: #6b7280; }
.sign-line { text-align: right; }
.sign-line .for { font-weight: 600; color: #374151; }
.sign-space { height: 34px; }

/* ---------- payments list ------------------------------------------------ */
.pay-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line-2); font-size: 13px; }
.pay-row:last-child { border-bottom: 0; }

/* ---------- modal -------------------------------------------------------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(17, 24, 39, .42);
  display: grid; place-items: center; padding: 20px; z-index: 60;
  animation: fade .12s ease-out;
}
.modal {
  background: #fff; border-radius: 14px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 460px; max-height: 90vh; overflow: auto;
  animation: pop .14s ease-out;
}
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line-2); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { font-size: 15px; }
.modal-body { padding: 18px 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line-2); display: flex; justify-content: flex-end; gap: 8px; background: #fcfcfd; border-radius: 0 0 14px 14px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.99); } }

/* ---------- toast -------------------------------------------------------- */
.toast-host { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: #111827; color: #fff; padding: 9px 15px; border-radius: 9px;
  font-size: 13px; box-shadow: var(--shadow-lg); animation: pop .15s ease-out;
  max-width: 90vw;
}
.toast.err { background: var(--red); }

/* ---------- misc --------------------------------------------------------- */
.hr { height: 1px; background: var(--line-2); margin: 18px 0; border: 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.right { text-align: right; }
.center { text-align: center; }
.linkish { color: var(--accent); cursor: pointer; font-weight: 550; }
.linkish:hover { text-decoration: underline; }
.notice { background: var(--amber-bg); border: 1px solid #fde68a; color: #92400e; border-radius: 9px; padding: 10px 12px; font-size: 12.5px; }

@media (max-width: 1100px) {
  /* one column: the items table needs the width more than the rail does */
  .ed { grid-template-columns: 1fr; }
  .ed-side { position: static; }
  /* the totals already say intra/inter, so drop the duplicate chrome */
  .ed-sum .tax-mode, .ed-savenew, .words-line { display: none; }
}

@media (max-width: 980px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .editor-grid, .editor-bottom { grid-template-columns: 1fr; }
  .ed-side { position: static; }
  .ed-fields { grid-template-columns: 1fr 1fr; }
  .ed-fields > .field:first-child { grid-column: 1 / -1; }
  .ed-items .table-wrap { max-height: none; }
  .sheet-foot { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav { flex-direction: row; overflow-x: auto; padding: 8px; gap: 4px; }
  .nav a { white-space: nowrap; padding: 7px 11px; }
  .nav .count { display: none; }
  .brand { padding: 12px 14px; border-bottom: 0; }
  .side-foot { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-top: 0; }
  .side-foot .who, .side-foot .demo-chip { margin: 0; }
  .main { padding: 18px 14px 50px; }
  .sheet { padding: 20px 16px; }
  .sheet-head { flex-direction: column; gap: 14px; }
  .doc-title, .doc-meta td:last-child { text-align: left; }
  .doc-meta td { padding-left: 0; padding-right: 14px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-val { font-size: 18px; }
  .page-title { font-size: 18px; }
}

/* ---------- row actions -------------------------------------------------- */
table.tbl td.row-actions { text-align: right; white-space: nowrap; width: 132px; }
.row-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  height: 27px; min-width: 27px; padding: 0 7px; margin-left: 4px;
  border: 1px solid var(--line); background: #fff; border-radius: 7px;
  color: var(--muted); font-size: 12px; font-weight: 600; cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
.row-btn svg { width: 14px; height: 14px; }
.row-btn:hover { background: var(--line-2); color: var(--ink); border-color: #d5d8dd; }
.row-btn-pay { color: var(--green); border-color: #b9e6d3; background: #f6fdfa; }
.row-btn-pay:hover { background: var(--green-bg); border-color: #8fd9bd; color: var(--green); }
.late { color: var(--red); font-weight: 600; }
.due-in { color: var(--muted-2); }

/* ---------- aging + trend ------------------------------------------------ */
.age-bar { display: flex; height: 10px; border-radius: 6px; overflow: hidden; background: var(--line-2); margin-bottom: 12px; }
.age-bar span { display: block; height: 100%; }
.seg-ok { background: #10b981; }
.seg-1 { background: #f59e0b; }
.seg-2 { background: #f97316; }
.seg-3 { background: #dc2626; }
.age-legend { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.age-legend > div { font-size: 12px; }
.age-legend .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; }
.age-legend .strong { font-size: 13px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.trend { display: flex; align-items: flex-end; gap: 8px; height: 108px; }
.trend-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; text-align: center; }
.trend-bar { background: linear-gradient(180deg, #818cf8, #4338ca); border-radius: 5px 5px 0 0; min-height: 2px; }
.trend-lbl { font-size: 11px; color: var(--muted); margin-top: 6px; }

/* ---------- onboarding --------------------------------------------------- */
.onboard { margin-bottom: 18px; }
.onboard-step { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--line-2); text-decoration: none; color: var(--ink-2); }
.onboard-step:last-child { border-bottom: 0; }
.onboard-step:hover { text-decoration: none; background: #fcfcfd; }
.onboard-step .tick { width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--line); display: grid; place-items: center; font-size: 11px; color: #fff; flex: 0 0 18px; }
.onboard-step.done .tick { background: var(--green); border-color: var(--green); }
.onboard-step.done .strong { color: var(--muted); text-decoration: line-through; }

/* ---------- quick amounts ------------------------------------------------ */
.quick-amounts { display: flex; gap: 6px; margin: -6px 0 14px; }

/* ---------- sidebar search ----------------------------------------------- */
.side-search {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 7px 10px; margin-bottom: 10px;
  background: var(--line-2); border: 1px solid transparent; border-radius: 8px;
  color: var(--muted); font-size: 12.5px; cursor: pointer; text-align: left;
}
.side-search:hover { border-color: var(--line); color: var(--ink-2); }
.side-search svg { width: 14px; height: 14px; }
.side-search kbd { margin-left: auto; }

kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10.5px;
  background: #fff; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; padding: 1px 4px; color: var(--muted);
}

/* ---------- command palette ---------------------------------------------- */
.cmdk-back { position: fixed; inset: 0; background: rgba(17, 24, 39, .38); z-index: 90; display: flex; justify-content: center; align-items: flex-start; padding-top: 12vh; }
.cmdk { width: 100%; max-width: 560px; background: #fff; border-radius: 14px; box-shadow: var(--shadow-lg); overflow: hidden; }
.cmdk input { width: 100%; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 15px 18px; font-size: 15px; outline: none; }
.cmdk input:focus { box-shadow: none; }
.cmdk-list { max-height: 320px; overflow: auto; padding: 6px; }
.cmdk-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border: 0; background: transparent; border-radius: 8px; cursor: pointer; text-align: left; }
.cmdk-item.on { background: var(--accent-soft); }
.cmdk-label { font-weight: 600; font-size: 13.5px; white-space: nowrap; }
.cmdk-sub { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmdk-item kbd { margin-left: auto; }
.cmdk-empty { padding: 22px; text-align: center; color: var(--muted); font-size: 13px; }
.cmdk-foot { display: flex; gap: 14px; padding: 9px 14px; border-top: 1px solid var(--line-2); background: #fcfcfd; font-size: 11.5px; color: var(--muted); }
.cmdk-foot kbd { margin-right: 3px; }

:focus-visible { outline: 2px solid #a5b4fc; outline-offset: 2px; }

/* ---------- phones: line items become cards ------------------------------ */
@media (max-width: 760px) {
  .page-head { position: sticky; top: 0; z-index: 6; background: var(--bg); padding: 10px 0; margin-bottom: 12px; }
  .side-search { display: none; }
  .age-legend { grid-template-columns: repeat(2, 1fr); }
  .items-table { min-width: 0; }
  .items-table thead { display: none; }
  .items-table tbody { display: block; }

  .row, .row-3 { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; justify-content: center; }
  table.tbl td.row-actions { width: 68px; }
  .row-btn-pay span { display: none; }
  .row-btn-pay { padding: 0; width: 27px; }

  /* the invoice list becomes a card per bill instead of a sideways-scrolling table */
  .tbl-invoices { min-width: 0; }
  .tbl-invoices thead { display: none; }
  .tbl-invoices, .tbl-invoices tbody { display: block; }
  .tbl-invoices tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "num status" "cust cust" "amt bal" "date actions";
    gap: 3px 10px; padding: 12px 4px; border-bottom: 1px solid var(--line-2);
  }
  .tbl-invoices tbody tr:last-child { border-bottom: 0; }
  .tbl-invoices tbody td { display: block; border: 0; padding: 0; }
  .tbl-invoices tbody td:nth-child(1) { grid-area: num; }
  .tbl-invoices tbody td:nth-child(2) { grid-area: cust; }
  .tbl-invoices tbody td:nth-child(3) { grid-area: date; font-size: 12px; }
  .tbl-invoices tbody td:nth-child(4) { grid-area: amt; font-size: 12.5px; }
  .tbl-invoices tbody td:nth-child(5) { grid-area: bal; text-align: right; font-size: 12.5px; }
  .tbl-invoices tbody td:nth-child(6) { grid-area: status; text-align: right; }
  .tbl-invoices tbody td:nth-child(7) { grid-area: actions; text-align: right; }
  .tbl-invoices tbody tr { cursor: pointer; }
}

/* ---------- print -------------------------------------------------------- */
@media print {
  @page { size: A4; margin: 11mm; }
  html, body { background: #fff; font-size: 11.5px; }
  /* Chrome's print viewport is narrow, so undo the responsive stacking */
  .sheet-head { flex-direction: row; gap: 24px; }
  .doc-title, .doc-meta td:last-child { text-align: right; }
  .doc-meta td { padding: 2px 0 2px 12px; }
  .sheet-foot { grid-template-columns: 1fr 240px; gap: 20px; }
  .stats, .grid-2, .editor-grid, .editor-bottom { grid-template-columns: none; }
  .ed { display: block; }
  .ed-more { display: none; }
  .sidebar, .page-head, .no-print, .toast-host, .modal-back, .page-actions { display: none !important; }
  .main { padding: 0; }
  .wrap, .wrap-wide { max-width: none; }
  .sheet {
    border: 0; border-radius: 0; box-shadow: none; padding: 0;
    max-width: none; margin: 0;
  }
  .sheet-scroll { overflow: visible; }
  table.sheet-items th { background: #f2f3f5 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .tot-box .grand { background: #f2f3f5 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .badge { border: 1px solid #d1d5db !important; }
  .sheet-foot { page-break-inside: avoid; }
}

/* ---------- first paint skeleton ----------------------------------------- */
.sk {
  display: inline-block; border-radius: 6px;
  background: linear-gradient(90deg, #dcd8ea 25%, #eeecf6 50%, #dcd8ea 75%);
  background-size: 200% 100%;
  animation: sk-shimmer 1.2s ease-in-out infinite;
}
.sk-line { height: 11px; width: 100%; }
.sk-dot  { width: 18px; height: 18px; border-radius: 5px; margin-right: 10px; flex: none; }
.sk-row  { height: 15px; margin-bottom: 14px; }
.sk-nav  { display: flex; align-items: center; padding: 9px 10px; }
.sk-nav .sk-line { height: 12px; }
@keyframes sk-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .sk { animation: none; } }

/* ---------- loading feedback --------------------------------------------- */
.progress {
  position: fixed; top: 0; left: 0; height: 2px; width: 0;
  background: var(--accent); z-index: 200; opacity: 0;
  transition: width .25s ease, opacity .3s ease;
}
.progress.on { opacity: 1; }

.btn.busy { position: relative; color: transparent !important; }
.btn.busy::after {
  content: ''; position: absolute; inset: 0; margin: auto;
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid rgba(67, 56, 202, .35); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
.btn-primary.busy::after { border-color: rgba(255,255,255,.45); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .progress { transition: none; }
  .btn.busy::after { animation: none; }
}
.badge.b-cn { background: #eef2ff; color: #3730a3; border-color: #c7d2fe; }

/* ---------- reports: collection forecast -------------------------------- */
.fc-row { display: grid; grid-template-columns: 120px 1fr 96px; align-items: center; gap: 10px; margin-bottom: 10px; }
.fc-lbl { font-size: 12.5px; color: var(--muted); }
.fc-track { height: 10px; background: var(--line-2); border-radius: 6px; overflow: hidden; }
.fc-fill { height: 100%; border-radius: 6px; }
.fc-val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; font-size: 13px; }
.fc-bad  { background: #dc2626; }
.fc-good { background: #059669; }
.fc-mid  { background: #f59e0b; }
.fc-soft { background: #a5b4fc; }

/* a typeahead row waiting on the database */
.ta-spin {
  display: inline-block; width: 9px; height: 9px; margin-right: 6px;
  border-radius: 50%; vertical-align: middle;
  border: 1.5px solid rgba(67, 56, 202, .25); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@media (prefers-reduced-motion: reduce) { .ta-spin { animation: none; } }
