:root {
  --navy: #1f3a5f;
  --navy-2: #2b4c78;
  --accent: #f5a524;
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #17202b;
  --muted: #637083;
  --line: #dde3ea;
  --ok: #1e8e5a;
  --warn: #b7791f;
  --err: #c0392b;
  --sev-alta: #c0392b;
  --sev-media: #e08a00;
  --sev-baja: #6b7f99;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1520; --card: #18212f; --text: #e8edf3; --muted: #93a1b4; --line: #2a3546; }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.4;
}
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.cap::first-letter { text-transform: uppercase; }
.center { text-align: center; }
.error { color: var(--err); }

/* Layout */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px; background: var(--navy); color: #fff;
}
.topbar h1 { flex: 1; margin: 0; font-size: 1.1rem; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo { font-size: 1.3rem; }
.icon-btn { background: rgba(255,255,255,0.12); border: 0; color: #fff; width: 38px; height: 38px; border-radius: 10px; font-size: 1.2rem; cursor: pointer; }
.content { padding: 16px 16px calc(96px + var(--safe-b)); max-width: 760px; margin: 0 auto; }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex;
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
}
.tabbar button { flex: 1; border: 0; background: none; padding: 8px 4px 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 0.72rem; color: var(--muted); cursor: pointer; }
.tabbar button.active { color: var(--navy-2); font-weight: 650; }
@media (prefers-color-scheme: dark) { .tabbar button.active { color: var(--accent); } }
.tabbar .ti { font-size: 1.25rem; }

.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.section { font-size: 1rem; margin: 22px 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.sub { font-size: 0.95rem; margin: 16px 0 8px; }

/* Cards */
.card {
  display: block; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin: 0 0 10px;
}
button.card { cursor: pointer; }
.card h3 { margin: 0 0 4px; font-size: 1rem; }
.card p { margin: 4px 0; }
.card.soft { background: transparent; border-style: dashed; }
.falla { border-left: 5px solid var(--sev-media); }
.falla.sev-alta { border-left-color: var(--sev-alta); }
.falla.sev-baja { border-left-color: var(--sev-baja); }
.doc.st-vencido { border-left: 5px solid var(--err); }
.doc.st-por_vencer { border-left: 5px solid var(--warn); }
.doc.st-vigente { border-left: 5px solid var(--ok); }

.badge { display: inline-block; font-size: 0.72rem; font-weight: 650; padding: 3px 8px; border-radius: 999px; background: var(--line); white-space: nowrap; }
.badge.warn { background: #fdecc8; color: #7a4d00; }
.st-abierta { background: #fde2e1; color: #8a1f17; }
.st-en_reparacion { background: #fdecc8; color: #7a4d00; }
.st-cerrada { background: #d8f2e4; color: #145c3b; }
.d-vencido { background: #fde2e1; color: #8a1f17; }
.d-por_vencer { background: #fdecc8; color: #7a4d00; }
.d-vigente { background: #d8f2e4; color: #145c3b; }

.banner { border-radius: 12px; padding: 10px 12px; margin: 0 0 12px; font-size: 0.92rem; }
.banner.info { background: #e3edf9; color: #1d3f6b; }
.banner.warn { background: #fdf1d6; color: #6b4500; }
.banner.error { background: #fde2e1; color: #7a1d15; }
.qerr { margin-top: 6px; }

/* Steps (jornada) */
.step { display: flex; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.step-n { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: var(--line); }
.step.todo .step-n { background: var(--accent); color: #2b1a00; }
.step.done .step-n { background: var(--ok); color: #fff; }
.step.locked { opacity: 0.6; }
.step.optional .step-n { background: transparent; border: 2px solid var(--muted); color: var(--muted); }
.step-body { flex: 1; }
.step-body h3 { margin: 4px 0; font-size: 1.05rem; }
.step-body p { margin: 2px 0 10px; }

/* Forms */
.label { display: block; font-size: 0.85rem; color: var(--muted); margin: 12px 0 4px; }
.input {
  display: block; width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); margin-bottom: 10px; font-size: 16px;
}
.input.big { font-size: 1.25rem; font-weight: 600; }
.input.sm { padding: 8px 10px; margin: 0; width: auto; min-width: 0; }
textarea.input { resize: vertical; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 16px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-weight: 600; cursor: pointer;
  text-decoration: none; color: inherit; min-height: 44px;
}
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.block { width: 100%; margin: 14px 0 8px; }
.btn.sm { padding: 7px 12px; min-height: 36px; }
.btn.danger-o { color: var(--err); border-color: var(--err); background: transparent; }
.link { background: none; border: 0; color: var(--navy-2); font-weight: 650; cursor: pointer; padding: 4px; text-decoration: underline; }
.link.danger { color: var(--err); }
@media (prefers-color-scheme: dark) { .link { color: var(--accent); } .btn.primary { background: var(--accent); border-color: var(--accent); color: #2b1a00; } }
.chips { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 2px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 14px; white-space: nowrap; cursor: pointer; }
.chip.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.range { margin-bottom: 14px; }
.range .input.sm { flex: 1; }
.summary { font-weight: 650; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }

/* Photos */
.photo-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 10px; }
.photo-grid.one { grid-template-columns: 1fr; max-width: 260px; }
.photo-slot, .photo-add {
  border: 2px dashed var(--line); border-radius: var(--radius); background: var(--card); padding: 0; overflow: hidden;
  display: flex; flex-direction: column; cursor: pointer; aspect-ratio: 4 / 3; position: relative;
}
.photo-slot.filled { border-style: solid; border-color: var(--ok); }
.ph-img { flex: 1; display: grid; place-items: center; font-size: 2rem; min-height: 0; }
.ph-img img { width: 100%; height: 100%; object-fit: cover; }
.ph-label { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.55); color: #fff; font-size: 0.8rem; padding: 4px 8px; }
.photo-add { align-items: center; justify-content: center; font-weight: 650; color: var(--muted); }
.pdf { font-weight: 700; font-size: 1rem; }
.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0; }
.g-cell { aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--line); display: grid; place-items: center; text-decoration: none; color: inherit; }
.g-cell img { width: 100%; height: 100%; object-fit: cover; }
.falla-form { border-left: 5px solid var(--sev-media); }

/* Modal / QR */
.modal { position: fixed; inset: 0; z-index: 20; background: rgba(10,15,25,0.6); display: flex; align-items: flex-end; }
.sheet { background: var(--card); width: 100%; max-width: 560px; margin: 0 auto; border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + var(--safe-b)); }
.sheet h2 { margin: 0 0 12px; font-size: 1.15rem; }
.sheet .row .btn { flex: 1; }
.qr-box { background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 1; margin-bottom: 12px; display: grid; place-items: center; color: #fff; }
.qr-box video { width: 100%; height: 100%; object-fit: cover; }

/* Login */
.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px 16px; max-width: 420px; margin: 0 auto; }
.brand { text-align: center; margin-bottom: 20px; }
.brand h1 { margin: 8px 0 2px; font-size: 1.5rem; }
.brand p { margin: 0; color: var(--muted); }
.logo-big { font-size: 3rem; }
.pin-dots { display: flex; gap: 12px; justify-content: center; margin: 8px 0 16px; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dots span.on { background: var(--navy); border-color: var(--navy); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.key { height: 58px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg); font-size: 1.4rem; font-weight: 600; cursor: pointer; }
.key.ok { background: var(--navy); color: #fff; border-color: var(--navy); }

/* Dashboard */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 640px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.kpi-l { font-size: 0.78rem; color: var(--muted); }
.kpi-v { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.kpi-s { font-size: 0.75rem; color: var(--muted); }
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 0.78rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
.chart { width: 100%; height: auto; }
.chart .grid { stroke: var(--line); }
.chart .axis { fill: var(--muted); font-size: 10px; }
.chart .bar.a { fill: var(--navy-2); }
.chart .bar.b { fill: var(--accent); }
.legend { display: flex; gap: 16px; font-size: 0.8rem; color: var(--muted); margin-top: 6px; }
.lg::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.lg.a::before { background: var(--navy-2); }
.lg.b::before { background: var(--accent); }
.amount { font-variant-numeric: tabular-nums; }

/* Feedback */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(80px + var(--safe-b)); z-index: 40; max-width: 520px; margin: 0 auto;
  background: #1d2733; color: #fff; padding: 12px 14px; border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,0.25);
  transform: translateY(20px); opacity: 0; transition: 0.25s;
}
.toast.show { transform: none; opacity: 1; }
.toast.ok { background: var(--ok); }
.toast.warn { background: #8a5a00; }
.toast.error { background: var(--err); }
.overlay { position: fixed; inset: 0; z-index: 30; background: rgba(10,15,25,0.55); display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff; gap: 10px; }
.spinner { width: 34px; height: 34px; border: 4px solid rgba(127,127,127,0.25); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 24px auto; }
.spinner.sm { width: 20px; height: 20px; border-width: 3px; margin: 0; }
.boot { min-height: 100vh; display: grid; place-items: center; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Dentro del portal (iframe): sin márgenes de barra de estado */
html.embed .topbar { padding-top: 10px; }
html.embed .logo { display: none; }
