/* Gestión de Alquileres — tema claro único (sin modo oscuro, a petición). */
:root {
  color-scheme: light;
  --bg: #F5F7FA;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --text: #1F2A37;
  --muted: #5B6778;
  --faint: #8A95A4;
  --line: #E2E7EE;
  --primary: #1D63C4;
  --primary-hover: #1857AD;
  --primary-weak: #E8F0FC;
  --primary-text: #164E9E;
  --ok: #1B7A4B;
  --ok-bg: #E4F4EB;
  --danger: #B3382A;
  --danger-bg: #FBEAE7;
  --warn: #8F5B0A;
  --warn-bg: #FDF2DE;
  --info: #2B62A8;
  --info-bg: #E9F1FB;
  --income: #2A78D6;
  --cost: #EB6834;
  --radius: 12px;
  --radius-s: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .05);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
body.modal-open { overflow: hidden; }
.hidden { display: none !important; }
h1, h2, h3 { line-height: 1.2; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--ok); }
.neg { color: var(--danger); }
.spacer { flex: 1; }

/* ---------- arranque y acceso ---------- */
.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 200; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.auth { min-height: 100vh; display: grid; place-items: center; padding: calc(var(--safe-top) + 24px) 16px 24px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px 24px; box-shadow: var(--shadow); }
.auth-card h1 { margin: 10px 0 4px; font-size: 22px; }
.auth-logo { border-radius: 12px; display: block; }
.auth-foot { margin: 22px 0 0; font-size: 13px; text-align: center; }
.stack { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.stack .btn { margin-top: 8px; }

/* ---------- estructura ---------- */
.shell-main { min-width: 0; }
.sidebar { display: none; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px; padding: calc(var(--safe-top) + 10px) 16px 10px; background: rgba(245, 247, 250, .94); backdrop-filter: saturate(1.2) blur(8px); -webkit-backdrop-filter: saturate(1.2) blur(8px); border-bottom: 1px solid var(--line); }
.topbar h1 { flex: 1; margin: 0; font-size: 19px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; gap: 6px; align-items: center; }
main#view { padding: 14px 16px calc(92px + var(--safe-bottom)); max-width: 1120px; margin: 0 auto; outline: none; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: var(--safe-bottom); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px; font-size: 11px; color: var(--muted); text-decoration: none; }
.tabbar a.active { color: var(--primary); font-weight: 600; }
.ico { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; font-weight: 650; }
.sidebar .brand img { border-radius: 8px; }
.sidebar .brand small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.sidebar a { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 8px; color: var(--text); text-decoration: none; font-size: 14.5px; }
.sidebar a:hover { background: var(--surface-2); }
.sidebar a.active { background: var(--primary-weak); color: var(--primary-text); font-weight: 600; }
.sidebar .sep { height: 1px; background: var(--line); margin: 8px 6px; }
@media (min-width: 900px) {
  #shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); }
  .sidebar { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px; }
  .tabbar { display: none; }
  .topbar { padding: 14px 28px; }
  main#view { padding: 20px 28px 48px; }
}

/* ---------- avisos de estado ---------- */
.banner { padding: 8px 16px; font-size: 13.5px; text-align: center; border-bottom: 1px solid var(--line); }
.banner-warn { background: var(--warn-bg); color: var(--warn); }
.banner-info { background: var(--info-bg); color: var(--info); }
.alert { border-radius: var(--radius-s); padding: 10px 12px; font-size: 14px; margin: 12px 0 0; }
.alert-danger { background: var(--danger-bg); color: var(--danger); }
.alert-ok { background: var(--ok-bg); color: var(--ok); }
.alert-info { background: var(--info-bg); color: var(--info); }
.alert-warn { background: var(--warn-bg); color: var(--warn); }

/* ---------- botones ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px; border-radius: var(--radius-s); border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-ghost { color: var(--danger); border-color: #F1C9C2; }
.btn-small { min-height: 34px; padding: 5px 11px; font-size: 13px; }
.btn-block { width: 100%; }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; font-size: 15px; flex-shrink: 0; }
.icon-btn:hover { background: var(--surface-2); }
.link { background: none; border: 0; padding: 4px 0; color: var(--primary); font: inherit; font-size: 14px; cursor: pointer; text-align: left; }
.link.danger { color: var(--danger); }
.disabled { pointer-events: none; opacity: .6; }

/* ---------- barras de herramientas ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
.toolbar select, .toolbar .select { width: auto; min-width: 0; max-width: 100%; flex: 1 1 150px; }
.toolbar .grow { flex: 1; }
.period { display: inline-flex; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 2px; }
.period button { border: 0; background: none; width: 34px; height: 34px; border-radius: 6px; cursor: pointer; font-size: 17px; color: var(--text); }
.period button:hover { background: var(--surface-2); }
.period span { min-width: 108px; text-align: center; font-weight: 600; font-size: 14px; text-transform: capitalize; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 2px; gap: 2px; }
.seg button { border: 0; background: none; padding: 7px 12px; border-radius: 6px; font: inherit; font-size: 13.5px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--primary-weak); color: var(--primary-text); }

/* ---------- tarjetas y secciones ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card h3 { margin: 0 0 10px; font-size: 15.5px; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.card-head h3 { margin: 0; flex: 1; }
.section-head { display: flex; align-items: center; gap: 8px; margin: 20px 0 10px; }
.section-head h2 { margin: 0; font-size: 16px; flex: 1; }
.grid-2 { display: grid; gap: 14px; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-2 > .card { margin-bottom: 0; } }
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
@media (min-width: 700px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.kpi .k { font-size: 12.5px; color: var(--muted); }
.kpi .v { font-size: 20px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi .s { font-size: 12px; color: var(--faint); }
.row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.row:last-child { border-bottom: 0; }
.row > span:first-child { color: var(--muted); }
.row > span:last-child { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.row.total > span { color: var(--text); font-weight: 700; font-size: 15px; }
.row.sub > span:first-child { padding-left: 12px; }
.row.head > span { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--faint); font-weight: 700; }
.note { font-size: 12.5px; color: var(--muted); margin: 8px 0 0; }

/* ---------- listas ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 13px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-align: left; font: inherit; color: inherit; cursor: pointer; box-shadow: var(--shadow); }
.item:hover { border-color: #CBD4DF; }
.item-icon { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); flex-shrink: 0; font-size: 17px; }
.item-icon.t-ok { background: var(--ok-bg); }
.item-icon.t-danger { background: var(--danger-bg); }
.item-icon.t-warn { background: var(--warn-bg); }
.item-icon.t-info { background: var(--info-bg); }
.item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.item-title { font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.item-right { text-align: right; flex-shrink: 0; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.item-amount { font-weight: 650; font-variant-numeric: tabular-nums; }
.group-label { font-size: 12.5px; font-weight: 700; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; margin: 16px 2px 2px; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.b-ok { background: var(--ok-bg); color: var(--ok); }
.b-danger { background: var(--danger-bg); color: var(--danger); }
.b-warn { background: var(--warn-bg); color: var(--warn); }
.b-info { background: var(--info-bg); color: var(--info); }
.b-neutral { background: #EEF1F5; color: var(--muted); }
.empty { text-align: center; padding: 26px 16px; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty p { margin: 0 0 10px; }

/* ---------- avisos del panel ---------- */
.alerts { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.alert-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); }
.alert-item .ai-icon { font-size: 18px; }
.alert-item .ai-main { flex: 1; min-width: 0; }
.alert-item .ai-title { font-weight: 600; font-size: 14px; }
.alert-item .ai-detail { font-size: 12.5px; color: var(--muted); }
.alert-item.l-danger { border-left: 4px solid var(--danger); }
.alert-item.l-warn { border-left: 4px solid #E0A33B; }
.alert-item.l-info { border-left: 4px solid var(--primary); }
.alert-item .x { border: 0; background: none; color: var(--faint); font-size: 16px; cursor: pointer; padding: 4px; }
.steps { display: grid; gap: 10px; }
.step { display: flex; gap: 12px; align-items: center; }
.step b { width: 28px; height: 28px; border-radius: 50%; background: var(--primary-weak); color: var(--primary-text); display: grid; place-items: center; flex-shrink: 0; }

/* ---------- tablas ---------- */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.t th, table.t td { padding: 8px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.t th:first-child, table.t td:first-child { text-align: left; white-space: normal; }
table.t th { font-size: 12px; color: var(--faint); font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }

/* ---------- gráfico ---------- */
.chart { width: 100%; }
.chart { min-height: 220px; }
.chart svg { display: block; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.chart-tip { position: fixed; pointer-events: none; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; font-size: 12.5px; box-shadow: 0 4px 14px rgba(16, 24, 40, .12); z-index: 150; }

/* ---------- formularios ---------- */
input, select, textarea { width: 100%; font: inherit; font-size: 16px; color: var(--text); background: var(--surface); border: 1px solid #D5DCE5; border-radius: var(--radius-s); padding: 9px 11px; min-height: 42px; outline: none; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29, 99, 196, .15); }
input[type=checkbox] { width: auto; min-height: 0; }
.label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.label b { color: var(--danger); font-weight: 600; }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px 14px; }
@media (min-width: 620px) { .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .field.full { grid-column: 1 / -1; } }
.field { min-width: 0; }
.field-error { color: var(--danger); font-size: 12.5px; }
.field.has-error input, .field.has-error select { border-color: var(--danger); }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.form-section { font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--faint); padding-top: 6px; border-top: 1px solid var(--line); margin-top: 4px; }
.form-error { margin-top: 12px; background: var(--danger-bg); color: var(--danger); border-radius: var(--radius-s); padding: 9px 12px; font-size: 14px; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 18px; }
.affix { position: relative; display: flex; align-items: center; }
.affix input { padding-right: 32px; }
.affix span { position: absolute; right: 11px; color: var(--faint); font-size: 14px; pointer-events: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid #D5DCE5; background: var(--surface); color: var(--text); border-radius: 999px; padding: 7px 13px; font: inherit; font-size: 14px; cursor: pointer; }
.chip.on { background: var(--primary-weak); border-color: var(--primary); color: var(--primary-text); font-weight: 600; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14.5px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .slider { width: 42px; height: 24px; border-radius: 999px; background: #CBD3DD; position: relative; flex-shrink: 0; transition: background .15s; }
.switch .slider::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); transition: transform .15s; }
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::after { transform: translateX(18px); }
.switch input:focus-visible + .slider { box-shadow: 0 0 0 3px rgba(29, 99, 196, .25); }
.file-field { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.file-name { font-size: 13.5px; }
.lines { display: flex; flex-direction: column; gap: 8px; }
.line-row { display: grid; grid-template-columns: minmax(0, 1fr) 120px 38px; gap: 6px; align-items: center; }
.ownership { display: flex; flex-direction: column; gap: 6px; }
.own-row { display: grid; grid-template-columns: minmax(0, 1fr) 110px; gap: 8px; align-items: center; }
.own-sum { font-size: 13px; font-weight: 600; }
.own-sum.ok { color: var(--ok); }
.own-sum.bad { color: var(--danger); }
.calc { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 8px 12px; }
.calc .row { padding: 4px 0; border: 0; }
.calc .row.total { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 7px; }
.confirm-msg { color: var(--muted); }
.confirm-msg p { margin: 0 0 10px; }

/* ---------- ventanas ---------- */
.modal { position: fixed; inset: 0; z-index: 100; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(31, 42, 55, .28); opacity: 0; transition: opacity .2s; }
.modal.open .modal-backdrop { opacity: 1; }
.modal-panel { position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; display: flex; flex-direction: column; background: var(--surface); border-radius: 18px 18px 0 0; box-shadow: 0 -8px 30px rgba(16, 24, 40, .12); transform: translateY(100%); transition: transform .22s ease; }
.modal.open .modal-panel { transform: none; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px 10px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { flex: 1; margin: 0; font-size: 17px; }
.modal-head .icon-btn { width: 34px; height: 34px; }
.modal-body { overflow-y: auto; padding: 14px 18px calc(18px + var(--safe-bottom)); -webkit-overflow-scrolling: touch; }
@media (min-width: 900px) {
  .modal-panel { left: 50%; top: 50%; right: auto; bottom: auto; width: min(580px, 92vw); max-height: 88vh; border-radius: 14px; opacity: 0; transform: translate(-50%, -47%); transition: transform .18s ease, opacity .18s ease; }
  .modal.open .modal-panel { opacity: 1; transform: translate(-50%, -50%); }
  .modal-panel.wide { width: min(860px, 94vw); }
}
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

/* ---------- toasts ---------- */
#toast-root { position: fixed; left: 50%; transform: translateX(-50%); top: calc(var(--safe-top) + 10px); z-index: 300; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 440px); pointer-events: none; }
@media (min-width: 900px) { #toast-root { top: auto; bottom: 28px; } }
.toast { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--ok); border-radius: 10px; padding: 11px 14px; font-size: 14px; box-shadow: 0 8px 24px rgba(16, 24, 40, .14); transition: opacity .3s, transform .3s; }
.toast-error { border-left-color: var(--danger); }
.toast-info { border-left-color: var(--primary); }
.toast.out { opacity: 0; transform: translateY(-8px); }
@media (min-width: 900px) { .toast.out { transform: translateY(8px); } }

/* ---------- menú «Más» ---------- */
.menu-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 700px) { .menu-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.menu-grid a { display: flex; flex-direction: column; gap: 8px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); text-decoration: none; box-shadow: var(--shadow); font-weight: 600; }
.menu-grid a .ico { color: var(--primary); }
.menu-grid a small { font-weight: 400; color: var(--muted); font-size: 12.5px; }

@media print {
  .sidebar, .tabbar, .topbar-actions, #banner, .toolbar button { display: none !important; }
  main#view { padding: 0; }
}
