/* Petty Cash Manager - application styles
   A restrained accounting interface: dense tables, clear figures, no decoration. */

:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-alt: #f8fafc;
    --border: #dfe4ec;
    --border-strong: #c3cbd8;
    --text: #1d2430;
    --text-muted: #6b7688;
    --brand: #14496b;
    --brand-dark: #0f3852;
    --brand-light: #e7eef5;
    --dr: #12694a;
    --cr: #a12d2d;
    --warning: #8a5b00;
    --warning-bg: #fdf4e0;
    --danger: #9d2222;
    --danger-bg: #fbeaea;
    --success: #14683f;
    --success-bg: #e8f5ee;
    --info-bg: #e8f0f8;
    --radius: 6px;
    --shadow: 0 1px 2px rgba(20, 33, 51, .06), 0 1px 8px rgba(20, 33, 51, .04);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
code { font-family: var(--mono); font-size: .85em; }

.muted { color: var(--text-muted); }
.small { font-size: .85rem; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.dr { color: var(--dr); }
.cr { color: var(--cr); }
.balance { color: var(--brand); }
.negative { color: var(--danger); }
.ok { color: var(--success); }
.warn { color: var(--warning); }
.bad { color: var(--danger); }

/* ---------------------------------------------------------------- Layout */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 236px;
    flex: 0 0 236px;
    background: var(--brand-dark);
    color: #dce6ef;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    display: flex;
    gap: .6rem;
    align-items: center;
    padding: 1.1rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, .1);
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: var(--radius);
    background: #2e7fae;
    color: #fff;
    font-weight: 700;
    letter-spacing: .5px;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { color: #fff; }
.brand-text small { color: #9fb6c9; font-size: .75rem; }

.sidebar-nav { padding: .75rem .5rem; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }

.nav-link {
    display: block;
    padding: .55rem .75rem;
    border-radius: var(--radius);
    color: #cddae5;
    font-size: .92rem;
}
.nav-link:hover { background: rgba(255, 255, 255, .08); color: #fff; text-decoration: none; }
.nav-link.active { background: #2e7fae; color: #fff; font-weight: 600; }

.sidebar-footer { margin-top: auto; padding: .75rem 1rem; font-size: .75rem; color: #7f97ab; }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .7rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.page-title { font-size: 1.05rem; margin: 0; font-weight: 600; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: .75rem; }
.topbar-user { display: flex; align-items: center; gap: .5rem; color: var(--text); }
.topbar-user:hover { text-decoration: none; }
.topbar-user-text { display: flex; flex-direction: column; line-height: 1.15; }
.topbar-user-text small { color: var(--text-muted); font-size: .75rem; }

.avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--brand-light);
    color: var(--brand);
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700;
}

.icon-btn {
    display: none;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .3rem .6rem;
    cursor: pointer;
    font-size: 1rem;
}

.content { padding: 1.25rem; max-width: 1500px; width: 100%; }

/* ----------------------------------------------------------------- Cards */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.1rem 1.25rem;
    margin-bottom: 1.1rem;
}

.page-head {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}
.section-title { margin-bottom: .15rem; }
.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; }

.breadcrumb { font-size: .85rem; color: var(--text-muted); margin-bottom: .3rem; }
.breadcrumb span { margin: 0 .35rem; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; align-items: start; }
.grid-form { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 1.1rem; align-items: start; }
.side-card h3 { margin-top: 1rem; }
.side-card h3:first-child { margin-top: 0; }
.form-card { max-width: 760px; }

/* ------------------------------------------------------------ Stat cards */

.stat-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: .75rem;
    margin-bottom: 1.1rem;
}
.stat-row-compact { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .75rem .9rem;
    display: flex;
    flex-direction: column;
    gap: .25rem;
    box-shadow: var(--shadow);
}
.stat-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.stat-value { font-size: 1.35rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.small-value { font-size: 1.05rem; }

/* --------------------------------------------------------------- Tables */

.table-scroll { overflow-x: auto; margin: 0 -1.25rem; padding: 0 1.25rem; }

.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: .55rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table thead th {
    background: var(--surface-alt);
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    font-weight: 700;
    border-bottom: 2px solid var(--border-strong);
    white-space: nowrap;
}
.table thead th a { color: inherit; }
.table tfoot th { background: var(--surface-alt); font-weight: 700; border-top: 2px solid var(--border-strong); }
.table-compact th, .table-compact td { padding: .4rem .5rem; font-size: .85rem; }
.table-hover tbody tr:hover { background: var(--brand-light); }
.table td.text-right, .table th.text-right { text-align: right; font-variant-numeric: tabular-nums; }
.ledger-table tbody tr:hover { background: var(--surface-alt); }
.row-receipt { background: rgba(18, 105, 74, .05); }
.row-opening td { background: var(--surface-alt); font-style: italic; color: var(--text-muted); }
.empty-cell { text-align: center; color: var(--text-muted); padding: 2rem .6rem; }
.link-strong { font-weight: 600; }
.table-footer { display: flex; flex-wrap: wrap; gap: .75rem; justify-content: space-between; align-items: center; margin-top: .75rem; }
.raw-preview td { font-family: var(--mono); font-size: .78rem; white-space: nowrap; }
.raw-preview .row-number { background: var(--surface-alt); color: var(--text-muted); }
.raw-preview .is-header-row { background: var(--brand-light); font-weight: 600; }
.check-col { width: 34px; }

/* --------------------------------------------------------------- Buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .45rem .85rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    background: var(--surface);
    color: var(--text);
    font-size: .88rem;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { border-color: var(--border-strong); color: var(--text); }
.btn-ghost:hover { background: var(--surface-alt); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #7f1c1c; }
.btn-danger-ghost { border-color: #e0bcbc; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-bg); }
.btn-sm { padding: .3rem .65rem; font-size: .82rem; }
.btn-xs { padding: .2rem .5rem; font-size: .78rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.inline-form { display: inline-flex; gap: .5rem; align-items: center; }

/* ----------------------------------------------------------------- Forms */

label { display: block; font-size: .85rem; font-weight: 600; color: #38414f; margin-bottom: .1rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="date"],
input[type="number"], input[type="search"], input[type="file"], select, textarea {
    width: 100%;
    padding: .45rem .6rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: .9rem;
    font-weight: 400;
    color: var(--text);
    background: #fff;
    margin-top: .25rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(46, 127, 174, .35); outline-offset: 1px; border-color: var(--brand); }
textarea { resize: vertical; }
.stack > * + * { margin-top: .9rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.form-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: 1rem; }
.fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem; margin: 0; }
.fieldset legend { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 700; padding: 0 .35rem; }
.fieldset > * + * { margin-top: .75rem; }
.checkbox-row, .radio-row { display: flex; gap: .5rem; align-items: flex-start; font-weight: 400; }
.checkbox-row input, .radio-row input { width: auto; margin-top: .3rem; }
.indent { margin-left: 1.6rem; padding-left: .8rem; border-left: 2px solid var(--border); }
.indent > * + * { margin-top: .75rem; }
.group-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 700; margin: .75rem 0 .25rem; }
.map-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .6rem; }

.currency-input { display: flex; align-items: stretch; margin-top: .25rem; }
.currency-input span {
    display: inline-flex; align-items: center; padding: 0 .6rem;
    background: var(--surface-alt); border: 1px solid var(--border-strong); border-right: 0;
    border-radius: var(--radius) 0 0 var(--radius); color: var(--text-muted); font-weight: 600;
}
.currency-input input { border-radius: 0 var(--radius) var(--radius) 0; margin-top: 0; font-size: 1.05rem; font-variant-numeric: tabular-nums; }

.type-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.type-option {
    display: flex; gap: .5rem; align-items: flex-start;
    border: 1px solid var(--border-strong); border-radius: var(--radius);
    padding: .6rem .7rem; cursor: pointer; font-weight: 400; background: #fff;
}
.type-option input { width: auto; margin-top: .25rem; }
.type-option span { display: flex; flex-direction: column; }
.type-option small { color: var(--text-muted); font-size: .78rem; }
.type-option.selected { border-color: var(--brand); background: var(--brand-light); }
.amount-fields { display: grid; gap: .9rem; }
.formula { font-family: var(--mono); background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem .6rem; font-size: .85rem; }

/* --------------------------------------------------------------- Filters */

.filter-bar { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; margin-bottom: .9rem; }
.filter-bar .grow { flex: 1 1 260px; }
.filter-actions { display: flex; gap: .5rem; align-items: flex-end; }
.filter-panel { border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem .75rem; margin-bottom: .9rem; background: var(--surface-alt); }
.filter-panel summary { cursor: pointer; font-weight: 600; font-size: .9rem; }
.filter-panel[open] summary { margin-bottom: .75rem; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .75rem; }
.filter-grid .span-2 { grid-column: span 2; }
.filter-summary { background: var(--info-bg); border: 1px solid #cddcea; border-radius: var(--radius); padding: .5rem .7rem; font-size: .88rem; margin-bottom: .75rem; }

.view-toggle, .chip-row { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .75rem; }
.chip {
    display: inline-flex; align-items: center; gap: .35rem;
    padding: .25rem .7rem; border-radius: 999px;
    border: 1px solid var(--border-strong); font-size: .82rem; color: var(--text);
    background: #fff;
}
.chip:hover { text-decoration: none; background: var(--surface-alt); }
.chip-active { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip-count { font-weight: 700; }

/* ---------------------------------------------------------------- Pills */

.pill {
    display: inline-block;
    padding: .1rem .5rem;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
    background: var(--surface-alt);
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.pill-success { background: var(--success-bg); color: var(--success); border-color: #bfe0cd; }
.pill-warning { background: var(--warning-bg); color: var(--warning); border-color: #ecd8a8; }
.pill-danger { background: var(--danger-bg); color: var(--danger); border-color: #e9c3c3; }
.pill-info { background: var(--info-bg); color: var(--brand); border-color: #cddcea; }
.pill-muted { background: var(--surface-alt); color: var(--text-muted); }

/* --------------------------------------------------------------- Alerts */

.flash-stack { margin-bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; }
.alert { border-radius: var(--radius); padding: .65rem .85rem; border: 1px solid var(--border); font-size: .9rem; }
.alert p { margin: .35rem 0 0; }
.alert-success { background: var(--success-bg); border-color: #bfe0cd; color: #10543a; }
.alert-error { background: var(--danger-bg); border-color: #e9c3c3; color: #7f1c1c; }
.alert-warning { background: var(--warning-bg); border-color: #ecd8a8; color: #7a5100; }
.alert-info { background: var(--info-bg); border-color: #cddcea; color: var(--brand-dark); }
.callout { background: var(--surface-alt); border-left: 3px solid var(--brand); padding: .6rem .75rem; border-radius: 0 var(--radius) var(--radius) 0; font-size: .88rem; }

/* ------------------------------------------------------------- Projects */

.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: .9rem; }
.project-card {
    display: flex; flex-direction: column; gap: .5rem;
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: .9rem; background: #fff; color: var(--text);
}
.project-card:hover { text-decoration: none; border-color: var(--brand); box-shadow: var(--shadow); }
.project-card header { display: flex; justify-content: space-between; gap: .5rem; align-items: flex-start; }
.project-card h3 { font-size: 1rem; margin: 0; }
.project-card-figures { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; border-top: 1px solid var(--border); padding-top: .5rem; }
.project-card-figures div { display: flex; flex-direction: column; font-variant-numeric: tabular-nums; font-weight: 600; font-size: .9rem; }

/* ------------------------------------------------------------ Pagination */

.pagination { display: flex; flex-wrap: wrap; gap: .25rem; align-items: center; }
.page-link { padding: .3rem .6rem; border: 1px solid var(--border-strong); border-radius: var(--radius); font-size: .85rem; }
.page-link:hover { background: var(--surface-alt); text-decoration: none; }
.page-link.current { background: var(--brand); border-color: var(--brand); color: #fff; }
.page-link.disabled { opacity: .45; pointer-events: none; }
.page-gap { color: var(--text-muted); padding: 0 .2rem; }

/* --------------------------------------------------------------- Preview */

.preview-table .row-messages { margin: .25rem 0 0; padding-left: 1rem; font-size: .78rem; color: var(--text-muted); }
.preview-row.status-error { background: var(--danger-bg); }
.preview-row.status-warning { background: var(--warning-bg); }
.preview-row.status-duplicate { background: #f5efe3; }
.preview-row.status-skipped { color: var(--text-muted); }
.sticky-actions {
    position: sticky; bottom: 0; background: var(--surface);
    border-top: 1px solid var(--border); padding-top: .75rem; margin-top: .5rem;
}
.cancel-import { margin-top: 1rem; }

/* ------------------------------------------------------------- Confirm */

.confirm-card { max-width: 720px; border-left: 4px solid var(--warning); }
.confirm-card.confirm-danger { border-left-color: var(--danger); }
.confirm-message { font-size: 1rem; color: #333c4a; }

/* ---------------------------------------------------- Detail lists, misc */

.detail-list { margin: 0 0 1rem; }
.detail-list div { display: flex; justify-content: space-between; gap: 1rem; padding: .35rem 0; border-bottom: 1px solid var(--border); font-size: .88rem; }
.detail-list dt { color: var(--text-muted); margin: 0; }
.detail-list dd { margin: 0; text-align: right; font-weight: 600; }

.empty-state { text-align: center; padding: 2.5rem 1rem; }
.empty-code { font-size: 2.4rem; font-weight: 700; color: var(--border-strong); }
.recalc-form { margin-top: 1rem; }

/* -------------------------------------------------------- Guest / install */

.guest-body, .install-body { background: linear-gradient(160deg, #12405e, #1d5f87); min-height: 100vh; margin: 0; }
.guest-shell { max-width: 420px; margin: 0 auto; padding: 4rem 1rem; }
.guest-brand { text-align: center; color: #fff; margin-bottom: 1.5rem; }
.guest-brand h1 { font-size: 1.4rem; margin: .75rem 0 .25rem; color: #fff; }
.guest-brand .muted { color: #bcd3e3; }
.guest-brand .brand-mark { margin: 0 auto; }
.guest-footer { text-align: center; color: #a9c4d6; font-size: .8rem; margin-top: 1.5rem; }
.auth-card h2 { margin-bottom: 1rem; }

.install-shell { max-width: 780px; margin: 0 auto; padding: 2.5rem 1rem; }
.install-header { display: flex; gap: .8rem; align-items: center; color: #fff; margin-bottom: 1.25rem; }
.install-header h1 { color: #fff; font-size: 1.35rem; margin: 0; }
.install-header .muted { color: #bcd3e3; margin: 0; }
.install-steps { display: flex; flex-wrap: wrap; gap: .5rem; list-style: none; padding: 0; margin: 0 0 1.25rem; }
.install-steps li {
    display: flex; align-items: center; gap: .4rem;
    background: rgba(255, 255, 255, .12); color: #cfe1ee;
    padding: .35rem .75rem; border-radius: 999px; font-size: .85rem;
}
.install-steps li span {
    width: 20px; height: 20px; border-radius: 50%;
    background: rgba(255, 255, 255, .2); display: inline-flex;
    align-items: center; justify-content: center; font-size: .75rem; font-weight: 700;
}
.install-steps li.current { background: #fff; color: var(--brand-dark); font-weight: 600; }
.install-steps li.current span { background: var(--brand); color: #fff; }
.install-steps li.done { background: rgba(255, 255, 255, .3); color: #fff; }
.install-footer { text-align: center; color: #a9c4d6; font-size: .8rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.form-grid .span-2 { grid-column: span 2; }

/* ------------------------------------------------------------- Statement */

.print-body { background: #eef1f5; }
.print-toolbar { display: flex; gap: .5rem; padding: 1rem; justify-content: center; }
.statement {
    background: #fff;
    max-width: 1000px;
    margin: 0 auto 2rem;
    padding: 2rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.statement-head { display: flex; justify-content: space-between; gap: 2rem; border-bottom: 2px solid var(--brand); padding-bottom: 1rem; margin-bottom: 1rem; }
.statement-head h1 { font-size: 1.4rem; color: var(--brand-dark); }
.statement-title { text-align: right; }
.statement-title h2 { font-size: 1.1rem; text-transform: uppercase; letter-spacing: .06em; }
.statement-meta, .statement-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin-bottom: 1.1rem; }
.statement-meta div, .statement-summary div { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem .65rem; }
.statement-meta span, .statement-summary span { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.statement-summary strong { font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.statement-table { font-size: .85rem; }
.statement-table th, .statement-table td { border: 1px solid var(--border); padding: .4rem .5rem; }
.statement-totals { display: flex; justify-content: flex-end; gap: 1.5rem; margin-top: 1rem; }
.statement-totals div { display: flex; flex-direction: column; text-align: right; }
.statement-totals span { font-size: .75rem; text-transform: uppercase; color: var(--text-muted); }
.statement-totals strong { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.statement-totals .closing strong { color: var(--brand); font-size: 1.2rem; }
.statement-foot { display: flex; gap: 2rem; margin-top: 3rem; }
.signature { flex: 1; text-align: center; }
.signature span { display: block; border-top: 1px solid var(--text-muted); margin-bottom: .3rem; height: 1px; }
.signature small { color: var(--text-muted); }

/* ------------------------------------------------------------ Responsive */

@media (max-width: 1080px) {
    .grid-form, .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
    .sidebar {
        position: fixed;
        left: 0; top: 0; bottom: 0;
        transform: translateX(-100%);
        transition: transform .2s ease;
        z-index: 40;
    }
    .sidebar.open { transform: translateX(0); box-shadow: 0 0 30px rgba(0, 0, 0, .3); }
    .icon-btn { display: inline-flex; }
    .content { padding: 1rem .75rem; }
    .table-scroll { margin: 0 -.75rem; padding: 0 .75rem; }
    .field-row, .type-toggle, .form-grid { grid-template-columns: 1fr; }
    .filter-grid .span-2 { grid-column: span 1; }
    .statement { padding: 1rem; }
    .statement-head { flex-direction: column; gap: .75rem; }
    .statement-title { text-align: left; }
}
