/* ============================================================
   Rockstone Finance — Stylesheet
   Brand: Navy #1F3864, Red #C00000
   ============================================================ */

:root {
    --navy:        #1F3864;
    --navy-dark:   #0F1E3D;
    --navy-light:  #2E4F8C;
    --red:         #C00000;
    --red-light:   #E63946;
    --green:       #548235;
    --green-soft:  #E2EFDA;
    --gray-900:    #1A202C;
    --gray-700:    #4A5568;
    --gray-500:    #718096;
    --gray-300:    #CBD5E0;
    --gray-100:    #EDF2F7;
    --gray-50:     #F7FAFC;
    --bg-soft:     #F4F6FA;
    --bg-accent:   #EAF1FB;
    --bg-red-soft: #FBE5E5;
    --bg-yellow:   #FFF4D6;
    --white:       #FFFFFF;

    --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 2px 8px rgba(0,0,0,.08);
    --shadow-lg: 0 6px 20px rgba(0,0,0,.10);

    --radius:    6px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0; padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Arial, sans-serif;
    color: var(--gray-900);
    background: var(--bg-soft);
    font-size: 14px;
    line-height: 1.5;
}

a { color: var(--navy-light); text-decoration: none; }
a:hover { text-decoration: underline; color: var(--red); }

code, .mono {
    font-family: "SF Mono", Menlo, Monaco, Consolas, monospace;
    font-size: 0.92em;
    background: var(--gray-100);
    padding: 1px 6px;
    border-radius: 3px;
}

.mono { background: transparent; padding: 0; }

.muted { color: var(--gray-500); }
.small { font-size: 0.85em; }
.text-center { text-align: center; }

/* ============================================================
   HEADER
   ============================================================ */

.app-header {
    background: linear-gradient(90deg, var(--navy) 0%, var(--navy-light) 100%);
    color: white;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    gap: 32px;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    font-size: 18px;
    color: white;
    border-right: 2px solid rgba(255,255,255,.2);
    padding-right: 24px;
}

.brand strong { font-weight: 700; }
.brand .tagline {
    display: block;
    font-size: 11px;
    color: var(--red-light);
    font-weight: 600;
    letter-spacing: 0.5px;
    margin-top: 2px;
}

.main-nav { display: flex; gap: 4px; flex: 1; }
.main-nav a {
    color: rgba(255,255,255,.85);
    padding: 8px 14px;
    border-radius: var(--radius);
    font-weight: 500;
    transition: all 0.15s;
}
.main-nav a:hover {
    background: rgba(255,255,255,.12);
    color: white;
    text-decoration: none;
}

.user-info {
    color: rgba(255,255,255,.85);
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.logout {
    color: white !important;
    background: var(--red);
    padding: 6px 14px;
    border-radius: var(--radius);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.logout:hover {
    background: var(--red-light);
    text-decoration: none !important;
}

/* ============================================================
   HEADER BRANCH CONTEXT INDICATOR
   ============================================================ */

/* Container */
.header-branch-ctx {
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    margin-right: 8px;
}

/* "Branch" label */
.hdr-branch-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .7px;
    text-transform: uppercase;
    color: rgba(255,255,255,.5);
    white-space: nowrap;
}

/* The branch pill — button for multi-branch, span for single */
.hdr-branch-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: rgba(255,255,255,.12);
    border: 1px solid rgba(255,255,255,.2);
    border-radius: 6px;
    padding: 5px 11px 5px 9px;
    cursor: pointer;
    color: white;
    font-family: inherit;
    font-size: 13px;
    transition: background 120ms, border-color 120ms;
    white-space: nowrap;
    line-height: 1;
}
.hdr-branch-btn:hover {
    background: rgba(255,255,255,.2);
    border-color: rgba(255,255,255,.4);
}
.hdr-branch-btn--static {
    cursor: default;
}
.hdr-branch-btn--static:hover {
    background: rgba(255,255,255,.12);
    border-color: rgba(255,255,255,.2);
}

/* Status dot */
.hdr-branch-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Code in monospace-ish weight */
.hdr-branch-code {
    font-weight: 700;
    font-size: 12px;
    letter-spacing: .3px;
}

/* Full branch name — hidden on narrow screens */
.hdr-branch-name {
    font-size: 12px;
    color: rgba(255,255,255,.8);
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Chevron arrow */
.hdr-branch-chevron {
    font-size: 9px;
    color: rgba(255,255,255,.6);
    margin-left: 2px;
}

/* Dropdown menu */
.hdr-branch-menu {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 220px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,.15);
    z-index: 200;
    overflow: hidden;
}
.hdr-branch-menu.is-open {
    display: block;
}

.hdr-branch-menu-head {
    padding: 8px 14px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .6px;
    text-transform: uppercase;
    color: #9CA3AF;
    border-bottom: 1px solid #f0f0f0;
}

/* Each branch item in the menu */
.hdr-branch-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    font-size: 13px;
    color: #1F3864;
    background: white;
    border: none;
    cursor: pointer;
    font-family: inherit;
    text-align: left;
    text-decoration: none;
    transition: background 80ms;
    border-bottom: 1px solid #f7f7f7;
}
.hdr-branch-menu-item:last-child { border-bottom: none; }
.hdr-branch-menu-item:hover { background: #F0F4FB; }
.hdr-branch-menu-item.is-current { background: #EBF4FF; }

.hdr-mi-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
}

.hdr-branch-menu-item span > strong {
    display: block;
    font-weight: 700;
    font-size: 13px;
    color: #1F3864;
    line-height: 1.2;
}
.hdr-branch-menu-item span > em {
    display: block;
    font-style: normal;
    font-size: 11px;
    color: #6B7280;
    margin-top: 1px;
}

.hdr-mi-check {
    margin-left: auto;
    color: #059669;
    font-weight: 700;
    font-size: 14px;
}

/* User name in header */
.hdr-username {
    font-size: 13px;
    font-weight: 600;
    color: rgba(255,255,255,.85);
    white-space: nowrap;
}

/* Responsive: hide branch name text on small screens, keep code + dot */
@media (max-width: 640px) {
    .hdr-branch-name { display: none; }
    .hdr-branch-label { display: none; }
    .hdr-username { display: none; }
}
@media (max-width: 400px) {
    .hdr-branch-code { display: none; }
}

/* ============================================================
   FOOTER
   ============================================================ */

.app-footer {
    background: white;
    border-top: 1px solid var(--gray-300);
    padding: 16px 24px;
    text-align: center;
    color: var(--gray-500);
    font-size: 12px;
    margin-top: 60px;
}
.app-footer .tagline {
    color: var(--red);
    font-weight: 600;
}

/* ============================================================
   CONTAINER
   ============================================================ */

.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 24px;
    min-height: calc(100vh - 200px);
}

.page-header {
    margin-bottom: 24px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.page-header h1 {
    margin: 0 0 4px 0;
    font-size: 24px;
    color: var(--navy);
    font-weight: 700;
}

.page-header p {
    margin: 0;
    color: var(--gray-500);
}

/* ============================================================
   CARDS
   ============================================================ */

.card {
    background: white;
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 24px;
    border: 1px solid var(--gray-100);
}

.card h1, .card h2, .card h3 {
    color: var(--navy);
    margin-top: 0;
}

.card h2 { font-size: 18px; }
.card h3 {
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray-500);
    margin-top: 24px;
    margin-bottom: 12px;
}

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
    display: inline-block;
    padding: 8px 18px;
    border-radius: var(--radius);
    background: white;
    color: var(--navy);
    border: 1px solid var(--gray-300);
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    font-size: 14px;
    transition: all 0.15s;
    line-height: 1.5;
    font-family: inherit;
}
.btn:hover {
    background: var(--gray-100);
    text-decoration: none;
    border-color: var(--gray-500);
}

.btn-primary {
    background: var(--navy);
    color: white;
    border-color: var(--navy);
}
.btn-primary:hover {
    background: var(--navy-dark);
    color: white;
    border-color: var(--navy-dark);
}

.btn-block {
    display: block;
    width: 100%;
}

/* ============================================================
   FORMS
   ============================================================ */

label {
    display: block;
    margin-bottom: 14px;
    font-weight: 500;
    color: var(--gray-700);
    font-size: 13px;
}

input[type="text"], input[type="email"], input[type="password"],
input[type="date"], input[type="number"], select, textarea {
    width: 100%;
    padding: 8px 12px;
    margin-top: 4px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 14px;
    background: white;
    font-family: inherit;
    color: var(--gray-900);
    transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--navy-light);
    box-shadow: 0 0 0 3px rgba(46, 79, 140, 0.1);
}

input[type="number"].amt {
    text-align: right;
    font-family: "SF Mono", Menlo, Monaco, Consolas, monospace;
}

.form-row {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.form-row .full-width { grid-column: span 2; }

.form-actions {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--gray-100);
    display: flex;
    gap: 12px;
}

.inline-form {
    display: inline-flex;
    align-items: flex-end;
    gap: 12px;
    margin: 0;
}

.inline-form label { margin: 0; }

/* ============================================================
   ALERTS
   ============================================================ */

.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    border-left: 4px solid;
}

.alert-success {
    background: var(--green-soft);
    border-color: var(--green);
    color: #1A3D0F;
}

.alert-error {
    background: var(--bg-red-soft);
    border-color: var(--red);
    color: #5A0000;
}

.alert-warning {
    background: var(--bg-yellow);
    border-color: #B8860B;
    color: #5C4400;
}

.alert-info {
    background: var(--bg-accent);
    border-color: var(--navy);
    color: var(--navy-dark);
}

/* ============================================================
   TABLES
   ============================================================ */

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th, .data-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--gray-100);
    text-align: left;
    vertical-align: top;
}

.data-table thead th {
    background: var(--bg-soft);
    color: var(--navy);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-bottom: 2px solid var(--navy);
}

.data-table tbody tr:hover {
    background: var(--bg-soft);
}

.data-table .num {
    text-align: right;
    font-family: "SF Mono", Menlo, Monaco, Consolas, monospace;
    font-size: 13px;
    white-space: nowrap;
}

.data-table .totals {
    background: var(--gray-100);
    font-weight: 700;
    font-size: 14px;
    border-top: 2px solid var(--navy);
}

.data-table .totals th {
    background: var(--gray-100);
    color: var(--navy);
    border-top: 2px solid var(--navy);
    text-transform: none;
    letter-spacing: 0;
    font-size: 14px;
}

.data-table .row-reversed {
    color: var(--gray-500);
    text-decoration: line-through;
}
.data-table .row-reversed .badge-bad { text-decoration: none; display: inline-block; }

/* Account type colours */
.type-asset    { color: var(--navy-light); font-weight: 600; }
.type-liability { color: var(--red); font-weight: 600; }
.type-equity   { color: #6B46C1; font-weight: 600; }
.type-income   { color: var(--green); font-weight: 600; }
.type-expense  { color: #B45309; font-weight: 600; }

/* ============================================================
   BADGES
   ============================================================ */

.badge-good, .badge-bad {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-good {
    background: var(--green-soft);
    color: #2E5316;
}

.badge-bad {
    background: var(--bg-red-soft);
    color: #8B0000;
}

/* ============================================================
   KPI CARDS
   ============================================================ */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: white;
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    border-top: 3px solid var(--navy);
    position: relative;
}

.kpi-card.kpi-good { border-top-color: var(--green); }
.kpi-card.kpi-bad  { border-top-color: var(--red); }

.kpi-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray-500);
    margin-bottom: 8px;
}

.kpi-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--navy);
    line-height: 1.1;
}

.kpi-card.kpi-good .kpi-value { color: var(--green); }
.kpi-card.kpi-bad .kpi-value  { color: var(--red); }

.kpi-link {
    display: inline-block;
    margin-top: 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--navy-light);
}

.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

/* ============================================================
   JOURNAL ENTRY FORM
   ============================================================ */

.je-form select { font-size: 13px; }
.je-form input { font-size: 13px; padding: 6px 10px; margin: 0; }

.balance-status {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    background: var(--gray-100);
    color: var(--gray-500);
}
.balance-status.balanced {
    background: var(--green-soft);
    color: #2E5316;
}
.balance-status.unbalanced {
    background: var(--bg-red-soft);
    color: #8B0000;
}

/* ============================================================
   REPORTS (TB / P&L / BS)
   ============================================================ */

.report-card { padding: 32px 40px; }

.report-meta {
    text-align: center;
    color: var(--gray-700);
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--gray-100);
    font-size: 13px;
}

.report-table {
    margin: 0 auto;
    max-width: 800px;
}

.report-table .particulars { width: 70%; }

.report-table .section-header th {
    background: var(--navy);
    color: white;
    font-size: 13px;
    padding: 10px 12px;
}

.report-table .group-header td {
    background: var(--bg-accent);
    padding-top: 8px;
    padding-bottom: 8px;
}

.report-table .indent {
    padding-left: 36px;
}

.report-table .subtotal th {
    background: var(--bg-soft);
    border-top: 1px solid var(--navy-light);
    border-bottom: 1px solid var(--navy-light);
    padding: 10px 12px;
}

.report-table .subtotal.pbt th {
    background: var(--bg-yellow);
    border: 2px solid #B8860B;
}

.report-table .grand-total th {
    background: var(--navy);
    color: white;
    font-size: 15px;
    padding: 12px;
    border: none;
}

.report-footnote {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--gray-100);
    font-style: italic;
}

/* ============================================================
   AUTH / SETUP PAGES
   ============================================================ */

.auth-body, .setup-body {
    background: linear-gradient(135deg, var(--navy) 0%, var(--navy-dark) 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.auth-container {
    width: 100%;
    max-width: 420px;
}

.setup-container {
    width: 100%;
    max-width: 720px;
}

.brand-large {
    text-align: center;
    color: white;
    margin-bottom: 32px;
    font-size: 32px;
}

.brand-large strong { font-weight: 700; }

.brand-large .tagline {
    font-size: 12px;
    color: var(--red-light);
    font-weight: 600;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    margin-top: 8px;
}

.setup-container .card {
    background: white;
}

.setup-steps {
    list-style: none;
    padding: 0;
    margin: 0 0 24px 0;
    display: flex;
    gap: 4px;
    color: white;
    counter-reset: step;
}

.setup-steps li {
    flex: 1;
    background: rgba(255,255,255,.1);
    padding: 12px;
    border-radius: var(--radius);
    text-align: center;
    font-size: 12px;
    counter-increment: step;
    position: relative;
    color: rgba(255,255,255,.6);
}

.setup-steps li::before {
    content: counter(step);
    display: inline-block;
    width: 22px;
    height: 22px;
    line-height: 22px;
    border-radius: 50%;
    background: rgba(255,255,255,.2);
    color: white;
    font-weight: 700;
    margin-right: 6px;
}

.setup-steps li.done {
    background: var(--green);
    color: white;
}
.setup-steps li.done::before { background: rgba(255,255,255,.3); }

.setup-steps li.active {
    background: var(--red);
    color: white;
    font-weight: 600;
}
.setup-steps li.active::before { background: white; color: var(--red); }

/* Responsive */
@media (max-width: 768px) {
    .app-header {
        flex-wrap: wrap;
        gap: 12px;
        padding: 12px 16px;
    }
    .brand { border-right: none; padding-right: 0; }
    .main-nav { width: 100%; flex-wrap: wrap; }
    .form-row { grid-template-columns: 1fr; }
    .form-row .full-width { grid-column: span 1; }
    .kpi-grid { grid-template-columns: 1fr; }
    .container { padding: 16px; }
    .data-table { font-size: 12px; }
    .data-table th, .data-table td { padding: 6px 8px; }
    .report-card { padding: 16px; }
}

/* ============================================================
   ADMIN-SPECIFIC STYLES
   ============================================================ */

.nav-admin {
    background: var(--red);
    color: white !important;
}
.nav-admin:hover { background: var(--red-light); }

.role-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.role-badge.role-admin      { background: var(--red); color: white; }
.role-badge.role-accountant { background: var(--navy-light); color: white; }
.role-badge.role-viewer     { background: var(--gray-300); color: var(--gray-900); }

.role-info {
    list-style: none;
    padding: 0;
}
.role-info li {
    padding: 8px 0;
    border-bottom: 1px solid var(--gray-100);
}
.role-info li:last-child { border-bottom: none; }

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 12px 0;
}
.checkbox-label input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.checkbox-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 4px 12px 4px 0;
    font-weight: normal;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}
.checkbox-inline:hover {
    background: var(--bg-soft);
}
.checkbox-inline input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.member-picker fieldset {
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    margin: 8px 0;
    padding: 8px 16px 12px;
}
.member-picker legend {
    padding: 0 8px;
    font-weight: 600;
    color: var(--navy);
    font-size: 13px;
}

.view-switcher {
    display: flex;
    gap: 4px;
}

.link-button {
    background: none;
    border: none;
    color: var(--red);
    cursor: pointer;
    padding: 0;
    text-decoration: none;
    font-size: inherit;
    font-family: inherit;
}
.link-button:hover { text-decoration: underline; }

input[disabled] {
    background: var(--gray-100);
    color: var(--gray-500);
    cursor: not-allowed;
}

/* ============================================================
   GOLDEN RULE VIOLATIONS UI
   ============================================================ */

.violations-card {
    border-left: 4px solid var(--red);
    background: #fff8f8;
}
.violations-heading {
    color: var(--red) !important;
}

.violations-list {
    list-style: none;
    padding: 0;
    margin: 16px 0;
}
.violation-item {
    padding: 12px 16px;
    margin: 8px 0;
    border-radius: var(--radius);
    background: white;
    border-left: 4px solid var(--gray-300);
}
.violation-item.violation-high   { border-color: var(--red);    background: var(--bg-red-soft); }
.violation-item.violation-medium { border-color: #B8860B;       background: var(--bg-yellow); }
.violation-item.violation-low    { border-color: var(--gray-500); background: var(--gray-50); }

.violation-severity {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    background: var(--gray-300);
    color: var(--gray-900);
    margin-right: 8px;
}
.violation-high   .violation-severity { background: var(--red);    color: white; }
.violation-medium .violation-severity { background: #B8860B;       color: white; }
.violation-low    .violation-severity { background: var(--gray-500); color: white; }

.violation-code {
    font-family: "SF Mono", Menlo, monospace;
    font-size: 12px;
    color: var(--gray-700);
    background: rgba(0,0,0,.04);
    padding: 1px 6px;
    border-radius: 3px;
}
.violation-desc {
    margin: 8px 0 0 0;
    color: var(--gray-900);
}

.btn-warning {
    background: #B8860B;
    color: white;
    border-color: #B8860B;
}
.btn-warning:hover {
    background: #8B6508;
    border-color: #8B6508;
    color: white;
}

.severity-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.severity-badge.severity-high   { background: var(--red);    color: white; }
.severity-badge.severity-medium { background: #B8860B;       color: white; }
.severity-badge.severity-low    { background: var(--gray-500); color: white; }

.violation-row.violation-high td   { background: rgba(192,0,0,0.04); }
.violation-row.violation-medium td { background: rgba(184,134,11,0.04); }

.violation-ack-form textarea {
    width: 100%;
    padding: 8px 12px;
    margin-top: 4px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
}

/* Auditor role badge */
.role-badge.role-auditor { background: #6B46C1; color: white; }

/* ============================================================
   LEDGER VIEW
   ============================================================ */

.ledger-form .form-row {
    grid-template-columns: 1fr 1fr 2fr;
    gap: 12px;
}
.ledger-form .full-width {
    grid-column: span 3;
}

.ledger-header h2 {
    color: var(--navy);
    margin-bottom: 4px;
}

.ledger-table .opening-row,
.ledger-table .closing-row {
    background: var(--bg-accent);
}
.ledger-table .opening-row td,
.ledger-table .closing-row th {
    border-top: 2px solid var(--navy-light);
    border-bottom: 2px solid var(--navy-light);
    font-weight: 600;
}

.ledger-table .row-reversed td {
    text-decoration: line-through;
    color: var(--gray-500);
}
.ledger-table .row-reversed .badge-bad {
    text-decoration: none;
}


/* ============================================================
   Layout v2.1 — Minimal top bar + grouped left sidebar
   Uses CSS Grid for the app shell (more robust than v2.0 fixed positioning).
   Appended May 2026
   ============================================================ */

:root {
    --sidebar-width: 240px;
    --header-height: 125px;
    --footer-height: 60px;
    --sidebar-bg: #FFFFFF;
    --sidebar-border: #E2E8F0;
    --sidebar-hover: #F4F6FA;
    --sidebar-active-bg: #EAF1FB;
    --sidebar-active-bar: var(--navy);
}

/* ------------------------------------------------------------
   App shell — CSS Grid layout
   ------------------------------------------------------------ */

body.has-sidebar {
    background: var(--bg-soft);
    margin: 0;
    min-height: 100vh;
}

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--header-height) 1fr auto;
    grid-template-areas:
        "header header"
        "sidebar main"
        "footer  footer";
    min-height: 100vh;
}

body.has-sidebar .app-header {
    grid-area: header;
    padding: 5px 20px;
    gap: 16px;
    min-height: var(--header-height);
    align-items: center;
    /* Sticky inside grid: stays at top during scroll */
    position: sticky;
    top: 0;
    z-index: 10;
}

.app-sidebar {
    grid-area: sidebar;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    overflow-y: auto;
    overflow-x: hidden;
    /* Make sidebar stick to top while scrolling main content */
    position: sticky;
    top: var(--header-height);
    align-self: start;
    height: calc(100vh - var(--header-height));
    box-shadow: var(--shadow-sm);
}

.app-main {
    grid-area: main;
    padding: 24px 32px;
    min-width: 0; /* prevent grid blow-out from wide content */
    background: var(--bg-soft);
}

body.has-sidebar .app-footer {
    grid-area: footer;
}

/* ------------------------------------------------------------
   Header refinements (only when in sidebar mode)
   ------------------------------------------------------------ */

.header-spacer {
    flex: 1;
}

body.has-sidebar .brand {
    border-right: none;
    padding-right: 0;
    font-size: 16px;
}

body.has-sidebar .brand .tagline {
    font-size: 10px;
}

.user-info .user-name {
    color: rgba(255, 255, 255, .9);
    font-weight: 500;
    padding: 4px 10px;
    border-radius: var(--radius);
    transition: background 0.15s;
}
.user-info .user-name:hover {
    background: rgba(255, 255, 255, .12);
    text-decoration: none;
    color: white;
}

/* ------------------------------------------------------------
   Sidebar toggle (hamburger) — visible only on mobile
   ------------------------------------------------------------ */

.sidebar-toggle {
    display: none;
    background: transparent;
    border: none;
    width: 36px;
    height: 36px;
    padding: 8px;
    cursor: pointer;
    flex-direction: column;
    justify-content: space-between;
    border-radius: var(--radius);
    transition: background 0.15s;
}
.sidebar-toggle:hover { background: rgba(255, 255, 255, .12); }
.sidebar-toggle span {
    display: block;
    height: 2px;
    background: white;
    border-radius: 2px;
    transition: all 0.2s;
}

/* ------------------------------------------------------------
   Sidebar nav
   ------------------------------------------------------------ */

.sidebar-nav {
    padding: 12px 0;
}

.nav-group {
    border-bottom: 1px solid var(--sidebar-border);
}
.nav-group:last-of-type {
    border-bottom: none;
}

.nav-group-summary {
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
    margin: 0;

    cursor: pointer;
    padding: 11px 18px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--gray-700);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    user-select: none;
    transition: all 0.15s;
}
.nav-group-summary:hover {
    background: var(--sidebar-hover);
    color: var(--navy);
}
.nav-group-summary:focus-visible {
    outline: 2px solid var(--navy-light);
    outline-offset: -2px;
}
.nav-group-summary.is-active {
    color: var(--navy);
}

.nav-group-label {
    flex: 1;
    min-width: 0;
}

.nav-chevron {
    flex-shrink: 0;
    font-size: 10px;
    color: var(--gray-500);
    transition: transform 0.2s;
    line-height: 1;
    display: inline-block;
}
.nav-group-summary[aria-expanded="true"] .nav-chevron {
    transform: rotate(90deg);
}

.nav-group-items {
    list-style: none;
    margin: 0;
    padding: 4px 0 8px 0;
}
.nav-group-items li { margin: 0; }

.nav-item {
    display: block;
    padding: 7px 18px 7px 32px;
    color: var(--gray-700);
    font-size: 13.5px;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: all 0.15s;
}
.nav-item:hover {
    background: var(--sidebar-hover);
    color: var(--navy);
    text-decoration: none;
    border-left-color: var(--gray-300);
}
.nav-item.is-current {
    color: var(--navy);
    background: var(--sidebar-active-bg);
    font-weight: 600;
    border-left-color: var(--sidebar-active-bar);
}
.nav-item.is-current:hover { color: var(--navy); }

.nav-group-admin {
    border-top: 2px solid var(--sidebar-border);
    margin-top: 8px;
    padding: 10px 0;
}
.nav-admin-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    color: var(--red);
    font-size: 13.5px;
    font-weight: 600;
    border-left: 3px solid transparent;
    transition: all 0.15s;
}
.nav-admin-link:hover {
    background: var(--bg-red-soft);
    color: var(--red);
    text-decoration: none;
    border-left-color: var(--red);
}
.nav-admin-link.is-current {
    background: var(--bg-red-soft);
    border-left-color: var(--red);
}

/* ------------------------------------------------------------
   Mobile drawer (< 900px) — sidebar becomes overlay
   ------------------------------------------------------------ */

.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 30, 61, 0.45);
    z-index: 8;
    opacity: 0;
    transition: opacity 0.2s;
}
.sidebar-backdrop.is-visible {
    display: block;
    opacity: 1;
}

@media (max-width: 900px) {
    .sidebar-toggle { display: flex; }

    .app-shell {
        grid-template-columns: 1fr;
        grid-template-areas:
            "header"
            "main"
            "footer";
    }

    .app-sidebar {
        grid-area: unset;
        position: fixed;
        top: var(--header-height);
        left: 0;
        width: var(--sidebar-width);
        height: calc(100vh - var(--header-height));
        z-index: 9;
        transform: translateX(-100%);
        transition: transform 0.25s cubic-bezier(.2,.8,.2,1);
        box-shadow: var(--shadow-lg);
    }
    .app-sidebar.is-open {
        transform: translateX(0);
    }

    .app-main {
        padding: 20px 16px;
    }
}

@media (max-width: 768px) {
    body.has-sidebar .app-header {
        flex-wrap: nowrap;
        gap: 10px;
        padding: 8px 12px;
    }
    body.has-sidebar .brand {
        font-size: 14px;
    }
    body.has-sidebar .brand .tagline {
        display: none;
    }
    .user-info {
        font-size: 12px;
        gap: 8px;
    }
    .logout {
        padding: 5px 10px;
    }
}

/* Body lock when drawer is open */
body.sidebar-locked {
    overflow: hidden;
}

/* ------------------------------------------------------------
   v2.0 compatibility shims — neutralize old rules that might
   still be referenced (in case install was a partial v2.0 -> v2.1)
   ------------------------------------------------------------ */
.container.with-sidebar {
    /* No-op when v2.1 layout is active. The new app-main grid handles spacing.
       Kept to avoid breakage if any legacy template uses .container with-sidebar. */
    margin-left: 0;
    padding: 0;
    max-width: none;
}
.container.with-sidebar > * {
    max-width: none;
}

/* ------------------------------------------------------------
   Header — logo + brand text + icon logout  (Layout v2.1 update)
   ------------------------------------------------------------ */

/* Brand: logo image + text stacked */
body.has-sidebar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    border-right: none;
    padding-right: 0;
    font-size: 16px;
    text-decoration: none;
}

.brand-logo {
    height: 115px;
    width: 115px;
    object-fit: contain;
    flex-shrink: 0;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,.25);
    background: white;
    padding: 4px;
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.brand-name {
    font-size: 15px;
    font-weight: 700;
    color: white;
    letter-spacing: 0.2px;
}

body.has-sidebar .brand .tagline {
    font-size: 10px;
    color: rgba(255, 255, 255, .65);
    font-weight: 400;
    letter-spacing: 0.3px;
}

/* Logout — icon-only circular button */
.logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    color: rgba(255, 255, 255, .85);
    background: rgba(255, 255, 255, .1);
    border: 1px solid rgba(255, 255, 255, .2);
    transition: all 0.15s;
    flex-shrink: 0;
}
.logout-btn:hover {
    background: rgba(192, 0, 0, .75);
    border-color: rgba(192, 0, 0, .9);
    color: white;
    text-decoration: none;
}
.logout-btn svg {
    display: block;
}

/* Mobile: keep logo legible on small screens */
@media (max-width: 768px) {
    .brand-logo { height: 60px; width: 60px; }
    .brand-name { font-size: 13px; }
    body.has-sidebar .brand .tagline { display: none; }
}

/* ------------------------------------------------------------
   Sidebar bottom user identity block
   ------------------------------------------------------------ */
.nav-group-user {
    border-top: 1px solid var(--sidebar-border);
    margin-top: auto;
    padding: 8px 0 4px 0;
}
.nav-user-name {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 8px 18px 4px 18px;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-700);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
