:root {
  /* brand: black, gold orbit, crimson AVORA */
  --navy: #2a2522;
  --navy-dark: #141210;
  --accent: #e3a14a;
  --crimson: #e01f4f;
  --bg: #f6f4f1;
  --card: #ffffff;
  --text: #1f1c1a;
  --muted: #74706b;
  --line: #e8e3dc;
  --primary: #b0601c;
  --primary-hover: #93501a;
  --danger: #c0392b;
  --success: #1e8a4c;
  --warn: #b7791f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 32, 64, .06), 0 2px 8px rgba(16, 32, 64, .05);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
.hidden { display: none !important; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h3 { font-size: 15px; margin-bottom: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.error { color: var(--danger); min-height: 1em; margin: 4px 0; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, var(--navy-dark), var(--navy)); padding: 16px; }
.login-card { background: var(--card); width: 100%; max-width: 360px; padding: 32px; border-radius: 14px; box-shadow: 0 10px 40px rgba(0,0,0,.25); text-align: center; }
.login-card h1 { margin-top: 12px; font-size: 22px; }
.login-card label { text-align: left; }
.login-card p.muted { margin: 4px 0 20px; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 232px; flex: none; background: var(--navy-dark); color: #cfdbea; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; flex-direction: column; gap: 4px; align-items: center; padding: 18px 16px 14px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand img { width: 196px; height: auto; display: block; border-radius: 8px; }
.login-logo { width: 280px; max-width: 100%; height: auto; display: block; margin: 0 auto; border-radius: 10px; }
.brand strong { display: block; color: #fff; letter-spacing: .5px; }
.brand small { color: var(--accent); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: 1px; }
.brand-mark { width: 36px; height: 36px; border-radius: 9px; background: var(--accent); color: var(--navy-dark); display: grid; place-items: center; font-weight: 800; font-size: 18px; flex: none; }
.brand-mark.big { width: 56px; height: 56px; font-size: 28px; margin: 0 auto; border-radius: 14px; }
.sidebar nav { padding: 10px 8px; flex: 1; overflow-y: auto; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; color: #cfdbea; padding: 9px 12px; border-radius: 8px; margin-bottom: 2px; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.sidebar nav a.active { background: rgba(232,163,23,.16); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.ico { width: 20px; text-align: center; opacity: .9; }
.sidebar-foot { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sidebar-foot .link { color: var(--accent); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 24px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar h2 { font-size: 18px; flex: 1; }
.menu-btn { display: none; border: 0; background: none; font-size: 22px; cursor: pointer; }
.view { padding: 24px; max-width: 1280px; width: 100%; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 500; white-space: nowrap; }
.btn:hover { background: #f0f3f8; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.wa { background: #25d366; border-color: #25d366; color: #fff; }
.btn.wa:hover { background: #1ebe5b; }
.btn.danger { color: var(--danger); border-color: #f0c8c3; }
.btn.danger:hover { background: #fdf0ee; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; padding: 10px; }
.or-sep { display: flex; align-items: center; gap: 10px; margin: 14px 0 12px; color: var(--muted, #8a7f75); font-size: 12px; }
.or-sep::before, .or-sep::after { content: ''; flex: 1; border-top: 1px solid var(--line, #e3dbd2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.link { border: 0; background: none; color: var(--primary); cursor: pointer; font: inherit; padding: 0; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 12px; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid #cfd7e3; border-radius: 7px; font: inherit; color: var(--text); background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(11,92,173,.25); border-color: var(--primary); }
textarea { resize: vertical; min-height: 64px; }
input[type=checkbox] { display: inline; width: auto; margin: 0 6px 0 0; }
.check { display: flex; align-items: center; color: var(--text); font-weight: 500; font-size: 13px; }

/* ---------- layout ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.card-head h3 { margin: 0; }
.grid { display: grid; gap: 0 16px; }
.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)); }
.span2 { grid-column: span 2; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar label { margin: 0; min-width: 140px; }
.toolbar .grow { flex: 1; min-width: 200px; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; border-top: 3px solid var(--primary); }
.stat .label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.stat.green { border-color: var(--success); }
.stat.amber { border-color: var(--accent); }
.stat.red { border-color: var(--danger); }
.dash-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
.chart-box { position: relative; height: 280px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); font-weight: 600; padding: 10px 12px; background: #f8fafc; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr.clickable:hover { background: #f7f9fc; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tfoot td { font-weight: 700; background: #f8fafc; border-top: 2px solid var(--line); }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- badges & tabs ---------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .3px; background: #eef2f7; color: var(--muted); white-space: nowrap; }
.badge.paid { background: #e3f4ea; color: var(--success); }
.badge.partial { background: #fff4dc; color: var(--warn); }
.badge.unpaid { background: #e8f0fb; color: var(--primary); }
.badge.overdue { background: #fde8e6; color: var(--danger); }
.badge.cancelled { background: #eee; color: #888; text-decoration: line-through; }
.badge.converted { background: #ece8fb; color: #5b45b0; }
.badge.t-EXPORT { background: #e6f5f5; color: #127a7a; }
.badge.t-TRAVEL { background: #f3eafc; color: #7a3fb5; }
.badge.t-TAX { background: #e8f0fb; color: var(--primary); }
.badge.t-PROFORMA { background: #fff4dc; color: var(--warn); }
.badge.t-CREDIT { background: #fde8e6; color: var(--danger); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 14px; font: inherit; font-weight: 500; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- invoice form ---------- */
.type-pick { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-bottom: 20px; }
.type-pick button { border: 1.5px solid var(--line); background: var(--card); border-radius: 10px; padding: 12px; cursor: pointer; text-align: left; font: inherit; }
.type-pick button strong { display: block; margin-bottom: 2px; }
.type-pick button small { color: var(--muted); font-size: 12px; }
.type-pick button.active { border-color: var(--primary); background: #f0f6fd; box-shadow: 0 0 0 3px rgba(11,92,173,.1); }
.type-pick button:disabled { cursor: default; }
table.items { width: 100%; border-collapse: collapse; }
table.items th { font-size: 11px; text-transform: uppercase; color: var(--muted); text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.items td { padding: 6px 4px; vertical-align: top; }
table.items input, table.items select { margin: 0; padding: 7px 8px; }
table.items .c-desc { min-width: 240px; }
table.items .c-hsn { width: 96px; }
table.items .c-qty { width: 72px; }
table.items .c-unit { width: 76px; }
table.items .c-rate { width: 110px; }
table.items .c-disc { width: 90px; }
table.items .c-gst { width: 82px; }
table.items .c-amt { width: 120px; text-align: right; padding-top: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.items .c-del { width: 32px; }
.del-line { border: 0; background: none; color: var(--muted); font-size: 18px; cursor: pointer; padding: 6px; }
.del-line:hover { color: var(--danger); }
.suggest { position: relative; }
.suggest-list { position: absolute; z-index: 20; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 260px; overflow-y: auto; }
.suggest-list div { padding: 8px 10px; cursor: pointer; }
.suggest-list div:hover, .suggest-list div.hl { background: #f0f6fd; }
.suggest-list small { color: var(--muted); display: block; }
.totals { margin-left: auto; width: 100%; max-width: 360px; }
.totals div { display: flex; justify-content: space-between; padding: 5px 0; font-variant-numeric: tabular-nums; }
.totals .grand { border-top: 2px solid var(--text); margin-top: 6px; padding-top: 10px; font-size: 18px; font-weight: 700; }
.words { font-style: italic; color: var(--muted); font-size: 13px; margin-top: 6px; text-align: right; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 20px 0 4px; }
.hint { background: #f0f6fd; border: 1px solid #d4e5f7; color: #2a4f78; padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }

/* ---------- invoice view ---------- */
.inv-view { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.preview-frame { width: 100%; height: 1150px; border: 0; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); }
.side-actions { display: flex; flex-direction: column; gap: 8px; }
.side-actions .btn { justify-content: center; }
.kv { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--line); font-variant-numeric: tabular-nums; }
.kv:last-child { border: 0; }
.cancel-note { margin-top: 10px; padding: 10px 12px; border-radius: 8px; background: #fdf0ee; color: #8a2a1f; font-size: 13px; line-height: 1.5; }

/* ---------- modal & toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(10, 20, 40, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--card); border-radius: 12px; width: 100%; max-width: 640px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { max-width: 860px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; }
.modal-head button { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(120px); background: var(--text); color: #fff; padding: 10px 18px; border-radius: 8px; transition: transform .25s; z-index: 60; max-width: calc(100vw - 32px); }
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .inv-view, .dash-grid { grid-template-columns: 1fr; }
  .type-pick { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .sidebar { position: fixed; left: -240px; z-index: 40; transition: left .2s; }
  .sidebar.open { left: 0; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .menu-btn { display: block; }
  .view { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .type-pick { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .top-actions .btn { padding: 7px 10px; }
}

/* ---------- phones: tables become cards, bill lines stack, actions first ---------- */
.hide-sm { display: inline; }
@media (max-width: 640px) {
  .hide-sm { display: none; }
  .view { padding: 12px; }
  .topbar { gap: 8px; }
  .topbar h2 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .card { padding: 14px; }
  .toolbar label, .toolbar .grow { min-width: 0; flex: 1 1 140px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px; }
  .stat .value { font-size: 17px; }

  /* Every data table: one card per row, each value with its column name (labels set by labelTables in core.js). */
  .table-wrap { overflow: visible; }
  table.data thead { display: none; }
  table.data, table.data tbody, table.data tfoot, table.data tr { display: block; width: 100%; }
  table.data tbody tr { padding: 10px 14px; border-bottom: 1px solid var(--line); }
  table.data tbody tr:last-child { border-bottom: 0; }
  table.data td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; border: 0; padding: 3px 0; text-align: right; white-space: normal; }
  table.data td::before { content: attr(data-label); flex: none; color: var(--muted); font-size: 12px; font-weight: 600; text-align: left; }
  table.data td:not([data-label])::before { content: none; }
  table.data td:not([data-label]) { justify-content: flex-start; text-align: left; }
  table.data td:empty { display: none; }
  table.data tbody td:first-child { font-weight: 600; font-size: 15px; }
  table.data tfoot tr { padding: 10px 14px; border-top: 2px solid var(--line); background: #f8fafc; }
  table.data tfoot td { background: none; border: 0; }

  /* New-bill item lines: description on top, the other fields in a 3-column grid under it. */
  table.items thead { display: none; }
  table.items, table.items tbody { display: block; }
  table.items tr[data-i] { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--line); position: relative; }
  table.items td { padding: 0; width: auto !important; min-width: 0 !important; }
  table.items td::before { content: attr(data-label); display: block; font-size: 11px; color: var(--muted); font-weight: 600; margin-bottom: 3px; }
  table.items td.c-desc { grid-column: 1 / -1; padding-right: 36px; }
  table.items td.c-amt { grid-column: 1 / -1; text-align: right; padding-top: 2px; font-weight: 700; font-size: 15px; }
  table.items td.c-amt::before { display: inline; margin-right: 8px; }
  table.items td.c-del { position: absolute; top: 28px; right: 0; }
  table.items td.c-del::before { content: none; }

  /* Bill screen: buttons and status above the preview. */
  .inv-view > div:last-child { order: -1; }
  .preview-frame { height: 520px; }
}
