:root {
  --bg: #f4f6f8; --card: #fff; --text: #1d2733; --muted: #607080; --line: #dde3ea;
  --brand: #1f5f8b; --brand-ink: #fff; --ok: #1d7a46; --warn: #a15c00; --bad: #b3261e;
  --ok-bg: #e3f4ea; --warn-bg: #fff1d6; --bad-bg: #fde7e5; --info-bg: #e5eef6;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11171d; --card: #1a232c; --text: #e8eef4; --muted: #93a3b3; --line: #2b3946;
    --brand: #5aa6d6; --brand-ink: #0b1620; --ok: #5ccf8c; --warn: #f0b24a; --bad: #ff8a80;
    --ok-bg: #153524; --warn-bg: #3a2c10; --bad-bg: #3d1b19; --info-bg: #16293a;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
a { color: var(--brand); }
.muted { color: var(--muted); }
.wrap { max-width: 1000px; margin: 0 auto; padding: .5rem 1rem calc(5.5rem + env(safe-area-inset-bottom)); }
header.top { position: sticky; top: 0; z-index: 5; background: var(--brand); color: var(--brand-ink);
  padding: calc(.6rem + env(safe-area-inset-top)) 1rem .6rem; display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
header.top strong { font-size: 1.05rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin: .75rem 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .6rem; margin: .75rem 0; }
.stat { text-align: left; width: 100%; font: inherit; color: inherit; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; }
.stat .v { font-size: 1.4rem; font-weight: 650; }
.stat .l { color: var(--muted); font-size: .85rem; }
.stat.warn .v { color: var(--warn); }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: .55rem .9rem; cursor: pointer; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: .4rem; text-decoration: none; color: var(--text); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--bad); }
.btn.small { padding: .3rem .7rem; font-size: .92rem; min-height: 40px; }
.btn.block { width: 100%; margin-top: .5rem; }
.btn.primary { color: var(--brand-ink); }
.btn:disabled { opacity: .5; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.row.between { justify-content: space-between; }
.form { display: grid; gap: .7rem; }
.form label { display: grid; gap: .2rem; }
.form label > span { font-size: .85rem; color: var(--muted); }
input, select, textarea { width: 100%; font-size: 16px; min-height: 44px; padding: .55rem .65rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.error { color: var(--bad); margin: 0; min-height: 1.2em; }
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .8rem; background: var(--info-bg); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .93rem; }
th, td { text-align: left; padding: .5rem .45rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; }
.alert { border-radius: 8px; padding: .6rem .8rem; margin: .4rem 0; background: var(--info-bg); }
.alert.error { background: var(--bad-bg); color: var(--bad); }
.alert.aviso { background: var(--warn-bg); color: var(--warn); }
details > summary { cursor: pointer; font-weight: 600; margin-bottom: .5rem; }
.login { max-width: 380px; margin: 12vh auto 0; padding: 0 1rem; }
#toast { position: fixed; left: 50%; bottom: calc(5rem + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #202b36; color: #fff;
  padding: .55rem 1rem; border-radius: 999px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; z-index: 20; }
#toast.show { opacity: 1; }

button.stat { cursor: pointer; }
button.stat:active, .btn:active { filter: brightness(.95); }
.ico { width: 22px; height: 22px; flex: 0 0 auto; }
.iconbtn { border: 0; background: transparent; color: inherit; width: 44px; height: 44px; border-radius: 999px; display: grid; place-items: center; cursor: pointer; }
.row-link { justify-content: flex-start; }
header.top .badge { color: var(--warn); }
nav.bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); }
nav.bottom button { flex: 1 1 0; min-width: 0; border: 0; background: transparent; color: var(--muted); display: grid; justify-items: center; gap: .1rem;
  padding: .5rem .1rem .4rem; font-size: .72rem; cursor: pointer; min-height: 56px; }
nav.bottom button[aria-current="page"] { color: var(--brand); font-weight: 650; }
dialog.sheet { border: 0; padding: 0; width: 100%; max-width: 520px; margin: auto auto 0; border-radius: 16px 16px 0 0; background: var(--card); color: var(--text); }
dialog.sheet::backdrop { background: rgba(0, 0, 0, .45); }
.sheet-in { padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom)); max-height: 85vh; overflow-y: auto; }
@media (min-width: 700px) { dialog.sheet { margin: auto; border-radius: 16px; } }
@media (max-width: 640px) {
  .tablewrap { overflow: visible; }
  table, thead, tbody, tr, td { display: block; }
  thead { position: absolute; left: -9999px; }
  tr { border: 1px solid var(--line); border-radius: var(--radius); padding: .4rem .7rem; margin: .6rem 0; background: var(--bg); }
  td, td.num { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: .3rem 0; text-align: right; white-space: normal; }
  td[data-label]::before { content: attr(data-label); color: var(--muted); text-align: left; flex: 0 0 38%; }
  td:last-child:not([data-label]) { justify-content: flex-end; }
  td > .row, td > span { justify-content: flex-end; text-align: right; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

[hidden] { display: none !important; }
.stat { display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-start; }

/* ---- v0.4: inicio con secciones desplegables, filtros y contratos ---- */
:root { --muted-bg: #eceff3; }
@media (prefers-color-scheme: dark) { :root { --muted-bg: #243140; } }
.badge.muted { background: var(--muted-bg); color: var(--muted); }
h2.sec { margin: 1.1rem 0 .1rem; font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.quick { margin: .25rem 0 .5rem; }

.strips { display: grid; gap: .4rem; margin: .6rem 0; }
.strip { display: flex; align-items: center; justify-content: space-between; gap: .5rem; width: 100%; text-align: left; font: inherit; font-weight: 600;
  border: 1px solid transparent; border-radius: var(--radius); padding: .7rem .9rem; min-height: 48px; cursor: pointer; color: inherit; }
.strip.bad { background: var(--bad-bg); color: var(--bad); }
.strip.warn { background: var(--warn-bg); color: var(--warn); }
.strip.info { background: var(--info-bg); }
.strip.ok { background: var(--ok-bg); color: var(--ok); }
.strip.static { cursor: default; }

details.fold { background: var(--card); border: 1px solid var(--line); border-left-width: 5px; border-radius: var(--radius); margin: .55rem 0; }
details.fold.st-alarma { border-left-color: var(--bad); }
details.fold.st-revisar { border-left-color: var(--warn); }
details.fold.st-pendiente { border-left-color: #6b8fb0; }
details.fold.st-ok { border-left-color: var(--ok); }
details.fold.st-libre { border-left-color: var(--line); }
details.fold > summary { list-style: none; cursor: pointer; margin: 0; padding: .8rem .9rem; display: flex; align-items: center; gap: .6rem; min-height: 56px; font-weight: 400; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::after { content: ''; flex: 0 0 auto; width: 9px; height: 9px; margin-left: .2rem; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(45deg); transition: transform .15s; }
details.fold[open] > summary::after { transform: rotate(-135deg); }
.fold-body { padding: 0 .9rem .9rem; }
.fh { display: flex; align-items: center; gap: .6rem; flex: 1 1 auto; min-width: 0; }
.fh-main { display: grid; min-width: 0; flex: 1 1 auto; }
.fh-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fh-main small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { flex: 0 0 auto; width: 12px; height: 12px; border-radius: 50%; background: var(--line); }
.dot.alarma { background: var(--bad); box-shadow: 0 0 0 4px var(--bad-bg); }
.dot.revisar { background: var(--warn); }
.dot.pendiente { background: #6b8fb0; }
.dot.ok { background: var(--ok); }

.room { border-top: 1px solid var(--line); padding: .65rem 0; display: grid; gap: .45rem; justify-items: start; }
.room-top { display: flex; justify-content: space-between; gap: .75rem; width: 100%; align-items: flex-start; }
.room-r { text-align: right; display: grid; gap: .2rem; justify-items: end; }
.upd { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: .6rem; flex-wrap: wrap; background: var(--bg); border-radius: 10px; padding: .5rem .65rem; }
.late { color: var(--bad); font-weight: 600; }

.chips { display: flex; gap: .4rem; overflow-x: auto; padding: .1rem 0 .4rem; margin: .5rem 0 0; -webkit-overflow-scrolling: touch; }
.chip { flex: 0 0 auto; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 999px; padding: .4rem .85rem; min-height: 40px; cursor: pointer; }
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
input[type="search"] { margin-top: .6rem; }

.kv { display: grid; gap: .3rem; margin-bottom: .6rem; }
.kv-i { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 1px dashed var(--line); padding: .2rem 0; }
.kv-i span:last-child { text-align: right; }
.row.actions { margin: .6rem 0; }
.files { border-top: 1px solid var(--line); margin-top: .6rem; padding-top: .6rem; display: grid; gap: .45rem; justify-items: start; }
.file { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; width: 100%; }
.pre { white-space: pre-wrap; }

nav.bottom .ni { position: relative; display: inline-grid; }
.nbadge { position: absolute; top: -4px; right: -10px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px; background: var(--bad); color: #fff;
  font-size: .68rem; line-height: 17px; text-align: center; font-weight: 700; }
.fh .badge { white-space: nowrap; flex: 0 0 auto; }
.fh-main small { white-space: normal; overflow: visible; }

/* ---- v0.5: plan, banner de prueba, tipos de inmueble ---- */
.plan-banner { display: block; width: 100%; margin: .5rem 0 0; padding: .6rem .9rem; min-height: 44px; border: 0; border-radius: var(--radius); background: var(--info-bg); color: var(--text); font: inherit; font-weight: 600; text-align: left; cursor: pointer; }
.plan-banner.bad { background: var(--bad-bg); color: var(--bad); }
.plans { display: grid; gap: .75rem; margin: .75rem 0; }
.plans .plan { display: grid; gap: .35rem; justify-items: start; margin: 0; }
.plans .plan.hl { border: 2px solid var(--brand); }
.plans .big { font-size: 1.6rem; font-weight: 700; }
@media (min-width: 700px) { .plans { grid-template-columns: 1fr 1fr; } }
