:root {
  --navy: #163a5f;
  --navy-2: #0f2b47;
  --ink: #17212b;
  --muted: #627181;
  --line: #d8e0e8;
  --surface: #ffffff;
  --canvas: #f3f6f8;
  --green: #147a52;
  --green-soft: #e7f5ef;
  --red: #b33642;
  --red-soft: #fbeaec;
  --blue-soft: #e9f0f6;
  --shadow: 0 12px 35px rgba(15, 43, 71, 0.09);
  color-scheme: light;
  font-family: "IBM Plex Sans", "Segoe UI", Aptos, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--canvas); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 92% -10%, rgba(35, 93, 137, 0.10), transparent 33rem),
    var(--canvas);
  padding: 72px 0 42px;
}

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }

.app-header {
  position: fixed;
  z-index: 50;
  inset: 0 0 auto;
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 8px clamp(16px, 4vw, 52px);
  color: #fff;
  background: rgba(15, 43, 71, 0.97);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(14px);
}

.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; background: #fff; color: var(--navy); font-weight: 800; font-size: 20px; }
.brand strong, .brand small { display: block; }
.brand strong { letter-spacing: .01em; }
.brand small { margin-top: 1px; color: #bdd0df; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }

.main-nav { display: flex; align-items: stretch; gap: 5px; align-self: stretch; overflow-x: auto; }
.nav-link { display: flex; align-items: center; padding: 0 13px; border-radius: 9px; color: #cfdae4; text-decoration: none; font-size: 14px; font-weight: 600; }
.nav-link:hover, .nav-link.is-active { color: #fff; background: rgba(255, 255, 255, .11); }
.user-area { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.user-name { color: #dfe8ef; font-size: 13px; }

.app-main { width: min(1460px, 92vw); margin: 0 auto; }
.app-footer { position: fixed; z-index: 40; inset: auto 0 0; height: 32px; display: flex; align-items: center; justify-content: space-between; padding: 0 clamp(16px, 4vw, 52px); color: #8fa0af; background: #0d2134; font-size: 11px; letter-spacing: .02em; }

.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin: 22px 0 18px; }
.page-heading h1, .auth-card h1, .setup-card h1 { margin: 2px 0 4px; font-size: clamp(27px, 3vw, 38px); letter-spacing: -.035em; }
.eyebrow { margin: 0; color: var(--navy); font-size: 11px; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
.muted { margin: 0; color: var(--muted); line-height: 1.55; }
.heading-actions { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 9px; padding-top: 9px; }

.button, summary.button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 41px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 9px;
  font-weight: 700;
  font-size: 13px;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.button:hover { transform: translateY(-1px); box-shadow: 0 6px 15px rgba(15, 43, 71, .10); }
.button-primary { color: #fff; background: var(--navy); }
.button-primary:hover { background: var(--navy-2); }
.button-secondary { color: var(--navy); background: #fff; border-color: #bcc9d4; }
.button-success { color: #fff; background: var(--green); }
.button-danger { color: #fff; background: var(--red); }
.button-ghost { color: inherit; background: transparent; border-color: rgba(128, 145, 160, .36); }
.app-header .button-ghost { color: #fff; }
.button-small { min-height: 34px; padding: 0 11px; font-size: 12px; }
.button-wide { width: 100%; }

.inline-form { display: inline-flex; margin: 0; }
.icon-button { appearance: none; display: inline-grid; place-items: center; width: 35px; height: 35px; padding: 0; border: 1px solid var(--line); border-radius: 9px; color: var(--navy); background: #fff; text-decoration: none; cursor: pointer; font-size: 18px; font-weight: 700; }
.icon-button:hover { border-color: #9fb1c0; background: #f8fafb; }
.icon-button.danger { color: var(--red); }

.date-toolbar { display: flex; align-items: center; gap: 9px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 13px; box-shadow: 0 4px 18px rgba(15, 43, 71, .04); }
.date-form { display: flex; align-items: center; gap: 9px; }
.date-form label { color: var(--muted); font-size: 12px; font-weight: 700; }
.date-form input { min-height: 35px; padding: 5px 9px; border: 1px solid #bfcbd5; border-radius: 8px; color: var(--ink); background: #fff; }
.selected-date-label { margin-left: auto; color: var(--navy); font-size: 15px; }

.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 14px 0; }
.summary-card { position: relative; overflow: hidden; padding: 17px 18px; background: #fff; border: 1px solid var(--line); border-radius: 13px; box-shadow: 0 5px 18px rgba(15, 43, 71, .045); }
.summary-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: #8297a8; }
.summary-card span { display: block; margin-bottom: 7px; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .065em; text-transform: uppercase; }
.summary-card strong { font-family: "IBM Plex Mono", "Cascadia Mono", Consolas, monospace; font-size: clamp(18px, 2.2vw, 25px); letter-spacing: -.04em; }
.receipt-card::before { background: var(--green); }
.payment-card::before { background: var(--red); }
.closing-card { background: var(--navy); border-color: var(--navy); color: #fff; }
.closing-card::before { background: #88c2ea; }
.closing-card span { color: #c5d7e6; }
.closing-card.is-negative { background: #742733; border-color: #742733; }

.table-card, .settings-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.table-card-header { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 15px 17px; border-bottom: 1px solid var(--line); }
.table-card-header h2 { margin: 0 0 2px; font-size: 16px; }
.table-card-header p { margin: 0; color: var(--muted); font-size: 12px; }
.privacy-chip { padding: 6px 9px; border-radius: 999px; color: #4c6173; background: var(--blue-soft); font-size: 11px; font-weight: 700; }
.table-scroll { overflow: auto; max-height: calc(100vh - 395px); }

table { width: 100%; border-collapse: collapse; }
th { position: sticky; top: 0; z-index: 2; padding: 10px 11px; color: #536575; background: #f5f8fa; border-bottom: 1px solid #cbd6df; text-align: left; font-size: 10px; letter-spacing: .055em; text-transform: uppercase; white-space: nowrap; }
td { padding: 10px 11px; border-bottom: 1px solid #e4e9ee; vertical-align: middle; font-size: 12.5px; }
tbody tr:hover { background: #f9fbfc; }
td small { display: block; margin-top: 3px; color: var(--muted); font-size: 10.5px; }
.cell-number { width: 44px; color: var(--muted); text-align: center; }
.mono, .money { font-family: "IBM Plex Mono", "Cascadia Mono", Consolas, monospace; }
.money { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.receipt-value { color: var(--green); }
.payment-value { color: var(--red); }
.masked-name { font-weight: 650; letter-spacing: .01em; }
.explanation-cell { min-width: 220px; max-width: 390px; color: #465766; }
.row-actions { width: 150px; text-align: right; white-space: nowrap; }
.row-actions .icon-button { width: 30px; height: 30px; margin-left: 3px; font-size: 16px; }
.type-pill { display: inline-flex; padding: 4px 7px; border-radius: 999px; font-size: 10px; font-weight: 800; }
.type-pill.receipt { color: #0e6443; background: var(--green-soft); }
.type-pill.payment { color: #902936; background: var(--red-soft); }
.entity-pill, .status-pill { display: inline-flex; padding: 4px 7px; border-radius: 999px; font-size: 10px; font-weight: 850; }
.entity-pill { color: var(--navy); background: var(--blue-soft); }
.status-pill.active { color: #0e6443; background: var(--green-soft); }
.status-pill.inactive { color: #6d7882; background: #e9edf0; }
tr.is-inactive { opacity: .67; }
tfoot td { background: #f1f5f8; font-weight: 800; }
tfoot td:first-child { text-align: right; }
tfoot .closing-row td { color: #fff; background: var(--navy); border-bottom: 0; }
.empty-row td { padding: 42px 16px; color: var(--muted); text-align: center; }
.empty-row strong, .empty-row span { display: block; }
.empty-row strong { margin-bottom: 5px; color: var(--ink); }

.export-menu { position: relative; }
.export-menu summary { list-style: none; }
.export-menu summary::-webkit-details-marker { display: none; }
.export-popover { position: absolute; z-index: 20; top: calc(100% + 8px); right: 0; width: 285px; overflow: hidden; padding: 6px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 18px 45px rgba(15, 43, 71, .18); }
.export-popover a { display: block; padding: 10px 11px; border-radius: 8px; text-decoration: none; }
.export-popover a:hover { background: #f2f6f9; }
.export-popover strong, .export-popover small { display: block; }
.export-popover strong { margin-bottom: 3px; color: var(--navy); font-size: 13px; }
.export-popover small { color: var(--muted); font-size: 11px; }

.notice { margin: 14px 0; padding: 11px 14px; border: 1px solid; border-radius: 10px; font-size: 13px; }
.notice-success { color: #0d6241; background: #e8f6ef; border-color: #b9dfcc; }
.notice-error { color: #8d2935; background: #fdeef0; border-color: #efc1c7; }

.modal { width: min(760px, 94vw); max-height: 92vh; padding: 0; border: 0; border-radius: 16px; background: transparent; box-shadow: 0 28px 80px rgba(10, 30, 48, .28); }
.modal::backdrop { background: rgba(11, 27, 42, .58); backdrop-filter: blur(3px); }
.modal-card { overflow: auto; max-height: 92vh; padding: 0; background: #fff; border-radius: 16px; }
.modal-header { position: sticky; top: 0; z-index: 3; display: flex; align-items: flex-start; justify-content: space-between; padding: 18px 20px 14px; background: #fff; border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 3px 0 0; font-size: 22px; }
.modal-actions { position: sticky; bottom: 0; z-index: 3; display: flex; justify-content: flex-end; gap: 9px; padding: 13px 20px; background: #f7f9fb; border-top: 1px solid var(--line); }
.pdf-modal { width: min(1080px, 96vw); }
.pdf-modal-card { height: min(88vh, 920px); display: grid; grid-template-rows: auto 1fr auto; overflow: hidden; }
.pdf-frame { width: 100%; height: 100%; min-height: 520px; border: 0; background: #e9eef2; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; }
.compact-grid { padding: 18px 20px 22px; }
.form-stack { display: grid; gap: 15px; margin-top: 22px; }
.form-grid label, .form-stack label { display: grid; gap: 6px; color: #354656; font-size: 12px; font-weight: 750; }
input, select, textarea { width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid #b9c6d1; border-radius: 8px; color: var(--ink); background: #fff; outline: none; }
textarea { min-height: 78px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: #3374a6; box-shadow: 0 0 0 3px rgba(51, 116, 166, .13); }
label small { color: var(--muted); font-size: 10.5px; font-weight: 500; line-height: 1.45; }
.span-2 { grid-column: 1 / -1; }
.form-section-title { grid-column: 1 / -1; margin-top: 5px; padding: 0 0 9px; color: var(--navy); border-bottom: 1px solid var(--line); font-size: 13px; font-weight: 850; letter-spacing: .035em; }
.form-actions { display: flex; justify-content: flex-end; padding-top: 4px; }
.settings-card { padding: 22px; margin-bottom: 25px; }
.info-panel { padding: 13px 15px; color: #405364; background: #eef4f8; border: 1px solid #d4e1ea; border-radius: 10px; }
.info-panel strong, .info-panel p { display: block; margin: 0; }
.info-panel p { margin-top: 4px; font-size: 12px; line-height: 1.5; }

.filter-bar { display: grid; grid-template-columns: repeat(4, minmax(145px, 1fr)) auto; align-items: end; gap: 10px; margin: 0 0 14px; padding: 13px 14px; background: #fff; border: 1px solid var(--line); border-radius: 13px; }
.filter-bar label { display: grid; gap: 5px; color: #405364; font-size: 11px; font-weight: 750; }
.filter-bar input, .filter-bar select { min-height: 38px; }
.document-table td { white-space: nowrap; }
.document-table td:nth-child(6) { min-width: 190px; white-space: normal; }

.auth-shell, .setup-shell { min-height: calc(100vh - 130px); display: grid; place-items: center; padding: 26px 0; }
.auth-card, .setup-card { width: min(460px, 94vw); padding: clamp(24px, 5vw, 38px); background: #fff; border: 1px solid var(--line); border-radius: 17px; box-shadow: 0 22px 60px rgba(15, 43, 71, .13); }
.setup-card { width: min(830px, 94vw); }
.setup-card .form-grid { margin-top: 24px; }
.audit-table td:nth-child(1), .audit-table td:nth-child(5) { white-space: nowrap; }
.audit-table td small { max-width: 540px; }

.error-shell { min-height: calc(100vh - 160px); display: grid; place-items: center; align-content: center; gap: 10px; text-align: center; }
.error-shell h1, .error-shell p { margin: 0; }
.error-shell p { max-width: 620px; color: var(--muted); }
.error-code { color: #aebdca; font-size: 70px; font-weight: 900; letter-spacing: -.08em; }
.error-shell .button { margin-top: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 900px) {
  body { padding-top: 118px; }
  .app-header { min-height: 108px; flex-wrap: wrap; gap: 5px 14px; align-content: center; }
  .main-nav { order: 3; width: 100%; height: 36px; overflow-x: auto; }
  .nav-link { padding: 0 10px; font-size: 12px; }
  .user-name { display: none; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .table-scroll { max-height: calc(100vh - 470px); }
}

@media (max-width: 640px) {
  body { padding-bottom: 34px; }
  .app-main { width: min(100% - 22px, 1460px); }
  .page-heading { align-items: stretch; flex-direction: column; margin-top: 15px; }
  .heading-actions { justify-content: flex-start; padding-top: 0; }
  .date-toolbar { flex-wrap: wrap; }
  .date-form { order: -1; width: 100%; }
  .date-form label { display: none; }
  .date-form input { flex: 1; }
  .selected-date-label { display: none; }
  .summary-grid { gap: 8px; }
  .summary-card { padding: 14px 13px; }
  .summary-card strong { font-size: 17px; }
  .privacy-chip { display: none; }
  .table-card-header { padding: 12px 13px; }
  .form-grid { grid-template-columns: 1fr; }
  .filter-bar { grid-template-columns: 1fr 1fr; }
  .filter-bar .button { grid-column: 1 / -1; }
  .span-2, .form-section-title { grid-column: 1; }
  .compact-grid { padding: 15px; }
  .settings-card { padding: 16px; }
  .app-footer span:first-child { display: none; }
  .app-footer { justify-content: flex-end; }
  .modal-actions { padding: 11px 15px; }
  .pdf-frame { min-height: 430px; }
}

@media print {
  .app-header, .app-footer, .heading-actions, .date-toolbar, .row-actions { display: none !important; }
  body { padding: 0; background: #fff; }
  .app-main { width: 100%; }
  .table-card { box-shadow: none; }
  .table-scroll { overflow: visible; max-height: none; }
}
