/* ════════ Nizami Complex — styles.css ════════
   Old theme + bill-card CSS (UNTOUCHED — the card becomes the
   PDF/PNG) + tab/analytics/modal CSS + v4 additions. */

:root {
  --bg: #111318;
  --surface: #1a1d24;
  --surface2: #20242e;
  --border: #2a2f3d;
  --border2: #333a4d;
  --gold: #d4a843;
  --gold2: #e8be5a;
  --gold-dim: rgba(212,168,67,0.15);
  --green: #1a6640;
  --green2: #22854f;
  --green-bright: #4ade80;
  --red: #f87171;
  --amber: #fbbf24;
  --text: #e8ecf4;
  --text2: #9ba3b8;
  --text3: #545e78;
  --card-bg: #161920;
  --radius: 12px;
  --font-mono: 'DM Mono', monospace;
  --font-head: 'Syne', sans-serif;
  --font-serif: 'Amiri', Georgia, serif;
}

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

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  min-height: 100vh;
  padding: 24px 16px 60px;
  background-image: radial-gradient(ellipse at 20% 10%, rgba(79,142,247,0.04) 0%, transparent 60%),
                    radial-gradient(ellipse at 80% 90%, rgba(212,168,67,0.04) 0%, transparent 60%);
}

/* ── HEADER ── */
.app-header {
  text-align: center;
  margin-bottom: 36px;
  padding-top: 8px;
}
.header-logo-wrap {
  display: inline-flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 10px;
  text-decoration: none;
}
.header-logo-svg {
  width: 56px;
  height: 56px;
  filter: drop-shadow(0 4px 12px rgba(201,162,39,0.3));
  flex-shrink: 0;
}
.header-text-wrap { text-align: left; }
.app-header h1 {
  font-family: var(--font-serif);
  font-size: clamp(24px, 4vw, 38px);
  font-weight: 700;
  letter-spacing: 2px;
  background: linear-gradient(135deg, #c9a227 0%, #daa520 40%, #f0c040 70%, #c9a227 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.1;
}
.app-header .sub {
  font-family: var(--font-head);
  font-size: 10px;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: var(--text3);
  margin-top: 2px;
}
.app-header p { color: var(--text2); font-size: 12px; margin-top: 6px; letter-spacing: 0.3px; }
.gold-rule {
  width: 80px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  margin: 10px auto 0;
}

/* ── LAYOUT ── */
.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  max-width: 1360px;
  margin: 0 auto;
}
@media (max-width: 960px) { .layout { grid-template-columns: 1fr; } }

/* ── PANEL ── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.panel-title {
  font-family: var(--font-head);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--border2), transparent);
}

/* ── FORM FIELDS ── */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 5px;
  letter-spacing: 0.5px;
}
.field label span.req { color: var(--red); margin-left: 2px; }
.field label span.opt { color: var(--text3); font-size: 10px; margin-left: 4px; }

input[type="text"], input[type="number"], input[type="date"], select, textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201,162,39,0.1);
}
input::placeholder { color: var(--text3); }
input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(0.7); cursor: pointer; }
input[type="date"] { color-scheme: dark; }
input:disabled { opacity: 0.35; cursor: not-allowed; }
textarea { resize: vertical; min-height: 48px; line-height: 1.5; }

select {
  cursor: pointer;
  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='%239ba3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.row4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 8px; }

/* ── MULTI-ENTRY LISTS ── */
.multi-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.multi-item {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 10px 10px 10px 12px;
  position: relative;
}
.multi-item-row { display: grid; gap: 6px; align-items: end; }
.multi-item-row.cols3 { grid-template-columns: auto 1fr 1fr 28px; }
.multi-item-row.cols4 { grid-template-columns: auto 1fr 1fr 1fr 28px; }
.multi-item input, .multi-item textarea { background: var(--surface); font-size: 12px; padding: 6px 9px; }
.multi-item textarea { min-height: 36px; resize: none; }
.mi-label { font-size: 10px; color: var(--text3); letter-spacing: 0.5px; margin-bottom: 3px; }
.mi-amount { font-weight: 600; color: var(--text); }
.btn-remove-item {
  background: none;
  border: 1px solid var(--border2);
  border-radius: 6px;
  color: var(--text3);
  cursor: pointer;
  font-size: 14px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
  align-self: end;
  padding: 0;
}
.btn-remove-item:hover { border-color: var(--red); color: var(--red); background: rgba(248,113,113,0.08); }
.btn-add-item {
  background: none;
  border: 1px dashed var(--border2);
  border-radius: 8px;
  color: var(--text3);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 7px 12px;
  cursor: pointer;
  width: 100%;
  transition: all 0.15s;
  text-align: center;
}
.btn-add-item:hover { border-color: var(--gold); color: var(--gold); }

/* Sub-section dividers within panels */
.sub-section { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.sub-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text3);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sub-label::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* Inline discount toggle in rates */
.rate-with-discount {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: end;
}
.rate-discount-toggle {
  background: none;
  border: 1px solid var(--border2);
  border-radius: 8px;
  color: var(--text3);
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 8px 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
  height: 34px;
  align-self: end;
}
.rate-discount-toggle:hover, .rate-discount-toggle.active { border-color: var(--gold); color: var(--gold); background: rgba(212,168,67,0.08); }
.discount-inline { display: none; margin-top: 6px; }
.discount-inline.show { display: block; }
.discount-inline input { font-size: 12px; }
.di-hint { font-size: 10px; color: var(--text3); margin-top: 3px; }

/* ── GENERATE BUTTONS ── */
.generate-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
  justify-content: center;
}
.btn-generate {
  font-family: var(--font-head);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 11px 22px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #1a6640, #0d9955);
  color: #fff;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  box-shadow: 0 4px 16px rgba(26,102,64,0.3);
  flex: 1;
  min-width: 140px;
}
.btn-generate:hover { opacity: 0.88; transform: translateY(-1px); }
.btn-generate:active { transform: translateY(0); }
.btn-gold {
  background: linear-gradient(135deg, #a07c0a, #c9a227);
  box-shadow: 0 4px 16px rgba(201,162,39,0.25);
}
.btn-reset {
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--text3);
  box-shadow: none;
  flex: 0 0 auto;
  min-width: 80px;
  font-size: 12px;
  border-radius: 10px;
  padding: 11px 18px;
  font-family: var(--font-head);
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-reset:hover { border-color: var(--red); color: var(--red); }

/* ── PREVIEW PANEL ── */
#preview-panel {
  position: sticky;
  top: 20px;
  align-self: start;
}

/* ── CARD ACTIONS (shown by renderCard via .visible once a valid bill previews) ── */
.card-actions {
  display: none;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.card-actions.visible { display: flex; }
.btn-action {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  padding: 9px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1;
}
.btn-copy-bill {
  background: rgba(34,133,79,0.12);
  border: 1px solid rgba(34,133,79,0.3);
  color: #22854f;
}
.btn-copy-bill:hover { background: rgba(34,133,79,0.22); }
.btn-copy-wa {
  background: rgba(201,162,39,0.1);
  border: 1px solid rgba(201,162,39,0.3);
  color: var(--gold);
}
.btn-copy-wa:hover { background: rgba(201,162,39,0.18); }
.btn-print {
  background: rgba(79,142,247,0.12);
  border: 1px solid rgba(79,142,247,0.3);
  color: #60a5fa;
}
.btn-print:hover { background: rgba(79,142,247,0.2); }
.btn-png {
  background: rgba(168,85,247,0.1);
  border: 1px solid rgba(168,85,247,0.3);
  color: #c084fc;
}
.btn-png:hover { background: rgba(168,85,247,0.18); }

/* ── BILL CARD ── */
.bill-card {
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  font-family: 'Segoe UI', Inter, Arial, sans-serif;
  color: #1a2010;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6), 0 0 0 1px rgba(212,168,67,0.12);
  display: flex;
  flex-direction: column;
}

/* Bill header */
.bc-header {
  background: linear-gradient(135deg, #0d4a2e 0%, #1a6640 60%, #0d4a2e 100%);
  padding: 20px 24px 18px;
  display: flex;
  align-items: center;
  gap: 16px;
  border-bottom: 3px solid #c9a227;
  position: relative;
  overflow: hidden;
}
.bc-header::after {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60'%3E%3Ccircle cx='30' cy='30' r='28' fill='none' stroke='rgba(201,162,39,0.06)' stroke-width='1'/%3E%3C/svg%3E") repeat;
  pointer-events: none;
}
.bc-logo-svg { width: 54px; height: 54px; flex-shrink: 0; filter: drop-shadow(0 2px 8px rgba(0,0,0,0.4)); }
.bc-header-text { flex: 1; }
.bc-title {
  font-family: 'Amiri', Georgia, serif;
  font-size: 26px;
  font-weight: 700;
  color: #c9a227;
  letter-spacing: 1px;
  line-height: 1.1;
}
.bc-subtitle {
  font-size: 10px;
  color: rgba(201,162,39,0.6);
  letter-spacing: 4px;
  text-transform: uppercase;
  margin-top: 2px;
  font-family: 'Segoe UI', sans-serif;
}
.bc-meta {
  text-align: right;
  font-size: 11px;
  color: rgba(201,162,39,0.7);
  line-height: 1.7;
  font-family: monospace;
  flex-shrink: 0;
}

/* Bill info bar */
.bc-infobar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  border-bottom: 1px solid #e5e0d0;
}
.bc-infobar-cell {
  padding: 12px 16px;
  border-right: 1px solid #e5e0d0;
  font-size: 12px;
  background: #faf8f2;
}
.bc-infobar-cell:last-child { border-right: none; }
.bc-info-label {
  font-size: 9px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #1a6640;
  font-weight: 700;
  margin-bottom: 4px;
}
.bc-info-val { font-weight: 700; color: #1a2010; font-size: 13px; }

/* Period bar */
.bc-period {
  background: #f0ede0;
  padding: 8px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  border-bottom: 1px solid #e0dac8;
}
.bc-period-label { color: #6b7255; font-weight: 600; letter-spacing: 1px; font-size: 10px; text-transform: uppercase; }
.bc-period-val { font-weight: 700; color: #1a2010; }

/* Table */
.bc-body { padding: 0 0 0; }
.bc-body-inner { }
.bc-footer-area { padding-bottom: 16px; }
.bc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.bc-table thead th {
  background: #1a6640;
  color: #c9a227;
  padding: 8px 14px;
  text-align: left;
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.bc-table thead th.amt { text-align: right; }
.bc-table tbody td {
  padding: 7px 14px;
  border-bottom: 1px solid #eee;
  color: #2a3020;
  vertical-align: top;
}
.bc-table tbody td.amt { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.bc-table tbody tr:hover { background: #f7f5ed; }
.bc-table tbody tr.row-alt { background: #faf8f2; }
.bc-table tbody tr.row-pastdue { background: #fff8e6; }
.bc-table tbody tr.row-credit { background: #f0fff5; }
.bc-table tbody tr.row-subtotal { background: #eef5ea; font-weight: 700; }
.bc-table tbody tr.row-subtotal td { border-top: 2px solid #c9a227; color: #1a6640; }
.bc-table tfoot td {
  padding: 10px 14px;
  background: #0d4a2e;
  color: #c9a227;
  font-weight: 800;
  font-size: 14px;
  border-top: 2px solid #c9a227;
}
.bc-table tfoot td.amt { text-align: right; font-size: 16px; }
.bc-table tfoot td.credit { color: #4ade80; }
.mini-date { font-size: 10px; color: #888; font-weight: normal; margin-left: 4px; }

/* Notice */
.bc-notice {
  margin: 12px 16px 4px;
  background: #fffbea;
  border-left: 3px solid #c9a227;
  padding: 10px 14px;
  font-size: 12px;
  color: #5a4a10;
  line-height: 1.6;
  display: none;
}
.bc-notice strong { color: #8a6a10; }

/* Note */
.bc-note {
  margin: 6px 16px 0;
  font-size: 10.5px;
  color: #999;
  line-height: 1.6;
}

/* Watermark */
.bc-watermark {
  margin: 10px 16px 4px;
  font-size: 9px;
  color: rgba(100,100,100,0.35);
  font-family: monospace;
  letter-spacing: 0.5px;
  display: none;
}
.bc-watermark.visible { display: block; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text3);
}
.empty-state .icon { font-size: 40px; margin-bottom: 14px; }
.empty-state p { font-size: 13px; color: var(--text2); }

/* Toast */
#toast, .toast {
  position: fixed;
  top: 16px;
  left: 50%;
  background: #1a6640;
  color: #ffe9a8;
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid rgba(201,162,39,0.45);
  box-shadow: 0 8px 28px rgba(0,0,0,0.55);
  opacity: 0;
  transform: translate(-50%, -16px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 99999;
  max-width: min(92vw, 540px);
  text-align: center;
}
#toast.show, .toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── STAMP PANEL ── */
.tab-bar { display: flex; gap: 8px; margin-bottom: 16px; }
.tab-btn {
  font-family: var(--font-mono); font-size: 11px; font-weight: 700;
  padding: 7px 16px; border-radius: 8px; border: 1px solid var(--border2);
  background: transparent; color: var(--text3); cursor: pointer; transition: all 0.15s;
  letter-spacing: 0.5px;
}
.tab-btn.active { background: var(--gold-dim); border-color: var(--gold); color: var(--gold); }
.tab-btn:hover:not(.active) { border-color: var(--text3); color: var(--text2); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

.stamp-upload-drop {
  border: 2px dashed var(--border2); border-radius: 10px; padding: 28px;
  text-align: center; cursor: pointer; transition: all 0.2s; margin-bottom: 14px;
}
.stamp-upload-drop:hover, .stamp-upload-drop.drag-over { border-color: var(--gold); background: var(--gold-dim); }
.stamp-upload-drop .up-icon { font-size: 32px; margin-bottom: 8px; }
.stamp-upload-drop p { font-size: 12px; color: var(--text2); }
.stamp-upload-drop small { font-size: 10px; color: var(--text3); }
.stamp-fname { font-size: 11px; color: var(--gold); margin-top: 6px; }

.stamp-sig-drop {
  border: 1px dashed var(--border2); border-radius: 8px; padding: 14px;
  text-align: center; cursor: pointer; transition: all 0.15s; margin-bottom: 10px;
  font-size: 11px; color: var(--text3);
}
.stamp-sig-drop:hover { border-color: var(--gold); color: var(--gold); }
.sig-preview-img { max-height: 48px; max-width: 160px; margin-top: 8px; border-radius: 4px; border: 1px solid var(--border2); }

.stamp-pdf-preview {
  background: var(--card-bg); border-radius: 10px; overflow: auto;
  max-height: 500px; position: relative; display: flex; justify-content: center;
  align-items: flex-start; padding: 12px; margin-top: 12px; min-height: 200px;
}
#stamp-canvas { max-width: 100%; box-shadow: 0 4px 20px rgba(0,0,0,0.5); border-radius: 4px; }
.stamp-overlay-preview {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%) rotate(-20deg);
  pointer-events: none; z-index: 10; text-align: center;
}
.stamp-badge {
  font-size: clamp(24px, 6vw, 56px); font-weight: 900;
  border: 5px solid; padding: 10px 24px; border-radius: 6px;
  text-transform: uppercase; letter-spacing: 5px;
  mix-blend-mode: multiply; display: none;
}
.stamp-badge.paid { display: block; color: rgba(25,128,25,0.9); border-color: rgba(25,128,25,0.9); background: rgba(25,128,25,0.12); }
.stamp-badge.past-due { display: block; color: rgba(200,20,20,0.9); border-color: rgba(200,20,20,0.9); background: rgba(200,20,20,0.12); }
.stamp-badge .s-ts { font-size: 0.28em; display: block; margin-top: 3px; font-family: monospace; letter-spacing: 1px; font-weight: 700; }
.stamp-badge .s-rm { font-size: 0.22em; display: block; margin-top: 2px; font-style: italic; font-weight: 600; max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.no-pdf-msg { text-align: center; padding: 40px 20px; color: var(--text3); font-size: 13px; }

.btn-stamp-paid {
  background: linear-gradient(135deg, #11998e, #38ef7d); color: #fff;
  font-family: var(--font-head); font-size: 13px; font-weight: 700;
  padding: 10px 20px; border: none; border-radius: 9px; cursor: pointer; transition: all 0.2s;
}
.btn-stamp-paid:hover { opacity: 0.88; transform: translateY(-1px); }
.btn-stamp-pastdue {
  background: linear-gradient(135deg, #eb3349, #f45c43); color: #fff;
  font-family: var(--font-head); font-size: 13px; font-weight: 700;
  padding: 10px 20px; border: none; border-radius: 9px; cursor: pointer; transition: all 0.2s;
}
.btn-stamp-pastdue:hover { opacity: 0.88; transform: translateY(-1px); }
.btn-stamp-clear {
  background: transparent; border: 1px solid var(--border2); color: var(--text3);
  font-family: var(--font-head); font-size: 13px; font-weight: 700;
  padding: 10px 16px; border-radius: 9px; cursor: pointer; transition: all 0.15s;
}
.btn-stamp-clear:hover { border-color: var(--red); color: var(--red); }
.btn-stamp-dl {
  background: linear-gradient(135deg, #4facfe, #00f2fe); color: #fff;
  font-family: var(--font-head); font-size: 12px; font-weight: 700;
  padding: 10px 16px; border: none; border-radius: 9px; cursor: pointer; transition: all 0.2s;
}
.btn-stamp-dl:hover { opacity: 0.88; }
.stamp-btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

/* Section hint */
.field-hint { font-size: 11px; color: var(--text3); margin-top: 3px; }
.row-sep { border: none; border-top: 1px solid var(--border); margin: 4px 0 12px; }

/* ── PRINT ── */
@media print {
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
  html, body {
    margin: 0 !important; padding: 0 !important;
    background: #fff !important;
    height: auto !important;
    overflow: visible !important;
  }
  body > * { display: none !important; }
  body.printing-bill #print-area {
    display: block !important;
    position: static !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  body.printing-bill #print-area * { display: revert !important; }
  body.printing-bill #print-area .bill-card {
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    border: none !important;
    display: block !important;
    overflow: visible !important;
  }
  body.printing-bill #print-area .bill-card .bc-body { display: block !important; height: auto !important; min-height: 0 !important; }
  body.printing-bill #print-area .bill-card .bc-body-inner { display: block !important; height: auto !important; }
  body.printing-bill #print-area .bill-card .bc-footer-area { margin-top: 8px !important; }
  @page { margin: 10mm; size: A4 portrait; }
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .row2, .row3 { grid-template-columns: 1fr; }
  .bc-infobar { grid-template-columns: 1fr; }
  .bc-infobar-cell { border-right: none; border-bottom: 1px solid #e5e0d0; }
  .bc-header { flex-direction: column; align-items: flex-start; }
  .bc-meta { text-align: left; }
}
/* ---- tabs / copy / values / modal / stat (from prior build) ---- */

/* ═══ v3 ADDITIONS — tabs, analytics, copy, modal ═══ */
.app-tabs { display:flex; gap:8px; justify-content:center; margin:0 auto 22px; max-width:1360px; flex-wrap:wrap; }
.app-tab {
  font-family: var(--font-head); font-size:12px; font-weight:700; letter-spacing:1px;
  padding:10px 22px; border-radius:10px; border:1px solid var(--border2);
  background:var(--surface); color:var(--text2); cursor:pointer; transition:all .15s;
}
.app-tab:hover:not(.active){ border-color:var(--text3); color:var(--text); }
.app-tab.active{ background:var(--gold-dim); border-color:var(--gold); color:var(--gold); box-shadow:0 2px 12px rgba(212,168,67,.15); }
.app-pane{ display:none; }
.app-pane.active{ display:block; }

/* copy buttons */
.copy-btn{
  background:none; border:1px solid var(--border2); border-radius:6px; color:var(--text3);
  cursor:pointer; font-size:11px; padding:3px 8px; transition:all .15s; font-family:var(--font-mono);
  display:inline-flex; align-items:center; gap:4px; white-space:nowrap;
}
.copy-btn:hover{ border-color:var(--gold); color:var(--gold); background:var(--gold-dim); }
.meter-copy{ width:26px; height:26px; padding:0; justify-content:center; font-size:12px; }

/* values helper panel */
.values-panel{ margin-top:14px; }
.values-grid{ display:flex; flex-direction:column; gap:5px; }
.value-row{
  display:flex; align-items:center; justify-content:space-between; gap:8px;
  background:var(--surface2); border:1px solid var(--border2); border-radius:8px; padding:7px 11px;
}
.value-row .vlabel{ font-size:11px; color:var(--text2); }
.value-row .vval{ font-size:12px; color:var(--text); font-weight:500; margin-left:auto; margin-right:8px; font-variant-numeric:tabular-nums; }

/* save/load button variants */
.btn-save-hist{ background:linear-gradient(135deg,#c9a227,#e6c552); color:#1a1407; font-weight:700; letter-spacing:.3px; border:1px solid rgba(201,162,39,.55); box-shadow:0 4px 16px rgba(201,162,39,.28); }
.btn-save-hist:hover{ filter:brightness(1.05); box-shadow:0 6px 22px rgba(201,162,39,.42); transform:translateY(-1px); }
.btn-save-hist:active{ transform:translateY(0); }
.btn-load-prev{ background:linear-gradient(135deg,#0369a1,#0ea5e9); color:#fff; box-shadow:0 4px 16px rgba(3,105,161,.3); }
.unsaved-dot{ display:inline-block; width:8px; height:8px; border-radius:50%; background:var(--amber); margin-left:6px; vertical-align:middle; }

/* modal */
.modal-back{ position:fixed; inset:0; background:rgba(0,0,0,.7); z-index:9998; display:none; align-items:flex-start; justify-content:center; padding:40px 16px; overflow:auto; }
.modal-back.show{ display:flex; }
.modal{ background:var(--surface); border:1px solid var(--border2); border-radius:14px; padding:22px; max-width:560px; width:100%; box-shadow:0 20px 60px rgba(0,0,0,.6); }
.modal h3{ font-family:var(--font-head); color:var(--gold); font-size:15px; letter-spacing:1px; margin-bottom:14px; }
.modal-close{ float:right; background:none; border:none; color:var(--text3); font-size:20px; cursor:pointer; line-height:1; }
.modal-close:hover{ color:var(--red); }
.opt-check{ display:flex; align-items:center; gap:8px; padding:8px 10px; border:1px solid var(--border2); border-radius:8px; margin-bottom:6px; cursor:pointer; font-size:12px; color:var(--text2); }
.opt-check input{ width:auto; }
.opt-check:hover{ border-color:var(--gold); }

/* analytics */
.stat-grid{ display:grid; grid-template-columns:repeat(auto-fit,minmax(180px,1fr)); gap:14px; margin-bottom:20px; }
.stat-card{ background:var(--surface); border:1px solid var(--border); border-radius:12px; padding:16px 18px; }
.stat-card .sc-label{ font-size:10px; letter-spacing:1.5px; text-transform:uppercase; color:var(--text3); font-weight:700; }
.stat-card .sc-val{ font-size:24px; font-weight:800; font-family:var(--font-head); margin-top:6px; }
.sc-val.green{ color:var(--green-bright); } .sc-val.red{ color:var(--red); } .sc-val.gold{ color:var(--gold2); } .sc-val.blue{ color:#60a5fa; }
.sc-sub{ font-size:11px; color:var(--text3); margin-top:3px; }
.an-table{ width:100%; border-collapse:collapse; font-size:12px; margin-top:8px; }
.an-table th{ background:var(--surface2); color:var(--gold); text-align:left; padding:8px 10px; font-size:10px; letter-spacing:1px; text-transform:uppercase; font-weight:700; position:sticky; top:0; }
.an-table th.num, .an-table td.num{ text-align:right; font-variant-numeric:tabular-nums; }
.an-table td{ padding:7px 10px; border-bottom:1px solid var(--border); color:var(--text); }
.an-table tr:hover td{ background:var(--surface2); }
.an-table tfoot td{ font-weight:700; color:var(--gold2); border-top:2px solid var(--border2); background:var(--surface2); }
.an-table .pos{ color:var(--red); } .an-table .neg{ color:var(--green-bright); }
.an-table-wrap{ max-height:420px; overflow:auto; border:1px solid var(--border); border-radius:10px; }
.an-chart-wrap{ background:var(--surface); border:1px solid var(--border); border-radius:12px; padding:16px; margin-bottom:18px; }
.an-chart-wrap canvas{ max-height:300px; }
.an-summary{ background:#fffbea; color:#5a4a10; border-left:3px solid var(--gold); border-radius:8px; padding:12px 16px; font-size:13px; line-height:1.7; margin-bottom:18px; }
.an-summary strong{ color:#8a6a10; }
.rep-pill{ display:inline-block; padding:2px 8px; border-radius:20px; font-size:10px; font-weight:700; letter-spacing:.5px; }
.rep-GOOD{ background:rgba(74,222,128,.15); color:#22c55e; }
.rep-AVERAGE{ background:rgba(251,191,36,.15); color:#d97706; }
.rep-BAD{ background:rgba(248,113,113,.15); color:#dc2626; }
.rep-TERRIBLE{ background:rgba(190,18,60,.2); color:#be123c; }
.status-pill{ display:inline-block; padding:2px 8px; border-radius:20px; font-size:10px; font-weight:700; }
.st-paid{ background:rgba(74,222,128,.15); color:#22c55e; }
.st-partial{ background:rgba(251,191,36,.15); color:#d97706; }
.st-unpaid{ background:rgba(248,113,113,.15); color:#dc2626; }
.an-section-title{ font-family:var(--font-head); font-size:13px; font-weight:700; letter-spacing:1px; color:var(--text); margin:24px 0 10px; padding-bottom:6px; border-bottom:1px solid var(--border); }

/* ════════ Nizami Complex — additions for the v4 rewrite ════════ */

/* form grids */
.grid-3-28{ display:grid; grid-template-columns:1fr 1fr 28px; gap:8px; align-items:end; }
.grid-prim{ display:grid; grid-template-columns:auto 1fr 1fr; gap:10px; align-items:end; margin-top:6px; }
.grid-room-a{ display:grid; grid-template-columns:1fr 1fr 90px 70px 28px; gap:8px; align-items:end; }
.grid-3{ display:grid; grid-template-columns:1fr 1fr 1fr; gap:8px; margin-top:8px; }
.grid-2-wide{ display:grid; grid-template-columns:1fr 1fr; gap:8px; margin-top:8px; }
.grid-dev{ display:grid; grid-template-columns:1fr 90px 90px 28px; gap:8px; align-items:end; }
.grid-item{ display:grid; grid-template-columns:130px 1fr 28px; gap:8px; align-items:end; }
.grid-2{ display:grid; grid-template-columns:1fr 1fr; gap:8px; margin-top:6px; }
.flag-row{ display:flex; gap:16px; margin:8px 0; flex-wrap:wrap; }
.mini-check{ display:inline-flex; align-items:center; gap:5px; font-size:11px; color:var(--text2); cursor:pointer; user-select:none; }
.mini-check input{ width:auto; }
.primary-check{ font-weight:600; color:var(--gold); }

/* hover help bubble */
.tip{ display:inline-block; width:14px; height:14px; line-height:14px; text-align:center; border-radius:50%;
  background:var(--border2); color:var(--text2); font-size:10px; cursor:help; margin-left:3px; }

/* per-charge waivers */
.waiver-box{ margin-top:10px; background:var(--surface2); border:1px solid var(--border); border-radius:8px; padding:9px 11px; }
.waiver-grid{ display:grid; grid-template-columns:repeat(auto-fit,minmax(130px,1fr)); gap:6px 16px; margin-top:6px; }
.waiver-cell{ display:flex; gap:12px; align-items:center; }

/* meters */
.meter-wrap{ margin-top:10px; border-top:1px dashed var(--border); padding-top:9px; }
.meter-head{ display:flex; justify-content:space-between; align-items:center; gap:8px; }
.meter-list{ display:flex; flex-direction:column; gap:6px; margin:7px 0; }
.meter-row{ display:grid; grid-template-columns:1fr 80px 80px 1fr 1fr 26px 26px; gap:5px; align-items:center; }

/* analytics */
.an-h{ font-family:var(--font-head); color:var(--gold); font-size:13px; letter-spacing:1px; margin:22px 0 8px; }
.range-note{ font-size:11px; color:var(--text3); margin-bottom:12px; }
.table-wrap{ overflow-x:auto; margin-bottom:6px; }
.stat-val{ font-size:22px; font-weight:800; font-family:var(--font-head); }
.stat-label{ font-size:10px; letter-spacing:1.5px; text-transform:uppercase; color:var(--text3); font-weight:700; margin-top:4px; }
.stat-sub{ font-size:11px; color:var(--text2); margin-top:3px; }
.paid-cell{ font-weight:700; font-variant-numeric:tabular-nums; }
.rep-src{ font-size:9px; color:var(--text3); text-transform:uppercase; margin-left:2px; }
.chart-wrap{ background:var(--surface); border:1px solid var(--border); border-radius:10px; padding:12px; margin:10px 0; }
.an-filters{ display:flex; gap:10px; flex-wrap:wrap; align-items:end; margin-bottom:16px; }
.an-filters .preset-btn{ font-size:11px; padding:7px 12px; border:1px solid var(--border2); background:var(--surface); color:var(--text2); border-radius:8px; cursor:pointer; }
.an-filters .preset-btn:hover{ border-color:var(--gold); color:var(--gold); }

/* copyable values panel (this rewrite's class names) */
.val-row{ display:flex; align-items:center; gap:8px; padding:5px 9px; border:1px solid var(--border); border-radius:7px; margin-bottom:4px; background:var(--surface); }
.val-label{ font-size:11px; color:var(--text2); min-width:118px; }
.val-num{ font-size:12px; color:var(--text); font-weight:500; margin-left:auto; margin-right:6px; font-variant-numeric:tabular-nums; }

/* carry-forward dues hint */
#carryHint{ display:none; margin:8px 0; padding:8px 11px; border:1px solid var(--amber); background:rgba(251,191,36,.08); border-radius:8px; font-size:12px; color:var(--text); }

/* building-costs editor */
.bc-editor{ background:var(--surface); border:1px solid var(--border); border-radius:12px; padding:16px 18px; margin-top:20px; }
.bc-grid{ display:grid; grid-template-columns:repeat(auto-fit,minmax(130px,1fr)); gap:10px; margin-top:10px; }

@media (max-width:640px){
  .grid-room-a, .grid-dev, .grid-3, .grid-2-wide, .grid-item, .grid-2, .grid-prim, .grid-3-28{ grid-template-columns:1fr 1fr; }
  .meter-row{ grid-template-columns:1fr 1fr; }
}

/* ════════════════════════════════════════════════════════════
   UI REFINEMENT PASS (app chrome only — no .bill-card / .bc-* touched)
   Adds the previously-undefined two-column layout, restores the
   intended type scale, and polishes panels, tabs, inputs & buttons.
   ════════════════════════════════════════════════════════════ */

/* ── Generate-pane layout (these classes were used in HTML but never defined) ── */
.bill-layout{
  display:grid;
  grid-template-columns:minmax(0,1fr) minmax(0,1.04fr);
  gap:22px;
  align-items:start;
}
.form-col{ min-width:0; display:flex; flex-direction:column; }
.preview-col{
  min-width:0;
  position:sticky;
  top:16px;
}
.preview-col .panel{ margin-bottom:0; }
@media (max-width:1024px){
  .bill-layout{ grid-template-columns:1fr; gap:16px; }
  .preview-col{ position:static; }
}

/* ── Panels: gentle elevation + hairline top sheen + gold edge on hover ── */
.panel{
  position:relative;
  background:linear-gradient(180deg, #1c2029 0%, var(--surface) 60%);
  box-shadow:0 1px 0 rgba(255,255,255,.02) inset, 0 6px 22px -14px rgba(0,0,0,.7);
  transition:border-color .18s ease, box-shadow .18s ease;
}
.panel:hover{
  border-color:var(--border2);
  box-shadow:0 1px 0 rgba(255,255,255,.03) inset, 0 10px 28px -16px rgba(0,0,0,.8);
}

/* ── Tabs: tighter, with a soft active glow ── */
.app-tab{ transition:all .18s ease; }
.app-tab.active{
  box-shadow:0 2px 14px rgba(212,168,67,.18), 0 0 0 1px rgba(212,168,67,.25) inset;
}

/* ── Inputs: hover affordance before focus ── */
input[type="text"]:hover:not(:focus),
input[type="number"]:hover:not(:focus),
input[type="date"]:hover:not(:focus),
select:hover:not(:focus),
textarea:hover:not(:focus){ border-color:var(--text3); }

/* ── Card action toolbar: primary action leads, helpers align as a row ── */
.card-actions{ align-items:center; padding-bottom:2px; }
.card-actions .btn-generate{ flex:1 1 150px; }
.card-actions .copy-btn{ padding:7px 11px; font-size:11px; border-radius:8px; }

/* ── Section sub-labels: tighten rhythm in the long Adjustments panel ── */
.sub-label{ margin-top:14px; }
.multi-list + .btn-add-item{ margin-top:2px; }

/* ── Empty preview state: calmer, on-brand ── */
.empty-state{ padding:72px 20px; }
.empty-state .icon{ opacity:.55; filter:grayscale(.2); }
.empty-state p{ letter-spacing:.3px; }

/* ── Dark scrollbars so panels/tables don't show bright OS bars ── */
*{ scrollbar-width:thin; scrollbar-color:var(--border2) transparent; }
*::-webkit-scrollbar{ width:10px; height:10px; }
*::-webkit-scrollbar-thumb{ background:var(--border2); border-radius:10px; border:2px solid transparent; background-clip:content-box; }
*::-webkit-scrollbar-thumb:hover{ background:var(--text3); background-clip:content-box; }
*::-webkit-scrollbar-track{ background:transparent; }

/* ── Gold-tinted text selection to match the brand ── */
::selection{ background:rgba(212,168,67,.28); color:var(--text); }

/* ── Honor reduced-motion preferences ── */
@media (prefers-reduced-motion:reduce){
  *,*::before,*::after{ transition:none !important; animation:none !important; scroll-behavior:auto !important; }
}

/* ════════════════════════════════════════════════════════════
   ANALYTICS CONTRAST PASS — richer stat cards, semantic value
   colors, higher-contrast tables & headings. App chrome only.
   ════════════════════════════════════════════════════════════ */

/* range note + section headings: lift off the background */
.range-note{ color:var(--text2); }
.an-h{
  display:flex; align-items:center; gap:9px;
  color:var(--text); font-size:13px; font-weight:700; letter-spacing:.4px;
  margin:26px 0 11px; padding-bottom:0; border-bottom:none;
}
.an-h::before{
  content:''; width:4px; height:15px; border-radius:2px; flex:0 0 auto;
  background:linear-gradient(180deg, var(--gold2), var(--gold));
}

/* stat cards: subtle gradient, semantic accent rail, brighter labels */
.stat-grid{ gap:14px; }
.stat-card{
  position:relative; overflow:hidden;
  background:linear-gradient(158deg, #1e222c 0%, #181b22 100%);
  border:1px solid var(--border2);
  border-radius:14px; padding:17px 18px 15px;
  box-shadow:0 10px 26px -20px rgba(0,0,0,.9);
}
.stat-card::before{
  content:''; position:absolute; left:0; top:0; bottom:0; width:3px;
  background:var(--gold); opacity:.5;
}
.stat-card:has(.is-good)::before{ background:var(--green-bright); opacity:.8; }
.stat-card:has(.is-warn)::before{ background:var(--amber); opacity:.8; }
.stat-card:has(.is-bad)::before{ background:var(--red); opacity:.8; }
.stat-card:has(.is-info)::before{ background:#60a5fa; opacity:.8; }
.stat-val{ font-size:26px; line-height:1.05; letter-spacing:.4px; color:var(--text); }
.stat-val.is-good{ color:var(--green-bright); }
.stat-val.is-warn{ color:var(--amber); }
.stat-val.is-bad{ color:var(--red); }
.stat-val.is-info{ color:#60a5fa; }
.stat-val.is-gold{ color:var(--gold2); }
.stat-label{ color:var(--text2); font-size:10px; letter-spacing:2px; margin-top:8px; }
.stat-sub{ color:var(--text2); }

/* tables: contained card, stronger header, zebra rows, calmer hover */
.table-wrap{
  border:1px solid var(--border2); border-radius:12px;
  overflow:hidden; overflow-x:auto; background:var(--surface);
  margin-bottom:8px;
}
.an-table th{
  background:#141821; color:var(--gold2);
  border-bottom:1px solid var(--border2);
  padding:9px 12px; letter-spacing:1px;
}
.an-table td{ color:var(--text); padding:8px 12px; border-bottom:1px solid var(--border); }
.an-table tbody tr:nth-child(even) td{ background:rgba(255,255,255,.018); }
.an-table tbody tr:hover td{ background:#1f2632; }
.an-table tbody tr:last-child td{ border-bottom:none; }

/* filter preset buttons: defined surface + clear hover */
.an-filters .preset-btn{
  background:var(--surface2); border-color:var(--border2);
  color:var(--text2); font-weight:600;
}
.an-filters .preset-btn:hover{ background:var(--gold-dim); border-color:var(--gold); color:var(--gold2); }

/* misc contrast: form section dividers a touch brighter */
.sub-label{ color:var(--text2); }

/* extra stat-value hues + accent rails for Water / Internet */
.stat-val.is-water{ color:#22d3ee; }
.stat-val.is-violet{ color:#a78bfa; }
.stat-card:has(.is-water)::before{ background:#22d3ee; opacity:.8; }
.stat-card:has(.is-violet)::before{ background:#a78bfa; opacity:.8; }

/* crisp paid/total cell — solid weight + tabular figures kill the "blurry" look */
.an-table td.paid-cell{
  font-weight:700; font-variant-numeric:tabular-nums; letter-spacing:.3px;
  white-space:nowrap;
}
.an-table tbody tr:hover td.paid-cell{ filter:brightness(1.08); }

/* building-costs save button — on-theme green, not the purple History style */
.btn-bc-save{
  margin-top:14px; padding:9px 18px; border-radius:9px; cursor:pointer;
  font-family:var(--font-mono); font-size:12px; font-weight:600; color:#04130b;
  border:1px solid transparent;
  background:linear-gradient(135deg, var(--green-bright), var(--green2));
  box-shadow:0 4px 16px rgba(34,197,94,.20);
  transition:filter .15s ease, transform .05s ease;
}
.btn-bc-save:hover{ filter:brightness(1.06); }
.btn-bc-save:active{ transform:translateY(1px); }

/* quick-load: carry-over toggle */
.io-check{ display:flex; align-items:center; gap:8px; margin-top:8px; font-size:12px; color:var(--text2); cursor:pointer; }
.io-check input{ width:auto; margin:0; }

/* ═══ v5: login overlay + session bar ═══ */
.login-overlay{ position:fixed; inset:0; z-index:9999; display:flex; align-items:center; justify-content:center;
  background:rgba(8,12,10,.92); backdrop-filter:blur(6px); }
.login-card{ width:min(360px,92vw); background:var(--panel,#12161a); border:1px solid rgba(200,164,21,.25);
  border-radius:14px; padding:26px 24px; display:flex; flex-direction:column; gap:12px; box-shadow:0 20px 60px rgba(0,0,0,.5); }
.login-title{ font-family:'Syne',sans-serif; font-weight:800; font-size:22px; color:var(--gold2,#daa520); text-align:center; }
.login-sub{ font-size:12px; color:var(--text2,#9aa5ad); text-align:center; margin-bottom:6px; }
.login-card input{ width:100%; padding:11px 12px; border-radius:9px; border:1px solid rgba(255,255,255,.12);
  background:rgba(255,255,255,.04); color:var(--text,#e8edf0); font-size:14px; box-sizing:border-box; }
.login-card input:focus{ outline:none; border-color:var(--gold,#c8a415); }
.login-btn{ margin-top:4px; padding:11px; border-radius:9px; border:none; cursor:pointer; font-weight:700; font-size:14px;
  color:#0d1a12; background:linear-gradient(135deg,#daa520,#b8860b); }
.login-btn:disabled{ opacity:.6; cursor:default; }
.login-err{ font-size:12px; color:#f87171; text-align:center; }
.login-foot{ font-size:11px; color:var(--text2,#9aa5ad); text-align:center; margin-top:4px; }
.session-bar{ position:fixed; top:8px; right:10px; z-index:50; display:flex; align-items:center; gap:8px; }
.session-badge{ font-size:11px; color:var(--text2,#9aa5ad); background:rgba(255,255,255,.05);
  padding:3px 9px; border-radius:20px; border:1px solid rgba(255,255,255,.08); }
.session-logout{ font-size:11px; color:var(--text2,#9aa5ad); background:transparent; cursor:pointer;
  border:1px solid rgba(255,255,255,.12); border-radius:20px; padding:3px 9px; }
.session-logout:hover{ color:#f87171; border-color:rgba(248,113,113,.4); }
body[data-role="manager"] .admin-only{ display:none !important; }

/* top-bar Reset button (hard refresh) */
.app-tabs{ position:relative; }
.tab-reset{ margin-left:auto; color:var(--text2); }
.tab-reset:hover{ color:var(--gold2); border-color:var(--gold); }