/* Estilos de la aplicación. Los tokens (colores, tipografía, tarjetas) vienen de /styles/tokens.css */
html { scroll-behavior: smooth; }
.app { display: flex; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; flex: none; overflow-y: auto; }
.brand { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 20px; }
.brand-name { display: flex; align-items: center; gap: 12px; color: #fff; font-weight: 700; font-size: 19px; letter-spacing: -0.025em; }
.brand-mark { width: 36px; height: 36px; flex: none; display: grid; place-items: center; }
.brand-mark svg { display: block; }
.brand-t { color: var(--brand-blue); }
.sidebar nav { flex: 1; }
.side-foot { padding-top: 16px; font-size: 12px; color: var(--navy-muted); }
main { flex: 1; min-width: 0; }
.page-header { position: sticky; top: 0; z-index: 500; }
.head-tools { display: flex; align-items: center; gap: 14px; }
.head-tools .input { width: 220px; height: 42px; }
.search { width: 300px; }
.search input { border: 0; background: none; outline: 0; font: inherit; color: var(--text); flex: 1; min-width: 0; }
.clock { margin-left: 6px; }
.mnav { display: none; }

button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
select.input { padding-right: 12px; }

.view { padding: 28px 40px 48px; display: grid; gap: var(--gap); }
.view.flush { padding: 0; display: block; }
.row2 { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: var(--gap); align-items: start; }
.col { display: grid; gap: var(--gap); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 24px; flex-wrap: wrap; }
.card-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.card-head .meta { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); }
.stat .kpi { font-size: 30px; }
.ok { color: var(--ok); } .warn { color: var(--warn); } .bad { color: var(--danger); }
.muted { color: var(--text-muted); } .faint { color: var(--text-faint); }
.mono { font-family: var(--font-mono); }

/* Botones */
.btn { height: 40px; padding: 0 18px; border: 0; border-radius: var(--radius); background: var(--accent); color: #fff; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { filter: brightness(.94); }
.btn.sm { height: 34px; padding: 0 14px; font-size: 13px; }
.btn.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); }
.btn.ghost:hover { background: var(--surface-muted); filter: none; }
.btn.danger { background: var(--danger-soft); color: var(--danger-strong); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.link { background: none; border: 0; padding: 0; color: var(--text-muted); font: inherit; font-size: 13px; text-decoration: underline; cursor: pointer; }

/* Tablas */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-family: var(--font-mono); font-size: 11px; font-weight: 500; letter-spacing: var(--label-tracking); text-transform: uppercase; color: var(--text-muted); background: var(--surface-muted); padding: 11px 16px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl th:first-child, .tbl td:first-child { padding-left: 24px; }
.tbl th:last-child, .tbl td:last-child { padding-right: 24px; }
.tbl td { padding: 14px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr.click { cursor: pointer; }
.tbl tbody tr.click:hover { background: var(--surface-muted); }
.tbl .num { font-family: var(--font-mono); font-weight: 600; letter-spacing: .02em; }
.tbl .sub { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }
.tbl td.right, .tbl th.right { text-align: right; }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; padding: 2px 10px; border-radius: 99px; border: 1px solid var(--border); color: var(--text-muted); background: var(--surface-muted); white-space: nowrap; }
.pill.ok { color: var(--ok); background: var(--ok-soft); border-color: #bbf7d0; }
.pill.warn { color: var(--warn); background: var(--warn-soft); border-color: #fde68a; }
.pill.bad { color: var(--danger-strong); background: var(--danger-soft); border-color: #fecaca; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-size: 12px; padding: 3px 4px 3px 10px; border-radius: 99px; background: var(--accent-soft); color: #1e40af; margin: 2px 6px 2px 0; }
.chip.ro { padding-right: 10px; }
.chip button { border: 0; background: none; color: inherit; cursor: pointer; font-size: 15px; line-height: 1; padding: 0 6px; border-radius: 99px; }
.chip button:hover { background: rgba(37, 99, 235, .18); }

/* Formularios */
.form-row { display: flex; gap: 10px; padding: 0 24px 6px; flex-wrap: wrap; }
.form-row .input { flex: 1; min-width: 150px; }
.hint { padding: 8px 24px 18px; font-size: 13px; min-height: 35px; color: var(--text-muted); }
.field { display: grid; gap: 6px; }
.field .label { margin: 0; }

/* Barras */
.bars { display: grid; gap: 14px; padding: 4px 24px 24px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 130px) 1fr 28px; gap: 12px; align-items: center; font-size: 13.5px; }
.bar-row span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 8px; border-radius: 99px; background: var(--neutral-soft); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; background: var(--accent); }
.bar-row b { text-align: right; font-weight: 600; }

/* Indicadores */
.metrics { display: grid; gap: 0; }
.metric { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 24px; border-top: 1px solid var(--border); font-size: 13.5px; }
.metric:first-child { border-top: 1px solid var(--border); }
.metric span { color: var(--text-muted); }
.metric b { font-weight: 600; text-align: right; }

.empty { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty strong { display: block; color: var(--text); font-weight: 600; margin: 14px 0 6px; }

/* Mapa */
.map-view { position: relative; height: calc(100vh - var(--header-h)); }
#map { position: absolute; inset: 0; background: var(--surface-muted); }
.map-panel { position: absolute; top: 16px; left: 16px; width: 330px; max-height: calc(100% - 32px); display: flex; flex-direction: column; z-index: 5; overflow: hidden; }
.map-panel .card-head { padding: 16px 18px 12px; }
.map-list { overflow-y: auto; }
.map-item { display: flex; gap: 12px; padding: 12px 18px; border-top: 1px solid var(--border); cursor: pointer; align-items: flex-start; }
.map-item:hover { background: var(--surface-muted); }
.map-item .swatch { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; flex: none; }
.map-item b { font-family: var(--font-mono); font-size: 13px; }
.map-item .sub { color: var(--text-muted); font-size: 12.5px; }
.map-msg { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: var(--text-muted); padding: 24px; }
.mapboxgl-popup-content { font-family: var(--font-sans); border-radius: var(--radius); padding: 14px 16px; font-size: 13px; line-height: 1.5; box-shadow: 0 6px 24px rgba(15, 23, 42, .18); }
.mapboxgl-popup-content b { font-family: var(--font-mono); }
.mapboxgl-popup-close-button { font-size: 18px; padding: 2px 8px; }

/* Panel lateral de detalle */
.drawer-bg { position: fixed; inset: 0; background: rgba(10, 18, 38, .35); opacity: 0; pointer-events: none; transition: opacity .15s; z-index: 900; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100vw); background: var(--surface); box-shadow: -12px 0 40px rgba(15, 23, 42, .18); transform: translateX(100%); transition: transform .18s; z-index: 910; overflow-y: auto; }
body.drawer-open .drawer-bg { opacity: 1; pointer-events: auto; }
body.drawer-open .drawer { transform: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 24px 28px 18px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin: 0; font-family: var(--font-mono); font-size: 20px; letter-spacing: .02em; }
.drawer-body { padding: 22px 28px 40px; display: grid; gap: 22px; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 20px; }
.facts .label { margin-bottom: 4px; }
.facts .v { font-weight: 600; }
.facts .sub { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }
.x { border: 0; background: var(--neutral-soft); width: 34px; height: 34px; border-radius: 50%; font-size: 18px; cursor: pointer; color: var(--text-muted); }
ol.tl { list-style: none; margin: 12px 0 0 6px; padding: 0 0 0 4px; border-left: 2px solid var(--border); }
ol.tl li { position: relative; padding: 0 0 14px 18px; }
ol.tl li::before { content: ""; position: absolute; left: -7px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
ol.tl .when { color: var(--text-muted); font-size: 12.5px; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px); background: var(--navy-950); color: #fff; padding: 12px 20px; border-radius: var(--radius); font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 2000; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger-strong); }

@media (max-width: 1180px) { .row2 { grid-template-columns: 1fr; } .stat-grid { grid-template-columns: repeat(3, 1fr); } .search { width: 220px; } }
@media (max-width: 900px) {
  .sidebar, .clock { display: none; }
  .page-header { padding: 0 16px; } .view { padding: 20px 16px 40px; }
  .head-tools .input { width: 140px; } .search { display: none; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .mnav { display: flex; gap: 4px; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border); overflow-x: auto; }
  .mnav a { padding: 8px 14px; border-radius: 99px; color: var(--text-muted); text-decoration: none; font-weight: 500; font-size: 14px; white-space: nowrap; }
  .mnav a.active { background: var(--navy-950); color: #fff; }
  .map-view { height: calc(100vh - var(--header-h) - 53px); }
  .map-panel { width: calc(100% - 32px); max-height: 38%; }
  .facts { grid-template-columns: 1fr; }
}

/* ---------- Contenedores: fila desplegable ---------- */
.tbl .chev { width: 18px; padding-right: 0; color: var(--text-faint); font-size: 12px; }
.tbl tbody tr.sel { background: var(--accent-soft); }
.tbl tbody tr.sel .chev { color: var(--accent); }
.tbl tbody tr.detail-row, .tbl tbody tr.detail-row:hover { background: var(--surface-muted); cursor: default; }
.tbl tbody tr.detail-row > td { padding: 0 !important; border-bottom: 1px solid var(--border); }
.detail { padding: 20px 24px 28px; display: grid; gap: 22px; animation: fade .2s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.detail-title { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.detail-title b { font-size: 17px; letter-spacing: .02em; }
.detail-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.detail-top { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 20px; align-items: stretch; }
.detail-map { position: relative; min-height: 440px; border-radius: var(--radius-lg); overflow: hidden; border: 1px solid var(--border); background: var(--surface); }
.detail-map #dmap { position: absolute; inset: 0; }
.map-legend { position: absolute; left: 12px; bottom: 12px; display: flex; gap: 6px 14px; flex-wrap: wrap; background: rgba(255,255,255,.94); padding: 8px 12px; border-radius: 8px; font-size: 12px; box-shadow: var(--shadow-card); max-width: calc(100% - 24px); z-index: 2; }
.map-legend:empty { display: none; }
.map-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.sec-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.sec-head .meta { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); }

/* ---------- Línea de tiempo ---------- */
.tl-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px 20px 8px; display: flex; flex-direction: column; min-height: 0; max-height: 440px; }
.tl-scroll { overflow-y: auto; margin: 0 -8px; padding: 0 8px 8px; }
.tline { list-style: none; margin: 0; padding: 0; }
.tl-item { display: grid; grid-template-columns: 62px 26px minmax(0, 1fr); gap: 0 10px; animation: tl-in .35s ease-out both; animation-delay: calc(var(--i) * 50ms); }
@keyframes tl-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.tl-when { text-align: right; padding-top: 1px; line-height: 1.25; }
.tl-when b { display: block; font-size: 13px; font-weight: 600; text-transform: capitalize; }
.tl-when span { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-muted); }
.tl-rail { position: relative; }
.tl-rail::before { content: ""; position: absolute; left: 12px; top: 0; bottom: 0; width: 2px; background: var(--accent); border-radius: 2px; }
.tl-item:first-child .tl-rail::before { top: 12px; }
.tl-item:last-child .tl-rail::before { bottom: auto; height: 12px; }
.tl-item:first-child:last-child .tl-rail::before { display: none; }
.tl-item.current .tl-rail::before { bottom: auto; height: 12px; }
.tl-item.current.has-next .tl-rail::after { content: ""; position: absolute; left: 11px; top: 12px; bottom: 0; border-left: 2px dashed var(--border-strong); }
.tl-item.pending .tl-rail::before { background: none; width: 0; left: 11px; border-left: 2px dashed var(--border-strong); border-radius: 0; bottom: auto; height: 12px; }
.tl-dot { position: absolute; left: 6px; top: 6px; width: 14px; height: 14px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tl-item.current .tl-dot { left: 4px; top: 4px; width: 18px; height: 18px; border: 4px solid #fff; box-shadow: 0 0 0 2px var(--accent); animation: ring 2s ease-out infinite; }
.tl-item.delivered .tl-dot { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); animation: none; }
.tl-item.current.delivered .tl-dot { box-shadow: 0 0 0 2px var(--ok); }
.tl-item.pending .tl-dot { background: var(--surface); border: 2px dashed var(--text-faint); box-shadow: none; }
@keyframes ring { 0% { box-shadow: 0 0 0 2px var(--accent), 0 0 0 2px rgba(37,99,235,.45); } 70% { box-shadow: 0 0 0 2px var(--accent), 0 0 0 11px rgba(37,99,235,0); } 100% { box-shadow: 0 0 0 2px var(--accent), 0 0 0 11px rgba(37,99,235,0); } }
.tl-body { padding: 0 0 20px; min-width: 0; }
.tl-item:last-child .tl-body { padding-bottom: 8px; }
.tl-title { font-weight: 600; font-size: 14px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tl-item.pending .tl-title { color: var(--text-muted); }
.tl-sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.tl-raw { font-size: 11.5px; color: var(--text-faint); margin-top: 3px; overflow-wrap: anywhere; }
.tl-gap { font-size: 11.5px; color: var(--text-faint); margin-top: 3px; font-family: var(--font-mono); }
.drawer .tl-panel { border: 0; padding: 0; max-height: none; }
.drawer .tl-item { grid-template-columns: 52px 26px minmax(0, 1fr); }

/* ---------- Lecturas del datalogger ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 18px; border-left-width: 4px; border-left-color: var(--border); }
.tile.ok { border-left-color: var(--ok); } .tile.warn { border-left-color: var(--warn); } .tile.bad { border-left-color: var(--danger); }
.tile .label { margin-bottom: 8px; }
.tile-v { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; line-height: 1; }
.tile-v small { font-size: 14px; font-weight: 500; color: var(--text-muted); margin-left: 3px; letter-spacing: 0; }
.tile-sub { margin-top: 8px; font-size: 12.5px; color: var(--text-muted); }
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 18px 10px; min-width: 0; }
.chart-card.wide { grid-column: 1 / -1; }
.chart-card h4 { margin: 0; font-size: 14px; font-weight: 600; }
.chart-card p { margin: 3px 0 10px; font-size: 12.5px; color: var(--text-muted); }
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--text-muted); font-size: 11px; font-family: var(--font-sans); }
.chart .band { fill: var(--ok); opacity: .1; }
.chart .oor { fill: var(--danger); stroke: #fff; stroke-width: 1.5; }
.chart .thr { stroke: var(--danger); stroke-width: 1.2; stroke-dasharray: 4 4; opacity: .7; }
.chart .guide { stroke: var(--text-faint); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .hdot { fill: #fff; stroke: var(--text); stroke-width: 2; }
.chart .tip { position: absolute; top: 0; transform: translateX(-50%); background: var(--navy-950); color: #fff; padding: 6px 10px; border-radius: 8px; font-size: 12px; pointer-events: none; display: grid; gap: 1px; white-space: nowrap; z-index: 5; }
.chart .tip[hidden] { display: none; }
.chart .tip span { color: var(--navy-text); font-size: 11px; }
.chart-empty { padding: 36px 12px; text-align: center; color: var(--text-faint); font-size: 13px; background: var(--surface-muted); border-radius: var(--radius); }

@media (max-width: 1180px) { .detail-top { grid-template-columns: 1fr; } .detail-map { min-height: 340px; } .tl-panel { max-height: 380px; } }
@media (max-width: 760px) { .charts { grid-template-columns: 1fr; } .detail { padding: 16px 12px 22px; } }
@media (prefers-reduced-motion: reduce) { .tl-item, .detail { animation: none; } .tl-item.current .tl-dot { animation: none; } }
.tl-scroll { position: relative; }

/* ---------- Lista de dataloggers ---------- */
.logger-list { margin-top: 14px; border-top: 1px solid var(--border); }
.logger-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--border); }
.logger-item:last-child { border-bottom: 0; }
.logger-main { min-width: 0; }
.logger-name { font-family: var(--font-mono); font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.logger-main .sub { color: var(--text-muted); font-size: 12.5px; margin-top: 3px; overflow-wrap: anywhere; }
.logger-side { display: flex; align-items: center; gap: 12px; flex: none; }

/* Cabecera en pantallas medianas */
.page-header h1 { white-space: nowrap; }
@media (max-width: 1180px) { .search { width: 190px; } .clock span { display: none; } .head-tools { gap: 10px; } }

/* ---------- Ingreso ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(340px, 5fr) 7fr; background: var(--surface); }
.auth[hidden], .app[hidden], .banner[hidden], .notice[hidden] { display: none; }
.auth-side { background: var(--navy-950); color: #fff; padding: 40px 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; isolation: isolate; }
/* Video de fondo del ingreso: tratado en tonos oscuros para que el texto se lea y el azul eléctrico no cubra la superficie (manual de marca) */
.auth-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: -2; filter: saturate(.55) contrast(1.05); }
.auth-shade { position: absolute; inset: 0; z-index: -1; background: linear-gradient(180deg, rgba(10,18,38,.9) 0%, rgba(10,18,38,.74) 38%, rgba(10,18,38,.8) 62%, rgba(10,18,38,.94) 100%); }
.brand-name.big { display: flex; align-items: center; gap: 16px; font-size: 34px; font-weight: 700; color: #fff; letter-spacing: -0.03em; }
.brand-name.big .brand-mark { width: 56px; height: 56px; }
.brand-lockup { display: grid; gap: 6px; }
.brand-desc { margin-left: 72px; font-size: 13.5px; letter-spacing: .06em; color: var(--brand-steel); }
.auth-claim h2 { font-size: 40px; line-height: 1.1; letter-spacing: -0.03em; margin: 0 0 18px; font-weight: 600; }
.auth-claim p { color: var(--navy-text); max-width: 380px; line-height: 1.6; margin: 0; }
.auth-foot { font-size: 11px; letter-spacing: .14em; color: var(--navy-muted); }
.auth-main { display: grid; place-items: center; padding: 32px 24px; background: var(--bg); }
.auth-card { width: min(420px, 100%); display: grid; gap: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 36px 34px; box-shadow: var(--shadow-card); }
.auth-card h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; }
.auth-card p { margin: -8px 0 4px; font-size: 14px; }
.auth-card .btn { height: 44px; }
.auth-err { color: var(--danger-strong); font-size: 13.5px; min-height: 18px; }
.auth-msg { background: var(--warn-soft); color: #92400e; padding: 10px 12px; border-radius: var(--radius); font-size: 13.5px; }
@media (max-width: 860px) { .auth { grid-template-columns: 1fr; } .auth-side { display: none; } }

/* ---------- Banner de soporte, aviso de suscripción ---------- */
.banner { position: sticky; top: 0; z-index: 1000; padding: 0 24px; font-size: 14px; }
.banner[hidden] { display: none; }
.link-light { background: none; border: 0; color: #fff; font: inherit; text-decoration: underline; cursor: pointer; }
body.support .sidebar { top: var(--banner-h); height: calc(100vh - var(--banner-h)); }
body.support .page-header { top: var(--banner-h); }
body.support .map-view { height: calc(100vh - var(--header-h) - var(--banner-h)); }
body.support .drawer { top: var(--banner-h); }
.notice { padding: 10px 40px; font-size: 14px; font-weight: 500; }
.notice.warn { background: var(--warn-soft); color: #92400e; }
.notice.bad { background: var(--danger-soft); color: var(--danger-strong); }
body.no-filters .client-only { display: none; }

/* ---------- Usuario en el menú lateral ---------- */
.side-user { border-top: 1px solid var(--navy-700); padding-top: 14px; display: grid; gap: 10px; }
.side-user-row { display: flex; align-items: center; gap: 12px; }
.side-user-txt { display: grid; min-width: 0; }
.side-user-txt b { color: #fff; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user-txt small { color: var(--navy-muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user-actions { display: flex; gap: 8px; }
.side-btn { flex: 1; height: 32px; border: 1px solid var(--navy-700); background: var(--navy-900); color: var(--navy-text); border-radius: 8px; font: inherit; font-size: 12.5px; cursor: pointer; }
.side-btn:hover { background: var(--navy-800); color: #fff; }
.side-sync { font-size: 11px; color: var(--navy-muted); }

/* ---------- Modales ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 18, 38, .5); display: grid; place-items: center; z-index: 1500; padding: 16px; }
.modal { background: var(--surface); border-radius: var(--radius-lg); width: min(480px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 24px 60px rgba(15, 23, 42, .35); }
.modal.wide { width: min(720px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 24px 6px; }
.modal-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
.modal-intro { margin: 0; padding: 4px 24px 0; font-size: 13.5px; }
.modal-body { padding: 16px 24px 8px; display: grid; gap: 16px; }
.modal-body small { font-size: 12px; }
.modal-err { color: var(--danger-strong); font-size: 13.5px; padding: 0 24px; min-height: 8px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 24px 22px; }
.modal textarea.input { height: auto; padding: 10px 14px; font: inherit; resize: vertical; }
.secret { display: flex; align-items: center; gap: 10px; background: var(--surface-muted); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.secret code { flex: 1; font-family: var(--font-mono); font-size: 15px; overflow-wrap: anywhere; user-select: all; }

/* ---------- Panel de APIs ---------- */
.api-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--gap); }
.api-card { padding: 20px 22px; }
.api-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.api-top b { font-size: 15px; }
.api-top .sub { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }
.api-use { margin-top: 14px; font-family: var(--font-mono); font-size: 13px; }
.api-err { margin-top: 10px; font-size: 12.5px; color: var(--danger-strong); background: var(--danger-soft); padding: 8px 10px; border-radius: 8px; }
.api-card .sub { color: var(--text-muted); font-size: 12.5px; }

/* ---------- Nuevo embarque, listas de selección, alertas ---------- */
.side-new { width: 100%; margin: 14px 0 4px; height: 42px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.side-new[hidden] { display: none; }
.nav-badge { margin-left: auto; background: var(--danger); color: #fff; font-size: 11px; font-weight: 600; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px; display: inline-grid; place-items: center; }
.nav-badge[hidden] { display: none; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.checks { display: grid; gap: 6px; max-height: 210px; overflow-y: auto; padding: 4px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-muted); }
.check { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); cursor: pointer; }
.check:hover { border-color: var(--accent); }
.check input { width: 17px; height: 17px; accent-color: var(--accent); flex: none; }
.check span { display: grid; min-width: 0; }
.check b { font-family: var(--font-mono); font-size: 13px; font-weight: 600; }
.check small { color: var(--text-muted); font-size: 12px; }
.sec-head .meta.ok { color: var(--ok); } .sec-head .meta.bad { color: var(--danger); }
.modal small.ok { color: var(--ok); } .modal small.bad { color: var(--danger); }
a.card.stat:hover { border-color: var(--accent); }

/* ---------- Inventario (superadmin) ---------- */
.inv-bar { display: flex; gap: 10px; padding: 0 24px 16px; flex-wrap: wrap; align-items: center; }
.inv-bar .input { height: 36px; width: 190px; }
.inv-bar #i-q { flex: 1; min-width: 200px; }
.inv-sel { display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: var(--accent-soft); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.inv-sel[hidden] { display: none; }
.tbl input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }

/* ---------- Menú lateral: la navegación hace scroll y lo demás queda fijo (en ventanas bajas nada se aplasta) ---------- */
.sidebar { overflow: hidden; }
.sidebar > * { flex: none; }
.sidebar nav { flex: 1 1 0; min-height: 0; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--navy-700) transparent; margin-right: -6px; padding-right: 6px; }
.side-user { margin-top: 10px; }

/* Botón «Nuevo embarque» */
.side-new { width: 100%; height: 46px; margin: 14px 0 4px; padding: 0 14px 0 10px; display: flex; align-items: center; gap: 12px; flex: none;
  background: var(--navy-800); color: #fff; border: 1px solid var(--navy-700); border-radius: var(--radius); font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; transition: background .15s, border-color .15s; }
.side-new[hidden] { display: none; }
.side-new .plus { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; flex: none; }
.side-new:hover { background: #22304f; border-color: var(--accent); }
.side-new:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Selector con búsqueda ---------- */
.picker { display: grid; gap: 8px; }
.picker-sel { display: flex; flex-wrap: wrap; gap: 4px 6px; max-height: 118px; overflow-y: auto; }
.picker-sel:empty { display: none; }
.picker-sel .chip { margin: 0; }
.picker-box { position: relative; }
.picker-menu { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 40; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: 0 12px 32px rgba(15, 23, 42, .18); max-height: 280px; overflow-y: auto; }
.picker-menu[hidden] { display: none; }
.picker-item { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; padding: 9px 14px; cursor: pointer; }
.picker-item.on, .picker-item:hover { background: var(--accent-soft); }
.picker-item b { font-family: var(--font-mono); font-size: 13px; font-weight: 600; }
.picker-item small { color: var(--text-muted); font-size: 12px; text-align: right; }
.picker-all { width: 100%; text-align: left; padding: 10px 14px; border: 0; border-bottom: 1px solid var(--border); background: var(--surface-muted); color: var(--accent); font: inherit; font-weight: 600; font-size: 13px; cursor: pointer; }
.picker-all:hover { background: var(--accent-soft); }
.picker-more, .picker-empty { padding: 10px 14px; font-size: 12.5px; color: var(--text-muted); }
.picker-empty:empty { display: none; }
.picker-foot { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; }
.picker-paste[hidden] { display: none; }
.modal-body { overflow: visible; }

/* ---------- Detalle de alerta ---------- */
.modal.xl { width: min(1000px, 100%); }
.modal.xl .modal-body { padding-top: 12px; }
.alert-lead { font-size: 16px; line-height: 1.55; padding: 16px 18px; background: var(--surface-muted); border: 1px solid var(--border); border-left: 4px solid var(--danger); border-radius: var(--radius); }
.facts4 { grid-template-columns: repeat(4, 1fr); }
.alert-cols { display: grid; grid-template-columns: 1fr 1.3fr; gap: 20px; align-items: start; }
.alert-map { width: 100%; height: auto; border-radius: var(--radius); border: 1px solid var(--border); display: block; }
.related { display: flex; flex-wrap: wrap; gap: 8px; }
.chip.rel { padding: 5px 12px; border: 0; cursor: pointer; font-family: var(--font-sans); background: var(--accent-soft); color: #1e40af; }
.chip.rel:hover { background: #c7dbff; }
.chart .mark { fill: var(--danger); opacity: .1; }
.tbl .more { color: var(--accent); font-size: 13px; font-weight: 500; white-space: nowrap; }
.tbl tbody tr.click:hover .more { text-decoration: underline; }
@media (max-width: 860px) { .facts4 { grid-template-columns: 1fr 1fr; } .alert-cols { grid-template-columns: 1fr; } }

.picker-q, .picker-paste textarea { width: 100%; }

/* ======================= Menú lateral colapsable ======================= */
.sidebar { transition: width .24s cubic-bezier(.4, 0, .2, 1), padding .24s ease; }
.nav-item { position: relative; white-space: nowrap; transition: background .15s, color .15s; }
.nav-item svg { flex: none; }
.brand { gap: 8px; }
.brand-name { min-width: 0; white-space: nowrap; }
.chip-dark { margin-left: auto; }
.side-toggle { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--navy-700); background: var(--navy-900); color: var(--navy-text); display: grid; place-items: center; cursor: pointer; flex: none; transition: background .15s, color .15s, border-color .15s; }
.side-toggle:hover { background: var(--navy-800); color: #fff; border-color: var(--accent); }
.side-toggle svg { transition: transform .24s ease; }
.side-btn { display: flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
.side-btn svg { flex: none; }
.side-new .lbl { white-space: nowrap; }

body.side-collapsed .sidebar { width: 78px; padding-left: 10px; padding-right: 10px; }
body.side-collapsed .side-toggle svg { transform: rotate(180deg); }
body.side-collapsed .brand { flex-direction: column; align-items: center; padding: 0 0 16px; gap: 12px; }
body.side-collapsed .brand-text, body.side-collapsed .chip-dark { display: none; }
body.side-collapsed .sidebar-card { display: none; }
body.side-collapsed .nav-label { display: none; }
body.side-collapsed .section.label { height: 1px; margin: 14px 12px; padding: 0; font-size: 0; line-height: 0; background: var(--navy-700); overflow: hidden; }
body.side-collapsed .nav-item { justify-content: center; padding: 0; gap: 0; }
body.side-collapsed .nav-badge { position: absolute; top: 3px; right: 5px; min-width: 16px; height: 16px; padding: 0 4px; font-size: 10px; margin: 0; }
body.side-collapsed .side-new { padding: 0; justify-content: center; gap: 0; }
body.side-collapsed .side-new .lbl { display: none; }
body.side-collapsed .side-user-row { justify-content: center; }
body.side-collapsed .side-user-txt, body.side-collapsed .side-sync, body.side-collapsed .side-btn span { display: none; }
body.side-collapsed .side-user-actions { flex-direction: column; }
body.side-collapsed .side-user { padding-top: 12px; }

/* ======================= Animaciones sencillas ======================= */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes grow { from { width: 0; } }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(220, 38, 38, .5); } 70% { box-shadow: 0 0 0 7px rgba(220, 38, 38, 0); } 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); } }
@keyframes spin { to { transform: rotate(360deg); } }

/* Al entrar a una página: el contenido sube y aparece, uno tras otro */
#view.enter > * { animation: rise .38s ease both; }
#view.enter > *:nth-child(2) { animation-delay: .06s; } #view.enter > *:nth-child(3) { animation-delay: .12s; }
#view.enter > *:nth-child(4) { animation-delay: .18s; } #view.enter > *:nth-child(n+5) { animation-delay: .24s; }
#view.enter .stat-grid > * { animation: rise .4s ease both; }
#view.enter .stat-grid > *:nth-child(2) { animation-delay: .05s; } #view.enter .stat-grid > *:nth-child(3) { animation-delay: .1s; }
#view.enter .stat-grid > *:nth-child(4) { animation-delay: .15s; } #view.enter .stat-grid > *:nth-child(5) { animation-delay: .2s; }
#view.enter .tbl tbody tr { animation: rise .3s ease both; }
#view.enter .tbl tbody tr:nth-child(1) { animation-delay: .08s; } #view.enter .tbl tbody tr:nth-child(2) { animation-delay: .12s; }
#view.enter .tbl tbody tr:nth-child(3) { animation-delay: .16s; } #view.enter .tbl tbody tr:nth-child(4) { animation-delay: .2s; }
#view.enter .tbl tbody tr:nth-child(5) { animation-delay: .24s; } #view.enter .tbl tbody tr:nth-child(n+6) { animation-delay: .28s; }

/* Tarjetas, botones y filas responden al cursor */
.card.stat { transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease; }
.card.stat:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(15, 23, 42, .09); }
.btn { transition: filter .15s, transform .1s, background .15s, border-color .15s; }
.btn:active, .side-new:active, .side-btn:active { transform: scale(.97); }
.tbl tbody tr.click { transition: background .12s; }
.pill, .chip { transition: background .15s, color .15s; }
.segmented button { transition: background .15s, color .15s, box-shadow .15s; }
.map-item { transition: background .15s; }

/* Ventanas y paneles */
.modal-bg { animation: fadeIn .18s ease both; }
.modal { animation: pop .24s cubic-bezier(.2, .9, .3, 1.1) both; }
.drawer-bg { transition: opacity .2s ease; }
.toast { transition: opacity .25s ease, transform .25s ease; }

/* Gráficos e indicadores */
.bar-fill { animation: grow .8s cubic-bezier(.2, .8, .2, 1) both; }
.chart path.draw { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1.1s ease .1s forwards; }
.tile, .chart-card { animation: rise .4s ease both; }
.nav-badge:not([hidden]) { animation: pulse 2.2s ease-out infinite; }
.pill.bad { position: relative; }
.dot.bad { animation: pulse 2.2s ease-out infinite; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* Las tarjetas no se ensanchan con su contenido: las tablas largas hacen scroll dentro de la tarjeta */
.view > *, .col > *, .row2 > * { min-width: 0; }
.card-head { min-width: 0; }

/* ---------- Mapa en vivo: selección ---------- */
.map-hint { padding: 0 18px 12px; font-size: 12.5px; color: var(--text-muted); line-height: 1.45; }
.map-item.sel { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.map-item.sel:hover { background: var(--accent-soft); }

/* Contenedores agrupados por nave (mapa y tabla) */
.check-inline { display: inline-flex; gap: 6px; align-items: center; font-size: 12.5px; color: var(--text-muted); cursor: pointer; user-select: none; }
.check-inline input { accent-color: var(--accent); cursor: pointer; }
.map-group { border-top: 1px solid var(--border); background: var(--surface-muted); }
.map-group-head { display: flex; gap: 12px; padding: 12px 18px 6px; align-items: flex-start; cursor: pointer; transition: background .15s; }
.map-group-head:hover, .map-group.sel .map-group-head { background: var(--accent-soft); }
.map-group-head b { font-size: 13px; }
.map-group-head .sub { color: var(--text-muted); font-size: 12.5px; }
.map-group-head .swatch.ship { width: 10px; height: 10px; border-radius: 3px; margin-top: 5px; flex: none; background: var(--text); }
.map-group .map-item { border-top: 0; padding: 7px 18px 7px 34px; }
.map-group .map-item.member:last-child { padding-bottom: 12px; }
.map-group .map-item:hover { background: var(--accent-soft); }
.tbl tr.group-row td { background: var(--surface-muted); padding: 9px 14px; font-size: 13px; border-top: 1px solid var(--border); }
.tbl tr.group-row .pill { margin-left: 6px; }
.tbl tr.member td:first-child { box-shadow: inset 3px 0 0 var(--accent-soft); }
.tbl tr.member.sel td:first-child { box-shadow: inset 3px 0 0 var(--accent); }

/* Escáner AIS (Panel de APIs) */
.scan-ctl { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; padding: 4px 18px 14px; }
.scan-ctl label { display: inline-flex; gap: 8px; align-items: center; font-size: 12.5px; color: var(--text-muted); }
.scan-ctl select { padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); font: inherit; color: var(--text); }
.scan-body { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; padding: 0 18px; }
#sc-map { height: 460px; border-radius: 10px; overflow: hidden; background: var(--surface-muted); position: relative; }
.scan-side { min-width: 0; }
@media (max-width: 900px) { .scan-body { grid-template-columns: 1fr; } #sc-map { height: 340px; } }


/* Solicitudes de contacto */
.sol-status { padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); font: inherit; color: var(--text); }
.sol-note { min-width: 180px; }
