:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-2: #eef3f9;
    --text: #152033;
    --muted: #667085;
    --line: #dfe5ee;
    --primary: #0d4f8b;
    --primary-dark: #083a67;
    --success: #147a5b;
    --success-bg: #e8f7f0;
    --danger: #a23333;
    --danger-bg: #fff0f0;
    --warning: #8a5b00;
    --warning-bg: #fff7df;
    --shadow: 0 14px 35px rgba(22, 34, 51, .08);
    --radius: 18px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background: var(--bg);
    font-family: Poppins, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.55;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input { font: inherit; }
.shell { width: min(1160px, calc(100% - 36px)); margin-inline: auto; }
.page { padding: 42px 0 56px; min-height: calc(100vh - 140px); }

.topbar { background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar__inner { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 22px; }
.brand { display: inline-flex; align-items: center; gap: 12px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand__mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; background: var(--primary); color: #fff; font-size: .78rem; font-weight: 800; letter-spacing: .05em; }
.brand__text { display: flex; flex-direction: column; line-height: 1.15; }
.brand__text strong { font-size: .98rem; }
.brand__text small { color: var(--muted); margin-top: 3px; font-weight: 600; letter-spacing: .08em; }
.topnav { display: flex; align-items: center; gap: 20px; font-size: .92rem; font-weight: 600; }
.inline-form { display: inline; margin: 0; }
.link-button { border: 0; background: none; padding: 0; cursor: pointer; color: var(--primary); font-weight: 600; }

.footer { border-top: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: .83rem; }
.footer__inner { min-height: 68px; display: flex; justify-content: space-between; align-items: center; gap: 18px; }

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: clamp(2rem, 4vw, 3rem); line-height: 1.08; letter-spacing: -.035em; }
h2 { margin-bottom: 16px; font-size: 1.18rem; letter-spacing: -.015em; }
p { color: var(--muted); }
.eyebrow { display: inline-block; margin-bottom: 10px; color: var(--primary); font-size: .76rem; font-weight: 800; letter-spacing: .11em; }
.muted { color: var(--muted); font-size: .9rem; }

.hero-card, .page-heading { display: flex; align-items: center; justify-content: space-between; gap: 26px; margin-bottom: 26px; }
.hero-card { padding: 30px; border: 1px solid var(--line); border-radius: 24px; background: linear-gradient(135deg, #fff, #f3f7fb); box-shadow: var(--shadow); }
.hero-card p, .page-heading p { margin-bottom: 0; max-width: 760px; }
.page-heading { margin-bottom: 28px; }
.page-heading h1 { font-size: clamp(1.9rem, 3vw, 2.55rem); }
.status-pill { flex: 0 0 auto; display: inline-flex; align-items: center; padding: 8px 13px; border-radius: 999px; font-size: .78rem; font-weight: 800; }
.status-pill--ok { color: var(--success); background: var(--success-bg); }
.status-pill--warn { color: var(--warning); background: var(--warning-bg); }

.grid { display: grid; gap: 22px; }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 24px; box-shadow: 0 8px 22px rgba(22, 34, 51, .045); }
.form-card { margin-top: 22px; }

.check-list { display: grid; gap: 10px; }
.check-row { display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.check-row:last-child { border-bottom: 0; }
.check-row strong { font-size: .74rem; letter-spacing: .05em; }
.check-icon { width: 25px; height: 25px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; }
.check-icon--ok { color: var(--success); background: var(--success-bg); }
.check-icon--bad { color: var(--danger); background: var(--danger-bg); }

.details { margin: 0; display: grid; gap: 0; }
.details div { padding: 11px 0; border-bottom: 1px solid var(--line); }
.details div:last-child { border-bottom: 0; }
.details dt { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .07em; font-weight: 700; }
.details dd { margin: 4px 0 0; font-weight: 650; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.field { display: grid; gap: 7px; }
.field--wide { grid-column: 1 / -1; }
.field > span { font-size: .84rem; font-weight: 700; }
.field small { color: var(--muted); font-size: .76rem; }
.field input { width: 100%; min-height: 46px; border: 1px solid #cfd7e3; border-radius: 11px; padding: 10px 12px; background: #fff; color: var(--text); outline: none; }
.field input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(13,79,139,.11); }
.form-actions { margin-top: 22px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 10px 17px; border: 0; border-radius: 11px; background: var(--primary); color: #fff; font-weight: 750; cursor: pointer; }
.button:hover { background: var(--primary-dark); text-decoration: none; }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button--secondary { background: var(--surface-2); color: var(--primary); }
.button--secondary:hover { background: #e2eaf4; }

.alert { margin: 0 0 22px; padding: 13px 15px; border-radius: 12px; font-size: .9rem; font-weight: 600; }
.alert--error { color: var(--danger); background: var(--danger-bg); border: 1px solid #f1caca; }
.alert--success { color: var(--success); background: var(--success-bg); border: 1px solid #bfe8d7; }

.auth-wrap { min-height: 62vh; display: grid; place-items: center; }
.auth-card { width: min(500px, 100%); border: 1px solid var(--line); border-radius: 24px; background: var(--surface); padding: 32px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: clamp(1.8rem, 5vw, 2.4rem); }
.stack-form { display: grid; gap: 17px; margin-top: 24px; }
.security-note { margin: 20px 0 0; font-size: .8rem; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.metric-card { min-height: 145px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); padding: 20px; display: flex; flex-direction: column; justify-content: space-between; }
.metric-card span { color: var(--muted); font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.metric-card strong { margin: 13px 0 4px; font-size: 1.35rem; line-height: 1.15; }
.metric-card small { color: var(--muted); }
.dashboard-grid { margin-bottom: 22px; }
.foundation-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.foundation-list li { display: flex; gap: 10px; align-items: flex-start; }
.foundation-list span { color: var(--success); font-weight: 800; }
.audit-list { display: grid; }
.audit-row { display: flex; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.audit-row:last-child { border-bottom: 0; }
.audit-row div { display: grid; }
.audit-row small, .audit-row time { color: var(--muted); font-size: .78rem; }
.next-card { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.next-card p { margin-bottom: 0; }
.empty-state { padding: 24px; border-radius: 14px; background: var(--surface-2); display: grid; gap: 5px; }
.empty-state span { color: var(--muted); }
.plain-list { padding-left: 20px; }

@media (max-width: 900px) {
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid--2 { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
    .shell { width: min(100% - 24px, 1160px); }
    .page { padding-top: 28px; }
    .topbar__inner { min-height: 64px; }
    .brand__text strong { font-size: .88rem; }
    .topnav { gap: 12px; font-size: .82rem; }
    .hero-card, .page-heading, .next-card { align-items: flex-start; flex-direction: column; }
    .hero-card { padding: 22px; }
    .card, .auth-card { padding: 20px; }
    .form-grid, .metric-grid { grid-template-columns: 1fr; }
    .field--wide { grid-column: auto; }
    .metric-card { min-height: 120px; }
    .footer__inner { min-height: 80px; align-items: flex-start; justify-content: center; flex-direction: column; gap: 3px; }
    .audit-row { flex-direction: column; gap: 4px; }
}

/* E1 - Accounting */
select { font: inherit; }
.field select,
.search-form input,
.mini-form input,
.journal-entry-table input,
.journal-entry-table select {
    width: 100%; min-height: 42px; border: 1px solid #cfd7e3; border-radius: 10px; padding: 8px 10px; background: #fff; color: var(--text); outline: none;
}
.field select:focus,
.search-form input:focus,
.mini-form input:focus,
.journal-entry-table input:focus,
.journal-entry-table select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(13,79,139,.11); }
.metric-card--link { color: var(--text); transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease; }
.metric-card--link:hover { text-decoration: none; transform: translateY(-2px); border-color: #bdcbdd; box-shadow: var(--shadow); }
.metric-grid--5 { grid-template-columns: repeat(4,minmax(0,1fr)); }
.accounting-home-grid { margin-bottom: 22px; }
.workflow-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0; }
.workflow-list li { display: grid; grid-template-columns: 120px 1fr; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.workflow-list li:last-child { border-bottom: 0; }
.workflow-list span { color: var(--muted); }
.compact-details div { padding: 8px 0; }
.notice { margin-top: 18px; padding: 14px 16px; border-radius: 12px; font-size: .88rem; }
.notice--warn { background: var(--warning-bg); color: #634500; border: 1px solid #ecd998; }
.notice--neutral { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.text-link { display: inline-flex; margin-top: 8px; font-weight: 700; font-size: .9rem; }
.quick-actions, .section-title-row, .journal-lines-heading, .critical-action-card { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.quick-actions h2, .section-title-row h2, .journal-lines-heading h2 { margin-bottom: 0; }
.action-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.accounting-form-card { margin-bottom: 22px; }
.checkbox-field { display: flex; align-items: flex-start; gap: 10px; font-size: .88rem; color: var(--text); }
.checkbox-field input { width: 18px; height: 18px; margin-top: 2px; flex: 0 0 auto; }
.search-form { display: grid; grid-template-columns: minmax(180px,280px) auto; gap: 8px; }
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; min-width: 760px; font-size: .87rem; }
.data-table th { text-align: left; color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .055em; padding: 11px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table td { padding: 13px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.table-sub { display: block; margin-top: 3px; color: var(--muted); font-size: .76rem; }
.amount-cell { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.status-badge { display: inline-flex; align-items: center; min-height: 28px; padding: 5px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: .7rem; font-weight: 800; letter-spacing: .025em; white-space: nowrap; }
.status-badge--validated, .status-badge--open, .status-badge--posted { background: var(--success-bg); color: var(--success); }
.status-badge--requires_review, .status-badge--review, .status-badge--draft, .status-badge--reopened { background: var(--warning-bg); color: var(--warning); }
.status-badge--closed, .status-badge--reversed { background: #edf0f5; color: #445066; }
.inline-details summary { cursor: pointer; color: var(--primary); font-weight: 700; }
.mini-form { margin-top: 10px; display: grid; gap: 8px; min-width: 250px; }
.button--small { min-height: 34px; padding: 7px 10px; font-size: .78rem; border-radius: 9px; }
.compact-form-card { margin-bottom: 22px; }
.inline-grid-form { display: grid; grid-template-columns: 180px 220px auto; gap: 14px; align-items: end; }
.field--button { align-self: end; }
.period-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-start; }
.accounting-entry-card { padding: 26px; }
.journal-lines-heading { margin: 28px 0 12px; }
.journal-entry-table { min-width: 1100px; }
.journal-entry-table th:first-child, .journal-entry-table td:first-child { width: 45px; text-align: center; }
.journal-entry-table td:nth-child(2) { min-width: 280px; }
.journal-entry-table td:nth-child(3) { min-width: 190px; }
.journal-entry-table td:nth-child(4), .journal-entry-table td:nth-child(5) { min-width: 120px; }
.journal-entry-table td:nth-child(6) { min-width: 190px; }
.journal-entry-table tfoot th { padding: 13px 12px; background: #fafbfd; border-top: 1px solid var(--line); }
.money-input { text-align: right; font-variant-numeric: tabular-nums; }
.document-mini { display: grid; grid-template-columns: 70px 1fr; gap: 6px; }
.line-remove { width: 32px; height: 32px; border: 0; border-radius: 9px; background: var(--danger-bg); color: var(--danger); font-size: 1.35rem; line-height: 1; cursor: pointer; }
.entry-metric-grid { margin-bottom: 22px; }
.critical-action-card { margin-top: 22px; align-items: flex-start; }
.critical-action-card > div:first-child { max-width: 680px; }
.confirm-form { display: grid; gap: 14px; min-width: min(360px,100%); }
.reversal-form { flex: 1; max-width: 600px; }
code { padding: 2px 6px; border-radius: 6px; background: var(--surface-2); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }

@media (max-width: 900px) {
    .metric-grid--5 { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .quick-actions, .section-title-row, .critical-action-card { align-items: flex-start; flex-direction: column; }
    .search-form { width: 100%; grid-template-columns: 1fr auto; }
    .inline-grid-form { grid-template-columns: 1fr 1fr; }
    .field--button { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
    .topnav { max-width: 65vw; overflow-x: auto; white-space: nowrap; padding: 8px 0; }
    .topnav .nav-maintenance { display: none; }
    .metric-grid--5 { grid-template-columns: 1fr; }
    .workflow-list li { grid-template-columns: 1fr; gap: 3px; }
    .action-row { width: 100%; }
    .action-row .button { flex: 1 1 auto; }
    .search-form, .inline-grid-form { grid-template-columns: 1fr; }
    .field--button { grid-column: auto; }
    .accounting-entry-card { padding: 18px; }
    .journal-lines-heading { align-items: flex-start; flex-direction: column; }
    .critical-action-card { padding: 20px; }
    .confirm-form { min-width: 0; width: 100%; }
}

/* E1.1 - review-account correction workflow */
.row-actions { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px; }
.row-actions .inline-details { min-width: 90px; }
.form-actions--split { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
@media (max-width: 680px) {
    .form-actions--split { flex-direction: column-reverse; align-items: stretch; }
    .form-actions--split .button { width: 100%; text-align: center; }
    .row-actions { min-width: 170px; }
}
