:root {
  color-scheme: light;
  --navy: #123943;
  --navy-2: #0d2d35;
  --teal: #0e8277;
  --teal-dark: #086a62;
  --gold: #b28a36;
  --paper: #f4f7f6;
  --surface: #ffffff;
  --ink: #19383f;
  --muted: #65777b;
  --line: #d9e3e0;
  --success: #187d53;
  --warning: #a46a13;
  --danger: #a44239;
  --shadow: 0 18px 45px rgba(20, 52, 58, .09);
  font-family: Inter, "Segoe UI", Tahoma, Arial, sans-serif;
}

/* Always honor application visibility state, even when a component has its
   own display:grid/flex rule. */
[hidden] { display: none !important; }

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--paper); color: var(--ink); font-size: 16px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 32px; background: linear-gradient(135deg, var(--navy-2), var(--navy) 62%, #174f59); }
.auth-panel { width: min(520px, 100%); padding: 42px; border-radius: 24px; background: rgba(255,255,255,.98); box-shadow: 0 30px 80px rgba(0,0,0,.25); }
.auth-logo { width: 165px; height: auto; margin-bottom: 28px; }
h1,h2,p { margin-top: 0; }
h1 { margin-bottom: 10px; color: var(--navy); font-size: clamp(2rem, 4vw, 3rem); letter-spacing: -.035em; line-height: 1.05; }
h2 { margin-bottom: 4px; color: var(--navy); font-size: 1.2rem; }
.eyebrow { margin-bottom: 8px; color: var(--teal); font-size: .78rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.muted, .panel-heading p, .section-actions p { color: var(--muted); }

.stack-form, .dialog-form, .notice-form { display: grid; gap: 18px; }
label { display: grid; gap: 7px; color: var(--ink); font-size: .9rem; font-weight: 650; }
input, select, textarea { width: 100%; border: 1px solid #cbd8d5; border-radius: 10px; background: #fff; color: var(--ink); padding: 11px 12px; outline: none; transition: border .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(14,130,119,.13); }
textarea { resize: vertical; line-height: 1.55; }

.primary, .secondary, .link-button { border: 0; border-radius: 10px; padding: 10px 15px; font-weight: 750; }
.primary { background: var(--teal); color: #fff; box-shadow: 0 8px 20px rgba(14,130,119,.18); }
.primary:hover { background: var(--teal-dark); }
.secondary { border: 1px solid var(--line); background: #fff; color: var(--ink); }
.secondary:hover { border-color: var(--teal); color: var(--teal); }
.secondary:disabled { opacity: .45; cursor: not-allowed; }
.link-button { padding: 4px 0; background: transparent; color: var(--teal); }
.form-message { min-height: 1.25rem; margin: 0; color: var(--danger); font-weight: 650; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 238px minmax(0,1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 28px 20px; background: var(--navy-2); color: #fff; }
.side-logo { width: 140px; margin: 0 auto 12px; filter: drop-shadow(0 10px 18px rgba(0,0,0,.14)); }
.side-label { margin: 0 auto 28px; color: #b8cfca; font-size: .78rem; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.sidebar nav { display: grid; gap: 7px; }
.nav-item { width: 100%; border: 0; border-radius: 11px; padding: 12px 14px; background: transparent; color: #c9d9d6; text-align: left; font-weight: 700; }
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,.1); color: #fff; }
.nav-item.active { box-shadow: inset 3px 0 var(--gold); }
.side-footer { margin-top: auto; padding: 16px 12px 4px; border-top: 1px solid rgba(255,255,255,.14); }
.user-name { font-weight: 800; }
.user-role { margin: 4px 0 10px; color: #9fb9b4; font-size: .8rem; }
.side-footer .link-button { color: #d9e8e5; }

.workspace { min-width: 0; padding: 34px 42px 50px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.topbar h1 { margin: 0; font-size: clamp(2rem, 3.2vw, 3.2rem); }
.top-actions, .section-actions, .form-actions { display: flex; align-items: center; gap: 10px; }
.section-actions { justify-content: space-between; margin: 0 0 16px; }
.section-actions p { margin: 0; }

.view { display: none; }
.active-view { display: block; }
.kpi-grid { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { min-height: 142px; padding: 20px; border: 1px solid var(--line); border-radius: 17px; background: var(--surface); box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: .84rem; font-weight: 700; }
.kpi .value { margin: 17px 0 5px; color: var(--navy); font-size: clamp(1.55rem, 2.4vw, 2.2rem); font-weight: 850; letter-spacing: -.03em; }
.kpi .detail { color: var(--teal); font-size: .8rem; font-weight: 750; }

.dashboard-grid { display: grid; grid-template-columns: 1.45fr 1fr; gap: 18px; }
.panel { min-width: 0; border: 1px solid var(--line); border-radius: 17px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.wide-panel, .panel:not(.notice-form) { padding: 22px; }
.full-panel { grid-column: 1 / -1; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 20px; }
.panel-heading p { margin: 5px 0 0; font-size: .86rem; }

.stage-chart { display: grid; gap: 18px; }
.stage-row { display: grid; grid-template-columns: 150px 1fr 120px; gap: 14px; align-items: center; }
.stage-name { font-weight: 800; }
.bar-track { height: 13px; overflow: hidden; border-radius: 999px; background: #e7eeec; }
.bar-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--teal), #24a899); }
.stage-value { text-align: right; color: var(--navy); font-size: .86rem; font-weight: 800; }
.status-list { display: grid; gap: 11px; }
.status-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 11px; border-bottom: 1px solid #edf1f0; }
.status-item:last-child { border-bottom: 0; }
.collection-total { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.collection-total span { color: var(--muted); font-size: 12px; }
.collection-total strong { color: var(--teal); font-size: 20px; }
.monthly-collection-chart { display: flex; align-items: flex-end; gap: 18px; min-height: 220px; overflow-x: auto; padding: 12px 4px 2px; }
.month-collection { display: grid; grid-template-rows: 130px auto auto auto; justify-items: center; gap: 5px; min-width: 125px; color: var(--ink); }
.month-bar-track { width: 54px; height: 130px; display: flex; align-items: flex-end; overflow: hidden; border-radius: 12px 12px 4px 4px; background: #e6efed; }
.month-bar-fill { width: 100%; border-radius: 12px 12px 4px 4px; background: linear-gradient(180deg, var(--teal), #0d625d); min-height: 0; }
.month-collection strong { font-size: 13px; white-space: nowrap; }
.month-collection span { font-size: 13px; color: var(--muted); }
.month-collection small { color: var(--muted); }
.status-pill { display: inline-flex; align-items: center; gap: 8px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--teal); }
.status-count { color: var(--navy); font-weight: 850; }

.table-wrap { width: 100%; overflow: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th { padding: 12px 11px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: .74rem; letter-spacing: .06em; text-align: left; text-transform: uppercase; }
td { padding: 14px 11px; border-bottom: 1px solid #edf1f0; color: var(--ink); font-size: .88rem; }
tbody tr:hover { background: #f7faf9; }
.number { text-align: right; font-variant-numeric: tabular-nums; }
.large-table { max-height: calc(100vh - 220px); }
.filter-bar { display: grid; grid-template-columns: minmax(240px,1fr) 190px 200px auto auto; gap: 10px; margin-bottom: 14px; }
.small-status { display: inline-block; border-radius: 999px; padding: 5px 9px; background: #e7f3f0; color: var(--teal-dark); font-size: .75rem; font-weight: 750; }
.row-actions { display: flex; align-items: center; gap: 12px; }

.report-builder { margin-bottom: 18px; }
.report-controls { display: grid; grid-template-columns: minmax(220px, 320px) minmax(190px, 260px) auto; gap: 12px; align-items: end; }
.report-guidance { margin: 16px 0 0; padding: 12px 14px; border-left: 3px solid var(--gold); background: #fbf8f0; color: var(--muted); font-size: .85rem; }
.management-report-preview { padding: 12px; border-radius: 17px; background: #dfe7e5; overflow: auto; }
.embedded-report { width: min(1120px, 100%); min-height: 720px; margin: 0 auto; border-radius: 5px; box-shadow: 0 16px 40px rgba(13, 49, 57, .14); }
.report-executive-summary { margin: 22px 0; padding: 14px 18px; border-left: 4px solid var(--teal); background: #f4f8f7; }
.report-executive-summary h2 { margin-top: 0; }
.report-executive-summary p { margin: 0; line-height: 1.65; }
.report-kpis-four { grid-template-columns: repeat(4, 1fr); }
.report-kpi small { display: block; margin-top: 6px; color: var(--muted); font-size: 10px; }
.report-callout, .report-period-note { padding: 10px 12px; border: 1px solid var(--line); background: #fffaf0; font-size: 11px; }
.report-total-row { background: #edf6f4; }

.generator-layout { display: grid; grid-template-columns: minmax(0,1.05fr) minmax(420px,.95fr); gap: 18px; align-items: start; }
.notice-form { padding: 24px; }
.form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 15px; }
.form-actions { justify-content: flex-end; }
.preview-panel { position: sticky; top: 22px; }
.notice-paper { min-height: 760px; padding: 36px 42px 28px; border: 1px solid #cfdad7; background: #fff; box-shadow: 0 15px 35px rgba(22,58,67,.08); }
.notice-letterhead { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding-bottom: 20px; border-bottom: 2px solid var(--teal); }
.notice-letterhead img { height: auto; }
.official-hadya-header { width: 205px; }
.official-gravita-header { width: 115px; }
.gravita-wordmark { color: var(--navy); font-size: 1.8rem; font-weight: 900; letter-spacing: .16em; }
.notice-meta { display: grid; grid-template-columns: 1fr auto; gap: 7px 15px; margin: 26px 0; color: var(--muted); font-size: .84rem; }
.notice-subject { margin: 30px 0 22px; color: var(--navy); font-size: 1.15rem; font-weight: 850; text-align: center; text-transform: uppercase; }
.notice-body { white-space: pre-wrap; color: #243d43; line-height: 1.75; }
.notice-body.rtl { direction: rtl; text-align: right; font-family: Tahoma, Arial, sans-serif; }
.notice-amount { margin: 24px 0; padding: 15px; border: 1px solid var(--line); background: #f3f8f7; font-weight: 800; }
.notice-signature { width: 230px; margin: 34px 0 8px; color: var(--navy); }
.notice-signature.rtl { margin-right: auto; text-align: right; }
.notice-signature strong { display: block; font-size: .95rem; }
.signature-space { height: 48px; }
.notice-signature span { color: var(--muted); font-size: .78rem; }
.signature-line { margin-top: 8px; border-bottom: 1px solid #879a9e; }
.notice-footer { margin-top: 48px; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: .78rem; }
.official-hadya-footer { display: block; width: 100%; height: auto; }
.gravita-footer { display: flex; align-items: center; justify-content: space-between; gap: 18px; color: #b58a52; }
.gravita-footer span { color: var(--muted); text-align: right; }

.report-document { padding: 18mm 16mm; background: #fff; color: #1e343a; }
.report-document.landscape { page: legal-wide; }
.report-header { display: flex; align-items: flex-start; gap: 28px; padding-bottom: 18px; border-bottom: 3px solid var(--teal); }
.report-header img { width: 145px; }
.report-header h1 { margin: 5px 0; color: var(--navy); font-size: 25px; }
.report-header p { margin: 0; color: var(--muted); }
.report-department { color: var(--gold); font-size: 11px; font-weight: 850; letter-spacing: .11em; }
.report-kpis { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin: 22px 0; }
.report-kpi { padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: #f4f8f7; }
.report-kpi span { display: block; color: var(--muted); font-size: 11px; }
.report-kpi strong { display: block; margin-top: 5px; color: var(--navy); font-size: 17px; }
.report-document h2 { margin: 26px 0 10px; color: var(--navy); font-size: 16px; }
.report-details { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); }
.report-details > div { display: grid; grid-template-columns: 150px 1fr; gap: 10px; padding: 10px; border-bottom: 1px solid var(--line); }
.report-details span { color: var(--muted); font-size: 11px; }
.report-details strong { font-size: 12px; }
.report-document table { white-space: normal; }
.report-document th, .report-document td { padding: 8px 7px; font-size: 10px; }
.report-notes, .report-empty { padding: 12px; border: 1px solid var(--line); background: #fafcfc; white-space: pre-wrap; }
.report-footer { margin-top: 28px; padding-top: 10px; border-top: 1px solid var(--line); color: var(--muted); font-size: 9px; text-align: center; }

dialog { width: min(740px, calc(100vw - 32px)); max-height: calc(100vh - 40px); overflow: auto; border: 0; border-radius: 18px; padding: 0; box-shadow: 0 30px 80px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(8,29,34,.6); backdrop-filter: blur(3px); }
.dialog-form { padding: 26px; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; }
.icon-button { border: 0; background: transparent; color: var(--muted); font-size: 1.8rem; }

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(3,1fr); }
  .dashboard-grid, .generator-layout { grid-template-columns: 1fr; }
  .preview-panel { position: static; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: static; height: auto; padding: 18px; }
  .side-logo { width: 120px; }
  .sidebar nav { grid-template-columns: repeat(2,1fr); }
  .side-footer { display: flex; align-items: center; gap: 12px; }
  .user-role { margin: 0; }
  .workspace { padding: 24px 16px 40px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .filter-bar, .form-grid, .report-controls { grid-template-columns: 1fr; }
  .report-kpis-four { grid-template-columns: 1fr 1fr; }
  .stage-row { grid-template-columns: 105px 1fr; }
  .stage-value { grid-column: 2; text-align: left; }
}

@media print {
  body:not(.printing-report) * { visibility: hidden !important; }
  body:not(.printing-report) #noticePreview, body:not(.printing-report) #noticePreview * { visibility: visible !important; }
  body:not(.printing-report) #noticePreview { position: absolute; inset: 0; width: 100%; min-height: 100vh; border: 0; box-shadow: none; padding: 12mm 14mm 9mm; }
  body.printing-report * { visibility: hidden !important; }
  body.printing-report #reportDocument, body.printing-report #reportDocument * { visibility: visible !important; }
  body.printing-report #reportDocument { display: block !important; position: absolute; inset: 0; width: 100%; padding: 12mm; }
  .report-page-break { break-before: page; }
  .report-document tr { break-inside: avoid; }
  @page { size: A4; margin: 0; }
  @page legal-wide { size: A4 landscape; margin: 0; }
}
