/* Plataforma de SIMS · Telemática y Controles */
:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --ink: #111418;
  --ink-2: #4b5260;
  --muted: #7a818e;
  --line: #e3e6eb;
  --brand: #14375e;
  --brand-ink: #ffffff;
  --accent: #2a78d6;
  --accent-soft: #e6f0fc;
  --bar: #2a78d6;
  --bar-empty: #c3c8d1;
  --good: #0ca30c;  --good-soft: #e5f6e5;  --good-ink: #0b6a0b;
  --warn: #fab219;  --warn-soft: #fff4d9;  --warn-ink: #7a5200;
  --crit: #d03b3b;  --crit-soft: #fbe7e7;  --crit-ink: #a02323;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .06);
  --tabbar-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1114; --surface: #1a1c20; --surface-2: #22252a; --ink: #f2f3f5; --ink-2: #c3c7ce; --muted: #8b919c;
    --line: #2d3137; --brand: #0f2a48; --accent: #5598e7; --accent-soft: #1c2c42; --bar: #3987e5; --bar-empty: #4a4f57;
    --good-soft: #15301a; --good-ink: #5fd35f; --warn-soft: #3a2e10; --warn-ink: #fac857; --crit-soft: #3b1a1a; --crit-ink: #f08a8a;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1114; --surface: #1a1c20; --surface-2: #22252a; --ink: #f2f3f5; --ink-2: #c3c7ce; --muted: #8b919c;
  --line: #2d3137; --brand: #0f2a48; --accent: #5598e7; --accent-soft: #1c2c42; --bar: #3987e5; --bar-empty: #4a4f57;
  --good-soft: #15301a; --good-ink: #5fd35f; --warn-soft: #3a2e10; --warn-ink: #fac857; --crit-soft: #3b1a1a; --crit-ink: #f08a8a;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
body.min { padding-bottom: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: 0 0 .25rem; line-height: 1.25; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
h2 { font-size: 1rem; margin: 0 0 .75rem; }
h1 small, h2 small { font-weight: 400; font-size: .8em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .01em; }
.xl { font-size: 1.6rem; font-weight: 600; }
.center { text-align: center; }
.ico { width: 20px; height: 20px; flex: none; vertical-align: middle; }
.ico-sm { width: 16px; height: 16px; }
.ico-lg { width: 36px; height: 36px; }
[hidden] { display: none !important; }

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--brand); color: var(--brand-ink);
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
}
.brand { color: inherit; display: flex; align-items: center; gap: 8px; font-weight: 700; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand small { font-weight: 400; opacity: .7; display: none; }
.topsearch { flex: 1; position: relative; max-width: 520px; }
.topsearch .ico { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); opacity: .7; }
.topsearch input {
  width: 100%; border: 0; border-radius: 10px; padding: 9px 12px 9px 36px; font-size: 16px;
  background: rgba(255,255,255,.14); color: #fff;
}
.topsearch input::placeholder { color: rgba(255,255,255,.7); }
.topsearch input:focus { outline: 2px solid rgba(255,255,255,.5); background: rgba(255,255,255,.22); }
.deskmenu { display: none; gap: 4px; align-items: center; }
.deskmenu a { color: rgba(255,255,255,.85); padding: 6px 10px; border-radius: 8px; }
.deskmenu a:hover, .deskmenu a.on { background: rgba(255,255,255,.14); color: #fff; text-decoration: none; }
.deskmenu .user { border: 1px solid rgba(255,255,255,.3); }

/* ---------- Barra inferior (celular) ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex;
  background: var(--surface); border-top: 1px solid var(--line);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .75rem;
}
.tabbar a.on { color: var(--accent); font-weight: 600; }
.tabbar a:hover { text-decoration: none; }
.tabbar .ico { width: 24px; height: 24px; }

.sheet { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.35); display: flex; align-items: flex-end; }
.sheet-panel {
  background: var(--surface); width: 100%; border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 4px;
}
.sheet-panel > a, .sheet-panel .linklike {
  display: flex; gap: 12px; align-items: center; padding: 12px 8px; color: var(--ink); border-radius: 10px; font-size: 1rem;
}
.sheet-panel > a:hover, .sheet-panel .linklike:hover { background: var(--surface-2); text-decoration: none; }
.linklike { background: none; border: 0; width: 100%; cursor: pointer; font: inherit; text-align: left; }

/* ---------- Contenido ---------- */
.wrap { max-width: 1280px; margin: 0 auto; padding: 16px; }
.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 12px; }
.pagehead p { margin: 0; }
.actions { display: flex; gap: 8px; }
.back { display: inline-flex; align-items: center; gap: 2px; margin-bottom: 4px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); min-width: 0;
}
.grid { display: grid; grid-template-columns: 1fr; gap: 12px; grid-auto-flow: row dense; }
.grid > .card { margin-bottom: 0; }
.empty { text-align: center; padding: 32px 16px; }
.note { margin: 12px 0 0; }

.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; border: 1px solid transparent; }
.flash-ok { background: var(--good-soft); color: var(--good-ink); border-color: color-mix(in srgb, var(--good) 30%, transparent); }
.flash-warn { background: var(--warn-soft); color: var(--warn-ink); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.flash-error { background: var(--crit-soft); color: var(--crit-ink); border-color: color-mix(in srgb, var(--crit) 30%, transparent); }
.flash a { color: inherit; text-decoration: underline; }

/* ---------- Botones y formularios ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 8px 16px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--crit); border-color: var(--crit); color: #fff; }
.btn-sm { min-height: 34px; padding: 4px 12px; font-size: .875rem; }
.full { width: 100%; }
.danger-txt { color: var(--crit-ink); cursor: pointer; }
.iconbtn { background: none; border: 0; color: var(--muted); padding: 6px; border-radius: 8px; cursor: pointer; display: inline-flex; }
.iconbtn:hover { color: var(--accent); background: var(--accent-soft); }

.form label, .filtergrid label, .login-card label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--ink-2); font-weight: 500; margin-bottom: 12px; }
input, select, textarea {
  font: inherit; font-size: 16px; /* evita zoom en iPhone */
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink); min-height: 42px;
}
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
.formgrid { display: grid; grid-template-columns: 1fr; gap: 0 16px; }
.formactions { display: flex; gap: 8px; flex-wrap: wrap; }
.field-err { color: var(--crit-ink); font-size: .8rem; }
.hint { display: block; font-size: .8rem; margin: -8px 0 10px; min-height: 1em; }
.hint.ok { color: var(--good-ink); }
.hint.bad { color: var(--crit-ink); }
.hint.warn { color: var(--warn-ink); }
.inputbtn { position: relative; display: block; }
.inputbtn .iconbtn { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: flex-end; }
.inline-form label { margin-bottom: 0; flex: 1 1 160px; }

/* ---------- Búsqueda y filtros ---------- */
.searchbar { margin-bottom: 12px; }
.searchrow { display: flex; gap: 8px; }
.searchbox { position: relative; flex: 1; }
.searchbox > .ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.searchbox input { padding-left: 40px; padding-right: 44px; min-height: 46px; border-radius: 12px; }
.searchbox .iconbtn { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.filters { margin-top: 8px; }
.filters summary { cursor: pointer; color: var(--ink-2); font-size: .9rem; display: inline-flex; gap: 6px; align-items: center; padding: 4px 0; }
.filtergrid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; margin-top: 8px; }
.filtergrid label { margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 4px 12px; font-size: .85rem; }
.chip:hover { text-decoration: none; filter: brightness(.97); }

/* ---------- Tarjetas de línea (celular) ---------- */
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.lcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); position: relative; box-shadow: var(--shadow); }
.lcard > a { display: block; padding: 12px 14px; color: var(--ink); }
.lcard > a:hover { text-decoration: none; background: var(--surface-2); border-radius: var(--radius); }
.lcard .pick { position: absolute; right: 10px; bottom: 10px; z-index: 2; padding: 6px; }
.lcard-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; }
.lcard-dn { font-size: 1.2rem; font-weight: 600; }
.lcard-row { margin-top: 6px; }
.lcard-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 4px; padding-right: 36px; }
.alert-txt { color: var(--warn-ink); margin-top: 4px; padding-right: 36px; }
.is-baja { opacity: .6; }
.pill { background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 1px 10px; font-size: .78rem; font-weight: 600; color: var(--ink-2); white-space: nowrap; }

.sem { display: inline-flex; align-items: center; gap: 5px; font-size: .75rem; font-weight: 700; padding: 2px 10px; border-radius: 999px; white-space: nowrap; }
.sem::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.sem-verde { background: var(--good-soft); color: var(--good-ink); }
.sem-amarillo { background: var(--warn-soft); color: var(--warn-ink); }
.sem-rojo { background: var(--crit-soft); color: var(--crit-ink); }
.sem-baja { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }

.bulkbar {
  position: sticky; top: 64px; z-index: 10; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 10px; padding: 8px 12px; margin-bottom: 8px;
}

/* ---------- Tablas ---------- */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl-lineas tbody tr { cursor: pointer; }
.tbl-lineas tbody tr:hover { background: var(--surface-2); }
.desk-only { display: none; }

.pager { display: flex; justify-content: space-between; align-items: center; margin: 16px 0; }

/* ---------- Tablero ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
  display: flex; flex-direction: column; gap: 2px; color: var(--ink); box-shadow: var(--shadow); border-top: 4px solid var(--accent);
}
.tile:hover { text-decoration: none; background: var(--surface-2); }
.tile-good { border-top-color: var(--good); }
.tile-warn { border-top-color: var(--warn); }
.tile-crit { border-top-color: var(--crit); }
.tile-label { font-size: .8rem; color: var(--ink-2); font-weight: 600; display: flex; align-items: center; gap: 4px; }
.tile-label .ico { width: 16px; height: 16px; }
.tile-good .tile-label .ico { color: var(--good-ink); }
.tile-warn .tile-label .ico { color: var(--warn-ink); }
.tile-crit .tile-label .ico { color: var(--crit-ink); }
.tile-num { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.tile-sub { font-size: .75rem; color: var(--muted); }

.stack { display: flex; gap: 2px; height: 18px; border-radius: 4px; overflow: hidden; }
.stack-mini { height: 10px; min-width: 120px; }
.stack-seg { min-width: 3px; }
.seg-good { background: var(--good); }
.seg-warn { background: var(--warn); }
.seg-crit { background: var(--crit); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: .85rem; color: var(--ink-2); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: baseline; }

.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.bars a {
  display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; align-items: center; gap: 10px;
  color: var(--ink); padding: 5px 6px; border-radius: 8px;
}
.bars a:hover { background: var(--surface-2); text-decoration: none; }
.bar-label { font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 12px; }
.bar-fill { display: block; height: 100%; background: var(--bar); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-empty { background: var(--bar-empty); }
.bar-val { font-size: .85rem; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.bar-val small { font-weight: 400; color: var(--muted); display: inline-block; min-width: 3.4em; }

.qlist { list-style: none; margin: 0; padding: 0; }
.qlist a { display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 8px 6px; border-bottom: 1px solid var(--line); color: var(--ink); }
.qlist li:last-child a { border-bottom: 0; }
.qlist a:hover { background: var(--surface-2); text-decoration: none; }
.qlist a.muted { color: var(--muted); }
.qlist .ico { margin-right: 6px; color: var(--muted); }
.strong-warn { color: var(--warn-ink); font-weight: 700; }

.feed { list-style: none; margin: 0 0 8px; padding: 0; }
.feed li { display: flex; flex-direction: column; gap: 1px; padding: 8px 0; border-bottom: 1px solid var(--line); word-break: break-word; }
.feed li:last-child { border-bottom: 0; }

/* ---------- Ficha ---------- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--muted); font-size: .85rem; }
.kv dd { margin: 0; word-break: break-word; }
.bignum { margin-bottom: 12px; }
.copyrow { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; word-break: break-all; }

/* ---------- Catálogos ---------- */
.tabs { display: flex; gap: 4px; overflow-x: auto; margin-bottom: 12px; }
.tabs a { padding: 8px 14px; border-radius: 999px; color: var(--ink-2); background: var(--surface); border: 1px solid var(--line); white-space: nowrap; }
.tabs a.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.tabs a:hover { text-decoration: none; }
.catlist { list-style: none; margin: 0; padding: 0; }
.catlist > li { border-bottom: 1px solid var(--line); padding: 4px 0; }
.catlist > li:last-child { border-bottom: 0; }
.catlist summary { display: flex; justify-content: space-between; gap: 8px; align-items: center; cursor: pointer; padding: 8px 0; list-style: none; }
.catlist summary::-webkit-details-marker { display: none; }
.catlist details[open] { padding-bottom: 12px; }
.rowactions { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 8px; align-items: flex-end; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--brand); }
.login-card { width: 100%; max-width: 380px; padding: 24px; }
.login-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 20px; color: var(--brand); font-size: 1.2rem; }
@media (prefers-color-scheme: dark) { .login-brand { color: var(--ink); } }

/* ---------- Pantallas medianas y grandes ---------- */
@media (min-width: 720px) {
  .tiles { grid-template-columns: repeat(4, 1fr); }
  .grid { grid-template-columns: 1fr 1fr; }
  .span2 { grid-column: span 2; }
  .formgrid { grid-template-columns: 1fr 1fr; }
  .filtergrid { grid-template-columns: repeat(3, 1fr); }
  .brand small { display: inline; }
}
@media (min-width: 1024px) {
  body { padding-bottom: 0; }
  .tabbar, .cards { display: none; }
  .desk-only { display: block; }
  .deskmenu { display: flex; }
  .filtergrid { grid-template-columns: repeat(5, 1fr); }
  .formgrid { grid-template-columns: repeat(3, 1fr); }
  .grid { grid-template-columns: repeat(3, 1fr); }
  .span2 { grid-column: span 2; }
  .bulkbar { top: 70px; }
}
@media (max-width: 719px) {
  .hide-sm { display: none; }
  .topbar:has(form.topsearch) .brand span { display: none; }
}
@media print {
  .topbar, .tabbar, .searchbar, .actions, .bulkbar { display: none !important; }
  body { background: #fff; }
}
