/* ──────────────────────────────────────────────────────────────
   Delaware Rental Pulse — Editorial intelligence aesthetic
   Palette: deep ink, warm paper, signal coral, slate teal
   ────────────────────────────────────────────────────────────── */

:root {
    --ink:        #0d1b2a;
    --ink-soft:   #1b2a3d;
    --ink-line:   #2b3a4e;
    --paper:      #f4ede2;
    --paper-soft: #ebe3d4;
    --paper-line: #d9cfba;

    --signal-hot:     #d94e2f;   /* < 14 days */
    --signal-warm:    #e8954a;   /* 14-30 */
    --signal-neutral: #c9a957;   /* 30-60 */
    --signal-cold:    #5b8a8f;   /* 60+ */
    --signal-unknown: #8b8579;   /* still active */
    --accent-gold:    #c8a951;

    --serif:  'Fraunces', 'Times New Roman', serif;
    --sans:   'IBM Plex Sans', system-ui, sans-serif;
    --mono:   'IBM Plex Mono', ui-monospace, monospace;

    --header-h: 76px;
    --sidebar-w: 340px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: var(--sans);
    color: var(--ink);
    background: var(--paper);
    overflow: hidden;
}

button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

/* ──────────────────────────────────────────────────────────────
   HEADER
   ────────────────────────────────────────────────────────────── */
.site-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-h);
    background: var(--ink);
    color: var(--paper);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    z-index: 1000;
    border-bottom: 1px solid var(--ink-line);
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
    font-size: 36px;
    line-height: 1;
    color: var(--accent-gold);
    transform: rotate(-15deg);
    font-family: var(--serif);
}
.brand-name {
    font-family: var(--serif);
    font-weight: 500;
    font-size: 22px;
    letter-spacing: -0.01em;
    line-height: 1.1;
    font-variation-settings: "opsz" 36, "SOFT" 50;
}
.brand-tag {
    font-family: var(--mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: rgba(244, 237, 226, 0.55);
    margin-top: 4px;
}

.header-stats { display: flex; gap: 36px; align-items: center; }
.stat { display: flex; flex-direction: column; align-items: flex-end; }
.stat-num {
    font-family: var(--serif);
    font-size: 22px;
    font-weight: 400;
    line-height: 1;
    color: var(--paper);
    font-variation-settings: "opsz" 36;
}
.stat-lbl {
    font-family: var(--mono);
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: rgba(244, 237, 226, 0.5);
    margin-top: 5px;
}
.sync-stat .stat-num { color: var(--accent-gold); font-family: var(--mono); font-size: 16px; }
.sync-stat.stale-warn .stat-num     { color: var(--signal-warm); animation: pulse 2s ease-in-out infinite; }
.sync-stat.stale-warn .stat-lbl     { color: var(--signal-warm); }
.sync-stat.stale-critical .stat-num { color: var(--signal-hot); animation: pulse 1.5s ease-in-out infinite; }
.sync-stat.stale-critical .stat-lbl { color: var(--signal-hot); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ──────────────────────────────────────────────────────────────
   LAYOUT
   ────────────────────────────────────────────────────────────── */
.app {
    position: fixed;
    top: var(--header-h);
    left: 0; right: 0; bottom: 28px;
    display: flex;
}

.sidebar {
    width: var(--sidebar-w);
    background: var(--paper);
    border-right: 1px solid var(--paper-line);
    padding: 28px 24px;
    overflow-y: auto;
}

.map-wrap {
    flex: 1;
    position: relative;
}

#map {
    width: 100%;
    height: 100%;
    background: var(--ink-soft);
}

/* ──────────────────────────────────────────────────────────────
   SIDEBAR PANELS
   ────────────────────────────────────────────────────────────── */
.panel { margin-bottom: 32px; }

.panel-title {
    font-family: var(--serif);
    font-weight: 500;
    font-size: 16px;
    margin: 0 0 14px 0;
    color: var(--ink);
    display: flex;
    align-items: baseline;
    gap: 10px;
    border-bottom: 1px solid var(--paper-line);
    padding-bottom: 10px;
    font-variation-settings: "opsz" 18;
}
.panel-num {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--accent-gold);
    letter-spacing: 0.1em;
}
.panel-hint {
    font-size: 12px;
    color: rgba(13, 27, 42, 0.6);
    margin: -6px 0 12px;
    line-height: 1.5;
}

/* Segmented buttons */
.segmented {
    display: flex;
    background: var(--paper-soft);
    border-radius: 0;
    padding: 3px;
    gap: 0;
}
.seg {
    flex: 1;
    padding: 9px 8px;
    border: none;
    background: transparent;
    font-size: 12px;
    font-weight: 500;
    color: rgba(13, 27, 42, 0.65);
    letter-spacing: 0.02em;
    transition: all 0.15s ease;
}
.seg:hover { color: var(--ink); }
.seg.active {
    background: var(--ink);
    color: var(--paper);
}

/* Field rows */
.field-row { margin-bottom: 12px; }
.field-row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field-lbl {
    font-family: var(--mono);
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: rgba(13, 27, 42, 0.55);
}
.field input, .field select, .amenity-dist {
    padding: 8px 10px;
    border: 1px solid var(--paper-line);
    background: var(--paper);
    font-size: 13px;
    color: var(--ink);
    border-radius: 0;
    transition: border 0.15s;
}
.field input:focus, .field select:focus, .amenity-dist:focus {
    outline: none;
    border-color: var(--ink);
}

/* Amenity rows */
.amenity-row {
    display: grid;
    grid-template-columns: 1fr 1.2fr;
    gap: 10px;
    margin-bottom: 8px;
    align-items: center;
}
.amenity-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    cursor: pointer;
}
.amenity-toggle, .check-row input { accent-color: var(--ink); }
.amenity-name { font-weight: 500; }
.amenity-dist { font-size: 11px; padding: 7px 8px; }

.check-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    font-size: 13px;
    cursor: pointer;
    color: var(--ink);
}
.check-row:hover { color: var(--signal-hot); }

.reset-btn {
    width: 100%;
    padding: 12px;
    background: transparent;
    border: 1px solid var(--ink);
    color: var(--ink);
    font-family: var(--mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    transition: all 0.2s;
    margin-top: 8px;
}
.reset-btn:hover {
    background: var(--ink);
    color: var(--paper);
}

/* ──────────────────────────────────────────────────────────────
   MAP OVERLAYS
   ────────────────────────────────────────────────────────────── */
.legend {
    position: absolute;
    bottom: 24px;
    left: 24px;
    background: var(--paper);
    padding: 14px 18px;
    border: 1px solid var(--paper-line);
    z-index: 500;
    box-shadow: 0 8px 24px rgba(13, 27, 42, 0.12);
}
.legend-title {
    font-family: var(--mono);
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--ink);
    margin-bottom: 10px;
}
.legend-scale {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 6px 8px;
    font-size: 11px;
    color: var(--ink);
    align-items: center;
}
.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}
.dot.hot     { background: var(--signal-hot); }
.dot.warm    { background: var(--signal-warm); }
.dot.neutral { background: var(--signal-neutral); }
.dot.cold    { background: var(--signal-cold); }
.dot.unknown { background: var(--signal-unknown); border: 1px solid var(--ink); }

.result-count {
    position: absolute;
    top: 20px;
    right: 20px;
    background: var(--paper);
    padding: 10px 16px;
    border: 1px solid var(--paper-line);
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.08em;
    color: var(--ink);
    z-index: 500;
    box-shadow: 0 4px 12px rgba(13, 27, 42, 0.08);
}
.result-count strong {
    font-family: var(--serif);
    font-size: 16px;
    font-weight: 500;
    margin-right: 4px;
    color: var(--signal-hot);
}

/* Polygon stats */
.poly-stats {
    position: absolute;
    top: 70px;
    right: 20px;
    width: 320px;
    background: var(--paper);
    border: 1px solid var(--paper-line);
    padding: 22px;
    z-index: 600;
    box-shadow: 0 10px 30px rgba(13, 27, 42, 0.15);
}
.poly-stats.hidden { display: none; }

/* Trend panel */
.trend-panel {
    position: absolute;
    top: 70px;
    right: 20px;
    width: 420px;
    max-height: calc(100vh - var(--header-h) - 90px);
    overflow-y: auto;
    background: var(--paper);
    border: 1px solid var(--paper-line);
    padding: 22px;
    z-index: 650;
    box-shadow: 0 10px 30px rgba(13, 27, 42, 0.18);
}
.trend-panel.hidden { display: none; }
.trend-meta {
    font-family: var(--mono);
    font-size: 10px;
    color: rgba(13, 27, 42, 0.6);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px dotted var(--paper-line);
}
.trend-chart-wrap {
    height: 160px;
    margin-bottom: 18px;
    position: relative;
}
.poly-close {
    position: absolute;
    top: 8px;
    right: 12px;
    background: transparent;
    border: none;
    font-size: 22px;
    color: var(--ink);
    line-height: 1;
}
.poly-title {
    font-family: var(--serif);
    font-size: 18px;
    font-weight: 500;
    margin-bottom: 14px;
    border-bottom: 1px solid var(--paper-line);
    padding-bottom: 10px;
}
.poly-body { font-size: 13px; line-height: 1.6; }
.poly-stat {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px dotted var(--paper-line);
}
.poly-stat-label {
    font-family: var(--mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: rgba(13, 27, 42, 0.6);
}
.poly-stat-value {
    font-family: var(--serif);
    font-size: 16px;
    color: var(--ink);
}

/* Detail modal */
.detail-modal {
    position: fixed;
    inset: 0;
    background: rgba(13, 27, 42, 0.6);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.detail-modal.hidden { display: none; }
.detail-card {
    background: var(--paper);
    width: 460px;
    max-width: 92vw;
    padding: 36px 32px;
    position: relative;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.3);
}
.detail-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    font-size: 26px;
    color: var(--ink);
    line-height: 1;
}
.detail-card h3 {
    font-family: var(--serif);
    font-size: 26px;
    margin: 0 0 4px;
    font-weight: 500;
}
.detail-meta {
    font-family: var(--mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: rgba(13, 27, 42, 0.6);
    margin-bottom: 18px;
}
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px 20px;
    margin: 18px 0;
}
.detail-grid > div { display: flex; flex-direction: column; gap: 3px; }
.detail-grid .lbl {
    font-family: var(--mono);
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: rgba(13, 27, 42, 0.55);
}
.detail-grid .val {
    font-family: var(--serif);
    font-size: 18px;
    color: var(--ink);
}
.detail-cta {
    margin-top: 22px;
    padding-top: 22px;
    border-top: 1px solid var(--paper-line);
}
.detail-cta p { font-size: 12px; color: rgba(13, 27, 42, 0.7); margin: 0 0 12px; line-height: 1.5; }
.cta-btn {
    display: inline-block;
    background: var(--ink);
    color: var(--paper);
    padding: 12px 22px;
    text-decoration: none;
    font-family: var(--mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    transition: background 0.2s;
}
.cta-btn:hover { background: var(--signal-hot); }

/* Custom Leaflet pin styles */
.pin {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--paper);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
.pin.hot     { background: var(--signal-hot); }
.pin.warm    { background: var(--signal-warm); }
.pin.neutral { background: var(--signal-neutral); }
.pin.cold    { background: var(--signal-cold); }
.pin.unknown { background: var(--signal-unknown); }

.amenity-pin {
    width: 18px; height: 18px;
    background: var(--accent-gold);
    border: 2px solid var(--ink);
    border-radius: 2px;
    transform: rotate(45deg);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.amenity-pin.library { background: #8aa9d6; }
.amenity-pin.park    { background: #88b07a; }
.amenity-pin.ymca    { background: #d6a86a; }
.amenity-pin.transit { background: #a08abf; }
.amenity-pin.school-top { background: #2d8659; border-color: #1a4d33; }   /* 8+ */
.amenity-pin.school-mid { background: #c8a951; }                            /* 6-8 */
.amenity-pin.school-low { background: #8b8579; opacity: 0.7; }              /* <6 */

/* ──────────────────────────────────────────────────────────────
   FOOTER
   ────────────────────────────────────────────────────────────── */
.site-footer {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 28px;
    background: var(--ink);
    color: rgba(244, 237, 226, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.08em;
    border-top: 1px solid var(--ink-line);
}
.site-footer p { margin: 0; }

/* ──────────────────────────────────────────────────────────────
   RESPONSIVE
   ────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .header-stats { display: none; }
    .sidebar { position: absolute; left: 0; top: 0; bottom: 0; z-index: 600; transform: translateX(-100%); transition: transform 0.3s; }
    .sidebar.open { transform: translateX(0); }
}

/* Leaflet tweaks for our aesthetic */
.leaflet-tile-pane { filter: grayscale(0.4) contrast(1.05) brightness(0.95); }
.leaflet-control-attribution {
    background: rgba(244, 237, 226, 0.85) !important;
    font-family: var(--mono) !important;
    font-size: 9px !important;
}
.leaflet-popup-content-wrapper {
    background: var(--paper);
    border-radius: 0;
    box-shadow: 0 6px 20px rgba(13, 27, 42, 0.2);
}
.leaflet-popup-content {
    margin: 14px 16px;
    font-family: var(--sans);
    font-size: 12px;
}
.leaflet-popup-tip { background: var(--paper); }
.popup-title {
    font-family: var(--serif);
    font-size: 16px;
    font-weight: 500;
    color: var(--ink);
    margin-bottom: 6px;
}
.popup-row { display: flex; justify-content: space-between; padding: 2px 0; font-size: 11px; }
.popup-row .l { color: rgba(13, 27, 42, 0.6); font-family: var(--mono); font-size: 9px; text-transform: uppercase; letter-spacing: 0.1em; }
.popup-row .v { font-weight: 500; }
.popup-btn {
    display: block;
    margin-top: 10px;
    padding: 6px 10px;
    background: var(--ink);
    color: var(--paper);
    text-align: center;
    text-decoration: none;
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}
