:root {
  --bg: #0a0c14;
  --bg-radial: #131629;
  --card: #12141f;
  --card-2: #171a29;
  --border: #262a3d;
  --text: #e7e9f3;
  --text-dim: #8b8fa8;
  --text-faint: #5c6080;
  --accent: #6d6af7;
  --accent-2: #8b7cf6;
  --green: #34d399;
  --amber: #f5a623;
  --red: #ef5a6f;
  --blue: #38bdf8;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 20% -10%, var(--bg-radial), var(--bg) 60%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
}

button, select, input, textarea { font-family: inherit; font-size: inherit; color: inherit; }

a { color: inherit; }

.hidden { display: none !important; }

/* ---- Top nav ---- */
header.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 24px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: rgba(10,12,20,0.9); backdrop-filter: blur(8px); z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; }
.brand .name { font-weight: 700; font-size: 16px; }
.brand .name b { color: var(--accent-2); }
.brand .subtitle { font-size: 10px; letter-spacing: 0.06em; color: var(--text-faint); text-transform: uppercase; }

nav.tabs { display: flex; gap: 6px; }
nav.tabs button {
  background: transparent; border: 1px solid transparent; color: var(--text-dim);
  padding: 8px 14px; border-radius: 20px; cursor: pointer; display: flex; align-items: center; gap: 6px;
  transition: all .15s;
}
nav.tabs button:hover { color: var(--text); }
nav.tabs button.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: white; }

.topbar-right { display: flex; align-items: center; gap: 10px; }
select.account-switch, .pill-select {
  background: var(--card-2); border: 1px solid var(--border); color: var(--text);
  padding: 7px 12px; border-radius: 20px; cursor: pointer;
}
.itc-pill {
  background: rgba(52,211,153,0.12); border: 1px solid rgba(52,211,153,0.35); color: var(--green);
  padding: 7px 14px; border-radius: 20px; font-weight: 600; display:flex; align-items:center; gap:6px;
}
.icon-btn {
  background: var(--card-2); border: 1px solid var(--border); color: var(--text-dim);
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer; display:flex; align-items:center; justify-content:center;
}
.icon-btn:hover { color: var(--text); }

.hamburger-btn { display: none; }

main { max-width: 1400px; margin: 0 auto; padding: 24px; }

/* ---- Cards / grid ---- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px;
}
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.grid-3 { display: grid; grid-template-columns: 1.1fr 1.6fr 1.1fr; gap: 16px; margin-bottom: 16px; }
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
@media (max-width: 1100px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.stat-card { border-left: 3px solid var(--accent); }
.stat-card.green { border-left-color: var(--green); }
.stat-card.amber { border-left-color: var(--amber); }
.stat-card.blue { border-left-color: var(--blue); }
.stat-top { display: flex; justify-content: space-between; align-items: flex-start; color: var(--text-dim); font-size: 13px; }
.stat-value { font-size: 26px; font-weight: 700; margin: 8px 0 4px; }
.stat-sub { color: var(--text-faint); font-size: 12px; }

.section-label { font-size: 11px; letter-spacing: .06em; color: var(--text-faint); text-transform: uppercase; margin-bottom: 4px; }
.card h3 { margin: 0 0 2px; font-size: 15px; }
.card .desc { color: var(--text-faint); font-size: 12px; margin-bottom: 12px; }

.segmented { display: inline-flex; background: var(--card-2); border: 1px solid var(--border); border-radius: 20px; padding: 3px; gap: 2px; }
.segmented button { background: transparent; border: none; color: var(--text-dim); padding: 5px 12px; border-radius: 16px; cursor: pointer; font-size: 12px; }
.segmented button.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: white; }

.filter-chips { display: flex; gap: 8px; }
.filter-chips button { background: var(--card-2); border: 1px solid var(--border); color: var(--text-dim); padding: 5px 12px; border-radius: 8px; cursor: pointer; font-size: 12px; }
.filter-chips button.active { background: var(--accent); color: white; border-color: var(--accent); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--text-faint); font-size: 11px; letter-spacing: .04em; text-transform: uppercase; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr.row-clickable:hover { background: rgba(255,255,255,0.02); }

.badge { display: inline-block; padding: 3px 9px; border-radius: 6px; font-size: 11px; font-weight: 700; letter-spacing: .02em; }
.badge.buyer { background: rgba(109,106,247,0.15); color: var(--accent-2); border: 1px solid rgba(109,106,247,0.3); }
.badge.eligible { background: rgba(52,211,153,0.15); color: var(--green); }
.badge.pending { background: rgba(245,166,35,0.15); color: var(--amber); }
.badge.paid { background: rgba(52,211,153,0.15); color: var(--green); }
.badge.ineligible { background: rgba(239,90,111,0.15); color: var(--red); }

button.btn { background: var(--card-2); border: 1px solid var(--border); color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; display:inline-flex; align-items:center; gap:6px; }
button.btn:hover { border-color: var(--accent); }
button.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; color: white; }
button.btn.danger { background: rgba(239,90,111,0.12); border-color: rgba(239,90,111,0.3); color: var(--red); }
button.btn.small { padding: 5px 10px; font-size: 12px; }
button.icon-only { padding: 6px 8px; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-faint); }
.empty-state .icon { font-size: 32px; margin-bottom: 10px; }

/* ---- Recent invoices list (Dashboard) ---- */
.recent-row {
  display: flex; align-items: center; gap: 10px; padding: 10px; border-bottom: 1px solid var(--border); font-size: 13px;
}
.recent-row:last-child { border-bottom: none; }
.recent-row.row-clickable { cursor: pointer; }
.recent-row.row-clickable:hover { background: rgba(255,255,255,0.02); }
.recent-header { color: var(--text-faint); font-size: 11px; letter-spacing: .04em; text-transform: uppercase; cursor: default; }
.recent-header:hover { background: none; }
.rr-buyer { flex: 1.1; } .rr-invoice { flex: 1.4; } .rr-vendor { flex: 1.3; }
.rr-amount { flex: 1; } .rr-itc { flex: 1.2; } .rr-action { flex: 0.8; text-align: right; }

.chart-wrap { width: 100%; }

/* ---- Ledger list ---- */
.ledger-row {
  display: flex; align-items: center; gap: 10px; padding: 10px; border-bottom: 1px solid var(--border); font-size: 13px;
}
.ledger-row:last-child { border-bottom: none; }
.ledger-row.ledger-header { color: var(--text-faint); font-size: 11px; letter-spacing: .04em; text-transform: uppercase; }
.lg-check { flex: 0 0 20px; } .lg-buyer { flex: 1.1; } .lg-quarter { flex: 0.9; }
.lg-invoice { flex: 1.3; } .lg-amount { flex: 1; } .lg-payment { flex: 1; }
.lg-itc { flex: 1.1; } .lg-actions { flex: 1.2; }

.ledger-search-row { display: flex; gap: 8px; margin-bottom: 14px; }
.ledger-search-row input { flex: 1; }
.filter-toggle-btn { display: flex; flex: 0 0 auto; }
.mobile-export-btn { display: none; }

.ledger-filters { display: none; }
.ledger-filters.filters-open { display: block; }

.status-chip { padding: 7px 14px; border-radius: 20px; font-size: 12px; font-weight: 600; background: var(--card-2); border: 1px solid var(--border); color: var(--text-dim); }
.status-chip.on { background: rgba(52,211,153,0.12); border-color: rgba(52,211,153,0.35); color: var(--green); }

.ledger-pagination { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.ledger-pagination select { width: auto; }
.ledger-pagination button:disabled { opacity: .4; cursor: default; }

/* ---- ITC utilisation list ---- */
.itc-row {
  display: flex; align-items: center; gap: 10px; padding: 10px; border-bottom: 1px solid var(--border); font-size: 13px;
}
.itc-row:last-child { border-bottom: none; }
.itc-row.itc-header { color: var(--text-faint); font-size: 11px; letter-spacing: .04em; text-transform: uppercase; }
.itc-date { flex: 1; } .itc-account { flex: 1.2; } .itc-period { flex: 1.2; } .itc-amount { flex: 1; } .itc-actions { flex: 0.8; }

/* ---- Voucher list ---- */
.voucher-row {
  display: flex; align-items: center; gap: 10px; padding: 10px; border-bottom: 1px solid var(--border); font-size: 13px;
}
.voucher-row:last-child { border-bottom: none; }
.voucher-row.voucher-header { color: var(--text-faint); font-size: 11px; letter-spacing: .04em; text-transform: uppercase; }
.vc-voucher { flex: 1.1; } .vc-vendor { flex: 1.3; } .vc-amount { flex: 1; }
.vc-mode { flex: 1.2; } .vc-challan { flex: 1; } .vc-auth { flex: 1; } .vc-actions { flex: 0.6; }

/* ---- Forms ---- */
label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
input[type=text], input[type=number], input[type=date], input[type=file], input[type=email], input[type=password], select, textarea {
  width: 100%; background: var(--card-2); border: 1px solid var(--border); color: var(--text);
  padding: 9px 11px; border-radius: 8px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.field { margin-bottom: 14px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-section-title { color: var(--accent-2); font-weight: 600; font-size: 13px; margin: 20px 0 12px; display: flex; align-items: center; gap: 6px; }
.form-section-title:first-child { margin-top: 0; }
.checkbox-row { display: flex; gap: 10px; align-items: flex-start; background: var(--card-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.checkbox-row input { width: auto; margin-top: 2px; }
.checkbox-row .ctext { font-size: 13px; }
.checkbox-row .ctext .sub { color: var(--text-faint); font-size: 11px; }

.compute-panel { background: var(--card-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.compute-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13px; color: var(--text-dim); }
.compute-row.total { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 12px; font-weight: 700; color: var(--text); font-size: 15px; }
.verified-badge { background: rgba(52,211,153,0.12); border: 1px solid rgba(52,211,153,0.35); color: var(--green); text-align: center; padding: 8px; border-radius: 8px; font-size: 13px; font-weight: 600; margin-bottom: 14px; }

.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 40px 20px; text-align: center;
  cursor: pointer; color: var(--text-dim);
}
.dropzone:hover { border-color: var(--accent); }
.dropzone .big { font-size: 15px; color: var(--text); margin: 8px 0 4px; }
.dropzone .small { font-size: 12px; color: var(--text-faint); }

.bill-preview { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--card-2); }
.bill-preview img { display: block; width: 100%; max-height: 520px; object-fit: contain; background: #000; }
.bill-preview iframe { display: block; width: 100%; height: 520px; border: none; }
.bill-preview.compact img { max-height: 340px; }
.bill-preview.compact iframe { height: 340px; }

/* ---- Modal ---- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); width: 640px; max-width: 92vw; max-height: 88vh; overflow-y: auto; padding: 22px; }
.modal.wide { width: 900px; }
.modal-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
.modal-header h2 { margin: 0 0 2px; font-size: 17px; }
.modal-header .desc { color: var(--text-faint); font-size: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.bank-item { display: flex; justify-content: space-between; align-items: center; background: var(--card-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; margin-bottom: 8px; }
.bank-item .name { font-weight: 600; }
.bank-item .sub { color: var(--text-faint); font-size: 12px; }

canvas { max-width: 100%; }

.toast { position: fixed; bottom: 20px; right: 20px; background: var(--card-2); border: 1px solid var(--accent); padding: 12px 18px; border-radius: 8px; z-index: 200; box-shadow: 0 10px 30px rgba(0,0,0,0.4); }

.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 360px; max-width: 100%; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; }

/* ---- Mobile ---- */
@media (max-width: 860px) {
  main { padding: 14px; }
  .hamburger-btn { display: flex; }

  header.topbar { flex-wrap: wrap; padding: 10px 14px; }
  nav.tabs, .topbar-right { display: none; flex-basis: 100%; }
  header.topbar.nav-open nav.tabs, header.topbar.nav-open .topbar-right { display: flex; }
  nav.tabs { flex-direction: column; gap: 4px; margin-top: 12px; }
  nav.tabs button { justify-content: flex-start; padding: 10px 14px; }
  .topbar-right {
    flex-wrap: wrap; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border);
  }
  select.account-switch { flex: 1 1 100%; }
  .itc-pill { flex: 1 1 auto; justify-content: center; }

  .field-row { grid-template-columns: 1fr; gap: 0; }
  .modal { padding: 16px; }

  table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }

  .grid-4 > *, .grid-3 > *, .grid-2 > * { min-width: 0; }

  .recent-card-head { flex-wrap: wrap; gap: 10px; }
  .recent-card-head button { flex: 1 1 100%; white-space: nowrap; justify-content: center; }

  .recent-row.recent-header { display: none; }
  .recent-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    grid-template-areas:
      "buyer   itc     action"
      "invoice vendor  vendor"
      "invoice amount  amount";
    column-gap: 8px; row-gap: 4px; align-items: center;
  }
  .rr-buyer   { grid-area: buyer; }
  .rr-invoice { grid-area: invoice; align-self: start; }
  .rr-itc     { grid-area: itc; justify-self: end; }
  .rr-action  { grid-area: action; justify-self: end; }
  .rr-vendor  { grid-area: vendor; justify-self: end; text-align: right; color: var(--text-dim); }
  .rr-amount  { grid-area: amount; justify-self: end; text-align: right; font-weight: 700; }

  /* Ledger toolbar: bank options moved into Settings, export moved next to heading */
  .mobile-export-btn { display: flex; }
  #btn-export-csv, #btn-bank-options { display: none; }

  .desc-hide-mobile { display: none; }

  /* Ledger row: stacked card, no horizontal scroll */
  .ledger-row.ledger-header { display: none; }
  .ledger-row { flex-wrap: wrap; }
  .lg-check { display: none; }
  .ledger-row:not(.ledger-header) {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "buyer   payment"
      "invoice amount"
      "quarter itc"
      "actions actions";
    column-gap: 8px; row-gap: 4px; align-items: start;
  }
  .lg-buyer   { grid-area: buyer; }
  .lg-invoice { grid-area: invoice; }
  .lg-quarter { grid-area: quarter; }
  .lg-payment { grid-area: payment; justify-self: end; text-align: right; }
  .lg-amount  { grid-area: amount; justify-self: end; text-align: right; }
  .lg-itc     { grid-area: itc; justify-self: end; text-align: right; }
  .lg-actions { grid-area: actions; margin-top: 4px; }
  .lg-actions > div { justify-content: flex-end; }

  /* Voucher row: stacked card, no horizontal scroll */
  .voucher-row.voucher-header { display: none; }
  .voucher-row:not(.voucher-header) {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "voucher amount"
      "vendor  mode"
      "challan auth"
      "actions actions";
    column-gap: 8px; row-gap: 4px; align-items: start;
  }
  .vc-voucher { grid-area: voucher; }
  .vc-vendor  { grid-area: vendor; }
  .vc-amount  { grid-area: amount; justify-self: end; text-align: right; font-weight: 700; }
  .vc-mode    { grid-area: mode; justify-self: end; text-align: right; }
  .vc-challan { grid-area: challan; }
  .vc-auth    { grid-area: auth; justify-self: end; text-align: right; }
  .vc-actions { grid-area: actions; justify-self: end; margin-top: 4px; }

  /* ITC row: stacked card, no horizontal scroll */
  .itc-row.itc-header { display: none; }
  .itc-row:not(.itc-header) {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "date    amount"
      "account period"
      "actions actions";
    column-gap: 8px; row-gap: 4px; align-items: start;
  }
  .itc-date    { grid-area: date; }
  .itc-account { grid-area: account; }
  .itc-period  { grid-area: period; justify-self: end; text-align: right; }
  .itc-amount  { grid-area: amount; justify-self: end; text-align: right; font-weight: 700; }
  .itc-actions { grid-area: actions; justify-self: end; margin-top: 4px; }

  .ledger-pagination { flex-direction: column; align-items: stretch; }
}

/* ---- Print ---- */
#print-area { display: none; }

@media print {
  @page { size: A4; margin: 15mm; }
  body > *:not(#print-area) { display: none !important; }
  body { background: #fff !important; }
  #print-area { display: block !important; color: #000; background: #fff; font-family: Arial, Helvetica, sans-serif; }
  .print-doc { page-break-after: always; }
  .print-doc:last-child { page-break-after: auto; }
  .print-doc * { color: #000 !important; background: #fff !important; box-shadow: none !important; }
  .print-doc h1 { font-size: 19px; margin: 0 0 4px; }
  .print-doc h2 { font-size: 14px; margin: 16px 0 8px; border-bottom: 1.5px solid #000; padding-bottom: 4px; }
  .print-doc .print-meta { font-size: 12px; margin-bottom: 4px; }
  .print-doc .meta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
  .print-doc .box { border: 1px solid #000 !important; padding: 8px 10px; border-radius: 0; }
  .print-doc .p-label { font-size: 10px; letter-spacing: .04em; text-transform: uppercase; margin-bottom: 2px; }
  .print-doc .p-value { font-size: 13px; font-weight: 700; }
  .print-doc table { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
  .print-doc th, .print-doc td { border: 1px solid #000 !important; padding: 6px 9px; text-align: left; font-size: 12px; }
  .print-doc th { font-weight: 700; }
  .print-doc tr.total-row td { font-weight: 700; font-size: 13px; }
  .print-doc .bill-thumb { width: 100%; max-width: 100%; height: 140mm; max-height: 140mm; object-fit: contain; border: 1px solid #000 !important; display: block; }
  .print-doc .sig-row { display: flex; justify-content: space-between; margin-top: 60px; }
  .print-doc .sig-line { border-top: 1px solid #000; width: 220px; padding-top: 5px; font-size: 11px; text-align: center; }
}
