/* ============================================================
   Flip Tracker — design system
   Warm-professional dark theme. Amber = value/equity, green =
   profit, red = loss. Space Grotesk display + Inter UI + mono
   for every dollar figure.
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
    --bg:        #0f1217;
    --bg2:       #161a22;
    --bg3:       #1f2530;
    --bg4:       #2a313e;
    --border:    #2b323f;
    --border2:   #3a4150;
    --text:      #e9edf4;
    --text-dim:  #9099a8;
    --text-mut:  #646c7a;
    --accent:    #e3a13a;
    --accent-h:  #f0b14e;
    --accent-dim:#5a4422;
    --green:     #46b67c;
    --green-dim: #1d3a2c;
    --red:       #e8576f;
    --red-dim:   #3e2230;
    --blue:      #4f9df5;

    --font-disp: 'Space Grotesk', sans-serif;
    --font-ui:   'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, monospace;

    --radius:    11px;
    --radius-sm: 7px;
    --shadow:    0 12px 34px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    overflow-x: clip;   /* never allow sideways drift/rubber-band */
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3 { font-family: var(--font-disp); font-weight: 600; letter-spacing: -0.01em; }

.mono { font-family: var(--font-mono); }
.muted { color: var(--text-dim); }
.dim { color: var(--text-mut); }
.hidden { display: none !important; }
.right { text-align: right; }
.center { text-align: center; }
.profit { color: var(--green); }
.loss { color: var(--red); }
.spacer { flex: 1; }
.row { display: flex; align-items: center; gap: 0.6rem; }
.wrap { flex-wrap: wrap; }

/* ---------- top bar ---------- */
.topbar {
    position: sticky; top: 0; z-index: 50;
    display: flex; align-items: center; gap: 1.4rem;
    padding: 0 1.4rem; height: 60px;
    background: rgba(18,22,30,0.85);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}
.brand {
    display: flex; align-items: center; gap: 0.55rem;
    font-family: var(--font-disp); font-weight: 700; font-size: 1.15rem;
    color: var(--text); letter-spacing: -0.02em;
}
.brand .mark {
    display: grid; place-items: center;
    width: 30px; height: 30px; border-radius: 8px;
    background: linear-gradient(135deg, var(--accent), #b9792a);
    color: #1a1205; box-shadow: 0 2px 10px rgba(227,161,58,.35);
}
.brand .mark svg { width: 18px; height: 18px; }
.topnav { display: flex; gap: 0.3rem; }
.topnav a {
    color: var(--text-dim); font-weight: 500; font-size: 0.9rem;
    padding: 0.45rem 0.8rem; border-radius: var(--radius-sm);
}
.topnav a:hover { color: var(--text); background: var(--bg3); }
.topnav a.active { color: var(--accent); background: var(--accent-dim); }
.topbar .user-chip {
    display: flex; align-items: center; gap: 0.45rem;
    color: var(--text-dim); font-size: 0.88rem;
}
.topbar .user-chip svg { width: 16px; height: 16px; }

/* ---------- layout ---------- */
.container { max-width: 1180px; margin: 0 auto; padding: 1.8rem 1.4rem 4rem; }
.pagebar {
    display: flex; align-items: flex-end; justify-content: space-between;
    gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem;
}
.pagebar h1 { margin: 0; font-size: 1.7rem; }
.pagebar .sub { color: var(--text-dim); font-size: 0.9rem; margin-top: 0.2rem; }

/* ---------- buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 0.45rem;
    font-family: var(--font-ui); font-weight: 600; font-size: 0.88rem;
    padding: 0.55rem 0.95rem; border-radius: var(--radius-sm);
    border: 1px solid var(--border2); background: var(--bg3); color: var(--text);
    cursor: pointer; transition: background .12s, border-color .12s, transform .05s;
    white-space: nowrap;
}
.btn:hover { background: var(--bg4); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }
.btn-primary {
    background: var(--accent); border-color: var(--accent); color: #1a1205;
}
.btn-primary:hover { background: var(--accent-h); border-color: var(--accent-h); }
.btn-red { background: var(--red); border-color: var(--red); color: #2a0c12; }
.btn-red:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--bg3); color: var(--text); }
.btn-sm { padding: 0.35rem 0.6rem; font-size: 0.8rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 0.95rem; }
.field label { font-size: 0.78rem; font-weight: 600; color: var(--text-dim);
    text-transform: uppercase; letter-spacing: 0.04em; }
input, select, textarea {
    width: 100%; padding: 0.6rem 0.75rem; font: inherit; font-size: 16px;
    background: var(--bg); color: var(--text);
    border: 1px solid var(--border2); border-radius: var(--radius-sm);
    transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(227,161,58,.15);
}
textarea { resize: vertical; min-height: 70px; }
.field-row { display: flex; gap: 0.8rem; }
.field-row .field { flex: 1; }
.input-money { position: relative; }
.input-money::before {
    content: '$'; position: absolute; left: 0.7rem; top: 50%; transform: translateY(-50%);
    color: var(--text-mut); font-family: var(--font-mono); pointer-events: none;
}
.input-money input { padding-left: 1.5rem; font-family: var(--font-mono); }

/* ---------- cards ---------- */
.card {
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.2rem;
}
.grid { display: grid; gap: 1.1rem; }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

/* property card */
.prop-card {
    display: flex; flex-direction: column; gap: 0.85rem;
    cursor: pointer; transition: border-color .12s, transform .08s, box-shadow .12s;
}
.prop-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow); }
.prop-card .head { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.6rem; }
.prop-card .name { font-family: var(--font-disp); font-weight: 600; font-size: 1.08rem; }
.prop-card .addr { color: var(--text-dim); font-size: 0.82rem; margin-top: 0.1rem; }
.prop-card .figures { display: flex; gap: 1.2rem; flex-wrap: wrap; }

/* ---------- stat blocks ---------- */
.stat { display: flex; flex-direction: column; gap: 0.15rem; }
.stat .label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-mut); }
.stat .value { font-family: var(--font-mono); font-weight: 600; font-size: 1.12rem; }
.stat .value.lg { font-size: 1.5rem; }

.summary-strip {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem; margin-bottom: 1.6rem;
}
.summary-strip .card { padding: 1rem 1.1rem; }

/* ---------- status badge ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 0.35rem;
    font-size: 0.72rem; font-weight: 600; padding: 0.22rem 0.55rem;
    border-radius: 100px; border: 1px solid var(--border2);
    text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.s-Prospect   { color: #9099a8; }
.badge.s-Purchased  { color: var(--blue);   border-color: #24405e; background: #16243a; }
.badge.s-Renovating { color: var(--accent); border-color: var(--accent-dim); background: #2a2212; }
.badge.s-Listed     { color: #b98ff0; border-color: #3c2c54; background: #221836; }
.badge.s-Sold       { color: var(--green);  border-color: var(--green-dim); background: #14271e; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
thead th {
    text-align: left; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--text-mut); font-weight: 600; padding: 0.55rem 0.7rem;
    border-bottom: 1px solid var(--border);
}
tbody td { padding: 0.6rem 0.7rem; border-bottom: 1px solid var(--border); }
tbody tr:hover { background: var(--bg3); }
td.num, th.num { text-align: right; font-family: var(--font-mono); }
.row-actions { display: flex; gap: 0.3rem; justify-content: flex-end; opacity: 0; transition: opacity .1s; }
tr:hover .row-actions { opacity: 1; }

/* ---------- category bars ---------- */
.cat-list { display: flex; flex-direction: column; gap: 0.7rem; }
.cat-row { display: grid; grid-template-columns: 130px 1fr auto; align-items: center; gap: 0.8rem; }
.cat-row .cat-name { font-size: 0.85rem; color: var(--text-dim); }
.cat-bar { height: 9px; background: var(--bg4); border-radius: 100px; overflow: hidden; }
.cat-bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-h)); border-radius: 100px; }
.cat-row .cat-val { font-family: var(--font-mono); font-size: 0.85rem; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.4rem; }
.tab {
    padding: 0.65rem 1rem; font-weight: 600; font-size: 0.92rem; color: var(--text-dim);
    cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
    background: none; border-top: none; border-left: none; border-right: none;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- modal (used by dialog.js + custom modals) ---------- */
.modal-overlay {
    position: fixed; inset: 0; z-index: 2000;
    background: rgba(6,8,12,0.7); backdrop-filter: blur(3px);
    display: flex; align-items: center; justify-content: center; padding: 1.2rem;
}
.modal-box {
    background: var(--bg2); border: 1px solid var(--border2);
    border-radius: var(--radius); padding: 1.4rem; width: 100%; max-width: 520px;
    box-shadow: var(--shadow); max-height: 90vh; overflow-y: auto;
}
.modal-box h2 { margin: 0 0 1rem; font-size: 1.2rem; }
.section-icon { width: 18px; height: 18px; vertical-align: -3px; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1.2rem; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.4rem; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .brand { justify-content: center; font-size: 1.5rem; margin-bottom: 0.4rem; }
.auth-card .brand .mark { width: 38px; height: 38px; }
.auth-card .brand .mark svg { width: 22px; height: 22px; }
.auth-tag { text-align: center; color: var(--text-dim); font-size: 0.9rem; margin-bottom: 1.6rem; }
.auth-toggle { display: flex; background: var(--bg3); border-radius: var(--radius-sm); padding: 0.25rem; margin-bottom: 1.4rem; }
.auth-toggle button { flex: 1; background: none; border: none; color: var(--text-dim); font: inherit; font-weight: 600; padding: 0.5rem; border-radius: 5px; cursor: pointer; }
.auth-toggle button.active { background: var(--bg); color: var(--accent); }
.auth-msg { font-size: 0.85rem; margin-top: 0.4rem; min-height: 1.1rem; }
.auth-msg.err { color: var(--red); }

/* ---------- expense list (responsive, phone-first) ---------- */
.exp-list { display: flex; flex-direction: column; }
.exp-item { display: flex; align-items: center; gap: 0.7rem; padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--border); }
.exp-item:last-child { border-bottom: none; }
.exp-item .main { flex: 1; min-width: 0; }
.exp-item .item-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.exp-item .meta { color: var(--text-dim); font-size: 0.8rem; margin-top: 0.1rem; }
.exp-item .amt { font-family: var(--font-mono); font-weight: 600; white-space: nowrap; }
.exp-acts { display: flex; gap: 0.15rem; opacity: 0; transition: opacity .1s; }
.exp-item:hover .exp-acts { opacity: 1; }
.exp-total { display: flex; justify-content: space-between; padding: 0.8rem 0.9rem; border-top: 1px solid var(--border2);
    font-weight: 700; }
.exp-total span:last-child { font-family: var(--font-mono); color: var(--accent); }

/* ---------- key/value list ---------- */
.kv-row { display: flex; justify-content: space-between; gap: 1rem; padding: 0.45rem 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.kv-row:last-child { border-bottom: none; }
.kv-row .k { color: var(--text-dim); }
.kv-row .v { font-family: var(--font-mono); }
tfoot td { border-top: 1px solid var(--border2); border-bottom: none; }

/* ---------- empty state ---------- */
.empty {
    text-align: center; padding: 3.5rem 1rem; color: var(--text-dim);
    border: 1px dashed var(--border2); border-radius: var(--radius);
}
.empty svg { width: 38px; height: 38px; color: var(--text-mut); margin-bottom: 0.8rem; }
.empty h3 { margin: 0 0 0.4rem; color: var(--text); }

/* ---------- floor plan editor ---------- */
.fp-bar { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.9rem; }
.fp-plantabs { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.fp-plantab {
    padding: 0.35rem 0.7rem; font-size: 0.84rem; font-weight: 600; border-radius: var(--radius-sm);
    background: var(--bg3); color: var(--text-dim); cursor: pointer; border: 1px solid transparent;
}
.fp-plantab.active { background: var(--accent-dim); color: var(--accent); border-color: var(--accent-dim); }
.fp-layout { display: grid; grid-template-columns: 1fr 250px; gap: 1rem; align-items: start; }
.fp-stage {
    background: #f6f4ee; border: 1px solid var(--border); border-radius: var(--radius);
    overflow: auto; padding: 0; max-height: 72vh;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15);
}
.fp-stage svg { display: block; touch-action: none; user-select: none; background: #f6f4ee; }
.fp-tools { display: flex; gap: 0.35rem; flex-wrap: wrap; align-items: center; }
.fp-zoom { display: inline-flex; gap: 0.2rem; margin-left: auto; }
.fp-side .card { padding: 1rem; }
.fp-side h3 { margin: 0 0 0.8rem; font-size: 1rem; }
.fp-side .hint { color: var(--text-dim); font-size: 0.82rem; line-height: 1.5; }
.fp-total { font-family: var(--font-mono); font-weight: 600; color: var(--accent); }
.fp-typegrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.35rem; margin-top: 0.4rem; }
.fp-typebtn { padding: 0.35rem; font-size: 0.78rem; border-radius: 5px; border: 1px solid var(--border2);
    background: var(--bg3); color: var(--text); cursor: pointer; text-align: left; display: flex; align-items: center; gap: 0.4rem; }
.fp-typebtn .swatch { width: 12px; height: 12px; border-radius: 3px; border: 1px solid rgba(0,0,0,.3); }
.fp-typebtn.active { border-color: var(--accent); }
.fp-sidepad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.4rem; }
.fp-sidepad-mid { display: grid; place-items: center; background: var(--bg3); border-radius: var(--radius-sm);
    font-size: 0.8rem; color: var(--text-dim); min-height: 58px; }
.fp-sidebtn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.2rem;
    padding: 0.55rem 0.3rem; border: 1px solid var(--border2); background: var(--bg3); color: var(--text);
    border-radius: var(--radius-sm); cursor: pointer; font: inherit; font-size: 0.78rem; }
.fp-sidebtn:hover { border-color: var(--accent); background: var(--bg4); }
.fp-sidebtn svg { width: 18px; height: 18px; }

/* svg editor element styling */
.fp-room rect.body { cursor: move; }
.fp-room.selected rect.body { stroke: var(--accent); stroke-width: 2.5; }
.fp-handle { fill: var(--accent); stroke: #1a1205; stroke-width: 1; cursor: nwse-resize; }
.fp-grid-line { stroke: #e7e2d5; stroke-width: 1; }
.fp-grid-line.major { stroke: #d8d2c2; }
.fp-ruler-txt { fill: #a89f8a; font: 10px var(--font-mono); }
.fp-room-label { font: 600 13px var(--font-disp); fill: #2a2417; pointer-events: none; text-anchor: middle; }
.fp-room-dim { font: 11px var(--font-mono); fill: #8a8068; pointer-events: none; text-anchor: middle; }
.fp-sel-outline { fill: none; stroke: var(--accent); stroke-width: 2; stroke-dasharray: 4 3; pointer-events: none; }

/* ---------- print / PDF report ---------- */
#print-report { display: none; }
@media print {
    body > *:not(#print-report) { display: none !important; }
    #print-report {
        display: block !important; color: #111; background: #fff;
        font-family: var(--font-ui); padding: 0;
    }
    #print-report .pr-head { border-bottom: 2px solid #222; padding-bottom: 6px; margin-bottom: 6px; }
    #print-report h1 { font-size: 22px; margin: 0; font-family: var(--font-disp); }
    #print-report .pr-sub { color: #555; font-size: 12px; margin-top: 2px; }
    #print-report h2 { font-size: 15px; margin: 16px 0 6px; border-bottom: 1px solid #bbb; padding-bottom: 3px; }
    #print-report h3 { font-size: 13px; margin: 10px 0 4px; }
    #print-report table { width: 100%; border-collapse: collapse; font-size: 12px; }
    #print-report tr, #print-report td, #print-report th { background: none !important; }
    #print-report .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
    #print-report .pr-pnl td { padding: 3px 4px; border: none; }
    #print-report .pr-strong td { font-weight: 700; border-top: 1px solid #999; }
    #print-report .pos td { color: #15803d; }
    #print-report .neg td { color: #b91c1c; }
    #print-report .pr-exp th { text-align: left; border-bottom: 1px solid #999; padding: 4px; }
    #print-report .pr-exp td { border-bottom: 1px solid #ddd; padding: 4px; }
    #print-report .pr-exp tfoot td { font-weight: 700; border-top: 1px solid #999; border-bottom: none; }
    #print-report .pr-plan { page-break-inside: avoid; margin-bottom: 12px; }
    #print-report svg { max-width: 100%; height: auto; }
    @page { margin: 14mm; }
}

@media (max-width: 820px) {
    .fp-layout { grid-template-columns: 1fr; }
    .topnav a { padding: 0.45rem 0.55rem; }
    .field-row { flex-direction: column; gap: 0; }
    /* iOS Safari won't shrink date inputs to width:100% with the native
       appearance, making them wider than other fields (and overflowing the
       modal). appearance:none lets them size normally; tapping still opens
       the native date picker. */
    input[type="date"], input[type="time"], input[type="datetime-local"] {
        -webkit-appearance: none; appearance: none; min-width: 0;
    }
    .container { padding: 1.3rem 1rem 4rem; }
    .pagebar h1 { font-size: 1.45rem; }
}

/* phones — the primary device for this app */
@media (max-width: 600px) {
    .topbar { gap: 0.5rem; padding: 0 0.8rem; height: 56px; }
    .topnav a { padding: 0.4rem 0.5rem; font-size: 0.85rem; }
    .topbar .user-chip { display: none; }
    .brand-label { display: none; }
    .btn-label { display: none; }
    .summary-strip { grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 0.7rem; }
    .summary-strip .card { padding: 0.8rem 0.9rem; }
    .stat .value.lg { font-size: 1.3rem; }
    .grid-cards { grid-template-columns: 1fr; }
    .pagebar { gap: 0.6rem; }
    /* row actions can't rely on hover on touch devices */
    .exp-acts, .row-actions { opacity: 1; }
    .cat-row { grid-template-columns: 84px 1fr auto; gap: 0.5rem; }
    .cat-row .cat-name { font-size: 0.8rem; }
    .modal-box { padding: 1.1rem; }
    .tab { padding: 0.6rem 0.7rem; font-size: 0.88rem; }
}
