/*
 * Casafari Analyzer — estilo limpio, profesional.
 * Sin gradientes ni cards con border-left de colores.
 * Fuente system-ui para máxima legibilidad y neutralidad.
 */

:root {
    --bg:            #F7F7F8;
    --surface:       #FFFFFF;
    --border:        #E4E4E7;
    --border-strong: #D4D4D8;
    --text:          #18181B;
    --text-muted:    #71717A;
    --text-soft:     #A1A1AA;
    --accent:        #0F172A;
    --accent-hover:  #1E293B;
    --link:          #2563EB;
    --success:       #15803D;
    --success-bg:    #F0FDF4;
    --warning:       #B45309;
    --warning-bg:    #FFFBEB;
    --danger:        #B91C1C;
    --danger-bg:     #FEF2F2;
    --radius:        6px;
    --radius-sm:     4px;
    --shadow-sm:     0 1px 2px rgba(0,0,0,0.04);
    --shadow-md:     0 4px 12px rgba(0,0,0,0.08);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
}

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

/* ─── Topbar ─── */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar .brand {
    font-weight: 600;
    font-size: 15px;
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: 10px;
}
.mode-badge {
    font-weight: 500;
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 3px;
    letter-spacing: 0;
}
.mode-internal { background: #EFF6FF; color: #1D4ED8; }
.mode-casafari { background: #F0FDF4; color: #15803D; }
.notice-warn {
    background: #FFFBEB;
    border-bottom: 1px solid #FDE68A;
    color: #92400E;
    padding: 10px 20px;
    font-size: 13px;
    text-align: center;
}
.notice-warn code { background: #fff; padding: 1px 6px; border-radius: 3px; font-family: var(--mono); font-size: 12px; }
.notice-warn a { color: #B45309; font-weight: 600; }
.topbar nav {
    display: flex;
    gap: 20px;
    align-items: center;
}
.topbar nav a {
    color: var(--text);
    font-size: 13px;
    padding: 6px 0;
    border-bottom: 2px solid transparent;
}
.topbar nav a:hover { text-decoration: none; border-bottom-color: var(--border-strong); }
.topbar nav a.active { border-bottom-color: var(--accent); }
.topbar nav .user { color: var(--text-muted); font-size: 13px; }
.topbar nav .muted { color: var(--text-muted); }

/* ─── Main ─── */
main {
    padding: 20px;
    max-width: 1600px;
    margin: 0 auto;
}

/* ─── Stats ─── */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.stat .label {
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.stat .value {
    font-size: 22px;
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

/* ─── Actions bar ─── */
.actions {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.actions .hint {
    color: var(--text-muted);
    font-size: 12px;
    margin-left: auto;
}

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    text-decoration: none;
    font-family: inherit;
}
.btn:hover { background: #FAFAFA; border-color: var(--text-soft); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn.ghost:hover { background: #F0F0F1; color: var(--text); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn .badge {
    background: rgba(255,255,255,0.2);
    padding: 1px 6px;
    border-radius: 10px;
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}
.btn:not(.primary) .badge { background: var(--accent); color: #fff; }

/* ─── Filters ─── */
.filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
}
.filters input, .filters select {
    padding: 6px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-family: inherit;
    font-size: 13px;
    color: var(--text);
    min-width: 140px;
}
.filters input[type="search"] { flex: 1; min-width: 220px; }
.filters input[type="number"] { max-width: 130px; }
.filters input:focus, .filters select:focus {
    outline: none;
    border-color: var(--accent);
}

/* ─── Table ─── */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}
thead {
    background: #FAFAFA;
    border-bottom: 1px solid var(--border);
}
th {
    text-align: left;
    padding: 10px 12px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
}
th.num, td.num { text-align: right; }
th.col-check, td.col-check { width: 40px; padding-left: 14px; padding-right: 0; }
td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    vertical-align: middle;
}
tbody tr:hover { background: #FAFAFA; }
tbody tr.selected { background: #F0F9FF; }
tbody tr.selected:hover { background: #E0F2FE; }

.cell-desc { min-width: 300px; max-width: 400px; }
.cell-desc .ref-internal {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text-muted);
}
.cell-desc .address {
    color: var(--text);
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 400px;
}
.cell-desc .meta {
    color: var(--text-muted);
    font-size: 11px;
    margin-top: 2px;
}

.sub-badge {
    display: inline-block;
    padding: 2px 7px;
    font-size: 11px;
    border-radius: 3px;
    font-weight: 500;
}
.sub-okupado   { background: #FEF2F2; color: #B91C1C; }
.sub-alquilado { background: #FFFBEB; color: #B45309; }
.sub-wip       { background: #EFF6FF; color: #1D4ED8; }
.sub-libre     { background: #F0FDF4; color: #15803D; }

.metric-cell {
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}
.metric-good { color: var(--success); }
.metric-bad  { color: var(--danger); }
.metric-warn { color: var(--warning); }
.metric-none { color: var(--text-soft); }

.row-action {
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    padding: 0 4px;
}
.row-action:hover { color: var(--text); }

/* ─── Pagination ─── */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    padding: 14px;
    border-top: 1px solid var(--border);
    background: #FAFAFA;
    color: var(--text-muted);
    font-size: 13px;
}

/* ─── Modals ─── */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.35);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}
.modal:not([hidden]) { display: flex; }
.modal-box {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px 28px;
    max-width: 520px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-md);
    position: relative;
}
.modal-box.wide { max-width: 900px; }
.modal-box h2 {
    margin: 0 0 12px;
    font-size: 18px;
    letter-spacing: -0.01em;
}
.modal-close {
    position: absolute;
    top: 12px;
    right: 14px;
    background: none;
    border: none;
    font-size: 22px;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}
.log {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 12px;
    padding: 10px;
    background: #FAFAFA;
    border-radius: var(--radius-sm);
    max-height: 200px;
    overflow-y: auto;
    display: none;
}
.log.active { display: block; }

/* ─── Progress ─── */
.progress {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin: 12px 0;
}
.progress-bar {
    height: 100%;
    background: var(--accent);
    width: 0;
    transition: width 0.3s;
}

/* ─── Detail modal ─── */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-top: 16px;
}
.detail-cell {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.detail-cell .label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.detail-cell .value {
    font-size: 18px;
    font-weight: 600;
    margin-top: 4px;
}
.detail-cell .sub {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ─── Login ─── */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}
.login-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 30px 34px;
    width: 100%;
    max-width: 340px;
    box-shadow: var(--shadow-sm);
}
.login-box h1 {
    margin: 0 0 20px;
    font-size: 18px;
    text-align: center;
}
.login-box label {
    display: block;
    margin-bottom: 12px;
    font-size: 13px;
    color: var(--text-muted);
}
.login-box input {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 9px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
}
.login-box input:focus { outline: none; border-color: var(--accent); }
.login-box button {
    width: 100%;
    padding: 10px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    margin-top: 6px;
}
.login-box button:hover { background: var(--accent-hover); }
.login-box .error {
    background: var(--danger-bg);
    color: var(--danger);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 14px;
}

/* ─── Settings page ─── */
.settings h1 { font-size: 22px; margin: 0 0 8px; letter-spacing: -0.01em; }
.settings .muted { color: var(--text-muted); margin: 0 0 20px; }
.settings .notice {
    background: var(--success-bg);
    color: var(--success);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: 13px;
}
.settings-form fieldset {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 16px;
    background: var(--surface);
}
.settings-form legend {
    padding: 0 8px;
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-weight: 500;
}
.settings-form label {
    display: grid;
    grid-template-columns: 260px 140px 1fr;
    gap: 14px;
    align-items: center;
    margin: 10px 0;
    font-size: 13px;
}
.settings-form input {
    padding: 6px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
}
.settings-form small { color: var(--text-muted); font-size: 12px; }
.settings-actions {
    display: flex;
    gap: 8px;
    padding-top: 8px;
}

/* ─── Utility ─── */
.muted { color: var(--text-muted); }
.mono  { font-family: var(--mono); font-size: 12px; }

/* Responsive: on mobile, tabla horizontal-scroll */
@media (max-width: 900px) {
    main { padding: 12px; }
    .table-wrap { overflow-x: auto; }
    .filters { flex-direction: column; }
    .filters input, .filters select { width: 100%; }
}
