/* Hotel finance app — light/dark theme via CSS variables */
:root {
    color-scheme: light;
    --page: #f9f9f7;
    --surface: #fcfcfb;
    --ink: #0b0b0b;
    --ink-2: #52514e;
    --muted: #898781;
    --grid: #e1e0d9;
    --baseline: #c3c2b7;
    --border: rgba(11, 11, 11, 0.10);
    --income: #2a78d6;      /* series 1 blue  */
    --expense: #eb6834;     /* series 2 orange */
    --dividend: #4a3aa7;    /* series 7 violet */
    --profit: #1baf7a;      /* series 3 aqua — profitable month */
    --loss: #e34948;        /* series 8 red — losing month */
    --accent: #2a78d6;
    --accent-ink: #ffffff;
    --good: #006300;
    --bad: #d03b3b;
    --danger: #d03b3b;
    --wash: rgba(11, 11, 11, 0.045);
    --shadow: 0 1px 3px rgba(11, 11, 11, 0.08);
}
@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --page: #0d0d0d;
        --surface: #1a1a19;
        --ink: #ffffff;
        --ink-2: #c3c2b7;
        --muted: #898781;
        --grid: #2c2c2a;
        --baseline: #383835;
        --border: rgba(255, 255, 255, 0.10);
        --income: #3987e5;
        --expense: #d95926;
        --dividend: #9085e9;
        --profit: #199e70;
        --loss: #e66767;
        --accent: #3987e5;
        --accent-ink: #ffffff;
        --good: #0ca30c;
        --bad: #e66767;
        --danger: #e66767;
        --wash: rgba(255, 255, 255, 0.06);
        --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    background: var(--page);
    color: var(--ink);
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: 14px;
    line-height: 1.45;
}
button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; color: var(--ink); }

/* ---------- top bar ---------- */
.topbar {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 0 20px;
    height: 54px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar-brand { display: flex; align-items: center; gap: 9px; font-weight: 650; white-space: nowrap; }
.topbar-logo {
    display: inline-flex; align-items: center; justify-content: center;
    width: 26px; height: 26px; border-radius: 7px;
    background: var(--accent); color: var(--accent-ink);
    font-weight: 700; font-size: 15px;
}
.topbar-nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.topbar-nav a {
    color: var(--ink-2); text-decoration: none;
    padding: 6px 12px; border-radius: 8px; white-space: nowrap;
}
.topbar-nav a:hover { background: var(--wash); color: var(--ink); }
.topbar-nav a.active { background: var(--wash); color: var(--ink); font-weight: 600; }
.topbar-user { position: relative; }
.user-btn {
    background: none; border: 1px solid var(--border); border-radius: 8px;
    padding: 5px 12px; cursor: pointer; color: var(--ink-2);
}
.user-btn:hover { background: var(--wash); }
.user-menu {
    position: absolute; right: 0; top: calc(100% + 6px);
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 10px; box-shadow: var(--shadow);
    min-width: 180px; padding: 4px; z-index: 30;
}
.user-menu button {
    display: block; width: 100%; text-align: left;
    background: none; border: 0; padding: 8px 12px;
    border-radius: 7px; cursor: pointer;
}
.user-menu button:hover { background: var(--wash); }

/* ---------- layout ---------- */
.view { max-width: 1160px; margin: 0 auto; padding: 20px 20px 60px; }
.loading { color: var(--muted); padding: 40px; text-align: center; }
.page-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin: 6px 0 16px; flex-wrap: wrap;
}
.page-head h2 { margin: 0; font-size: 20px; }
.hidden { display: none !important; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 4px; font-size: 14px; font-weight: 650; }
.card .card-sub { color: var(--muted); font-size: 12px; margin: 0 0 12px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
/* KPI tiles: 3 + 2 on desktop, 2 + 2 + full-width on mobile */
.tiles { display: grid; grid-template-columns: repeat(6, 1fr); gap: 16px; }
.tiles .tile { grid-column: span 2; }
.tiles .tile:nth-child(4), .tiles .tile:nth-child(5) { grid-column: span 3; }
@media (max-width: 860px) {
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
.stack { display: grid; gap: 16px; }

/* ---------- KPI tiles ---------- */
.tile .tile-label { color: var(--ink-2); font-size: 13px; }
.tile .tile-value { font-size: 26px; font-weight: 700; margin: 2px 0; }
.tile .tile-delta { font-size: 12.5px; color: var(--muted); }
.tile .tile-delta .up { color: var(--good); font-weight: 600; }
.tile .tile-delta .down { color: var(--bad); font-weight: 600; }

/* ---------- filters ---------- */
.filters {
    display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.filters select, .filters input[type="date"], .filters input[type="search"],
.form-row input, .form-row select, .form-row textarea {
    background: var(--surface);
    border: 1px solid var(--baseline);
    border-radius: 8px;
    padding: 7px 10px;
}
.filters input[type="search"] { min-width: 160px; }
.seg {
    display: inline-flex; border: 1px solid var(--baseline);
    border-radius: 8px; overflow: hidden;
}
.seg button {
    background: none; border: 0; padding: 7px 12px; cursor: pointer;
    color: var(--ink-2); border-right: 1px solid var(--baseline);
}
.seg button:last-child { border-right: 0; }
.seg button.active { background: var(--wash); color: var(--ink); font-weight: 600; }

/* ---------- buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    border: 1px solid var(--baseline); background: var(--surface);
    border-radius: 8px; padding: 7px 14px; cursor: pointer;
}
.btn:hover { background: var(--wash); }
.btn-primary {
    background: var(--accent); color: var(--accent-ink);
    border-color: var(--accent);
}
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-sm { padding: 3px 9px; font-size: 12.5px; border-radius: 7px; }
.btn-block { width: 100%; justify-content: center; }
.icon-btn {
    background: none; border: 0; cursor: pointer; padding: 4px 6px;
    border-radius: 6px; color: var(--muted); font-size: 14px;
}
.icon-btn:hover { background: var(--wash); color: var(--ink); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.data {
    width: 100%; border-collapse: collapse; font-size: 13.5px;
}
table.data th {
    text-align: left; color: var(--muted); font-weight: 500;
    padding: 8px 10px; border-bottom: 1px solid var(--grid);
    white-space: nowrap;
}
table.data td {
    padding: 8px 10px; border-bottom: 1px solid var(--grid);
    vertical-align: top;
}
table.data tr:last-child td { border-bottom: 0; }
table.data tr:hover td { background: var(--wash); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount-income { color: var(--good); font-weight: 600; }
.amount-expense { color: var(--ink); font-weight: 600; }

.badge {
    display: inline-block; padding: 1px 8px; border-radius: 20px;
    font-size: 12px; border: 1px solid var(--border); color: var(--ink-2);
}
.badge-income { border-color: var(--income); color: var(--income); }
.badge-expense { border-color: var(--expense); color: var(--expense); }
.badge-dividend { border-color: var(--dividend); color: var(--dividend); }
.badge-muted { color: var(--muted); }

/* ---------- charts ---------- */
.chart-legend {
    display: flex; gap: 16px; align-items: center;
    font-size: 12.5px; color: var(--ink-2); margin-bottom: 8px;
}
.chart-legend .dot {
    display: inline-block; width: 9px; height: 9px; border-radius: 50%;
    margin-right: 6px; vertical-align: 1px;
}
.chart-legend .line-swatch {
    display: inline-block; width: 16px; height: 3px; border-radius: 2px;
    margin-right: 6px; vertical-align: 3px;
}

/* category type tints in <select> lists */
option.opt-income { background-color: color-mix(in srgb, var(--income) 16%, var(--surface)); }
option.opt-expense { background-color: color-mix(in srgb, var(--expense) 16%, var(--surface)); }
option.opt-dividend { background-color: color-mix(in srgb, var(--dividend) 16%, var(--surface)); }
svg.chart { width: 100%; height: auto; display: block; }
svg.chart text { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; }
svg.chart .gridline { stroke: var(--grid); stroke-width: 1; }
svg.chart .baseline { stroke: var(--baseline); stroke-width: 1; }
svg.chart .tick { fill: var(--muted); font-size: 11px; }
svg.chart rect.bar { cursor: pointer; }
svg.chart rect.bar:hover { filter: brightness(1.12); }

.hbar-row {
    display: grid; grid-template-columns: 130px 1fr 90px;
    gap: 10px; align-items: center; padding: 5px 0;
    border-radius: 6px;
}
.hbar-row:hover { background: var(--wash); }
.hbar-label {
    font-size: 13px; color: var(--ink-2);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hbar-track { height: 14px; position: relative; }
.hbar-fill {
    position: absolute; left: 0; top: 0; bottom: 0;
    border-radius: 0 4px 4px 0; min-width: 2px;
}
.hbar-value {
    font-size: 12.5px; text-align: right;
    font-variant-numeric: tabular-nums; color: var(--ink);
}
.empty-note { color: var(--muted); font-size: 13px; padding: 12px 0; }

.chart-tooltip {
    position: fixed; z-index: 100; pointer-events: none;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 8px; box-shadow: var(--shadow);
    padding: 7px 10px; font-size: 12.5px; max-width: 260px;
}
.chart-tooltip .tt-title { font-weight: 600; margin-bottom: 2px; }
.chart-tooltip .tt-row { display: flex; gap: 8px; justify-content: space-between; }
.chart-tooltip .tt-row b { font-variant-numeric: tabular-nums; }

/* ---------- forms & modal ---------- */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4);
    display: flex; align-items: flex-start; justify-content: center;
    padding: 6vh 16px; z-index: 50; overflow-y: auto;
}
.modal {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 14px; box-shadow: var(--shadow);
    width: 100%; max-width: 440px; padding: 20px;
}
.modal h3 { margin: 0 0 14px; font-size: 17px; }
.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 4px; }
.form-row input, .form-row select, .form-row textarea { width: 100%; }
.form-row textarea { resize: vertical; min-height: 60px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.form-error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }

/* ---------- toast ---------- */
.toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    background: var(--ink); color: var(--page);
    padding: 9px 18px; border-radius: 10px; font-size: 13.5px;
    z-index: 90; box-shadow: var(--shadow);
}

/* ---------- dictionary lists ---------- */
.dict-item {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 4px; border-bottom: 1px solid var(--grid);
}
.dict-item:last-child { border-bottom: 0; }
.dict-item .dict-name { flex: 1; }
.dict-item.archived .dict-name { color: var(--muted); text-decoration: line-through; }
.dict-add { display: flex; gap: 8px; margin-top: 12px; }
.dict-add input { flex: 1; }

/* ---------- login ---------- */
.login-body {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 16px;
}
.login-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 16px; box-shadow: var(--shadow);
    padding: 32px; width: 100%; max-width: 380px;
}
.login-logo {
    width: 44px; height: 44px; border-radius: 12px;
    background: var(--accent); color: var(--accent-ink);
    display: flex; align-items: center; justify-content: center;
    font-size: 24px; font-weight: 700; margin-bottom: 14px;
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-sub { color: var(--ink-2); margin: 0 0 18px; font-size: 13.5px; }
.login-card label { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 12px; }
.login-card input {
    width: 100%; margin-top: 4px;
    background: var(--surface); border: 1px solid var(--baseline);
    border-radius: 8px; padding: 9px 11px;
}
.login-card .btn-block { margin-top: 6px; padding: 10px; }
.alert {
    background: color-mix(in srgb, var(--danger) 10%, var(--surface));
    border: 1px solid var(--danger); color: var(--danger);
    border-radius: 8px; padding: 8px 12px; font-size: 13px; margin-bottom: 14px;
}

/* ---------- mobile ---------- */
.mobile-only { display: none; }
.bottom-nav { display: none; }

@media (max-width: 720px) {
    body { font-size: 15px; }
    input, select, textarea { font-size: 16px; } /* prevents iOS focus zoom */

    .desktop-only { display: none !important; }
    .mobile-only { display: block; }

    /* top bar: brand + user only, nav moves to the bottom */
    .topbar { padding: 0 12px; gap: 10px; }
    .topbar-nav { display: none; }
    .topbar-user { margin-left: auto; }
    .user-btn {
        max-width: 46vw; overflow: hidden;
        text-overflow: ellipsis; white-space: nowrap;
    }

    .bottom-nav {
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
        display: flex;
        background: var(--surface);
        border-top: 1px solid var(--border);
        padding-bottom: env(safe-area-inset-bottom);
    }
    .bottom-nav a {
        flex: 1; display: flex; flex-direction: column; align-items: center;
        gap: 2px; padding: 7px 4px 6px;
        text-decoration: none; color: var(--muted); font-size: 11px;
    }
    .bottom-nav a .bn-icon { font-size: 20px; line-height: 1.1; }
    .bottom-nav a.active { color: var(--accent); font-weight: 600; }

    .view { padding: 12px 10px calc(84px + env(safe-area-inset-bottom)); }
    .page-head { margin: 2px 0 12px; }
    .page-head h2 { font-size: 18px; }
    .stack { gap: 10px; }
    .grid-2, .grid-3 { gap: 10px; }
    .card { padding: 12px; }

    /* compact KPI tiles: two per row, account balance full width */
    .tiles { grid-template-columns: 1fr 1fr; gap: 8px; }
    .tiles .tile,
    .tiles .tile:nth-child(4) { grid-column: span 1; padding: 10px 12px; }
    .tiles .tile:nth-child(5) { grid-column: 1 / -1; }
    .tile .tile-label { font-size: 12px; }
    .tile .tile-value { font-size: 19px; margin: 1px 0; }
    .tile .tile-delta { font-size: 11px; }

    /* filters stack comfortably */
    .filters { gap: 6px; }
    .filters select,
    .filters input[type="search"] { flex: 1 1 45%; min-width: 0; }
    .filters input[type="date"] { flex: 1 1 40%; min-width: 0; width: 0; }
    .seg { display: flex; width: 100%; }
    .seg button { flex: 1; padding: 8px 2px; font-size: 13px; white-space: nowrap; }

    /* wide charts scroll instead of shrinking below readability */
    .chart-slot { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .chart-slot svg.chart { min-width: 640px; }

    /* transaction cards */
    .tx-card { padding: 10px 2px; border-bottom: 1px solid var(--grid); }
    .tx-card:last-child { border-bottom: 0; }
    .tx-card-top { display: flex; align-items: center; gap: 8px; }
    .tx-card-date { color: var(--muted); font-size: 12.5px; }
    .tx-card-amount {
        margin-left: auto; font-weight: 700; font-size: 15.5px;
        font-variant-numeric: tabular-nums; white-space: nowrap;
    }
    .tx-card-cat { font-weight: 600; margin-top: 3px; }
    .tx-card-note { color: var(--ink-2); font-size: 13.5px; margin-top: 2px; }
    .tx-card-foot {
        display: flex; justify-content: space-between; align-items: center;
        color: var(--muted); font-size: 12.5px; margin-top: 2px;
    }
    .tx-card-foot .icon-btn { font-size: 17px; padding: 6px 10px; }
    .tx-totals { flex-wrap: wrap; gap: 8px 16px !important; }

    /* modal: full width, larger touch targets */
    .modal-backdrop { padding: 12px 10px; align-items: flex-start; }
    .modal { max-width: 100%; padding: 16px; }
    .form-actions .btn { padding: 10px 16px; }

    .hbar-row { grid-template-columns: 96px 1fr 84px; }
    .toast { bottom: calc(76px + env(safe-area-inset-bottom)); max-width: 92vw; }
}
