:root {
    --brand: #0e7490;
    --brand-dark: #155e75;
    --bg: #f8fafc;
    --surface: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --danger: #dc2626;
    --ok: #16a34a;
    --warn: #d97706;
    --chip-bg: #e2e8f0;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f172a;
        --surface: #1e293b;
        --text: #f1f5f9;
        --muted: #94a3b8;
        --border: #334155;
        --chip-bg: #334155;
    }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* ---------- chrome ---------- */

.app-header {
    background: var(--brand);
    color: #fff;
    padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 500;
}
.app-header h1 { font-size: 1.1rem; font-weight: 600; }
.home-link { color: inherit; text-decoration: none; }

.action-block h4 {
    margin: 10px 0 4px;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted, #6b7280);
}
.action-list {
    list-style: none;
    margin: 0 0 6px;
    padding: 0;
}
.action-list li {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 3px 0;
}
.action-list label {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    flex: 1;
    cursor: pointer;
}
.action-list input[type="checkbox"] {
    margin-top: 3px;
    accent-color: var(--brand, #0e7490);
}
.action-list .done {
    text-decoration: line-through;
    color: var(--muted, #6b7280);
}
.action-add {
    display: flex;
    gap: 8px;
    margin: 6px 0;
}
.action-add input {
    flex: 1;
}

.card-date {
    color: var(--muted, #6b7280);
    font-size: 0.78rem;
    margin-left: auto;
    white-space: nowrap;
}

.pid {
    color: var(--muted, #6b7280);
    font-size: 0.72em;
    font-weight: 400;
    white-space: nowrap;
}

.lang-switch {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 8px;
    font-size: 0.8rem;
    padding: 4px 6px;
    margin-left: 10px;
}
.lang-switch option { color: #000; }

.net-status {
    font-size: 0.75rem;
    background: var(--danger);
    padding: 2px 8px;
    border-radius: 999px;
}

.app-main {
    flex: 1;
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.view { padding: 12px 12px calc(env(safe-area-inset-bottom, 0px) + 76px); }
.view[hidden] { display: none !important; }

.tabbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    z-index: 600;
}
.tab {
    flex: 1;
    border: none;
    background: none;
    color: var(--muted);
    font-size: 0.7rem;
    padding: 8px 0 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    cursor: pointer;
    position: relative;
    touch-action: manipulation;
}
.tab.active { color: var(--brand); font-weight: 600; }
.tab-icon { font-size: 1.25rem; line-height: 1; }
.badge {
    position: absolute;
    top: 4px;
    right: calc(50% - 22px);
    background: var(--danger);
    color: #fff;
    font-size: 0.65rem;
    min-width: 16px;
    height: 16px;
    line-height: 16px;
    border-radius: 999px;
    padding: 0 4px;
}

/* ---------- list ---------- */

.toolbar { display: flex; gap: 8px; margin-bottom: 8px; }
.toolbar input[type="search"] {
    flex: 1;
    font-size: 1rem;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
}
.filters-row select {
    flex: 1;
    font-size: 0.9rem;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
}
.btn-icon {
    border: none;
    border-radius: 10px;
    background: var(--brand);
    color: #fff;
    font-size: 1.3rem;
    width: 44px;
    cursor: pointer;
    touch-action: manipulation;
}

.chips { display: flex; gap: 6px; margin-bottom: 8px; overflow-x: auto; }
.chip {
    border: none;
    background: var(--chip-bg);
    color: var(--text);
    font-size: 0.8rem;
    padding: 6px 12px;
    border-radius: 999px;
    cursor: pointer;
    white-space: nowrap;
    touch-action: manipulation;
}
.chip.active { background: var(--brand); color: #fff; }

#list-count { font-size: 0.8rem; margin: 2px 2px 8px; }

.prop-list { display: flex; flex-direction: column; gap: 10px; }

.prop-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    cursor: pointer;
}
.prop-card.has-thumb {
    flex-direction: row;
    gap: 12px;
    align-items: stretch;
}
.card-thumb {
    width: 92px;
    min-height: 92px;
    object-fit: cover;
    border-radius: 9px;
    flex: none;
    align-self: center;
    background: var(--bg);
}
.prop-card .card-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.pp-stars { margin: 2px 0; }
.pp-thumb {
    width: 100%;
    max-height: 110px;
    object-fit: cover;
    border-radius: 8px;
    margin-bottom: 6px;
    display: block;
}
.prop-card .row1 { display: flex; align-items: center; gap: 8px; }
.prop-card h3 { font-size: 1rem; flex: 1; }
.prop-card .addr { font-size: 0.82rem; color: var(--muted); }
.prop-card .facts { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.85rem; }
.prop-card .facts b { font-weight: 600; }
.prop-card .meta-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.75rem;
    color: var(--muted);
}
.prop-card .meta-row .spacer { flex: 1; }

.pill {
    font-size: 0.68rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
    color: #fff;
    white-space: nowrap;
}
.pill.actief { background: var(--brand); }
.pill.nieuw { background: var(--ok); }
.pill.afgewezen { background: var(--muted); }
.pill.verkocht { background: #b91c1c; }

.cmp-btn {
    border: 1px solid var(--border);
    background: none;
    color: var(--muted);
    border-radius: 8px;
    font-size: 0.9rem;
    padding: 4px 10px;
    cursor: pointer;
    touch-action: manipulation;
}
.cmp-btn.on { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------- map ---------- */

#view-kaart { display: flex; flex-direction: column; padding-bottom: 0; height: calc(100dvh - 118px); }
.map-chips { flex: none; }
#map {
    flex: 1;
    border-radius: 12px;
    min-height: 300px;
    z-index: 1;
}
.leaflet-popup-content { font-size: 0.85rem; }
.leaflet-popup-content .pp-name { font-weight: 600; font-size: 0.95rem; }
.leaflet-popup-content a { color: var(--brand); font-weight: 600; }

.marker-dot {
    width: 100%;
    height: 100%;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,.4);
}

/* ---------- compare ---------- */

.card-pad { padding: 8px 4px; }
.compare-wrap { overflow-x: auto; }
.compare-table {
    border-collapse: collapse;
    min-width: 100%;
    font-size: 0.82rem;
    background: var(--surface);
    border-radius: 12px;
}
.compare-table th, .compare-table td {
    border: 1px solid var(--border);
    padding: 8px;
    text-align: left;
    vertical-align: top;
    min-width: 120px;
}
.compare-table th:first-child, .compare-table td:first-child {
    position: sticky;
    left: 0;
    background: var(--bg);
    font-weight: 600;
    min-width: 110px;
    z-index: 2;
}
.compare-table thead th { background: var(--brand); color: #fff; }
.compare-table thead th:first-child { background: var(--brand); }
.compare-table .best { background: rgba(22, 163, 74, 0.15); }

/* ---------- detail ---------- */

.detail-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.detail-head h2 { font-size: 1.15rem; flex: 1; }
.btn-back {
    border: none;
    background: none;
    color: var(--brand);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px 8px;
    touch-action: manipulation;
}

.detail-grid { display: flex; flex-direction: column; gap: 12px; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
}
.card h2, .card h3 { font-size: 0.95rem; margin-bottom: 10px; }
.card p { font-size: 0.9rem; line-height: 1.5; }

.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.kv .item { min-width: 0; }
.kv .k { font-size: 0.7rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.kv .v { font-size: 0.92rem; overflow-wrap: anywhere; }
.kv .v.big { font-size: 1.15rem; font-weight: 700; }
.kv .item.wide { grid-column: 1 / -1; }

.muted { color: var(--muted); font-size: 0.85rem; }

.btn {
    display: inline-block;
    border: none;
    border-radius: 10px;
    background: var(--brand);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    padding: 10px 16px;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    touch-action: manipulation;
}
.btn.secondary { background: var(--chip-bg); color: var(--text); }
.btn.danger { background: var(--danger); }
.btn.small { font-size: 0.8rem; padding: 6px 10px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }

#mini-map, #form-map {
    height: 220px;
    border-radius: 10px;
    margin-top: 10px;
    z-index: 1;
}

.proscons { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.proscons ul { padding-left: 18px; font-size: 0.88rem; display: flex; flex-direction: column; gap: 4px; }
.proscons .pros-h { color: var(--ok); }
.proscons .cons-h { color: var(--danger); }
@media (max-width: 480px) { .proscons { grid-template-columns: 1fr; } }

.listing-imgs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    margin-bottom: 10px;
    -webkit-overflow-scrolling: touch;
}
.listing-imgs img {
    height: 130px;
    border-radius: 8px;
    flex: none;
}
.listing-title { font-weight: 600; margin-bottom: 4px; }
.listing-price { color: var(--brand); font-weight: 700; font-size: 1.05rem; margin-bottom: 6px; }
.listing-desc { font-size: 0.85rem; color: var(--text); margin-bottom: 6px; white-space: pre-line; }

.doc-list, .note-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.doc-list li, .note-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 0.88rem;
}
.doc-list .doc-main { flex: 1; min-width: 0; }
.doc-list .doc-name { overflow-wrap: anywhere; font-weight: 600; }
.doc-list .doc-sub { font-size: 0.75rem; color: var(--muted); }
.doc-list a { color: var(--brand); text-decoration: none; font-weight: 600; }

.note-list .note-main { flex: 1; }
.note-list .note-sub { font-size: 0.72rem; color: var(--muted); margin-top: 2px; }

.del-x {
    border: none;
    background: none;
    color: var(--danger);
    font-size: 1.05rem;
    cursor: pointer;
    padding: 4px 6px;
    touch-action: manipulation;
}

.upload-row, .note-form { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.upload-row input[type="file"] { flex: 1 1 100%; font-size: 0.85rem; }
.upload-row input[type="text"], .note-form textarea, .note-form input {
    flex: 1;
    font-size: 0.95rem;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
}
.note-form textarea { resize: vertical; min-height: 60px; }

/* ---------- form ---------- */

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 0.75rem; color: var(--muted); }
.form-grid label.wide { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea {
    font-size: 0.95rem;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
    width: 100%;
}
.form-grid textarea { resize: vertical; min-height: 64px; }

/* ---------- project page ---------- */

.section-h { font-size: 1rem; margin: 14px 4px 8px; }

.crit-list { display: flex; flex-direction: column; gap: 6px; }
.crit-row { display: flex; align-items: center; gap: 6px; }
.crit-row .crit-name {
    flex: 1;
    font-size: 0.88rem;
    padding: 7px 9px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    min-width: 0;
}
.crit-row .crit-weight {
    width: 60px;
    font-size: 0.88rem;
    padding: 7px 6px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    text-align: right;
}
.crit-pct { color: var(--muted); font-size: 0.85rem; }
.weight-warn { color: var(--warn); font-weight: 600; }

/* total row aligned under the weight inputs */
.crit-total {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    font-size: 0.88rem;
}
.crit-total-label {
    flex: 1;
    text-align: right;
    color: var(--muted);
}
.crit-total-value {
    width: 60px;
    box-sizing: border-box;
    text-align: right;
    padding: 0 7px 0 0;   /* mirror the input's inner right padding + border */
    font-weight: 700;
}
.crit-total-spacer { width: 27px; }  /* mirrors the delete-button column */

.matrix-table input.mx-score {
    width: 54px;
    font-size: 0.88rem;
    padding: 5px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    text-align: center;
}
.matrix-table .mx-total td { font-size: 0.9rem; }
.mx-remove {
    border: none;
    background: none;
    color: #fff;
    opacity: 0.7;
    cursor: pointer;
    font-size: 0.8rem;
    margin-left: 4px;
}

/* vertical timeline */
.tl { position: relative; padding-left: 30px; display: flex; flex-direction: column; gap: 12px; }
.tl::before {
    content: '';
    position: absolute;
    left: 14px;
    top: 6px;
    bottom: 6px;
    width: 2px;
    background: var(--border);
}
.tl-item { position: relative; }
.tl-dot {
    position: absolute;
    left: -26px;
    top: 14px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--brand);
    border: 2px solid var(--bg);
    z-index: 1;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}
.tl-date { font-size: 0.75rem; color: var(--muted); font-weight: 600; }
.tl-title { font-weight: 700; font-size: 0.95rem; margin: 2px 0 6px; }
.tl-body { font-size: 0.85rem; white-space: pre-line; margin-bottom: 8px; }
.tl-docs { margin-bottom: 8px; }
.tl-attach { margin-top: 8px; }

/* ---------- star ratings / criteria scoring ---------- */

.stars { position: relative; display: inline-block; line-height: 0; color: var(--border); }
.stars svg { display: inline-block; fill: currentColor; }
.stars-fill {
    position: absolute;
    top: 0;
    left: 0;
    overflow: hidden;
    white-space: nowrap;
    color: #f59e0b;
}
.card-stars { line-height: 0; }
.rating-stars { font-weight: 400; margin-left: 8px; }
.rating-stars b { margin-left: 4px; }

.rate-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.rate-row { display: flex; align-items: center; gap: 8px; }
.rate-name { flex: 1; font-size: 0.85rem; }
.rate-score {
    width: 64px;
    font-size: 0.9rem;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    text-align: center;
}

/* ---------- icons / photos / lightbox ---------- */

.icon { vertical-align: -3px; }
.count-chip { display: inline-flex; align-items: center; gap: 3px; }
.del-x svg { vertical-align: -2px; }

.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
    gap: 8px;
}
.photo-cell { position: relative; cursor: pointer; }
.photo-cell img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 10px;
    display: block;
    background: var(--bg);
}
.photo-del {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(15, 23, 42, 0.6) !important;
    color: #fff !important;
    border-radius: 8px;
    padding: 4px 6px;
}

.video-list { display: flex; flex-direction: column; gap: 12px; }
.video-item video {
    width: 100%;
    max-height: 320px;
    border-radius: 10px;
    background: #000;
}
.video-item .doc-sub {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.78rem;
    color: var(--muted);
    margin-top: 4px;
}

.listing-imgs img { cursor: pointer; }

#lightbox {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.92);
    z-index: 1200;
    display: none;
    align-items: center;
    justify-content: center;
}
#lightbox.open { display: flex; }
#lightbox img {
    max-width: 94vw;
    max-height: 84vh;
    border-radius: 8px;
    object-fit: contain;
}
.lb-btn {
    position: absolute;
    border: none;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}
.lb-close { top: calc(env(safe-area-inset-top, 0px) + 14px); right: 14px; }
.lb-prev { left: 10px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 10px; top: 50%; transform: translateY(-50%) rotate(180deg); }
.lb-caption {
    position: absolute;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
    left: 0;
    right: 0;
    text-align: center;
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.85rem;
    padding: 0 20px;
}

/* ---------- in-app dialogs ---------- */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.15s;
    padding: 20px;
}
.modal-overlay.open { opacity: 1; }
.modal {
    background: var(--surface);
    border-radius: 14px;
    padding: 18px;
    max-width: 380px;
    width: 100%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
    transform: translateY(8px);
    transition: transform 0.15s;
}
.modal-overlay.open .modal { transform: none; }
.modal h3 { font-size: 1rem; margin-bottom: 8px; }
.modal p { font-size: 0.92rem; line-height: 1.45; overflow-wrap: anywhere; }
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.modal-input {
    width: 100%;
    margin-top: 10px;
    font-size: 0.95rem;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
}

.rescore-toast {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 70px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--brand);
    color: #fff;
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 0.85rem;
    z-index: 1100;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    max-width: 90vw;
}

.app-footer,
.logout-link { color: var(--muted); text-decoration: none; }

.login-main { justify-content: center; display: flex; flex-direction: column; padding: 16px; }
.login-error { color: var(--danger); font-size: 0.9rem; margin: 8px 0; }
.login-form { display: flex; gap: 8px; margin-top: 12px; }
.login-form input {
    flex: 1;
    font-size: 1rem;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
}
.login-form button {
    font-size: 1rem;
    padding: 10px 18px;
    border: none;
    border-radius: 8px;
    background: var(--brand);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}

.app-footer {
    display: flex;
    justify-content: space-between;
    max-width: 760px;
    width: 100%;
    margin: 0 auto;
    padding: 12px 16px;
    font-size: 0.8rem;
}
