:root {
    --bg: #ffffff;
    --bg-soft: #fafafa;
    --bg-sunken: #f5f5f4;
    --text: #0f172a;
    --text-muted: #64748b;
    --text-dim: #94a3b8;
    --border: #e5e7eb;
    --border-strong: #d4d4d8;
    --accent: #0f172a;
    --accent-hover: #1e293b;
    --focus: #0f172a;
    --radius: 6px;
    --radius-sm: 4px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
    color: var(--text);
    background: var(--bg);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    display: flex;
    height: 100vh;
}

/* Sidebar */
#sidebar {
    width: 440px;
    min-width: 280px;
    max-width: 720px;
    padding: 24px 24px 80px;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--bg);
    border-right: 1px solid var(--border);
    flex-shrink: 0;
    position: relative;
}

/* Resize handle on sidebar's right edge */
#sidebar-resizer {
    position: absolute;
    top: 0;
    right: -3px;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    z-index: 10;
    background: transparent;
    transition: background 120ms ease;
}

#sidebar-resizer:hover,
#sidebar-resizer.active {
    background: var(--border-strong);
}

body.resizing,
body.resizing * {
    cursor: col-resize !important;
    user-select: none;
}

#sidebar h1 {
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin-bottom: 2px;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.78rem;
    margin-bottom: 24px;
}

/* Search */
.search-box {
    display: flex;
    gap: 6px;
}

.search-box input {
    flex: 1;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    color: var(--text);
    background: var(--bg);
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

.search-box input::placeholder {
    color: var(--text-dim);
}

.search-box input:focus,
.field input:focus,
.field select:focus,
select:focus {
    outline: none;
    border-color: var(--focus);
    box-shadow: 0 0 0 3px rgba(15, 23, 42, 0.08);
}

.search-box button {
    padding: 9px 16px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 120ms ease;
}

.search-box button:hover {
    background: var(--accent-hover);
}

/* Indicator */
.htmx-indicator {
    display: none;
    padding: 12px 0;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    display: block;
}

/* Results container */
#results {
    margin-top: 20px;
}

.empty {
    padding: 18px 0;
    color: var(--text-muted);
}

.empty strong {
    color: var(--text);
    font-weight: 500;
}

.hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.result {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.address {
    font-size: 0.95rem;
    color: var(--text);
    font-weight: 500;
    line-height: 1.4;
}

.meta-line {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.45;
}

.meta-line.muted {
    color: var(--text-dim);
}

.meta-line .sep {
    color: var(--text-dim);
    margin: 0 4px;
}

/* Block (section card without heavy chrome) */
.block {
    margin-top: 22px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.section-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

/* Fields */
.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.8rem;
    min-width: 0;
}

.field.full { grid-column: 1 / -1; }

.field-label {
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.field input[type="number"],
.field input[type="text"],
.field select,
select#tipologia-select,
select#omi-range-select {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    padding: 7px 9px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    font-size: 0.85rem;
    color: var(--text);
    transition: border-color 120ms ease, box-shadow 120ms ease;
    text-overflow: ellipsis;
}

.field select option {
    font-size: 0.85rem;
}

.field-group {
    margin-top: 10px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.grid-2 {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px 12px;
}

.checkboxes {
    display: flex;
    gap: 18px;
    margin-top: 6px;
    font-size: 0.85rem;
}

.checkboxes label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text);
}

/* Form */
#estimate-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* History */
.history {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chart-wrap {
    height: 180px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
}

/* Estimate result */
.estimate-result:empty { display: none; }

.estimate-result {
    margin-top: 18px;
    padding: 18px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.stima-main {
    text-align: left;
    margin-bottom: 10px;
}

.stima-centrale {
    font-size: 1.8rem;
    font-weight: 600;
    color: var(--text);
    line-height: 1.1;
    letter-spacing: -0.02em;
}

.stima-range {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.stima-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.breakdown {
    margin-top: 10px;
    font-size: 0.78rem;
}

.breakdown summary {
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px 0;
    font-size: 0.75rem;
    list-style: none;
}

.breakdown summary::-webkit-details-marker { display: none; }
.breakdown summary::before { content: "▸ "; color: var(--text-dim); }
.breakdown[open] summary::before { content: "▾ "; }

.breakdown ul {
    list-style: none;
    margin-top: 6px;
    padding-left: 14px;
}

.breakdown li {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
    color: var(--text-muted);
}

.breakdown-val {
    font-variant-numeric: tabular-nums;
    color: var(--text);
    font-weight: 500;
}

/* Map */
#map {
    flex: 1;
    height: 100vh;
}

/* Responsive */
@media (max-width: 768px) {
    #app {
        flex-direction: column;
    }

    #sidebar {
        width: 100%;
        min-width: auto;
        height: 50vh;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    #map {
        height: 50vh;
    }
}

/* Scrollbar polish */
#sidebar::-webkit-scrollbar { width: 6px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
#sidebar::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ---------- Auth nav + saved searches ---------- */
.sidebar-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.auth-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.auth-nav a {
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 1px dotted var(--border-strong);
    padding-bottom: 1px;
}

.auth-nav a:hover {
    color: var(--text);
    border-bottom-color: var(--text);
}

.user-email {
    color: var(--text-muted);
    font-size: 0.8rem;
    max-width: 14ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.inline-form { display: inline; margin: 0; }

.link-button {
    background: none;
    border: none;
    padding: 0;
    color: var(--text-muted);
    font: inherit;
    cursor: pointer;
    text-align: left;
    border-bottom: 1px dotted var(--border-strong);
}

.link-button:hover { color: var(--text); }

.icon-button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 1.1rem;
    line-height: 1;
    padding: 0 0.25rem;
}

.icon-button:hover { color: #dc2626; }

.ghost-button {
    background: none;
    border: 1px solid var(--border-strong);
    color: var(--text);
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    border-radius: 4px;
    cursor: pointer;
    margin: 0.5rem 0;
}

.ghost-button:hover {
    background: var(--bg-alt, #f8fafc);
    border-color: var(--text);
}

.save-search-form { margin: 0.5rem 0; }

.block-title {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin: 0 0 0.5rem 0;
    font-weight: 600;
}

.saved-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.saved-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.5rem;
    border-radius: 4px;
}

.saved-item:hover { background: #f8fafc; }

.saved-load {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border-bottom: none;
}

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

/* ---------- Auth pages ---------- */
.auth-page {
    background: #f8fafc;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.auth-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2rem;
    width: 100%;
    max-width: 380px;
}

.auth-card h1 {
    margin: 0 0 0.25rem 0;
    font-size: 1.5rem;
}

.auth-card .subtitle {
    color: var(--text-muted);
    margin: 0 0 1.5rem 0;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.auth-form label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.auth-form label span {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.auth-form input {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.95rem;
    box-sizing: border-box;
}

.auth-form input:focus {
    outline: none;
    border-color: var(--accent);
}

.auth-form button {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.6rem;
    border-radius: 4px;
    font-size: 0.95rem;
    cursor: pointer;
    margin-top: 0.5rem;
}

.auth-form small {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.auth-error {
    background: #fef2f2;
    color: #991b1b;
    padding: 0.6rem 0.75rem;
    border-radius: 4px;
    font-size: 0.85rem;
    margin: 0 0 1rem 0;
}

.auth-meta {
    margin: 1rem 0 0 0;
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
}

.auth-meta a {
    color: var(--text);
}

/* ---------- Logo / brand ---------- */
.brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.brand h1 {
    margin: 0;
    line-height: 1.1;
}

.brand .subtitle {
    margin: 0.1rem 0 0 0;
}

.logo-mark {
    width: 32px;
    height: 32px;
    color: var(--accent);
    flex-shrink: 0;
}

/* On the auth card, stack the brand block above the form heading. */
.brand-centered {
    justify-content: center;
    margin-bottom: 1.5rem;
    text-align: left;
}

.brand-centered .logo-mark {
    width: 36px;
    height: 36px;
}

.auth-card .auth-heading {
    font-size: 1.25rem;
    margin: 0 0 0.25rem 0;
    color: var(--text);
}

/* ---------- Cadastral parcel popup (Leaflet) ---------- */
.parcel-popup .leaflet-popup-content {
    margin: 0.6rem 0.85rem;
    min-width: 180px;
}

.parcel-popup-body h4 {
    margin: 0 0 0.4rem 0;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    font-weight: 600;
}

.parcel-popup-body dl {
    margin: 0;
    display: grid;
    grid-template-columns: max-content 1fr;
    column-gap: 0.7rem;
    row-gap: 0.15rem;
    font-size: 0.85rem;
}

.parcel-popup-body dt {
    color: var(--text-muted);
}

.parcel-popup-body dd {
    margin: 0;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}
