:root {
    --bg: #f7f7f5;
    --surface: #ffffff;
    --surface-muted: #f1f0ec;
    --text: #1f1e1c;
    --text-secondary: #6b6a65;
    --text-muted: #9a9993;
    --border: #e4e2dc;
    --border-strong: #cfcdc5;
    --accent: #185fa5;
    --accent-hover: #0c447c;
    --accent-bg: #e6f1fb;
    --danger: #a32d2d;
    --danger-bg: #fcebeb;
    --success: #3b6d11;
    --success-bg: #eaf3de;
    --warning: #854f0b;
    --warning-bg: #faeeda;
    --series-1: #2a78d6;
    --series-2: #eb6834;
    --series-3: #1baf7a;
    --series-4: #eda100;
    --series-5: #e87ba4;
    --radius: 8px;
    --radius-lg: 12px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

h1, h2, h3 { font-weight: 500; margin: 0; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }

/* Layout */

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar-inner, .container {
    max-width: 920px;
    margin: 0 auto;
    padding: 0 16px;
}

.topbar-inner {
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: 56px;
    flex-wrap: wrap;
}

.brand { font-weight: 500; color: var(--text); margin-right: 16px; }

.nav-link {
    color: var(--text-secondary);
    padding: 6px 10px;
    border-radius: var(--radius);
}

.nav-link:hover { color: var(--text); background: var(--surface-muted); }
.nav-link.active { color: var(--text); background: var(--surface-muted); }

.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 4px; }

.container { padding-top: 24px; padding-bottom: 48px; }

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.back { display: inline-block; font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }

.guest {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.guest .card { width: 100%; max-width: 400px; }
.guest-brand { text-align: center; font-weight: 500; margin-bottom: 16px; }

/* Cards and lists */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.card + .card { margin-top: 16px; }
.card h2 { margin-bottom: 16px; }

.list {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.list-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

.list-row:last-child { border-bottom: none; }
a.list-row:hover { background: var(--surface-muted); color: var(--text); }
.list-row.muted { color: var(--text-secondary); }
.list-main { flex: 1; min-width: 0; }
.list-meta { font-size: 13px; color: var(--text-secondary); }

.empty { padding: 32px 16px; text-align: center; color: var(--text-secondary); }

.avatar {
    width: 36px;
    height: 36px;
    flex: none;
    border-radius: 50%;
    background: var(--accent-bg);
    color: var(--accent-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 500;
}

.avatar.lg { width: 48px; height: 48px; font-size: 15px; }
.avatar.off { background: var(--surface-muted); color: var(--text-secondary); }

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

.fields { margin: 0; }

.field-row {
    display: grid;
    grid-template-columns: 140px minmax(0, 1fr);
    gap: 12px;
    padding: 10px 0;
    border-top: 1px solid var(--border);
}

.field-row dt { color: var(--text-secondary); font-size: 14px; }
.field-row dd { margin: 0; overflow-wrap: anywhere; }

.badge {
    display: inline-block;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: var(--radius);
    white-space: nowrap;
}

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-neutral { background: var(--surface-muted); color: var(--text-secondary); }

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 20px; }
.actions form { margin: 0; }

.muted { color: var(--text-secondary); }
.small { font-size: 13px; }
.pre { white-space: pre-line; }

/* Forms */

.form-group { margin-bottom: 14px; }

label { display: block; font-size: 14px; color: var(--text-secondary); margin-bottom: 4px; }

input[type=text], input[type=email], input[type=password], input[type=tel], textarea {
    width: 100%;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 8px 10px;
    min-height: 40px;
}

textarea { min-height: 96px; resize: vertical; }

input:focus, textarea:focus, .btn:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-bg);
}

.checkbox { display: flex; align-items: center; gap: 8px; color: var(--text); }
.checkbox input { width: 16px; height: 16px; margin: 0; }

.hint { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.error { font-size: 13px; color: var(--danger); margin-top: 4px; }
.has-error input, .has-error textarea { border-color: var(--danger); }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 38px;
    padding: 0 14px;
    font: inherit;
    font-size: 14px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    cursor: pointer;
}

.btn:hover { background: var(--surface-muted); color: var(--text); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-danger { color: var(--danger); }
.btn-ghost { border-color: transparent; background: none; color: var(--text-secondary); }
.btn-block { width: 100%; }
.btn-google { gap: 10px; }

.or-divider { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: var(--text-secondary); font-size: 13px; }
.or-divider::before, .or-divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

.form-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 18px; }

/* Flash messages */

.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 14px;
}

.alert-success { background: var(--success-bg); color: var(--success); }
.alert-danger { background: var(--danger-bg); color: var(--danger); }

@media (max-width: 600px) {
    .field-row { grid-template-columns: 1fr; gap: 0; }
    .list-row .list-phone { display: none; }
    .btn { min-height: 44px; }
}

/* Apartments and tenancies */

.grid { display: grid; gap: 12px; }
.grid > .card + .card { margin-top: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin-bottom: 20px; }

.card-link { display: block; color: var(--text); }
.card-link:hover { border-color: var(--border-strong); color: var(--text); }
.card.dashed { border-style: dashed; }

.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.card-title { font-weight: 500; font-size: 16px; }

.stat { background: var(--surface-muted); border-radius: var(--radius); padding: 14px 16px; }
.stat-label { font-size: 13px; color: var(--text-secondary); }
.stat-value { font-size: 22px; font-weight: 500; }

.section-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 24px 0 10px; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

select {
    width: 100%;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 8px 10px;
    min-height: 40px;
}

input[type=date] {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 8px 10px;
    min-height: 40px;
    width: 100%;
}

input[type=file] { font: inherit; font-size: 14px; max-width: 100%; }

.input-suffix { position: relative; }
.input-suffix input { padding-right: 32px; }
.input-suffix span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }

.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 12px; }

.subform { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 14px 2px; margin-bottom: 14px; background: var(--bg); }

.file-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); }
.file-row .list-main a { overflow-wrap: anywhere; }
.file-icon { flex: none; width: 34px; height: 34px; border-radius: var(--radius); background: var(--surface-muted); color: var(--text-secondary); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 500; }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: 13px; }

/* Money */

.input-big { font-size: 22px !important; min-height: 52px !important; }
.amount-positive { color: var(--success); white-space: nowrap; }
.amount-negative { color: var(--danger); white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* Ledger table */

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.ledger { width: 100%; border-collapse: collapse; font-size: 14px; }
.ledger th { font-weight: 400; font-size: 12px; color: var(--text-muted); text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.ledger td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.ledger tbody tr:last-child td { border-bottom: none; }
.ledger tfoot td { border-top: 1px solid var(--border-strong); border-bottom: none; font-weight: 500; }
.ledger .num { text-align: right; }
.ledger .cell { color: var(--text); white-space: nowrap; }
.ledger .cell:hover { color: var(--accent); }
.clip { font-size: 12px; }
.todo { display: inline-block; background: var(--warning-bg); color: var(--warning); border-radius: 4px; padding: 0 6px; font-size: 13px; }
.todo:hover { color: var(--warning); text-decoration: underline; }
.year-switch { display: flex; gap: 2px; }
.year-switch .nav-link { font-size: 13px; padding: 4px 8px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.chip { font-size: 12px; padding: 2px 8px; border: 1px solid var(--border); border-radius: var(--radius); color: var(--text-secondary); }

/* Tenant view */

.stat-danger { background: var(--danger-bg); color: var(--danger); }
.stat-danger .stat-label { color: var(--danger); }
.stat-success { background: var(--success-bg); color: var(--success); }
.stat-success .stat-label { color: var(--success); }

.jump { margin-bottom: 4px; }

.month { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); margin-bottom: 8px; }
.month summary { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; cursor: pointer; font-weight: 500; list-style: none; }
.month summary::-webkit-details-marker { display: none; }
.month summary::before { content: "›"; color: var(--text-muted); margin-right: 8px; transition: transform 0.15s; display: inline-block; }
.month[open] summary::before { transform: rotate(90deg); }
.month summary span:first-child { flex: 1; }
.month-line { display: flex; justify-content: space-between; gap: 12px; padding: 8px 16px; border-top: 1px solid var(--border); font-size: 14px; }
.clip-hidden { filter: grayscale(1); opacity: 0.5; }

.profile-link { display: inline-flex; align-items: center; gap: 8px; }
.avatar.sm { width: 26px; height: 26px; font-size: 11px; }

@media (max-width: 600px) {
    .topbar-inner { flex-wrap: nowrap; gap: 0; padding: 0 8px; }
    .hide-mobile { display: none; }
    .nav-link { padding: 6px 8px; font-size: 14px; }
    .profile-name { display: none; }
    .topbar-user .btn-ghost { padding: 0 8px; font-size: 14px; }
}

.input-with-button { display: flex; gap: 8px; }
.input-with-button input { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.rename summary { color: var(--accent); cursor: pointer; display: inline-block; margin-top: 2px; }
.rename[open] summary { margin-bottom: 6px; }
.rename input[type=text] { min-height: 32px; padding: 4px 8px; font-family: inherit; }

/* Delete confirmation */

.danger-card { border-color: var(--danger-bg); }
.delete-summary { margin: 0 0 16px; padding-left: 20px; }
.delete-summary li { margin: 2px 0; }
.delete-summary strong { font-weight: 500; }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: #791f1f; border-color: #791f1f; color: #fff; }

.month summary .badge { font-weight: 400; }

/* Honeypot field for bots (partials/bot-check) */
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

/* Cars */

.narrow { max-width: 560px; }

.car-photo { width: 64px; height: 64px; flex: none; border-radius: var(--radius); object-fit: cover; display: block; }
.car-photo.sm { width: 44px; height: 44px; }
.car-photo.placeholder { background: var(--accent-bg); color: var(--accent-hover); display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 500; }
.car-photo.placeholder.sm { font-size: 16px; }
.car-summary { display: flex; align-items: center; gap: 12px; color: var(--text); }
.car-summary:hover { color: var(--text); }
.car-header { display: flex; align-items: center; gap: 12px; margin: 4px 0 12px; }

.section-nav { display: flex; gap: 4px; overflow-x: auto; margin: 0 -16px 20px; padding: 0 16px 8px; border-bottom: 1px solid var(--border); -webkit-overflow-scrolling: touch; }
.section-nav a { flex: none; color: var(--text-secondary); padding: 6px 10px; border-radius: var(--radius); font-size: 14px; }
.section-nav a:hover, .section-nav a.active { color: var(--text); background: var(--surface-muted); }

.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.btn-big { min-height: 48px; font-size: 16px; }

.menu { position: relative; }
.menu summary { list-style: none; width: 100%; }
.menu summary::-webkit-details-marker { display: none; }
.menu-items { position: absolute; z-index: 10; right: 0; left: 0; margin-top: 4px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.menu-items a { display: block; padding: 10px 12px; color: var(--text); border-bottom: 1px solid var(--border); }
.menu-items a:last-child { border-bottom: none; }
.menu-items a:hover { background: var(--surface-muted); }

.dot { width: 10px; height: 10px; flex: none; border-radius: 50%; }
.dot-danger { background: var(--danger); }
.dot-warning { background: #d9a441; }

.alert-warning { background: var(--warning-bg); color: var(--warning); }

fieldset.plain { border: 0; margin: 0; padding: 0; min-width: 0; }
fieldset.plain:disabled input, fieldset.plain:disabled select, fieldset.plain:disabled textarea { background: var(--surface-muted); color: var(--text-secondary); }

.input-suffix.wide input { padding-right: 52px; }
.checkbox.big { font-size: 16px; min-height: 32px; }
.checkbox.big input { width: 20px; height: 20px; }

.thumb { width: 44px; height: 44px; flex: none; display: block; border-radius: var(--radius); object-fit: cover; }

.ledger td:first-child { min-width: 170px; }

.defect-row .form-group:last-child { display: flex; justify-content: space-between; align-items: center; }

[hidden] { display: none !important; }

/* Charts (partials/chart-bars, partials/chart-line) */

.chart { display: block; width: 100%; height: auto; }
.chart text { fill: var(--text-secondary); font-size: 14px; }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart-dot { stroke: var(--surface); stroke-width: 2; }
.chart-hit { fill: transparent; }
.chart-hit:hover { fill: var(--text); fill-opacity: 0.05; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 10px; font-size: 13px; color: var(--text-secondary); }
.swatch { display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 2px; }
.chart-data { margin-top: 10px; font-size: 14px; }
.chart-data summary { color: var(--accent); cursor: pointer; margin-bottom: 8px; }
.ledger.compact td:first-child { min-width: 0; }
.ledger.compact th, .ledger.compact td { padding-left: 10px; padding-right: 10px; }

a.chip { padding: 6px 10px; font-size: 13px; }
a.chip:hover { color: var(--text); border-color: var(--border-strong); }
a.chip.active { background: var(--surface-muted); color: var(--text); border-color: var(--border-strong); }

.section-header .btn { flex: none; white-space: nowrap; }

.export-link { margin: 16px 0 0; font-size: 14px; text-align: right; }

@media (max-width: 600px) {
    .input-big { font-size: 20px !important; }
    input[type=text], input[type=email], input[type=password], input[type=date], select, textarea { font-size: 16px; } /* iOS zooms in on smaller inputs */
}
