/* ============================================================
   Equipos fríos · Leche Mukki
   Línea gráfica: naranja Mukki #EB671B sobre azul noche.
   ============================================================ */
:root {
  --orange: #EB671B;
  --orange-600: #d45810;
  --orange-soft: rgba(235, 103, 27, .14);
  --green: #2fbf71;
  --amber: #f0b429;
  --blue: #6c8cff;
  --red: #ef5b5b;
  --gray: #8a93a8;
  --radius-lg: 18px;
  --radius: 12px;
  --radius-sm: 9px;
  --font: 'Plus Jakarta Sans', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --tabs-h: 0px;
  --bn-h: 0px;
}
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141925;
  --bg-2: #181e2b;
  --surface: #1b2130;
  --surface-2: #222a3b;
  --surface-3: #2a3346;
  --border: #2b3447;
  --border-strong: #3a4459;
  --text: #eef1f7;
  --text-2: #b9c0cf;
  --muted: #8a93a8;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --map-filter: none;
}
html[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f4f7;
  --bg-2: #eceef3;
  --surface: #ffffff;
  --surface-2: #f5f6f9;
  --surface-3: #eceff4;
  --border: #e1e4eb;
  --border-strong: #cfd4de;
  --text: #182031;
  --text-2: #3d4659;
  --muted: #6a7387;
  --shadow: 0 10px 30px rgba(24, 32, 49, .08);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Layout ---------- */
.app { min-height: 100vh; padding-bottom: calc(var(--bn-h) + env(safe-area-inset-bottom)); }
.view { max-width: 1320px; margin: 0 auto; padding: 8px 28px 48px; outline: none; }

.topbar {
  max-width: 1320px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: calc(14px + env(safe-area-inset-top)) 28px 14px;
}
.brand { display: flex; align-items: center; gap: 14px; text-decoration: none; min-width: 0; }
.brand-logo { height: 38px; width: auto; flex: none; }
.brand-sep { width: 1px; height: 36px; background: var(--border-strong); flex: none; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 19px; font-weight: 800; letter-spacing: -.01em; line-height: 1.2; }
.brand-text small { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-meta { text-align: right; font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.topbar-meta b { color: var(--text-2); font-weight: 700; }

.icon-btn {
  width: 42px; height: 42px; border-radius: 999px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--border); color: var(--text); cursor: pointer;
}
.icon-btn:hover { border-color: var(--border-strong); }
.icon-btn svg { width: 19px; height: 19px; }

.menu-wrap { position: relative; }
.user-btn { padding: 5px 14px 5px 5px !important; }
.avatar { width: 32px; height: 32px; border-radius: 999px; background: var(--orange); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 14px; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 1200; min-width: 230px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 6px; display: flex; flex-direction: column;
}
.menu a, .menu button {
  text-align: left; padding: 10px 12px; border-radius: 8px; text-decoration: none; background: none; border: 0; cursor: pointer; font-weight: 500; font-size: 14px;
}
.menu a:hover, .menu button:hover { background: var(--surface-2); }
.menu .danger { color: var(--red); }

/* ---------- Tabs (como la referencia) ---------- */
.tabs {
  max-width: 1320px; margin: 4px auto 18px; padding: 0 28px;
  display: flex; overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 20px; border-radius: 999px; text-decoration: none;
  color: var(--text-2); font-weight: 600; font-size: 15px; white-space: nowrap;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { background: var(--orange); color: #fff; box-shadow: 0 6px 18px rgba(235, 103, 27, .35); }
.tabs a svg { width: 17px; height: 17px; }
.tabs a span, .bottom-nav span { display: inline-flex; }
.tabs-shell {
  display: inline-flex; gap: 4px; padding: 6px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
}

.bottom-nav { display: none; }

/* ---------- Tipografía de secciones ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 6px 0 16px; }
.page-head h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -.015em; }
.page-head p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.sec-title { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; margin: 30px 0 12px; }
.sec-title h2 { margin: 0; font-size: 18px; font-weight: 800; letter-spacing: -.01em; }
.sec-title span { color: var(--muted); font-size: 13px; }

/* ---------- Tarjetas ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 20px;
}
.card-pad-0 { padding: 0; overflow: hidden; }
.card h3 { margin: 0 0 12px; font-size: 15px; font-weight: 800; }

.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 16px; }
.kpi {
  position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 18px 20px 20px; text-decoration: none; display: block; min-width: 0;
}
a.kpi:hover { border-color: var(--border-strong); }
.kpi-label { font-size: 12.5px; font-weight: 700; color: var(--muted); padding-right: 40px; letter-spacing: .02em; line-height: 1.3; }
.kpi-value { font-size: 32px; font-weight: 800; letter-spacing: -.02em; margin: 6px 0 4px; line-height: 1.1; }
.kpi-sub { font-size: 13.5px; color: var(--text-2); }
.kpi-icon {
  position: absolute; top: 14px; right: 14px; width: 36px; height: 36px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}
.kpi-icon svg { width: 18px; height: 18px; }
.bar { height: 5px; border-radius: 999px; background: var(--surface-3); margin-top: 14px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: inherit; }

.tint-orange { background: rgba(235, 103, 27, .16); color: var(--orange); }
.tint-green { background: rgba(47, 191, 113, .15); color: var(--green); }
.tint-amber { background: rgba(240, 180, 41, .16); color: var(--amber); }
.tint-blue { background: rgba(108, 140, 255, .16); color: var(--blue); }
.tint-red { background: rgba(239, 91, 91, .15); color: var(--red); }
.tint-gray { background: rgba(138, 147, 168, .16); color: var(--gray); }
.fill-orange { background: var(--orange); } .fill-green { background: var(--green); } .fill-amber { background: var(--amber); }
.fill-blue { background: var(--blue); } .fill-red { background: var(--red); } .fill-gray { background: var(--gray); }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }

/* Barras por departamento */
.hbars { display: flex; flex-direction: column; gap: 12px; }
.hbar-row { display: grid; grid-template-columns: 150px 1fr 44px; gap: 12px; align-items: center; font-size: 14px; }
.hbar-row .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-2); }
.hbar-row .track { height: 10px; background: var(--surface-3); border-radius: 999px; overflow: hidden; display: flex; }
.hbar-row .track i { height: 100%; }
.hbar-row .num { text-align: right; font-weight: 700; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 16px; font-size: 12.5px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 999px; display: inline-block; flex: none; }

/* Listas */
.list { display: flex; flex-direction: column; }
.list-item {
  display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); text-decoration: none;
}
.list-item:first-child { border-top: 0; padding-top: 0; }
.list-item:hover .li-title { color: var(--orange); }
.li-icon { width: 34px; height: 34px; border-radius: 10px; flex: none; display: flex; align-items: center; justify-content: center; }
.li-icon svg { width: 17px; height: 17px; }
.li-body { min-width: 0; flex: 1; }
.li-title { display: block; font-weight: 700; font-size: 14.5px; }
.li-sub { display: block; color: var(--muted); font-size: 13px; }
.li-meta { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.empty { color: var(--muted); font-size: 14px; padding: 18px 0; text-align: center; }
.empty .btn { margin-top: 10px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  font-size: 12.5px; font-weight: 700; white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; }
.st-instalado { background: rgba(47, 191, 113, .15); color: var(--green); }
.st-mantenimiento { background: rgba(240, 180, 41, .16); color: #d99a0b; }
html[data-theme="dark"] .st-mantenimiento { color: var(--amber); }
.st-bodega { background: rgba(108, 140, 255, .16); color: var(--blue); }
.st-baja { background: rgba(138, 147, 168, .18); color: var(--gray); }
.badge-alert { background: rgba(239, 91, 91, .15); color: var(--red); }
.badge-soft { background: var(--surface-2); color: var(--text-2); }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  font-weight: 700; font-size: 14.5px; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
  min-height: 42px;
}
.btn:hover { border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 17px; height: 17px; flex: none; }
.btn-primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn-primary:hover { background: var(--orange-600); border-color: var(--orange-600); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--red); }
.btn-danger:hover { border-color: var(--red); }
.btn-sm { padding: 6px 12px; min-height: 34px; font-size: 13px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Filtros y buscador ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.search {
  position: relative; flex: 1 1 280px; min-width: 0;
}
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--muted); pointer-events: none; }
.search input { padding-left: 42px !important; }
.input, .select, textarea.input {
  width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; min-height: 44px; font-size: 15px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus { border-color: var(--orange); box-shadow: 0 0 0 3px var(--orange-soft); }
.select {
  appearance: none; -webkit-appearance: none; padding-right: 38px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a93a8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
.toolbar .select { width: auto; min-width: 150px; flex: 0 1 auto; }
textarea.input { min-height: 90px; resize: vertical; line-height: 1.45; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 13px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); font-size: 13.5px; font-weight: 600; cursor: pointer; color: var(--text-2);
}
.chip.on { border-color: var(--orange); color: var(--text); background: var(--orange-soft); }
.chip b { font-weight: 800; color: var(--text); }

/* ---------- Tabla de equipos ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th {
  text-align: left; font-weight: 700; font-size: 12.5px; color: var(--muted); padding: 12px 14px;
  border-bottom: 1px solid var(--border); white-space: nowrap; cursor: pointer; user-select: none;
}
.tbl th[data-sort]:hover { color: var(--text); }
.tbl th .arrow { opacity: .8; }
.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr { cursor: pointer; }
.tbl tbody tr:hover td { background: var(--surface-2); }
.tbl .code { font-weight: 800; white-space: nowrap; }
.tbl .sub { color: var(--muted); font-size: 12.5px; }
.thumb { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; background: var(--surface-3); display: block; flex: none; }
.thumb-ph { width: 44px; height: 44px; border-radius: 10px; background: var(--surface-2); display: flex; align-items: center; justify-content: center; color: var(--muted); flex: none; }
.thumb-ph svg { width: 20px; height: 20px; }
.cell-flex { display: flex; align-items: center; gap: 12px; min-width: 0; }

.cards-list { display: none; flex-direction: column; gap: 10px; }
.eq-card {
  display: flex; gap: 12px; padding: 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); text-decoration: none; align-items: center;
}
.eq-card .thumb, .eq-card .thumb-ph { width: 58px; height: 58px; }
.eq-card-body { flex: 1; min-width: 0; }
.eq-card-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.eq-card-title { font-weight: 800; font-size: 15px; }
.eq-card-sub { color: var(--text-2); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.eq-card-meta { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Mapa ---------- */
.map-layout { display: grid; grid-template-columns: 360px 1fr; gap: 16px; height: calc(100vh - 210px); min-height: 480px; }
.map-side { display: flex; flex-direction: column; min-height: 0; }
.map-side .card { display: flex; flex-direction: column; min-height: 0; flex: 1; padding: 16px; }
.map-list { overflow-y: auto; margin: 10px -16px -16px; padding: 0 16px 16px; flex: 1; -webkit-overflow-scrolling: touch; }
.map-list .list-item { cursor: pointer; }
.map-list .list-item.sel .li-title { color: var(--orange); }
.map-box { border-radius: var(--radius-lg); overflow: hidden; border: 1px solid var(--border); position: relative; min-height: 0; }
.map-box .leaflet-container, #bigMap { height: 100%; width: 100%; }
.map-count { font-size: 13px; color: var(--muted); margin-top: 10px; }
.map-float {
  position: absolute; z-index: 500; left: 12px; bottom: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px;
  font-size: 12.5px; display: flex; gap: 12px; flex-wrap: wrap; box-shadow: var(--shadow);
}
.map-float span { display: inline-flex; align-items: center; gap: 6px; }

.leaflet-container { font-family: var(--font); background: var(--surface-2); }
html[data-theme="dark"] .leaflet-bar a, html[data-theme="dark"] .leaflet-control-layers { background: var(--surface); color: var(--text); border-color: var(--border); }
html[data-theme="dark"] .leaflet-bar { border-color: var(--border) !important; }
html[data-theme="dark"] .leaflet-control-attribution { background: rgba(27, 33, 48, .8); color: var(--muted); }
html[data-theme="dark"] .leaflet-control-attribution a { color: var(--text-2); }
.leaflet-popup-content-wrapper { border-radius: 14px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.leaflet-popup-tip { background: var(--surface); }
.leaflet-popup-content { margin: 12px 14px; font-size: 13.5px; line-height: 1.45; min-width: 210px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.pop-img { width: 100%; height: 110px; object-fit: cover; border-radius: 10px; margin-bottom: 8px; background: var(--surface-2); display: block; }
.pop-title { font-weight: 800; font-size: 15px; }
.pop-sub { color: var(--muted); font-size: 12.5px; margin: 2px 0 8px; }
.pop-actions { display: flex; gap: 6px; margin-top: 10px; }
.pop-actions a { flex: 1; text-align: center; padding: 7px 10px; border-radius: 999px; font-weight: 700; font-size: 12.5px; text-decoration: none; border: 1px solid var(--border); color: var(--text) !important; }
.pop-actions a.primary { background: var(--orange); border-color: var(--orange); color: #fff !important; }

.pin { position: relative; width: 30px; height: 38px; }
.pin svg { width: 30px; height: 38px; filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .35)); }
.pin.has-alert::after {
  content: ''; position: absolute; top: -2px; right: -2px; width: 11px; height: 11px; border-radius: 999px;
  background: var(--red); border: 2px solid #fff;
}
.marker-cluster-custom {
  background: rgba(235, 103, 27, .25); border-radius: 999px; display: flex; align-items: center; justify-content: center;
}
.marker-cluster-custom div {
  width: 34px; height: 34px; border-radius: 999px; background: var(--orange); color: #fff; font-weight: 800; font-size: 13px;
  display: flex; align-items: center; justify-content: center; border: 2px solid #fff;
}

/* ---------- Ficha (detalle) ---------- */
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin: 4px 0 18px; }
.detail-title { display: flex; gap: 16px; align-items: center; min-width: 0; }
.detail-code {
  font-size: 30px; font-weight: 800; letter-spacing: -.02em; line-height: 1.05;
}
.detail-title .sub { color: var(--text-2); font-size: 15px; margin-top: 4px; }
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px; margin-bottom: 10px; }
.back:hover { color: var(--text); }
.back svg { width: 16px; height: 16px; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.detail-grid > div { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.dl { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px 18px; margin: 0; }
.dl div { min-width: 0; }
.dl dt { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.dl dd { margin: 2px 0 0; font-weight: 600; font-size: 14.5px; word-break: break-word; }
.dl dd.none { color: var(--muted); font-weight: 400; }
.dl .span-3 { grid-column: 1 / -1; }
.dl .span-2 { grid-column: span 2; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-head h3 { margin: 0; }
.mini-map { height: 240px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.coords { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 10px; font-size: 13.5px; color: var(--text-2); }
.coords a { color: var(--orange); font-weight: 700; text-decoration: none; }
.photo-big { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--radius); background: var(--surface-2); display: block; }
.photo-empty-box {
  width: 100%; aspect-ratio: 4 / 3; border-radius: var(--radius); background: var(--surface-2); border: 1px dashed var(--border-strong);
  display: flex; flex-direction: column; gap: 8px; align-items: center; justify-content: center; color: var(--muted); text-align: center; padding: 16px; font-size: 13.5px;
}
.photo-empty-box svg { width: 28px; height: 28px; }

.alerts { display: flex; flex-direction: column; gap: 8px; }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: var(--radius); font-size: 14px; }
.alert-danger { background: rgba(239, 91, 91, .12); color: var(--red); border: 1px solid rgba(239, 91, 91, .3); }
.alert-warn { background: rgba(240, 180, 41, .1); border: 1px solid rgba(240, 180, 41, .35); color: var(--text); }
.alert-warn svg { color: var(--amber); }
.alert svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.alert .grow { flex: 1; }

.timeline { position: relative; display: flex; flex-direction: column; }
.tl-item { position: relative; display: grid; grid-template-columns: 36px 1fr; gap: 12px; padding-bottom: 18px; }
.tl-item::before { content: ''; position: absolute; left: 17px; top: 36px; bottom: 0; width: 2px; background: var(--border); }
.tl-item:last-child::before { display: none; }
.tl-item:last-child { padding-bottom: 0; }
.tl-icon { width: 36px; height: 36px; border-radius: 11px; display: flex; align-items: center; justify-content: center; }
.tl-icon svg { width: 17px; height: 17px; }
.tl-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.tl-title { font-weight: 700; font-size: 14.5px; }
.tl-date { color: var(--muted); font-size: 12.5px; }
.tl-desc { color: var(--text-2); font-size: 13.5px; margin-top: 2px; }
.tl-meta { color: var(--muted); font-size: 12.5px; margin-top: 4px; display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.tl-meta a { color: var(--orange); font-weight: 700; text-decoration: none; }

/* ---------- Formularios ---------- */
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 700; color: var(--text-2); }
.field > span em { font-style: normal; color: var(--orange); }
.field input:not([type="checkbox"]):not([type="radio"]), .field select, .field textarea {
  width: 100%; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; min-height: 44px; font-size: 16px; outline: none; transition: border-color .15s, box-shadow .15s;
}
html[data-theme="light"] .field input:not([type="checkbox"]), html[data-theme="light"] .field select, html[data-theme="light"] .field textarea { background: #fff; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--orange); box-shadow: 0 0 0 3px var(--orange-soft); }
.field textarea { min-height: 84px; resize: vertical; line-height: 1.45; }
.field .hint { font-size: 12px; color: var(--muted); }
.span-2 { grid-column: span 2; }
.span-4 { grid-column: 1 / -1; }
.form-sec { margin-bottom: 16px; }
.form-sec > h3 { display: flex; align-items: center; gap: 10px; }
.step-n {
  width: 26px; height: 26px; border-radius: 999px; background: var(--orange-soft); color: var(--orange);
  display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 800; flex: none;
}
.form-actions {
  position: sticky; bottom: calc(var(--bn-h) + env(safe-area-inset-bottom)); z-index: 400;
  display: flex; justify-content: flex-end; gap: 10px; padding: 14px 0; margin-top: 4px;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

.geo-tools { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.picker-map { height: 320px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.geo-status { font-size: 13px; color: var(--muted); margin-top: 8px; min-height: 1.4em; }
.geo-status.ok { color: var(--green); }
.geo-status.err { color: var(--red); }

.photo-field { display: grid; grid-template-columns: 180px 1fr; gap: 16px; align-items: start; }
.photo-prev { width: 180px; aspect-ratio: 1; border-radius: var(--radius); object-fit: cover; background: var(--surface-2); border: 1px solid var(--border); }
.photo-prev-ph { width: 180px; aspect-ratio: 1; border-radius: var(--radius); border: 1px dashed var(--border-strong); background: var(--surface-2); display: flex; align-items: center; justify-content: center; color: var(--muted); }
.photo-prev-ph svg { width: 30px; height: 30px; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.seg { display: inline-flex; background: var(--bg-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px; gap: 2px; flex-wrap: wrap; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 7px 14px; border-radius: 999px; font-weight: 600; font-size: 13.5px; color: var(--text-2); }
.seg input:checked + span { background: var(--orange); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--orange); outline-offset: 1px; }

/* ---------- Modal ---------- */
.modal-root {
  position: fixed; inset: 0; z-index: 2000; background: rgba(8, 11, 18, .6);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
}
.modal {
  width: 100%; max-width: 760px; max-height: calc(100vh - 40px); overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  animation: pop .18s ease-out;
}
.modal.sm { max-width: 460px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 18px; font-weight: 800; }
.modal-head p { margin: 2px 0 0; color: var(--muted); font-size: 13.5px; }
.modal-body { padding: 20px 22px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); flex-wrap: wrap; }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }

.mov-types { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 18px; }
.mov-type { position: relative; }
.mov-type input { position: absolute; opacity: 0; pointer-events: none; }
.mov-type span {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--border);
  cursor: pointer; font-weight: 700; font-size: 14px; background: var(--bg-2); height: 100%;
}
.mov-type span svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.mov-type input:checked + span { border-color: var(--orange); background: var(--orange-soft); }
.mov-type input:checked + span svg { color: var(--orange); }
.mov-type input:disabled + span { opacity: .4; cursor: not-allowed; }
.mov-type input:focus-visible + span { outline: 2px solid var(--orange); outline-offset: 2px; }
.mov-note { font-size: 13.5px; color: var(--text-2); background: var(--bg-2); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px; border: 1px solid var(--border); }

/* ---------- Toasts ---------- */
.toasts { position: fixed; z-index: 3000; left: 50%; transform: translateX(-50%); bottom: calc(24px + var(--bn-h) + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; align-items: center; width: max-content; max-width: calc(100vw - 24px); }
.toast {
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 999px; font-weight: 600; font-size: 14px; box-shadow: var(--shadow);
  animation: pop .2s ease-out;
}
.toast.err { background: var(--red); color: #fff; }
.toast.ok { background: var(--green); color: #06170e; }

.loading { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 80px 0; color: var(--muted); }
.spinner { width: 20px; height: 20px; border-radius: 999px; border: 3px solid var(--surface-3); border-top-color: var(--orange); animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Login ---------- */
.login-body { min-height: 100vh; }
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.login-brand {
  background: var(--orange); color: #fff; display: flex; flex-direction: column; justify-content: flex-end; padding: 56px; position: relative; overflow: hidden;
}
.login-iso { position: absolute; width: 78%; max-width: 560px; right: -8%; top: 8%; filter: brightness(0) invert(1); opacity: .95; }
.login-brand-text { position: relative; font-size: 22px; font-weight: 700; line-height: 1.35; max-width: 420px; margin: 0; }
.login-card { align-self: center; justify-self: center; width: 100%; max-width: 400px; padding: 40px 28px; display: flex; flex-direction: column; gap: 16px; }
.login-logo { width: 170px; margin-bottom: 8px; }
.login-title { margin: 0; font-size: 28px; font-weight: 800; letter-spacing: -.02em; }
.login-sub { margin: -8px 0 6px; color: var(--muted); }
.login-card .field input { background: var(--surface) !important; }
.pass-wrap { position: relative; }
.pass-wrap input { padding-right: 46px !important; }
.pass-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; border: 0; background: none; color: var(--muted); cursor: pointer; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.theme-link { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 13px; text-decoration: underline; padding: 4px; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
  .grid-2, .detail-grid { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .map-layout { grid-template-columns: 1fr; height: auto; }
  .map-box { height: 62vh; min-height: 380px; order: -1; }
  .map-side .card { max-height: 420px; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar-meta { display: none; }
}
@media (max-width: 760px) {
  :root { --bn-h: 68px; }
  .view { padding: 4px 14px 32px; }
  .topbar { padding: calc(10px + env(safe-area-inset-top)) 14px 10px; }
  .brand-logo { height: 30px; }
  .brand-sep { height: 28px; }
  .brand-text strong { font-size: 16px; }
  .brand-text small { display: none; }
  .user-name { display: none; }
  .user-btn { padding: 4px !important; min-height: 0; border-radius: 999px; }
  .tabs { display: none; }
  .bottom-nav {
    display: flex; position: fixed; z-index: 1100; left: 0; right: 0; bottom: 0;
    height: calc(var(--bn-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--border);
  }
  .bottom-nav a, .bottom-nav button {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    text-decoration: none; color: var(--muted); background: none; border: 0; font-weight: 600; cursor: pointer; padding: 0;
  }
  .bottom-nav svg { width: 22px; height: 22px; }
  .bottom-nav small { font-size: 11px; }
  .bottom-nav a.active { color: var(--orange); }
  .bottom-nav .bn-add span {
    width: 44px; height: 44px; border-radius: 999px; background: var(--orange); color: #fff;
    display: flex; align-items: center; justify-content: center; margin-top: -18px; box-shadow: 0 6px 16px rgba(235, 103, 27, .45);
  }
  .bottom-nav .bn-add.active { color: var(--orange); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 14px 14px 16px; border-radius: 14px; }
  .kpi-value { font-size: 25px; }
  .kpi-label { font-size: 11.5px; padding-right: 30px; }
  .kpi-sub { font-size: 12.5px; }
  .kpi-icon { width: 30px; height: 30px; top: 10px; right: 10px; border-radius: 8px; }
  .kpi-icon svg { width: 15px; height: 15px; }
  .grid-3 { grid-template-columns: 1fr; }
  .card { padding: 16px; border-radius: 16px; }
  .hbar-row { grid-template-columns: 110px 1fr 34px; font-size: 13px; }
  .table-wrap.hide-mobile { display: none; }
  .cards-list { display: flex; }
  .toolbar .select { flex: 1 1 calc(50% - 5px); min-width: 0; }
  .dl { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dl .span-2 { grid-column: 1 / -1; }
  .form-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .form-grid .span-2 { grid-column: 1 / -1; }
  .photo-field { grid-template-columns: 1fr; }
  .photo-prev, .photo-prev-ph { width: 100%; aspect-ratio: 16 / 10; }
  .detail-code { font-size: 25px; }
  .detail-head .btn-row { width: 100%; }
  .detail-head .btn-row .btn { flex: 1; }
  .modal-root { padding: 0; align-items: flex-end; }
  .modal { max-width: none !important; border-radius: 20px 20px 0 0; max-height: 92vh; }
  .mov-types { grid-template-columns: 1fr 1fr; }
  .map-box { height: 58vh; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .page-head h1 { font-size: 20px; }
}
@media (max-width: 400px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .field { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Selects del formulario con flecha propia */
.field select {
  appearance: none; -webkit-appearance: none; padding-right: 36px !important; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a93a8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important; background-position: right 12px center !important;
}

/* Mapa de calles en modo oscuro (sin depender de otro proveedor) */
html[data-theme="dark"] .tiles-street { filter: invert(1) hue-rotate(180deg) brightness(.95) contrast(.88) saturate(.55); }

/* ============================================================
   Seguimiento y trazabilidad
   ============================================================ */
.card-sub { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.card-sub b { font-weight: 700; }
.badge-ok { background: rgba(47, 191, 113, .15); color: var(--green); }
.badge svg { flex: none; }

/* Tarjeta de evento */
.ev-list { padding: 4px 20px; }
.ev { display: grid; grid-template-columns: 38px minmax(0, 1fr); gap: 14px; padding: 16px 0; border-top: 1px solid var(--border); position: relative; }
.ev:first-child { border-top: 0; }
.ev-icon { width: 38px; height: 38px; border-radius: 12px; display: flex; align-items: center; justify-content: center; }
.ev-icon svg { width: 18px; height: 18px; }
.ev-body { min-width: 0; }
.ev-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.ev-title { font-weight: 800; font-size: 15px; }
.ev-code { color: var(--orange); text-decoration: none; margin-left: 4px; white-space: nowrap; }
.ev-code:hover { text-decoration: underline; }
.ev-rel { color: var(--text-2); font-weight: 600; font-size: 14px; }
.ev-date { color: var(--text-2); font-size: 13px; font-weight: 600; white-space: nowrap; }
.ev-route { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; margin-top: 6px; font-size: 13.5px; color: var(--text-2); }
.ev-route svg { width: 15px; height: 15px; color: var(--orange); flex: none; }
.ev-route .to { color: var(--text); font-weight: 700; }
.ev-comment { margin: 8px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); font-size: 14px; line-height: 1.5; white-space: pre-line; overflow-wrap: anywhere; }
.ev-desc { margin: 6px 0 0; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.ev-files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.ev-thumb { width: 72px; height: 72px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); padding: 0; cursor: zoom-in; display: flex; align-items: center; justify-content: center; }
.ev-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ev-thumb:hover { border-color: var(--orange); }
.ev-pdf { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 800; color: var(--red); }
.ev-pdf svg { width: 24px; height: 24px; }
.ev-who { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 10px; font-size: 13px; color: var(--text-2); }
.ev-who b { color: var(--muted); font-weight: 600; }
.ev-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-top: 10px; }
.ev-reg { color: var(--muted); font-size: 12px; flex: 1 1 200px; }
.ev-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-left: auto; }
.ev-link {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px; border: 0; background: none;
  color: var(--text-2); font-weight: 700; font-size: 13px; text-decoration: none; cursor: pointer; min-height: 34px;
}
.ev-link svg { width: 15px; height: 15px; }
.ev-link:hover { background: var(--surface-2); color: var(--text); }
.ev-link.strong { background: var(--orange); color: #fff; }
.ev-link.strong:hover { background: var(--orange-600); color: #fff; }

/* Línea de tiempo dentro de la ficha */
.timeline-ev .ev { border-top: 0; padding: 0 0 22px; }
.timeline-ev .ev::before { content: ''; position: absolute; left: 18px; top: 42px; bottom: 4px; width: 2px; background: var(--border); }
.timeline-ev .ev:last-child { padding-bottom: 0; }
.timeline-ev .ev:last-child::before { display: none; }

/* Zona de carga */
.dz { border: 1.5px dashed var(--border-strong); border-radius: var(--radius); padding: 14px; background: var(--bg-2); }
html[data-theme="light"] .dz { background: var(--surface-2); }
.dz.has-files { border-style: solid; border-color: var(--orange); }
.dz-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.dz-grid:not(:empty) { margin-bottom: 12px; }
.dz-item { position: relative; width: 88px; height: 88px; border-radius: 10px; overflow: hidden; background: var(--surface); border: 1px solid var(--border); }
.dz-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dz-pdf { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; gap: 4px; padding: 6px; color: var(--red); text-align: center; }
.dz-pdf svg { width: 26px; height: 26px; }
.dz-pdf small { color: var(--text-2); font-size: 10.5px; line-height: 1.2; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-all; }
.dz-busy { display: flex; align-items: center; justify-content: center; }
.dz-del { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 999px; border: 0; background: rgba(10, 13, 20, .72); color: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.dz-del svg { width: 14px; height: 14px; }
.dz-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.dz .hint { display: block; margin-top: 10px; color: var(--muted); font-size: 12.5px; }
.mv-sec { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 22px 0 12px; font-size: 15px; font-weight: 800; }
.mv-req { font-size: 12px; font-weight: 700; color: var(--muted); background: var(--surface-2); padding: 3px 10px; border-radius: 999px; }
.mv-req.on { color: var(--orange); background: var(--orange-soft); }
#mvWarn { margin-top: 12px; }
.alert-ok { background: rgba(47, 191, 113, .12); border: 1px solid rgba(47, 191, 113, .35); color: var(--text); }
.alert-ok svg { color: var(--green); }

/* Visor de imágenes */
.lb { position: fixed; inset: 0; z-index: 2500; background: rgba(6, 8, 13, .94); display: flex; flex-direction: column; color: #fff; }
.lb-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; }
.lb-name { font-size: 14px; font-weight: 600; opacity: .9; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.lb-actions { display: flex; gap: 6px; flex: none; }
.lb-btn { width: 42px; height: 42px; border-radius: 999px; border: 1px solid rgba(255, 255, 255, .18); background: rgba(255, 255, 255, .06); color: #fff; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; text-decoration: none; }
.lb-btn:hover { background: rgba(255, 255, 255, .14); }
.lb-btn svg { width: 18px; height: 18px; }
.lb-ask { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 10px; padding: 10px; background: rgba(239, 91, 91, .18); font-size: 14px; }
.lb-ask .btn { background: rgba(255, 255, 255, .1); color: #fff; border-color: rgba(255, 255, 255, .2); }
.lb-ask .btn-danger { background: var(--red); border-color: var(--red); }
.lb-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; position: relative; padding: 0 12px; }
.lb-stage img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; background: #fff; }
.lb-pdf { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; }
.lb-pdf svg { width: 64px; height: 64px; color: var(--red); }
.lb-pdf p { margin: 0; max-width: 320px; word-break: break-word; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 46px; height: 46px; border-radius: 999px; border: 0; background: rgba(0, 0, 0, .5); color: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.lb-nav svg { width: 22px; height: 22px; }
.lb-nav.prev { left: 12px; }
.lb-nav.next { right: 12px; }
.lb-foot { text-align: center; font-size: 12.5px; opacity: .7; padding: 10px 14px calc(12px + env(safe-area-inset-bottom)); }

/* Vista Seguimiento */
.seg-filters { display: grid; grid-template-columns: minmax(220px, 1.6fr) repeat(3, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.seg-filters .search { flex: none; }
.seg-range { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; }
.seg-range[hidden] { display: none; }
.seg-range .input { max-width: 200px; }
.seg-range span { color: var(--muted); font-size: 14px; }
.seg-chips { margin-bottom: 14px; }
.chip svg { flex: none; }
.chip-check { cursor: pointer; }
.chip-check input { accent-color: var(--orange); margin: 0; }
.seg-sum { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13.5px; color: var(--muted); margin-bottom: 4px; }
.seg-sum b { color: var(--text); font-weight: 800; }
.seg-sum .warn b, .seg-sum .warn { color: var(--red); }
.day-head { font-size: 14px; font-weight: 800; color: var(--text-2); margin: 22px 0 8px; }
.seg-more { display: flex; justify-content: center; margin-top: 18px; }

@media (max-width: 980px) {
  .seg-filters { grid-template-columns: 1fr 1fr; }
  .seg-filters .search, .seg-filters #sgEnc { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  .ev-list { padding: 2px 14px; }
  .ev { grid-template-columns: 32px minmax(0, 1fr); gap: 10px; }
  .ev-icon { width: 32px; height: 32px; border-radius: 10px; }
  .ev-icon svg { width: 16px; height: 16px; }
  .timeline-ev .ev::before { left: 15px; top: 36px; }
  .ev-thumb { width: 64px; height: 64px; }
  .ev-actions { margin-left: 0; width: 100%; }
  .ev-actions { gap: 6px; }
  .ev-actions .ev-link { flex: 1 1 auto; justify-content: center; background: var(--surface-2); white-space: nowrap; padding: 6px 8px; font-size: 12.5px; }
  .ev-actions .ev-link svg { width: 14px; height: 14px; }
  .ev-actions .ev-link.strong { background: var(--orange); }
  .seg-range .input { max-width: none; flex: 1; min-width: 0; }
  .dz-actions .btn { flex: 1 1 auto; }
  .lb-btn { width: 38px; height: 38px; }
}
