/* Autoevaluacion Institucional - Guia 34 | Gobernacion del Tolima
   Layout: app de tablero con cabecera fija, navegacion por pestanas y tarjetas de componente */
:root {
  /* Identidad Gobernacion del Tolima / Secretaria de Educacion: vinotinto + oro */
  --azul: #8a1538;        /* vinotinto institucional */
  --azul-700: #6c0f2b;
  --azul-050: #f8e9ee;
  --oro: #c0962b;
  --bg: #f6f3f1;
  --surface: #ffffff;
  --surface-2: #f3eef0;
  --fg: #221820;
  --muted: #6a5c63;
  --line: #e4d9dd;
  --accent: #8a1538;
  --ok: #1e8e54;         /* fortaleza */
  --ok-bg: #e4f4ea;
  --warn: #b7791f;       /* en consolidacion */
  --warn-bg: #fbf0da;
  --crit: #c23b3b;       /* oportunidad de mejora */
  --crit-bg: #fae3e3;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 35, 60, .08), 0 1px 2px rgba(20, 35, 60, .06);
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --azul: #e58aa6; --azul-700: #d1738f; --azul-050: #341019;
    --oro: #d9b24a;
    --bg: #171014; --surface: #231a1f; --surface-2: #1c1419;
    --fg: #f0e7ea; --muted: #b6a3ab; --line: #3a2b32; --accent: #e58aa6;
    --ok: #4cc585; --ok-bg: #13301f; --warn: #e0b057; --warn-bg: #352a12;
    --crit: #f07a7a; --crit-bg: #3a1b1b;
    --shadow: 0 1px 3px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --azul: #e58aa6; --azul-700: #d1738f; --azul-050: #341019;
  --oro: #d9b24a;
  --bg: #171014; --surface: #231a1f; --surface-2: #1c1419;
  --fg: #f0e7ea; --muted: #b6a3ab; --line: #3a2b32; --accent: #e58aa6;
  --ok: #4cc585; --ok-bg: #13301f; --warn: #e0b057; --warn-bg: #352a12;
  --crit: #f07a7a; --crit-bg: #3a1b1b;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: var(--sans); font-size: 15px; line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { text-wrap: balance; margin: 0; }
a { color: var(--azul); }
button { font-family: inherit; }
.tnum { font-variant-numeric: tabular-nums; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--fg);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background .15s, border-color .15s, transform .05s;
  min-height: 42px;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--azul); border-color: var(--azul); color: #fff; }
.btn-primary:hover { background: var(--azul-700); }
.btn-peligro { background: var(--crit); border-color: var(--crit); color: #fff; }
.btn-peligro:hover { filter: brightness(1.08); }
.card-del {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--crit); cursor: pointer; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; opacity: .65;
}
.card-del:hover { opacity: 1; background: var(--azul-050); border-color: var(--azul); color: var(--azul); }
.chk-group { border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; margin-bottom: 12px; }
.chk-row { display: flex; align-items: center; gap: 9px; padding: 7px 2px; font-size: 14px; font-weight: 500; color: var(--fg); cursor: pointer; }
.chk-row input { width: 17px; height: 17px; flex: 0 0 auto; }
.chk-todo { font-weight: 700; border-bottom: 1px solid var(--line); margin-bottom: 2px; }
.chk-clave { margin-bottom: 12px; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible,
.tab:focus-visible { outline: 3px solid color-mix(in srgb, var(--azul) 45%, transparent); outline-offset: 2px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- Campos ---------- */
label { font-size: 13px; font-weight: 600; color: var(--muted); }
input[type=text], input[type=password], input[type=search], input[type=date],
input[type=number], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 9px; background: var(--surface); color: var(--fg);
  font-family: inherit; font-size: 14px;
}
textarea { resize: vertical; min-height: 64px; line-height: 1.45; }

/* ---------- Cabecera ---------- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 30;
  background: var(--azul); color: #fff;
  box-shadow: var(--shadow);
}
.topbar-in {
  display: flex; align-items: center; gap: 12px;
  padding-block: 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  max-width: 1100px; margin: 0 auto;
}
.brand { display: flex; flex-direction: column; min-width: 0; }
.brand b { font-size: 15px; font-weight: 700; line-height: 1.2; }
.brand span { font-size: 11.5px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.icon-btn {
  background: rgba(255,255,255,.14); border: none; color: #fff; cursor: pointer;
  width: 38px; height: 38px; border-radius: 9px; font-size: 16px;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: rgba(255,255,255,.26); }

.wrap {
  max-width: 1100px; margin: 0 auto; width: 100%;
  padding-block: 20px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* ---------- Pantalla inicio ---------- */
.hero { text-align: center; padding: 10px 0 18px; }
.hero-logo { height: 92px; width: auto; margin: 0 auto 10px; display: block; }
.hero h1 { font-family: var(--serif); font-size: clamp(26px, 5vw, 40px); font-weight: 600; color: var(--azul); }
.hero p { color: var(--muted); margin-top: 8px; max-width: 60ch; margin-inline: auto; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 18px 0 14px; }
.toolbar .grow { flex: 1 1 240px; min-width: 0; }

.lista { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.card-ie {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); cursor: pointer; text-align: left;
  display: flex; flex-direction: column; gap: 6px; transition: border-color .15s, transform .05s;
}
.card-ie:hover { border-color: var(--azul); }
.card-ie:active { transform: translateY(1px); }
.card-ie .mun { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--azul); }
.card-ie .nom { font-weight: 600; line-height: 1.3; }
.card-ie .dane { font-size: 12px; color: var(--muted); }
.card-ie .estado { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.mini-prog { flex: 1; height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.mini-prog > i { display: block; height: 100%; background: var(--azul); }
.hint { color: var(--muted); font-size: 13px; }
.count { font-size: 13px; color: var(--muted); }

/* ---------- Pestanas ---------- */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 18px; scrollbar-width: thin; }
.tab {
  flex: 0 0 auto; border: none; background: transparent; color: var(--muted);
  padding: 11px 14px; font-size: 14px; font-weight: 600; cursor: pointer;
  border-bottom: 3px solid transparent; white-space: nowrap;
}
.tab[aria-selected="true"] { color: var(--azul); border-bottom-color: var(--azul); }

/* ---------- Identificacion ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.panel h2 { font-size: 18px; margin-bottom: 4px; }
.panel .sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }

/* ---------- Componentes ---------- */
.proc-head {
  display: flex; align-items: center; gap: 10px; margin: 20px 0 10px;
}
.proc-head h3 { font-size: 15px; color: var(--fg); }
.proc-head .ln { flex: 1; height: 1px; background: var(--line); }

.comp {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 14px; overflow: hidden;
}
.comp-top { padding: 14px 16px; display: flex; gap: 12px; align-items: flex-start; }
.cod {
  flex: 0 0 auto; font-weight: 700; font-size: 12.5px; color: #fff; background: var(--azul);
  padding: 4px 9px; border-radius: 7px; letter-spacing: .02em;
}
.comp-top .tit { min-width: 0; flex: 1; }
.comp-top .tit b { display: block; font-size: 15px; line-height: 1.3; }
.comp-top .tit .qe { color: var(--muted); font-size: 13px; margin-top: 3px; }
.val-badge { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; }
.chip-nivel { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.comp-body { padding: 0 16px 16px; display: grid; gap: 14px; }

.niveles { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 8px; }
.nivel {
  text-align: left; border: 1.5px solid var(--line); background: var(--surface-2);
  border-radius: 10px; padding: 10px 11px; cursor: pointer; font-size: 12.5px; color: var(--fg);
  display: flex; flex-direction: column; gap: 5px; line-height: 1.4; transition: border-color .12s, background .12s;
}
.nivel:hover { border-color: var(--azul); }
.nivel .n-h { display: flex; align-items: center; gap: 7px; font-weight: 700; font-size: 12.5px; color: var(--muted); }
.nivel .n-h i { width: 20px; height: 20px; border-radius: 50%; background: var(--surface); border: 1.5px solid var(--line); display: inline-flex; align-items: center; justify-content: center; font-style: normal; font-size: 12px; }
.nivel[aria-pressed="true"] { border-color: var(--azul); background: var(--azul-050); }
.nivel[aria-pressed="true"] .n-h { color: var(--azul); }
.nivel[aria-pressed="true"] .n-h i { background: var(--azul); border-color: var(--azul); color: #fff; }

.campos { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.campos .full { grid-column: 1 / -1; }
.campos label small { display: block; font-weight: 400; color: var(--muted); font-size: 11.5px; margin-top: 1px; }

/* ---------- Resultados ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.kpi .k-lab { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi .k-val { font-size: 30px; font-weight: 700; margin-top: 4px; font-family: var(--serif); }
.kpi .k-sub { font-size: 12.5px; color: var(--muted); }

.res-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.res-table th, .res-table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); }
.res-table th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.res-table td.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.tabla-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }

.estado-pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 700; }
.e-ok { background: var(--ok-bg); color: var(--ok); }
.e-warn { background: var(--warn-bg); color: var(--warn); }
.e-crit { background: var(--crit-bg); color: var(--crit); }
.e-none { background: var(--surface-2); color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; }

.foco { display: grid; gap: 10px; }
.foco-item { display: flex; gap: 12px; align-items: flex-start; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--crit); border-radius: 10px; padding: 12px 14px; box-shadow: var(--shadow); }
.foco-item .pr { font-weight: 700; color: var(--crit); font-size: 13px; flex: 0 0 auto; }

/* ---------- Barra de guardado ---------- */
.savebar {
  position: sticky; bottom: 0; z-index: 20; margin-top: 18px;
  background: var(--surface); border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding-block: 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
}
.save-state { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.save-state .dot { background: var(--muted); }
.save-state.saved { color: var(--ok); }
.save-state.saved .dot { background: var(--ok); }
.save-state.saving .dot { background: var(--warn); animation: pulse 1s infinite; }
.save-state.error { color: var(--crit); }
.save-state.error .dot { background: var(--crit); }
.live-ind { font-size: 12.5px; color: var(--azul); font-weight: 600; display: inline-flex; align-items: center; gap: 5px; }
@keyframes flashbg { 0% { background: var(--azul-050); } 100% { background: transparent; } }
.flash { animation: flashbg 1.4s ease-out; }
textarea.flash, input.flash { animation: flashbg 1.4s ease-out; }
@keyframes pulse { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- Progreso global ---------- */
.progwrap { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.progbar { flex: 1; height: 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 99px; overflow: hidden; }
.progbar > i { display: block; height: 100%; background: var(--azul); transition: width .3s; }

/* ---------- Modal ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(10, 18, 32, .55); z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-left, 0px));
}
.modal {
  background: var(--surface); border-radius: var(--radius); box-shadow: 0 20px 50px rgba(0,0,0,.3);
  width: 100%; max-width: 440px; padding: 22px; max-height: 90vh; overflow-y: auto;
}
.modal h2 { font-size: 19px; margin-bottom: 6px; }
.modal p { color: var(--muted); font-size: 13.5px; margin: 0 0 14px; }
.modal .field { margin-bottom: 14px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.msg { font-size: 13px; padding: 9px 12px; border-radius: 8px; margin-bottom: 12px; }
.msg-err { background: var(--crit-bg); color: var(--crit); }
.msg-ok { background: var(--ok-bg); color: var(--ok); }
.msg-info { background: var(--azul-050); color: var(--azul); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: max(20px, env(safe-area-inset-bottom, 0px)); z-index: 60;
  background: var(--fg); color: var(--bg); padding: 11px 18px; border-radius: 10px;
  font-size: 13.5px; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: 90vw;
}

.center-note { text-align: center; color: var(--muted); padding: 40px 16px; }

@media (max-width: 560px) {
  .campos { grid-template-columns: 1fr; }
  .comp-top { flex-wrap: wrap; }
}

/* ---------- Logo institucional ---------- */
.topbar { border-bottom: 3px solid var(--oro); }
.brand-logo { height: 40px; width: auto; max-width: 150px; background: #fff; border-radius: 6px; padding: 3px 6px; flex: 0 0 auto; }
.brand-logo[hidden] { display: none; }

/* ---------- Mapa del Tolima ---------- */
.map-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.map-toggle button { border: none; background: var(--surface); color: var(--muted); padding: 9px 16px; font-weight: 600; font-size: 14px; cursor: pointer; }
.map-toggle button[aria-pressed="true"] { background: var(--azul); color: #fff; }
.map-wrap { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 760px) { .map-wrap { grid-template-columns: 1fr; } }
.map-panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.map-svg { width: 100%; height: auto; max-height: 72vh; display: block; }
.map-svg path { stroke: var(--surface); stroke-width: 1.1; cursor: pointer; transition: opacity .12s; }
.map-svg path:hover { opacity: .78; stroke: var(--fg); stroke-width: 1.5; }
.map-svg path:focus { outline: none; stroke: var(--fg); stroke-width: 2; }
.map-lab { font-size: 9px; fill: rgba(0,0,0,.55); pointer-events: none; font-family: var(--sans); }
:root[data-theme="dark"] .map-lab, :root:not([data-theme="light"]) .map-lab { fill: rgba(255,255,255,.6); }
.legend { display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.legend .row { display: flex; align-items: center; gap: 9px; }
.legend .sw { width: 18px; height: 18px; border-radius: 5px; border: 1px solid rgba(0,0,0,.15); flex: 0 0 auto; }
.map-info { margin-top: 10px; font-size: 13px; color: var(--muted); }
.map-rank { margin-top: 14px; }
.map-rank h4 { font-size: 13px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin: 0 0 8px; }
.map-rank .mi { display: flex; align-items: center; gap: 9px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.map-rank .mi .nm { flex: 1; min-width: 0; }
.map-rank .mi .vl { font-variant-numeric: tabular-nums; font-weight: 700; }
.map-tip { position: fixed; z-index: 70; background: var(--fg); color: var(--bg); padding: 8px 11px; border-radius: 8px; font-size: 12.5px; pointer-events: none; max-width: 240px; box-shadow: 0 6px 18px rgba(0,0,0,.3); }

/* ---------- Impresion (respaldo del PDF) ---------- */
@media print {
  .topbar, .savebar, .tabs, .toolbar, .map-toggle, #btnTema, #btnAdmin, #btnSalir, .progwrap { display: none !important; }
  body { background: #fff; color: #000; }
  .panel, .kpi, .comp, .tabla-scroll, .foco-item { box-shadow: none; border-color: #bbb; }
  .wrap { max-width: none; }
  .kpis { break-inside: avoid; }
  .res-table { font-size: 11px; }
}
