:root {
  --navy: #10233f;
  --navy-light: #16305a;
  --accent: #d97706;
  --accent-light: #f59e0b;
  --bg: #f4f6f9;
  --card: #ffffff;
  --border: #e2e6ed;
  --text: #1a2233;
  --text-muted: #6b7688;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --blue: #2563eb;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

a { color: inherit; text-decoration: none; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  background: var(--navy);
  color: #dce4f2;
  flex-shrink: 0;
  padding: 20px 0;
}
.sidebar .brand {
  padding: 0 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 12px;
}
.sidebar .brand .name { font-weight: 700; font-size: 16px; color: #fff; }
.sidebar .brand .tag { font-size: 10.5px; letter-spacing: 0.06em; color: #9fb0cc; margin-top: 2px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 20px; font-size: 13.5px; color: #c3cee0;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.05); color: #fff; }
.sidebar nav a.active { background: var(--navy-light); color: #fff; border-left-color: var(--accent); font-weight: 600; }
.sidebar .section-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: #6c7d9e;
  padding: 14px 20px 4px;
}

/* Collapsible accordion nav — groups B–G under a clickable header so the sidebar doesn't
   dump 20+ links on screen at once; only the section containing the current page auto-opens. */
.nav-accordion { display: flex; flex-direction: column; }
.nav-accordion .nav-top {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; font-size: 13.5px; font-weight: 600; color: #c3cee0;
  border-left: 3px solid transparent;
}
.nav-accordion .nav-top:hover { background: rgba(255,255,255,0.05); color: #fff; }
.nav-accordion .nav-top.active { background: var(--navy-light); color: #fff; border-left-color: var(--accent); }
.nav-top-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 5px;
  background: rgba(255,255,255,0.1); font-size: 11px; font-weight: 700;
}
.nav-group { border-top: 1px solid rgba(255,255,255,0.06); }
.nav-group summary {
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; user-select: none; list-style: none;
  padding: 12px 20px; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: 0.08em; color: #9fb0cc; font-weight: 700;
}
.nav-group summary::-webkit-details-marker { display: none; }
.nav-group summary:hover { color: #fff; }
.nav-group summary .chevron {
  font-size: 13px; color: #6c7d9e; transition: transform 0.15s ease; transform: rotate(90deg);
}
.nav-group:not([open]) summary .chevron { transform: rotate(0deg); }
.nav-group[open] summary { background: rgba(255,255,255,0.03); }
.nav-group-links { display: flex; flex-direction: column; padding-bottom: 4px; }
.nav-group-links a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 20px 8px 28px; font-size: 13px; color: #c3cee0;
  border-left: 3px solid transparent;
}
.nav-group-links a:hover { background: rgba(255,255,255,0.05); color: #fff; }
.nav-group-links a.active { background: var(--navy-light); color: #fff; border-left-color: var(--accent); font-weight: 600; }

.main { flex: 1; min-width: 0; }
.topbar {
  background: #fff; border-bottom: 1px solid var(--border);
  padding: 14px 28px; display: flex; align-items: center; justify-content: space-between;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 700; }
.topbar .sub { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }
.topbar .user-badge {
  background: var(--bg); border: 1px solid var(--border); border-radius: 20px;
  padding: 6px 14px; font-size: 12.5px; color: var(--text-muted);
}

.content { padding: 24px 28px 60px; }

.flash {
  padding: 10px 16px; border-radius: 8px; margin-bottom: 18px; font-size: 13.5px; font-weight: 500;
}
.flash.success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.flash.error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.flash.info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 20px; margin-bottom: 20px;
}
.card h2 { margin: 0 0 14px; font-size: 15px; font-weight: 700; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.stat-tile {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px;
}
.stat-tile .label { font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-tile .value { font-size: 22px; font-weight: 700; margin-top: 6px; }
.stat-tile.accent .value { color: var(--accent); }
.stat-tile.green .value { color: var(--green); }
.stat-tile.blue .value { color: var(--blue); }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); border-bottom: 1px solid var(--border); padding: 8px 10px; background: #fafbfc;
}
tbody td { padding: 10px; border-bottom: 1px solid #eef1f5; vertical-align: middle; }
tbody tr:hover { background: #fafbfd; }
.table-wrap { overflow-x: auto; }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700;
  letter-spacing: 0.02em; text-transform: uppercase;
}
.badge.pending { background: #fef3c7; color: #92400e; }
.badge.ready { background: #dbeafe; color: #1e40af; }
.badge.draft { background: #e0e7ff; color: #3730a3; }
.badge.billed { background: #dcfce7; color: #166534; }
.badge.cancelled { background: #fee2e2; color: #991b1b; }
.badge.hold { background: #f3f4f6; color: #374151; }
.badge.generated { background: #dcfce7; color: #166534; }
.badge.rejected { background: #fee2e2; color: #991b1b; }
.badge.active { background: #dcfce7; color: #166534; }
.badge.inactive { background: #f3f4f6; color: #6b7280; }
.badge.invoiced { background: #dbeafe; color: #1e40af; }
.badge.not-invoiced { background: #f3f4f6; color: #6b7280; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border);
  background: #fff; border-radius: 7px; padding: 8px 14px; font-size: 13px; font-weight: 600;
  cursor: pointer; color: var(--text);
}
.btn:hover { background: #f5f7fa; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-light); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.accent:hover { background: var(--accent-light); }
.btn.danger { background: #fff; border-color: #fca5a5; color: var(--red); }
.btn.danger:hover { background: #fee2e2; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 16px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 11.5px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.field input, .field select, .field textarea {
  border: 1px solid var(--border); border-radius: 7px; padding: 8px 10px; font-size: 13.5px; min-width: 150px;
  font-family: inherit;
}
.field textarea { min-width: 280px; }

.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.form-grid .field { min-width: 0; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; }

.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.mono { font-variant-numeric: tabular-nums; }
.mt-0 { margin-top: 0; }
.empty-state { padding: 40px; text-align: center; color: var(--text-muted); }
.help-text { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.warning-box { background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412; padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }

.pill-select { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- Invoice document (A4 letterhead) ---- */
.invoice-doc-wrap { background: #7c8698; padding: 30px 0; min-height: 100vh; }
.invoice-doc {
  width: 210mm; min-height: 297mm; background: #fff; margin: 0 auto; padding: 14mm 14mm;
  box-shadow: 0 4px 24px rgba(0,0,0,0.25); position: relative; color: #111;
}
.invoice-doc .watermark {
  position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%) rotate(-30deg);
  font-size: 90px; font-weight: 800; color: rgba(217, 119, 6, 0.12); letter-spacing: 10px; pointer-events: none;
}
/* ---- Letterhead invoice (exact-copy layout of the printed Aamod Finserv format) ---- */
.invoice-doc.letterhead { font-family: Arial, Helvetica, sans-serif; padding: 0; overflow: hidden; }

.ribbon { display: flex; height: 26px; }
.ribbon .band-blue {
  background: #1e3a72; flex: 0 0 60%; clip-path: polygon(0 0, 100% 0, 88% 100%, 0 100%);
  display: flex; align-items: center; padding-left: 12mm; color: #fff; font-size: 10.5px; font-weight: 600; letter-spacing: 0.03em;
}
.ribbon .band-orange {
  background: #d9622b; flex: 1; margin-left: -8%; clip-path: polygon(9% 0, 100% 0, 100% 100%, 0 100%);
  display: flex; align-items: center; justify-content: flex-end; padding-right: 12mm; color: #fff; font-size: 10.5px; font-weight: 600;
}
.ribbon-footer { margin-top: 16px; }

.lh-header { display: flex; justify-content: space-between; align-items: flex-start; padding: 12px 12mm 8px; border-bottom: 2px solid #1e3a72; margin-bottom: 8px; }
.lh-logo-block { display: flex; align-items: center; gap: 10px; }
.lh-logo-img { height: 46px; }
.lh-wordmark .lh-name { font-size: 18px; font-weight: 800; color: #1e3a72; letter-spacing: 0.5px; }
.lh-wordmark .lh-name span { font-size: 9px; font-weight: 600; color: #6b7688; vertical-align: super; }
.lh-wordmark .lh-tagline { font-size: 8.5px; color: #d9622b; letter-spacing: 1.5px; font-weight: 700; margin-top: 2px; }
.lh-contact-block { text-align: right; }
.lh-contact-block .lh-company-name { font-size: 14px; font-weight: 800; color: #d9622b; margin-bottom: 3px; }
.lh-contact-block .lh-contact-line { font-size: 10.5px; color: #333; line-height: 1.5; }
.lh-contact-block .lh-contact-indent { padding-right: 0; }

.tax-invoice-title { text-align: center; font-size: 13px; font-weight: 800; letter-spacing: 2px; margin: 4px 12mm 8px; }

table.doc-grid { width: calc(100% - 24mm); margin: 0 12mm; border-collapse: collapse; font-size: 11px; }
table.doc-grid td { border: 1px solid #b9c0cc; padding: 5px 8px; vertical-align: top; }
table.doc-grid td.lbl { font-weight: 700; white-space: nowrap; width: 1%; }
table.doc-grid td.lbl .normal { font-weight: 400; white-space: normal; }
table.doc-grid td.section-hdr { font-weight: 700; text-align: center; background: #eef1f6; text-transform: none; }

table.items { width: calc(100% - 24mm); margin: 10px 12mm 0; border-collapse: collapse; font-size: 11px; border: 1px solid #b9c0cc; }
table.items th { background: #1e3a72; color: #fff; padding: 6px 8px; text-align: left; font-size: 10px; font-weight: 700; border: 1px solid #2a4a8c; }
table.items td { padding: 6px 8px; border: 1px solid #b9c0cc; }
table.items tr.period-row td { font-style: italic; color: #555; background: #f7f8fa; }
table.items tr.subtotal-row td { font-weight: 700; background: #f2f4f8; }
table.items tr.grand-total-row td { font-weight: 800; background: #eef1f6; border-top: 2px solid #1e3a72; }

.words-row { width: calc(100% - 24mm); margin: 10px 12mm 0; font-size: 12px; border-top: 1px solid #b9c0cc; padding-top: 8px; }

.bottom-row { display: flex; justify-content: space-between; margin-top: 22px; padding: 0 12mm; align-items: flex-start; }
table.bank-mini { font-size: 11.5px; border-collapse: collapse; }
table.bank-mini td { padding: 2px 6px 2px 0; }
table.bank-mini td.lbl { font-weight: 700; width: 80px; }
.signatory { text-align: center; font-size: 11.5px; min-width: 220px; }
.signatory .lh-for-stamp { color: #1e3a72; font-style: italic; font-weight: 700; margin-top: 4px; }
.signatory .sig-labels { display: flex; justify-content: space-between; margin-top: 6px; border-top: 1px solid #111; padding-top: 4px; font-weight: 700; }

@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
  .invoice-doc-wrap { padding: 0; background: #fff; }
  .invoice-doc { box-shadow: none; margin: 0; width: auto; min-height: 0; }
}
