/* Proyecto TCM - estilos base */
:root {
  --bg: #04060d;
  --bg2: #0a1022;
  --panel: rgba(14, 22, 44, 0.62);
  --panel-solid: #0e162c;
  --panel-2: rgba(24, 36, 68, 0.55);
  --border: rgba(110, 190, 255, 0.16);
  --border-strong: rgba(110, 190, 255, 0.38);
  --text: #e6f0ff;
  --muted: #8ea3c4;
  --accent: #22d3ee;
  --accent-2: #a855f7;
  --accent-glow: rgba(34, 211, 238, 0.45);
  --ok: #22c55e;
  --warn: #f59e0b;
  --orange: #f97316;
  --bad: #ef4444;
  --grid: rgba(34, 211, 238, 0.06);
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --radius-sm: 9px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Orbitron", "Inter", system-ui, sans-serif;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #eef3fb;
  --bg2: #e2eaf7;
  --panel: rgba(255, 255, 255, 0.78);
  --panel-solid: #ffffff;
  --panel-2: rgba(240, 245, 253, 0.9);
  --border: rgba(30, 64, 120, 0.14);
  --border-strong: rgba(8, 145, 178, 0.45);
  --text: #0b1324;
  --muted: #52627e;
  --accent: #0891b2;
  --accent-2: #7c3aed;
  --accent-glow: rgba(8, 145, 178, 0.25);
  --grid: rgba(8, 145, 178, 0.07);
  --shadow: 0 10px 30px rgba(15, 30, 60, 0.12);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.45;
  overflow-x: hidden;
}
#fondo3d {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  width: 100%; height: 100%;
}
.fondo-grid {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse at 50% 30%, #000 30%, transparent 80%);
  -webkit-mask-image: radial-gradient(ellipse at 50% 30%, #000 30%, transparent 80%);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--font-display); letter-spacing: 0.04em; margin: 0 0 0.5em; font-weight: 600; }
h1 { font-size: clamp(1.35rem, 3.2vw, 2rem); }
h2 { font-size: 1.05rem; text-transform: uppercase; color: var(--muted); letter-spacing: 0.12em; }
h3 { font-size: 0.95rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.tiny { font-size: 0.75rem; }

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.marca { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 700; letter-spacing: 0.12em; color: var(--text); white-space: nowrap; }
.marca:hover { text-decoration: none; }
.marca .logo {
  width: 30px; height: 30px; border-radius: 8px; position: relative;
  background: conic-gradient(from 200deg, var(--accent), var(--accent-2), var(--accent));
  box-shadow: 0 0 18px var(--accent-glow);
  animation: girar 8s linear infinite;
}
.marca .logo::after { content: ""; position: absolute; inset: 5px; border-radius: 5px; background: var(--bg); }
@keyframes girar { to { transform: rotate(360deg); } }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  color: var(--muted); padding: 8px 14px; border-radius: 999px; font-weight: 500; font-size: 0.92rem;
  border: 1px solid transparent; transition: all .2s;
}
.nav a:hover { color: var(--text); text-decoration: none; border-color: var(--border); }
.nav a.activo { color: var(--text); border-color: var(--border-strong); background: var(--panel-2); box-shadow: 0 0 16px var(--accent-glow) inset; }
.acciones-top { display: flex; align-items: center; gap: 8px; }
.usuario-chip { font-size: 0.85rem; color: var(--muted); white-space: nowrap; }
.btn.menu-btn { display: none; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--panel-2); color: var(--text);
  font: inherit; font-weight: 600; font-size: 0.9rem; cursor: pointer;
  transition: transform .15s, box-shadow .2s, background .2s; text-decoration: none;
}
.btn:hover { box-shadow: 0 0 18px var(--accent-glow); text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primario { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; color: #fff; }
.btn-peligro { border-color: rgba(239, 68, 68, .5); color: var(--bad); }
.btn-icono { padding: 8px; width: 38px; height: 38px; }
.btn-chico { padding: 6px 10px; font-size: 0.8rem; }
.btn svg { width: 18px; height: 18px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }

/* ---------- Contenedor y paneles ---------- */
.contenido { position: relative; z-index: 1; max-width: 1440px; margin: 0 auto; padding: 22px 20px 60px; }
.encabezado { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.encabezado p { margin: 0; }
.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; position: relative; overflow: hidden;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.panel::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), var(--accent-2), transparent);
  opacity: .6;
}
.panel-titulo { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-titulo h2 { margin: 0; }
.rejilla { display: grid; gap: 16px; }
.r-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.r-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.r-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.r-estrategia { grid-template-columns: minmax(0, 1fr) 380px; align-items: start; }
.mb { margin-bottom: 16px; }

/* ---------- KPI ---------- */
.kpi { padding: 16px 18px; }
.kpi .etiqueta { font-size: 0.75rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.kpi .valor { font-family: var(--font-display); font-size: clamp(1.4rem, 2.6vw, 2rem); font-weight: 700; margin-top: 4px; }
.kpi .valor.acento { background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.kpi .sub { font-size: 0.8rem; color: var(--muted); }

/* ---------- Formularios ---------- */
label { display: block; font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 4px; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--panel-solid); color: var(--text);
  font: inherit; font-size: 0.92rem; outline: none; transition: border .2s, box-shadow .2s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.filtros { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; align-items: end; }
.campo { min-width: 0; }
.switch { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; padding: 3px; background: var(--panel-solid); }
.switch button { white-space: nowrap; border: 0; background: transparent; color: var(--muted); padding: 6px 12px; border-radius: 999px; font: inherit; font-size: 0.85rem; font-weight: 600; cursor: pointer; }
.switch button.activo { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }

/* ---------- Tablas ---------- */
.tabla-wrap { overflow: auto; border-radius: var(--radius-sm); border: 1px solid var(--border); max-height: 560px; }
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--panel-solid); color: var(--muted); font-weight: 600; font-size: 0.74rem; text-transform: uppercase; letter-spacing: .08em; cursor: pointer; user-select: none; z-index: 1; }
tbody tr { transition: background .15s; }
tbody tr:hover { background: var(--panel-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.texto-largo { white-space: normal; min-width: 220px; }

/* ---------- Chips de partido / categoria ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 0.76rem; font-weight: 600; border: 1px solid var(--border); background: var(--panel-2); white-space: nowrap; }
.chip i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; box-shadow: 0 0 8px currentColor; }
.cat-holgada { color: var(--ok); }
.cat-competida { color: var(--warn); }
.cat-recuperable { color: var(--orange); }
.cat-dificil { color: var(--bad); }
.cat-sin { color: var(--muted); }

/* ---------- Tarjetas de gobierno ---------- */
.gob-card { display: flex; gap: 14px; align-items: center; padding: 14px; }
.gob-card .barra { width: 4px; align-self: stretch; border-radius: 4px; }
.gob-card .cargo { font-size: 0.72rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.gob-card .nombre { font-weight: 700; font-size: 1rem; }
.gob-card .det { font-size: 0.8rem; color: var(--muted); }
.lista-gob { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.lista-gob .item { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--panel-2); display: flex; gap: 10px; align-items: center; transition: transform .2s, border .2s; }
.lista-gob .item:hover { transform: translateY(-2px); border-color: var(--border-strong); }
.lista-gob .item .punto { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: 0 0 10px currentColor; }
.lista-gob .item .t1 { font-weight: 600; font-size: 0.88rem; }
.lista-gob .item .t2 { font-size: 0.76rem; color: var(--muted); }

/* ---------- Barras de reparto ---------- */
.reparto { display: flex; height: 14px; border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.reparto span { height: 100%; transition: width 1s cubic-bezier(.2,.8,.2,1); }
.leyenda { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 8px; font-size: 0.8rem; color: var(--muted); }
.leyenda b { color: var(--text); }

/* ---------- Mapa ---------- */
.mapa { height: 560px; border-radius: var(--radius-sm); border: 1px solid var(--border); overflow: hidden; background: var(--bg2); position: relative; }
.leaflet-container { background: var(--bg2) !important; font-family: var(--font) !important; }
.leaflet-tooltip.tt { background: var(--panel-solid); color: var(--text); border: 1px solid var(--border-strong); border-radius: 8px; box-shadow: var(--shadow); font-size: 0.8rem; }
.leaflet-tooltip.tt::before { display: none; }
.leaflet-bar a { background: var(--panel-solid) !important; color: var(--text) !important; border-color: var(--border) !important; }
.vista3d { height: 560px; border-radius: var(--radius-sm); border: 1px solid var(--border); overflow: hidden; position: relative; background: radial-gradient(ellipse at 50% 40%, var(--bg2), var(--bg)); cursor: grab; touch-action: none; }
.vista3d:active { cursor: grabbing; }
.vista3d canvas { display: block; width: 100%; height: 100%; }
.ayuda3d { position: absolute; left: 10px; bottom: 10px; font-size: 0.75rem; color: var(--muted); background: var(--panel); padding: 4px 8px; border-radius: 6px; border: 1px solid var(--border); pointer-events: none; }
.tt3d { position: absolute; pointer-events: none; background: var(--panel-solid); border: 1px solid var(--border-strong); border-radius: 8px; padding: 6px 9px; font-size: 0.8rem; box-shadow: var(--shadow); display: none; z-index: 5; max-width: 260px; }

/* ---------- Detalle de seccion ---------- */
#hist th, #hist td { padding: 6px 7px; }
.detalle h3 { font-family: var(--font-display); font-size: 1.4rem; margin-bottom: 4px; }
.mensaje { padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--panel-2); margin: 10px 0; font-size: 0.92rem; }
.mensaje.holgada { border-color: rgba(34,197,94,.5); }
.mensaje.competida { border-color: rgba(245,158,11,.5); }
.mensaje.recuperable { border-color: rgba(249,115,22,.5); }
.mensaje.dificil { border-color: rgba(239,68,68,.5); }
.barra-voto { display: grid; grid-template-columns: 120px 1fr 64px; gap: 8px; align-items: center; font-size: 0.8rem; margin: 5px 0; }
.barra-voto .b { height: 10px; border-radius: 999px; background: var(--panel-2); overflow: hidden; }
.barra-voto .b span { display: block; height: 100%; border-radius: 999px; transition: width .8s cubic-bezier(.2,.8,.2,1); }

/* ---------- Modal ---------- */
.modal-fondo { position: fixed; inset: 0; background: rgba(2, 6, 18, .6); backdrop-filter: blur(4px); z-index: 100; display: none; align-items: center; justify-content: center; padding: 16px; }
.modal-fondo.abierto { display: flex; animation: aparecer .2s ease; }
.modal { width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; background: var(--panel-solid); border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: var(--shadow), 0 0 40px var(--accent-glow); padding: 20px; }
.modal .pie { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .ancho { grid-column: 1 / -1; }

/* ---------- Avisos ---------- */
.aviso { padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--panel-2); font-size: 0.88rem; margin-bottom: 12px; }
.aviso.error { border-color: rgba(239,68,68,.5); color: var(--bad); }
.aviso.ok { border-color: rgba(34,197,94,.5); color: var(--ok); }
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 200; padding: 12px 16px; border-radius: var(--radius-sm); background: var(--panel-solid); border: 1px solid var(--border-strong); box-shadow: var(--shadow); transform: translateY(20px); opacity: 0; transition: all .3s; pointer-events: none; }
.toast.visible { transform: none; opacity: 1; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; position: relative; z-index: 1; }
.login { width: 100%; max-width: 400px; padding: 30px; }
.login h1 { text-align: center; margin-bottom: 4px; }
.login .marca { justify-content: center; margin-bottom: 18px; font-size: 1.1rem; }
.login form { display: grid; gap: 14px; margin-top: 16px; }

/* ---------- Animaciones ---------- */
@keyframes aparecer { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.anim { opacity: 0; animation: aparecer .6s cubic-bezier(.2,.8,.2,1) forwards; }
.anim:nth-child(2) { animation-delay: .06s; } .anim:nth-child(3) { animation-delay: .12s; } .anim:nth-child(4) { animation-delay: .18s; }
.anim:nth-child(5) { animation-delay: .24s; } .anim:nth-child(6) { animation-delay: .3s; }
.brillo { position: relative; }
.brillo::after { content: ""; position: absolute; inset: 0; background: linear-gradient(110deg, transparent 30%, rgba(255,255,255,.06) 50%, transparent 70%); background-size: 250% 100%; animation: barrido 4s ease-in-out infinite; pointer-events: none; }
@keyframes barrido { 0% { background-position: 150% 0; } 100% { background-position: -100% 0; } }
.cargando { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); padding: 30px; }
.cargando::before { content: ""; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--accent); animation: girar .8s linear infinite; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .anim { opacity: 1; }
}

/* ---------- Responsivo ---------- */
@media (max-width: 1100px) {
  .r-estrategia { grid-template-columns: 1fr; }
  .r-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .topbar { padding: 10px 14px; flex-wrap: wrap; }
  .btn.menu-btn { display: inline-flex; }
  .nav { display: none; order: 3; flex-basis: 100%; flex-direction: column; padding-top: 6px; }
  .nav.abierto { display: flex; }
  .usuario-chip { display: none; }
  .contenido { padding: 16px 16px 50px; }
  .r-2, .r-3 { grid-template-columns: 1fr; }
  .mapa, .vista3d { height: 420px; }
  .form-grid { grid-template-columns: 1fr; }
  .barra-voto { grid-template-columns: 90px 1fr 54px; }
}
@media (max-width: 480px) {
  .r-4 { grid-template-columns: 1fr 1fr; }
  .kpi { padding: 12px; }
  .panel { padding: 14px; }
}
