/* ================================================================
   Portal de gestión del alquiler · UI minimalista, responsive y accesible
   ================================================================ */

*, *::before, *::after { box-sizing: border-box; }

:root {
    --bg: #f7f8fb;
    --surface: #ffffff;
    --border: #e5e7eb;
    --text: #0f172a;
    --muted: #64748b;
    --brand: #4f46e5;
    --brand-strong: #4338ca;
    --success: #059669;
    --success-bg: #ecfdf5;
    --warn: #d97706;
    --warn-bg: #fffbeb;
    --error: #b91c1c;
    --error-bg: #fef2f2;
    --info: #0284c7;
    --info-bg: #f0f9ff;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(15,23,42,.04), 0 8px 24px rgba(15,23,42,.06);
}

html, body { height: 100%; margin: 0; }

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    line-height: 1.5;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; letter-spacing: -.02em; }
h2 { font-size: 1.125rem; letter-spacing: -.01em; }
h3 { font-size: 1rem; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.strong { font-weight: 600; }
.text-right { text-align: right; }
.mt-1 { margin-top: .25rem; }
.mt-3 { margin-top: .75rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lead { color: var(--muted); max-width: 60ch; margin: .5rem 0 0; }
.eyebrow { color: var(--brand-strong); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; margin: 0 0 .25rem; }
.big-value { font-size: 1.5rem; font-weight: 700; margin: 0; font-variant-numeric: tabular-nums; }

/* -------------- Layout autenticado -------------- */
.shell {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 100vh;
}
.sidebar {
    background: #fff;
    border-right: 1px solid var(--border);
    padding: 1.25rem 1rem;
    display: flex; flex-direction: column;
    position: sticky; top: 0; align-self: start; height: 100vh;
}
.brand { display: flex; align-items: center; gap: .75rem; padding: 0 .5rem 1rem; }
.brand-mark {
    width: 40px; height: 40px; border-radius: 12px;
    background: var(--text); color: #fff;
    display: grid; place-items: center; font-weight: 700;
}
.brand-mark.large { width: 48px; height: 48px; font-size: 1.25rem; }
.brand-title { font-weight: 700; }
.brand-sub { font-size: .75rem; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-link {
    display: flex; align-items: center; gap: .75rem;
    padding: .55rem .75rem; border-radius: 10px;
    color: #334155; font-size: .9rem;
}
.nav-link:hover { background: #f1f5f9; text-decoration: none; }
.nav-link.is-active { background: #eef2ff; color: var(--brand-strong); font-weight: 500; }
.nav-icon { width: 20px; text-align: center; }

.user-card {
    margin-top: .75rem;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .75rem;
    display: flex; flex-direction: column; gap: .35rem;
}
.user-name { font-weight: 600; font-size: .9rem; }
.user-email { font-size: .75rem; color: var(--muted); word-break: break-all; }

.content { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
    display: flex; align-items: center; gap: 1rem;
    padding: 1rem 1.5rem; border-bottom: 1px solid var(--border);
    background: rgba(255,255,255,.85); backdrop-filter: blur(10px);
    position: sticky; top: 0; z-index: 10;
}
.topbar-title { font-weight: 600; flex: 1; }
.menu-btn { display: none; }

.page { padding: 1.5rem; display: flex; flex-direction: column; gap: 1.5rem; max-width: 1100px; }

.page-header {
    display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap;
}
.page-header-side { text-align: right; }
.back { color: var(--muted); font-size: .8rem; }
.meta-row { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; margin-top: .25rem; color: var(--muted); }

/* -------------- Auth (login) -------------- */
.auth-body { background: linear-gradient(140deg, #f7f8fb 0%, #eef2ff 100%); }
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 2rem 1rem; }
.auth-card {
    background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 2rem; width: 100%; max-width: 420px; text-align: center;
}
.auth-header { margin-bottom: 1.5rem; }
.auth-header .brand-mark { margin: 0 auto .75rem; }
.auth-header p { color: var(--muted); margin: .25rem 0 0; }
.auth-footer { font-size: .75rem; color: var(--muted); margin: 1.5rem 0 0; }
.divider { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .75rem;
    text-transform: uppercase; letter-spacing: .05em; margin: 1.25rem 0; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* -------------- Componentes -------------- */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem;
}
.card > h2 { margin-bottom: .25rem; }
.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }

.empty {
    background: #f8fafc; border: 1px dashed var(--border); border-radius: var(--radius);
    padding: 2rem; text-align: center; color: var(--muted);
}

.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-top: 1rem; }
.stat {
    border: 1px solid var(--border); border-radius: 12px; padding: .75rem 1rem;
    display: flex; flex-direction: column; gap: .1rem; background: #f8fafc;
}
.stat-label { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 1.125rem; }
.stat-ok { background: var(--success-bg); color: var(--success); border-color: #a7f3d0; }
.stat-ok .stat-label, .stat-ok .stat-value { color: var(--success); }
.stat-warn { background: var(--warn-bg); color: var(--warn); border-color: #fde68a; }
.stat-warn .stat-label, .stat-warn .stat-value { color: var(--warn); }

.stat-card { display: flex; flex-direction: column; gap: .25rem; padding: 1.25rem; }

/* Formularios */
.field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1rem; }
.field label { font-weight: 500; font-size: .85rem; }
.field input:not([type='file']), .field select, .field textarea,
.mini-form input, .inline-form input, .reject-form textarea, .mark-paid input[type='file'] {
    width: 100%; padding: .55rem .75rem; border: 1px solid var(--border);
    border-radius: 10px; background: #fff; font: inherit; color: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none; border-color: var(--text); box-shadow: 0 0 0 3px rgba(15,23,42,.08);
}
.field textarea { resize: vertical; min-height: 3.5rem; }
.field input[type='file'] { padding: .35rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: end; }
.form-grid .field { margin-bottom: 0; }
.form-grid .span-2 { grid-column: span 2; }
.radio-group { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 1rem; background: #f8fafc; padding: 1rem; border-radius: 10px; }
.radio { display: inline-flex; gap: .5rem; align-items: center; font-size: .9rem; }
.inline-form { display: flex; align-items: flex-end; gap: .75rem; flex-wrap: wrap; }
.inline-form .field { margin-bottom: 0; }

/* Botones */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
    padding: .55rem 1rem; border-radius: 10px; border: 1px solid transparent;
    font: inherit; font-weight: 500; cursor: pointer; transition: all .15s ease;
    text-decoration: none; font-size: .9rem;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--text); color: #fff; }
.btn-primary:hover { background: #1e293b; color: #fff; }
.btn-secondary { background: #fff; border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: #f8fafc; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: #f1f5f9; color: var(--text); }
.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { background: #991b1b; }
.btn-sm { padding: .35rem .75rem; font-size: .8rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.danger-text { color: var(--error) !important; }

/* Alerts */
.alert { padding: .75rem 1rem; border-radius: 10px; font-size: .9rem; border: 1px solid transparent; }
.alert-success { background: var(--success-bg); color: var(--success); border-color: #a7f3d0; }
.alert-error { background: var(--error-bg); color: var(--error); border-color: #fecaca; }
.alert-info { background: var(--info-bg); color: var(--info); border-color: #bae6fd; }

/* Badges */
.badge {
    display: inline-flex; align-items: center; gap: .25rem;
    padding: .15rem .5rem; border-radius: 999px;
    font-size: .7rem; font-weight: 500; border: 1px solid transparent;
}
.badge-neutral { background: #f1f5f9; color: #334155; border-color: #e2e8f0; }
.badge-info    { background: var(--info-bg); color: var(--info); border-color: #bae6fd; }
.badge-warn    { background: var(--warn-bg); color: var(--warn); border-color: #fde68a; }
.badge-ok      { background: var(--success-bg); color: var(--success); border-color: #a7f3d0; }
.badge-error   { background: var(--error-bg); color: var(--error); border-color: #fecaca; }

/* Progress bar (estilo Cursor) */
.progress { display: flex; flex-direction: column; gap: .5rem; }
.progress-header, .progress-footer {
    display: flex; justify-content: space-between; font-size: .85rem;
}
.progress-label { font-weight: 500; }
.progress-values { color: var(--muted); font-variant-numeric: tabular-nums; }
.progress-footer { color: var(--muted); font-size: .75rem; }
.progress-track { height: 12px; background: #e2e8f0; border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 999px; transition: width .6s ease; }
.progress-bar.is-full { background: #059669; }
.progress-bar.is-high { background: #10b981; }
.progress-bar.is-mid  { background: #f59e0b; }
.progress-bar.is-low  { background: #f43f5e; }

/* Listas */
.list { list-style: none; padding: 0; margin: 0; }
.list-item {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: 1rem 0; border-bottom: 1px solid #f1f5f9; flex-wrap: wrap;
}
.list-item:last-child { border-bottom: none; }
.list-main { min-width: 0; flex: 1; }
.list-title-row { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; }
.list-title { font-weight: 500; color: var(--text); }
.list-meta { display: flex; flex-wrap: wrap; gap: 1rem; color: var(--muted); font-size: .8rem; margin-top: .35rem; }

.stack   { display: flex; flex-direction: column; gap: 1rem; }
.stack-3 { display: flex; flex-direction: column; gap: .75rem; }
.inline-actions { display: inline-flex; flex-wrap: wrap; gap: .35rem; align-items: center; }

/* Tabla */
.table-wrap { margin: 0 -.5rem; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th {
    text-align: left; padding: .5rem .75rem; font-size: .7rem;
    text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600;
}
.table td { padding: .75rem; border-top: 1px solid #f1f5f9; vertical-align: top; }
.table tbody tr:hover { background: #f8fafc; }

/* Compartición / share */
.share { border: 1px solid var(--border); border-radius: 12px; padding: 1rem; background: #fafbfc; }
.share-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.share-name { margin: 0; font-weight: 600; }
.share-actions { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-start; margin-top: 1rem; }
.mark-paid { display: flex; flex-direction: column; gap: .5rem; }
.mark-paid label { font-size: .8rem; color: var(--muted); }
.mark-paid input[type='file'] { padding: .35rem; }

.inline-details summary { list-style: none; }
.inline-details summary::-webkit-details-marker { display: none; }
.reject-form {
    display: flex; flex-direction: column; gap: .5rem;
    background: var(--error-bg); border: 1px solid #fecaca;
    padding: .75rem; border-radius: 10px; margin-top: .5rem; max-width: 320px;
}
.reject-form textarea { resize: vertical; min-height: 3rem; }

/* Usuarios admin */
.user-list { list-style: none; padding: 0; margin: 1rem 0 0; display: flex; flex-direction: column; gap: .75rem; }
.user-row { border: 1px solid var(--border); border-radius: 12px; padding: 1rem; background: #fff; }
.user-row-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.mini-form { margin-top: .75rem; background: #f8fafc; padding: .75rem; border-radius: 10px; }
.mini-form form { display: flex; align-items: flex-end; gap: .5rem; flex-wrap: wrap; }
.mini-form label { display: block; font-size: .8rem; margin-bottom: .25rem; }
.mini-form input { flex: 1; min-width: 180px; }

/* Month picker */
.month-picker {
    display: inline-flex; align-items: center; gap: .35rem;
    background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: .25rem;
}
.month-label { min-width: 10rem; text-align: center; font-weight: 500; font-size: .9rem; }

/* Visor PDF */
.pdf-viewer {
    position: relative; width: 100%; height: 70vh;
    background: #f1f5f9; border: 1px solid var(--border); border-radius: 12px;
    overflow: hidden; user-select: none; -webkit-user-select: none;
}
.pdf-viewer object, .pdf-viewer img { width: 100%; height: 100%; }
.pdf-viewer img { object-fit: contain; }
.pdf-fallback { display: grid; place-items: center; padding: 2rem; color: var(--muted); text-align: center; height: 100%; }

/* ============ Responsive ============ */
@media (max-width: 900px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed; top: 0; left: -100%; height: 100vh; z-index: 40;
        transition: left .25s ease; width: 260px;
    }
    body.nav-open .sidebar { left: 0; box-shadow: 0 0 40px rgba(0,0,0,.15); }
    .menu-btn {
        display: inline-flex; background: transparent; border: 1px solid var(--border);
        border-radius: 10px; padding: .35rem .6rem; font-size: 1.1rem; cursor: pointer;
    }
    .stats-grid { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .span-2 { grid-column: span 1; }
    .page { padding: 1rem; }
}
