:root {
  --bg: #0f1418; --surface: #161d23; --surface2: #1d262e; --line: #2a3640;
  --text: #e6edf2; --muted: #8fa1ae; --accent: #f2b233; --accent-ink: #1b1405;
  --primary: #2f8fe0; --success: #2eaa5c; --danger: #e0524a; --warn: #f08c1e;
  --chip: #24303a; --shadow: 0 8px 28px rgba(0,0,0,.35);
  --font: "IBM Plex Sans", system-ui, sans-serif; --mono: "IBM Plex Mono", ui-monospace, monospace;
}
:root[data-theme="light"] {
  --bg: #eef1f4; --surface: #ffffff; --surface2: #f5f7f9; --line: #dbe1e6;
  --text: #17212a; --muted: #5f6f7c; --chip: #e8edf1; --shadow: 0 8px 24px rgba(20,30,40,.14);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.w100 { width: 100%; }

/* ---------- Topbar ---------- */
.topbar { height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 38px; height: 38px; border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 700; font-family: var(--mono); }
.brand-title { font-weight: 700; letter-spacing: .02em; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-center { display: flex; gap: 10px; align-items: center; }
.top-right { display: flex; gap: 12px; align-items: center; }
.today { font-family: var(--mono); color: var(--muted); font-size: 12px; }
.user { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--chip); }
.seg { display: flex; background: var(--chip); border-radius: 8px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 5px 14px; border-radius: 6px; cursor: pointer; color: var(--muted); font-weight: 600; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.chip { font-size: 11px; padding: 4px 9px; border-radius: 999px; background: var(--chip); color: var(--muted); white-space: nowrap; }
.chip.ok { background: rgba(46,170,92,.18); color: var(--success); }
.chip.warn { background: rgba(240,140,30,.18); color: var(--warn); }
.icon-btn { border: 1px solid var(--line); background: var(--surface2); width: 32px; height: 32px; border-radius: 8px; cursor: pointer; }

/* ---------- Layout ---------- */
.layout { display: flex; height: calc(100% - 58px); }
.view-wrap { position: relative; flex: 1; min-width: 0; }
#viewDiv { position: absolute; inset: 0; }
.panel { width: 440px; max-width: 46vw; display: flex; flex-direction: column; background: var(--surface); border-left: 1px solid var(--line); }
.tabs { display: flex; overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 12px 6px; cursor: pointer; color: var(--muted);
  font-weight: 600; font-size: 12.5px; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.tab-body { flex: 1; overflow-y: auto; padding: 12px; }
.tab { display: none; } .tab.on { display: block; }

/* ---------- Blocks & forms ---------- */
.block { background: var(--surface2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.block-title { font-weight: 700; font-size: 13px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.step { width: 20px; height: 20px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 11px; display: grid; place-items: center; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
label > input:not([type=checkbox]), label > select, label > textarea, .tab-body select {
  display: block; width: 100%; margin-top: 4px; padding: 8px 9px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 7px; color: var(--text); outline: none; }
label > input:focus, label > select:focus, label > textarea:focus { border-color: var(--primary); }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); margin: 6px 0; cursor: pointer; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.row-btns { display: flex; gap: 8px; margin: 8px 0; } .row-btns select { margin: 0; }
.btn { border: 1px solid var(--line); background: var(--surface); padding: 9px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; margin-top: 4px; }
.btn:hover { filter: brightness(1.1); } .btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.sm { padding: 4px 8px; font-size: 12px; margin: 0; }
.empty { color: var(--muted); text-align: center; padding: 18px 8px; font-size: 13px; }

/* ---------- Segment list ---------- */
.list-head { display: flex; justify-content: space-between; align-items: center; margin: 4px 0 6px; }
.seg-list { max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.seg-item { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; align-items: center; padding: 7px 9px; border-bottom: 1px solid var(--line); cursor: pointer; }
.seg-item:last-child { border-bottom: 0; }
.seg-item:hover { background: var(--surface2); }
.seg-item.sel { background: rgba(0,229,255,.09); }
.seg-prog { font-family: var(--mono); font-size: 12px; }
.seg-desc { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 10.5px; font-weight: 700; padding: 3px 7px; border-radius: 999px; white-space: nowrap; }
.b-PROGRAMADO { background: var(--chip); color: var(--muted); }
.b-EJECUTADO { background: rgba(46,170,92,.18); color: #3fc272; }
.b-VALIDADO { background: rgba(33,118,214,.2); color: #5aa7ff; }
.b-OBSERVADO, .b-EN-REVISIÓN, .b-EN-GESTIÓN { background: rgba(240,140,30,.18); color: var(--warn); }
.b-ABIERTA, .b-PENDIENTE, .b-ANULADO { background: rgba(224,82,74,.18); color: #ff7a72; }
.b-CERRADA, .b-LIBERADA { background: rgba(46,170,92,.18); color: #3fc272; }
.sel-summary { font-size: 12.5px; padding: 8px 10px; border-radius: 8px; background: var(--surface); border: 1px dashed var(--line); margin-bottom: 10px; }
.foto-prev img { max-width: 100%; max-height: 140px; border-radius: 8px; margin-bottom: 8px; }

/* ---------- KPIs & tables ---------- */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.kpi { background: var(--surface2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.kpi .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi .v { font-size: 18px; font-weight: 700; margin-top: 3px; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 11px; color: var(--muted); margin-top: 2px; }
.kpi.hl .v { color: var(--accent); }
.kpis.small .kpi .v { font-size: 15px; }
.bar { height: 6px; background: var(--chip); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.bar > div { height: 100%; background: var(--success); }
.chart-box { position: relative; height: 230px; }
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
.tbl th { text-align: left; color: var(--muted); font-weight: 600; padding: 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl td.n, .tbl th.n { text-align: right; white-space: nowrap; }
.tbl tr.tot td { font-weight: 700; border-top: 2px solid var(--line); }

/* ---------- Cards (historial / incidencias) ---------- */
.card { background: var(--surface2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; }
.card-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.card-title { font-weight: 700; font-size: 13px; }
.card-meta { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.card-body { font-size: 12.5px; margin-top: 6px; }
.card-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.thumbs img { width: 84px; height: 64px; object-fit: cover; border-radius: 6px; cursor: zoom-in; border: 1px solid var(--line); }

/* ---------- Overlays on the view ---------- */
.legend { position: absolute; left: 12px; bottom: 26px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; box-shadow: var(--shadow); font-size: 12px; z-index: 5; }
.legend div { display: flex; align-items: center; gap: 7px; margin: 3px 0; }
.legend i { width: 14px; height: 10px; border-radius: 3px; display: inline-block; }
.hint { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); background: var(--accent); color: var(--accent-ink);
  padding: 8px 14px; border-radius: 999px; font-weight: 600; z-index: 6; box-shadow: var(--shadow); display: flex; gap: 10px; align-items: center; }
.hint button { border: 0; background: rgba(0,0,0,.15); border-radius: 999px; padding: 2px 9px; cursor: pointer; color: inherit; }
.info-card { position: absolute; top: 12px; right: 12px; width: 330px; max-height: calc(100% - 24px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 12px; z-index: 6; font-size: 12.5px; }
.info-card h4 { margin: 0 0 6px; font-size: 14px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 3px 8px; margin: 6px 0; }
.kv span:nth-child(odd) { color: var(--muted); }
.info-card details summary { cursor: pointer; color: var(--primary); margin-top: 8px; }
.time-badge { position: absolute; top: 12px; left: 12px; background: var(--surface); border: 1px solid var(--accent); color: var(--accent);
  padding: 6px 12px; border-radius: 8px; font-family: var(--mono); z-index: 5; }
.time-date { font-family: var(--mono); font-size: 20px; color: var(--accent); text-align: center; margin: 4px 0 8px; }
.range { width: 100%; accent-color: var(--accent); }
.vuelo { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.vuelo:last-child { border-bottom: 0; }
.progress { height: 8px; background: var(--chip); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.field-row { display: grid; grid-template-columns: 110px 1fr; gap: 8px; align-items: center; margin-bottom: 5px; font-size: 12px; }
.field-row select { margin: 0 !important; padding: 5px !important; font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; word-break: break-all; }

/* ---------- Modal, toast, loader ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-box { width: 520px; max-width: 100%; max-height: 92vh; display: flex; flex-direction: column; background: var(--surface); border-radius: 12px; border: 1px solid var(--line); box-shadow: var(--shadow); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); font-weight: 700; }
.modal-body { padding: 14px; overflow-y: auto; }
.modal-body img.full { max-width: 100%; border-radius: 8px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px;
  border-radius: 10px; z-index: 60; box-shadow: var(--shadow); font-weight: 600; max-width: 90vw; }
.toast.err { background: var(--danger); color: #fff; }
.loader { position: fixed; inset: 0; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; z-index: 100; color: var(--muted); }
.spinner { width: 42px; height: 42px; border: 4px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .layout { flex-direction: column; height: auto; }
  .view-wrap { height: 55vh; flex: none; }
  .panel { width: 100%; max-width: none; border-left: 0; border-top: 1px solid var(--line); }
  .tab-body { overflow: visible; }
  .today, .chip#dataMode { display: none; }
  .info-card { width: calc(100% - 24px); max-height: 45vh; }
  .topbar { padding: 0 10px; }
  .brand-sub { max-width: 40vw; }
}
@media (max-width: 520px) { .seg button { padding: 5px 9px; } .row3 { grid-template-columns: 1fr 1fr; } .user { display: none; } }

/* ---------- Secuencia constructiva (pestaña Tiempo) ---------- */
#timeFuente button { flex: 1; padding: 6px 8px; font-size: 12px; }
.fase { display: grid; grid-template-columns: 18px 1fr auto; gap: 6px 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.fase:last-child { border-bottom: 0; }
.fase .n { width: 18px; height: 18px; border-radius: 50%; background: var(--chip); color: var(--muted); font-size: 10px; font-weight: 700; display: grid; place-items: center; }
.fase.curso .n { background: var(--accent); color: var(--accent-ink); }
.fase.ok .n { background: var(--success); color: #fff; }
.fase .d { color: var(--muted); font-size: 11px; }
.fase .bar { grid-column: 2 / 4; height: 4px; background: var(--chip); border-radius: 2px; overflow: hidden; }
.fase .bar > div { height: 100%; background: var(--accent); }
.fase.ok .bar > div { background: var(--success); }
.fase.vacia { opacity: .55; }

/* ---------- Panel de herramientas de análisis ---------- */
.tools-btn { margin-top: 0; }
.tools-btn.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tools { position: absolute; top: 52px; left: 58px; width: 310px; max-height: calc(100% - 150px); overflow-y: auto; z-index: 6;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 10px 12px; font-size: 12px; }
.tools h5 { margin: 10px 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.tools h5:first-of-type { margin-top: 4px; }
.tools .t-head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 13px; }
.tools .t-row { display: grid; grid-template-columns: 18px 1fr 92px 30px; gap: 6px; align-items: center; padding: 3px 0; }
.tools .t-row.sub { padding-left: 14px; }
.tools .t-row span.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tools .t-row.grupo span.name { font-weight: 700; }
.tools .t-row .pct { text-align: right; color: var(--muted); font-family: var(--mono); font-size: 11px; }
.tools .t-slider { display: grid; grid-template-columns: 1fr 110px 34px; gap: 6px; align-items: center; padding: 3px 0; }
.tools input[type=range] { width: 100%; margin: 0; accent-color: var(--accent); }
.tools .seg button { flex: 1; padding: 5px 6px; font-size: 12px; }
.tools .t-capas { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 4px; }
@media (max-width: 900px) { .tools { left: 12px; width: calc(100% - 24px); max-height: 50vh; } }

/* ---------- Vista maximizada y mini reproductor ---------- */
.max-btn { position: absolute; top: 12px; right: 12px; z-index: 7; width: 34px; height: 34px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font-size: 18px; line-height: 1; box-shadow: var(--shadow); }
.max-btn:hover { background: var(--accent); color: var(--accent-ink); }
body.vista-max header, body.vista-max .panel { display: none !important; }
body.vista-max .layout { height: 100vh; }
body.vista-max .view-wrap { height: 100vh; }
.view-wrap .info-card { top: 54px; max-height: calc(100% - 70px); }
.mini-time { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 7; display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; box-shadow: var(--shadow); width: min(640px, calc(100% - 24px)); }
.mini-time .mini-date { font-family: var(--mono); color: var(--accent); font-weight: 700; white-space: nowrap; }
.mini-time input[type=range] { flex: 1; accent-color: var(--accent); }
.mini-time label.check { margin: 0; white-space: nowrap; font-size: 12px; }


/* ---------- Cuadro de avance (curva S) sobre el modelo ---------- */
.av-card { position: absolute; top: 12px; right: 56px; z-index: 5; width: 380px; max-height: calc(100% - 110px); overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 8px 10px; font-size: 11px; }
.av-card .av-h { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.av-card .av-h b { font-size: 12px; }
.av-card .av-h b .mono { color: var(--accent); }
.av-card .x { cursor: pointer; border: 0; background: none; color: var(--muted); font-size: 14px; padding: 0 3px; }
.av-card .av-kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 6px 0; }
.av-card .av-k { background: var(--chip); border-radius: 8px; padding: 5px 7px; }
.av-card .av-k .k { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .03em; }
.av-card .av-k .v { font-family: var(--mono); font-weight: 700; font-size: 13px; }
.av-card .av-k .s { color: var(--muted); font-size: 10px; }
.av-card .av-k .v.ok { color: var(--success); } .av-card .av-k .v.mal { color: var(--danger); } .av-card .av-k .v.med { color: var(--warn); }
.av-card .av-chart { height: 150px; position: relative; }
.av-card .av-fases { margin-top: 4px; }
.av-card .av-f { display: grid; grid-template-columns: 1fr 42px; gap: 2px 8px; padding: 2px 0; }
.av-card .av-f .bar { grid-column: 1 / 3; height: 3px; background: var(--chip); border-radius: 2px; overflow: hidden; }
.av-card .av-f .bar > div { height: 100%; background: var(--accent); }
.av-card .av-f span:last-of-type { text-align: right; font-family: var(--mono); }
.av-card.min .av-body { display: none; }
@media (max-width: 900px) { .av-card { width: calc(100% - 80px); } .av-card .av-chart { height: 110px; } }

/* ---------- Reporte ampliado ---------- */
.rep-bar { display: none; }
#tab-reporte.rep-max { position: fixed; inset: 0; z-index: 60; display: block; background: var(--bg); overflow-y: auto; padding: 16px 28px 40px; }
#tab-reporte.rep-max > * { max-width: 1400px; margin-left: auto; margin-right: auto; }
#tab-reporte.rep-max .rep-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-size: 16px; }
#tab-reporte.rep-max .kpis { grid-template-columns: repeat(6, minmax(0, 1fr)); }
#tab-reporte.rep-max .chart-box { height: 52vh; }
#tab-reporte .row-btns #repPdf { flex: 1; }
@media (max-width: 900px) { #tab-reporte.rep-max { padding: 12px; } #tab-reporte.rep-max .kpis { grid-template-columns: 1fr 1fr; } }
#tab-reporte.rep-max #repMax { display: none; }
