:root {
    --bg: #f4f7f6;
    --panel: #ffffff;
    --ink: #17201d;
    --muted: #68736e;
    --line: #dfe7e3;
    --green: #1f8a5b;
    --blue: #2d6cdf;
    --gold: #b47812;
    --red: #c94848;
    --shadow: 0 12px 28px rgba(23, 32, 29, .08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
}

.sidebar {
    width: 248px;
    height: 100vh;
    padding: 24px 18px;
    background: #13251f;
    color: #fff;
    position: fixed !important;
    top: 0;
    right: auto;
    left: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 34px;
}

.brand-mark {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    background: #f0b33d;
    color: #13251f;
    border-radius: 8px;
    font-weight: 800;
}

.brand strong,
.brand small {
    display: block;
}

.brand small {
    color: #b8c8c1;
    margin-top: 2px;
}

.sidebar nav {
    display: grid;
    gap: 8px;
}

.sidebar a {
    color: #dbe9e3;
    text-decoration: none;
    padding: 12px 14px;
    border-radius: 8px;
}

.sidebar a:hover,
.sidebar a.active {
    background: rgba(255, 255, 255, .1);
    color: #fff;
}

.nav-logout {
    margin-top: 18px;
    color: #13251f;
    background: #f0b33d;
    text-align: center;
    text-decoration: none;
    padding: 12px 14px;
    border-radius: 8px;
    font-weight: 700;
}

.sidebar a.nav-logout:hover,
.sidebar a.nav-logout.active {
    background: #f0b33d;
    color: #13251f;
}

.app {
    padding: 28px;
    max-width: 1400px;
    width: calc(100% - 248px);
    margin-left: 248px;
}

.topbar,
.panel-title,
.row-title,
.form-actions,
.head-form {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
}

.user-pill small {
    color: var(--green);
    font-size: 11px;
    font-weight: 800;
}

.logout-button {
    border-color: #f0b33d;
    background: #fff8e8;
    color: #13251f;
    font-weight: 700;
}

.icon-only {
    width: 42px;
    padding: 0;
}

.icon-only svg {
    width: 21px;
    height: 21px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sidebar .icon-only {
    justify-self: center;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: 28px;
}

h2 {
    font-size: 20px;
}

p {
    color: var(--muted);
    margin-top: 6px;
}

button,
.button,
select,
input {
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 12px;
    font: inherit;
}

button,
.button {
    background: #fff;
    color: var(--ink);
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.primary {
    border-color: var(--green);
    background: var(--green);
    color: #fff;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(180px, 1fr));
    gap: 16px;
    margin: 28px 0;
}

.monthly-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(180px, 1fr));
    gap: 16px;
    margin: 20px 0;
}

.summary-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-left: 5px solid var(--green);
    border-radius: 8px;
    padding: 18px;
    box-shadow: var(--shadow);
}

.summary-card span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 12px;
}

.summary-card strong {
    display: block;
    font-size: 24px;
}

.statement-page {
    margin-top: 22px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.statement-page h3 {
    margin: 0 0 16px;
    text-align: center;
    font-size: 18px;
    letter-spacing: 0;
}

.statement-table-wrap {
    overflow: auto;
}

.statement-table {
    min-width: 900px;
    border: 2px solid var(--ink);
}

.statement-table th,
.statement-table td {
    border: 1px solid var(--ink);
    padding: 9px 10px;
}

.statement-table th {
    color: var(--ink);
    background: #eef4f1;
}

.statement-section-row th,
.statement-table tfoot th {
    background: #dfe9e4;
    font-size: 15px;
}

.statement-table tfoot td {
    text-align: center;
    font-weight: 700;
}

@media print {
    body {
        display: block;
        background: #fff;
    }

    body:not(.print-transactions) * {
        visibility: hidden;
    }

    body:not(.print-transactions) .statement-page,
    body:not(.print-transactions) .statement-page * {
        visibility: visible;
    }

    body:not(.print-transactions) .statement-page {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        margin: 0;
        padding: 0;
        border: 0;
        box-shadow: none;
    }

    body:not(.print-transactions) .statement-table {
        width: 100%;
        min-width: 0;
    }

    body.print-transactions * {
        visibility: hidden;
    }

    body.print-transactions #records,
    body.print-transactions #records * {
        visibility: visible;
    }

    body.print-transactions #records {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        margin: 0;
        padding: 0;
        border: 0;
        box-shadow: none;
    }

    body.print-transactions .transaction-print-actions {
        display: none;
    }

    body.print-transactions #records .filters,
    body.print-transactions #records .panel-title p,
    body.print-transactions #records input,
    body.print-transactions #records select,
    body.print-transactions #records button,
    body.print-transactions #records .row-actions {
        display: none;
    }

    body.print-transactions table {
        width: 100%;
        min-width: 0;
    }
}

.summary-card.bank {
    border-left-color: var(--blue);
}

.summary-card.samurdhi,
.summary-card.total {
    border-left-color: var(--gold);
}

.summary-card.expense {
    border-left-color: var(--red);
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(160px, 1fr));
    gap: 16px;
    margin-top: 20px;
}

.compact-form {
    grid-template-columns: repeat(3, minmax(180px, 1fr));
}

label {
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
}

label input,
label select,
.filters input,
.filters select,
.head-form input,
.head-form select {
    width: 100%;
    background: #fff;
    color: var(--ink);
}

select[multiple] {
    min-height: 104px;
    padding: 8px;
}

.password-field {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: stretch;
}

.password-field input {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.password-toggle {
    min-width: 68px;
    border-left: 0;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    background: #f7faf8;
}

.wide {
    grid-column: span 2;
}

.filters {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    flex-wrap: wrap;
}

.compact-filter {
    min-width: 220px;
}

.transaction-total {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 18px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f7faf8;
}

.transaction-total span {
    color: var(--muted);
    font-size: 13px;
}

.transaction-total strong {
    font-size: 20px;
}

.transaction-print-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 16px;
}

.table-wrap {
    overflow: auto;
    margin-top: 18px;
}

.login-log-wrap {
    max-height: 340px;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.login-log-wrap table {
    margin: 0;
}

.login-log-wrap thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #fff;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 860px;
}

th,
td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.right {
    text-align: right;
}

.tag {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 0 9px;
    border-radius: 999px;
    font-size: 12px;
    color: #fff;
    background: var(--green);
}

.tag.expense {
    background: var(--red);
}

.tag.role-admin {
    background: var(--blue);
}

.tag.role-cashier,
.tag.status-pending {
    background: var(--gold);
}

.tag.role-staff {
    background: var(--gold);
}

.row-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

.row-actions button {
    min-height: 32px;
    padding: 0 9px;
}

.link-button {
    min-height: 0;
    border: 0;
    padding: 0;
    background: transparent;
    color: var(--blue);
    text-align: left;
    text-decoration: underline;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(23, 32, 29, .48);
}

.modal-backdrop[hidden] {
    display: none;
}

.modal {
    width: min(1280px, 100%);
    max-height: 88vh;
    overflow: auto;
    padding: 20px;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 24px 60px rgba(23, 32, 29, .25);
}

.modal table {
    min-width: 1280px;
}

.modal-title,
.modal-total {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.modal-total {
    margin-top: 16px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f7faf8;
}

.modal-total span {
    color: var(--muted);
    font-size: 13px;
}

.head-form {
    justify-content: flex-start;
    margin: 18px 0;
}

.head-form input {
    max-width: 420px;
}

.head-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(240px, 1fr));
    gap: 12px;
}

.chart-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(280px, 1fr));
    gap: 16px;
    margin-top: 20px;
}

.chart-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    background: #fff;
}

.chart-panel h3,
.settings-role h3 {
    margin: 0 0 12px;
    font-size: 16px;
}

.chart-panel canvas {
    display: block;
    width: 100%;
    height: auto;
}

.settings-grid {
    margin-top: 18px;
}

#viewSettingsRows {
    display: grid;
    grid-template-columns: repeat(2, minmax(220px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.settings-role {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}

.check-row {
    display: flex;
    grid-template-columns: none;
    align-items: center;
    gap: 10px;
    min-height: 34px;
    color: var(--ink);
}

.check-row input {
    width: auto;
    min-height: 0;
}

.head-group {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}

.head-group h3 {
    margin: 0 0 10px;
    font-size: 16px;
}

.head-item {
    display: flex;
    gap: 10px;
    padding: 8px 0;
    border-top: 1px solid var(--line);
}

.head-item code {
    color: var(--muted);
    min-width: 34px;
}

#formMessage,
#headMessage,
#passwordMessage,
#userMessage,
#waterMessage,
#settingsMessage {
    color: var(--green);
}

.setup-page {
    display: grid;
    grid-template-columns: 1fr;
    place-items: center;
    padding: 24px;
}

.login-page {
    display: grid;
    grid-template-columns: 1fr;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(135deg, rgba(31, 138, 91, .12), rgba(240, 179, 61, .16)),
        var(--bg);
}

.login-shell {
    width: min(920px, 100%);
    display: grid;
    grid-template-columns: 1fr 420px;
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.login-intro {
    padding: 44px;
    background: #13251f;
    color: #fff;
}

.login-intro h1 {
    margin-top: 62px;
    font-size: 34px;
}

.login-intro p {
    color: #cddbd5;
    max-width: 420px;
    line-height: 1.6;
}

.login-brand {
    margin-bottom: 0;
}

.login-card {
    padding: 44px;
}

.login-card h2 {
    margin-bottom: 18px;
}

.login-form {
    display: grid;
    gap: 16px;
}

.login-form button {
    width: 100%;
    margin-top: 4px;
}

.login-help {
    display: grid;
    gap: 6px;
    margin-top: 22px;
    padding: 14px;
    background: #f7faf8;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--muted);
    font-size: 13px;
}

.login-help strong {
    color: var(--ink);
}

.notice {
    margin-bottom: 14px;
}

.setup-box {
    width: min(520px, 100%);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 26px;
    box-shadow: var(--shadow);
}

.success {
    color: var(--green);
}

.error {
    color: var(--red);
}

@media (max-width: 980px) {
    .sidebar {
        width: 248px;
        height: 100vh;
    }

    .app {
        margin-left: 248px;
        width: calc(100% - 248px);
    }

    .sidebar nav {
        grid-template-columns: 1fr;
    }

    .summary-grid,
    .monthly-grid,
    .form-grid,
    .compact-form,
    .head-list,
    .chart-grid,
    #viewSettingsRows {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 640px) {
    .app {
        padding: 18px;
        margin-left: 0;
        padding-top: 108px;
        width: 100%;
    }

    .sidebar {
        width: 100%;
        height: auto;
        min-height: 0;
        max-height: 96px;
        padding: 12px;
    }

    .brand {
        margin-bottom: 10px;
    }

    .sidebar nav {
        display: flex;
        gap: 8px;
        overflow-x: auto;
    }

    .topbar,
    .panel-title,
    .row-title,
    .form-actions,
    .top-actions,
    .head-form,
    .filters {
        align-items: stretch;
        flex-direction: column;
    }

    .login-shell {
        grid-template-columns: 1fr;
    }

    .login-intro,
    .login-card {
        padding: 28px;
    }

    .login-intro h1 {
        margin-top: 32px;
        font-size: 28px;
    }

    .summary-grid,
    .monthly-grid,
    .form-grid,
    .compact-form,
    .head-list,
    .chart-grid,
    #viewSettingsRows {
        grid-template-columns: 1fr;
    }

    .wide {
        grid-column: span 1;
    }
}
