/* ============================================================================
   Observatorio Nacional de Justicia del Peru - Tema Teal & Coral
   ============================================================================ */
:root {
  --navy: #0b1d20;        /* header oscuro */
  --navy-2: #103338;      /* header gradiente */
  --gold: #14b8a6;        /* highlight primario (teal) */
  --gold-2: #2dd4bf;      /* highlight claro (turquesa) */
  --bg: #0c1719;          /* fondo teal oscuro */
  --surface: #112226;     /* paneles */
  --surface-2: #173036;
  --border: #244349;
  --text: #e7f1f0;
  --muted: #8aa6a3;
  --accent: #2dd4bf;      /* enlaces / foco */
  --green: #34d399;       /* ok / datos reales */
  --amber: #fbbf24;       /* advertencia */
  --red: #fb7185;         /* alerta (coral) */
  --shadow: 0 8px 30px rgba(0, 0, 0, .38);
  --radius: 14px;
}
[data-theme="light"] {
  --bg: #eef5f3;
  --surface: #ffffff;
  --surface-2: #e9f3f1;
  --border: #d3e6e2;
  --text: #0c2a2a;
  --muted: #557370;
  --navy: #0b1d20;
  --shadow: 0 8px 24px rgba(12, 42, 42, .08);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Header ---------- */
header.topbar {
  background: linear-gradient(120deg, var(--navy) 0%, var(--navy-2) 60%, #14305f 100%);
  color: #fff;
  border-bottom: 3px solid var(--gold);
  padding: 18px 22px;
  position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow);
}
.topbar-inner { max-width: 1320px; margin: 0 auto; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 13px; }
.brand .scales { font-size: 30px; filter: drop-shadow(0 2px 4px rgba(0,0,0,.3)); }
.brand h1 { font-size: 19px; margin: 0; font-weight: 800; letter-spacing: .2px; }
.brand .sub { font-size: 12px; color: #c9d4ec; margin: 0; }
.topbar-spacer { flex: 1; }
.badge-synthetic {
  background: rgba(241, 196, 15, .15); color: var(--gold-2);
  border: 1px solid rgba(241,196,15,.4); padding: 4px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 700; white-space: nowrap;
}
.icon-btn {
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.18);
  color: #fff; width: 38px; height: 38px; border-radius: 10px; cursor: pointer;
  font-size: 16px; display: grid; place-items: center; transition: .15s; text-decoration: none;
}
.icon-btn:hover { background: rgba(255,255,255,.18); text-decoration: none; }

/* ---------- Apoyo en cabecera ---------- */
.head-support { display: flex; align-items: center; gap: 6px; padding: 0 4px; }
.head-support .sup-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px;
  border-radius: 999px; font-size: 13px; font-weight: 800; cursor: pointer; text-decoration: none;
  border: 1px solid rgba(255,255,255,.18); transition: .15s; white-space: nowrap;
}
.head-support .sup-btn:hover { transform: translateY(-1px); filter: brightness(1.08); text-decoration: none; }
.head-support .sup-coffee { background: linear-gradient(135deg, var(--gold), var(--gold-2)); color: #06201d; }
.head-support .sup-ico {
  width: 34px; height: 34px; border-radius: 999px; display: inline-grid; place-items: center;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18); color: #fff;
  cursor: pointer; font-size: 15px; text-decoration: none; transition: .15s;
}
.head-support .sup-ico:hover { background: rgba(255,255,255,.2); transform: translateY(-1px); }
@media (max-width: 760px) { .head-support .lbl { display: none; } .head-support { gap: 4px; } }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: var(--surface); color: var(--text); border: 1px solid var(--gold);
  padding: 11px 18px; border-radius: 12px; font-size: 13.5px; font-weight: 700;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .25s; z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Apoyo en footer (card prominente) ---------- */
.footer-support-card {
  background: linear-gradient(135deg, rgba(20,184,166,.10), rgba(251,113,133,.08));
  border: 1px solid var(--border); border-radius: 14px; padding: 18px 20px; margin-top: 8px;
}
.footer-support-card a:hover, .footer-support-card button:hover { filter: brightness(1.08); transform: translateY(-1px); }

/* ---------- Nav tabs ---------- */
/* ---------- Layout con SIDEBAR ---------- */
.layout { display: flex; align-items: flex-start; max-width: 1480px; margin: 0 auto; }
.sidebar {
  width: 256px; flex-shrink: 0; position: sticky; top: 70px;
  height: calc(100vh - 70px); overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 14px 10px; z-index: 40;
}
.snav { display: flex; flex-direction: column; gap: 2px; }
.tab {
  background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 10px 12px; font-size: 13.5px; font-weight: 600; text-align: left;
  border-radius: 10px; border-left: 3px solid transparent; transition: .15s; width: 100%;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.active { color: var(--gold); background: var(--surface-2); border-left-color: var(--gold); font-weight: 800; }
/* sub-ítems (gráficos de la sección activa) */
.subitems { display: none; flex-direction: column; margin: 2px 0 6px 14px; padding-left: 8px; border-left: 1px solid var(--border); }
.subitems.open { display: flex; }
.subitems a {
  color: var(--muted); font-size: 12px; padding: 5px 8px; cursor: pointer;
  text-decoration: none; border-radius: 7px; line-height: 1.3;
}
.subitems a:hover { color: var(--text); background: var(--surface-2); }
.card, .chart, .table-wrap { scroll-margin-top: 90px; }

.sidebar-toggle { display: none; }

/* ---------- Layout ---------- */
main { flex: 1; min-width: 0; padding: 24px 22px 80px; }
@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; height: 100vh; width: 270px;
    transform: translateX(-100%); transition: transform .25s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  main { width: 100%; padding-top: 16px; }
  .sidebar-toggle {
    display: inline-flex; position: fixed; top: 12px; left: 12px; z-index: 60;
    background: var(--gold); color: #1a1300; border: none; border-radius: 10px;
    padding: 8px 13px; font-weight: 800; font-size: 13px; cursor: pointer; box-shadow: var(--shadow);
  }
}
.panel { display: none; animation: fade .25s ease; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.section-title { font-size: 17px; font-weight: 800; margin: 6px 0 4px; }
.section-sub { color: var(--muted); font-size: 13px; margin: 0 0 16px; }

/* ---------- KPI cards ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 22px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--gold); }
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.kpi .value { font-size: 27px; font-weight: 800; margin: 6px 0 2px; }
.kpi .hint { font-size: 12px; color: var(--muted); }
.kpi.alert::before { background: var(--red); }
.kpi.warn::before { background: var(--amber); }
.kpi.ok::before { background: var(--green); }

/* ---------- Cards / charts ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.card h3 { margin: 0 0 4px; font-size: 15px; }
.card .card-sub { color: var(--muted); font-size: 12.5px; margin: 0 0 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; }
.chart { width: 100%; height: 340px; }
.chart.tall { height: 420px; }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  background: var(--surface-2); color: var(--muted); text-align: left; padding: 11px 12px;
  font-weight: 700; text-transform: uppercase; font-size: 11px; letter-spacing: .3px;
  position: sticky; top: 0; cursor: pointer; user-select: none; white-space: nowrap;
}
thead th:hover { color: var(--text); }
tbody td { padding: 10px 12px; border-top: 1px solid var(--border); }
tbody tr:hover { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.bar-cell { position: relative; min-width: 120px; }
.bar-cell .bar { position: absolute; left: 0; top: 50%; transform: translateY(-50%); height: 60%; border-radius: 4px; opacity: .25; }
.bar-cell span { position: relative; }

/* ---------- Pills / alerts ---------- */
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.pill.green { background: rgba(46,204,113,.16); color: var(--green); }
.pill.amber { background: rgba(241,196,15,.16); color: var(--amber); }
.pill.red { background: rgba(231,76,60,.16); color: var(--red); }
.pill.blue { background: rgba(79,140,255,.16); color: var(--accent); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 5px; }

/* ---------- Controls ---------- */
.controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
select, input[type="search"], input[type="text"] {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 12px; font-size: 13px; outline: none;
}
select:focus, input:focus { border-color: var(--accent); }
.chip { background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
  border-radius: 999px; padding: 6px 13px; font-size: 12.5px; cursor: pointer; font-weight: 600; }
.chip.active { background: var(--gold); color: #1a1300; border-color: var(--gold); }

/* ---------- Map ---------- */
#map { height: 560px; border-radius: var(--radius); border: 1px solid var(--border); z-index: 1; }
.legend { background: var(--surface); padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); font-size: 12px; line-height: 1.7; box-shadow: var(--shadow); }
.legend i { width: 14px; height: 14px; display: inline-block; margin-right: 7px; border-radius: 3px; opacity: .85; }
.leaflet-popup-content-wrapper { background: var(--surface); color: var(--text); border-radius: 10px; }
.leaflet-popup-tip { background: var(--surface); }
.map-pop b { color: var(--gold); }

/* ---------- Modal (rotaciones) ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(4,8,20,.7); display: none; place-items: center; z-index: 100; padding: 20px; backdrop-filter: blur(3px); }
.modal-bg.open { display: grid; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; max-width: 620px; width: 100%; max-height: 86vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal-head { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: flex-start; gap: 12px; position: sticky; top: 0; background: var(--surface); }
.modal-head .x { margin-left: auto; cursor: pointer; font-size: 22px; color: var(--muted); background: none; border: none; }
.modal-body { padding: 18px 20px; }
.timeline { border-left: 2px solid var(--border); margin-left: 8px; padding-left: 18px; }
.timeline .step { position: relative; padding-bottom: 18px; }
.timeline .step::before { content: ""; position: absolute; left: -25px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--gold); border: 2px solid var(--surface); }
.timeline .step .yr { font-weight: 800; color: var(--gold); font-size: 13px; }
.timeline .step .ct { font-weight: 700; }
.timeline .step .mt { color: var(--muted); font-size: 12px; }

/* ---------- AI assistant ---------- */
.ai-fab { position: fixed; right: 22px; bottom: 22px; z-index: 90;
  background: linear-gradient(135deg, var(--gold), var(--gold-2)); color: #2a1d00;
  border: none; border-radius: 999px; padding: 13px 18px; font-weight: 800; font-size: 14px;
  cursor: pointer; box-shadow: var(--shadow); display: flex; gap: 8px; align-items: center; }
.ai-fab:hover { transform: translateY(-2px); }
.ai-panel { position: fixed; right: 22px; bottom: 78px; width: 370px; max-width: calc(100vw - 30px);
  height: 520px; max-height: calc(100vh - 120px); background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow); display: none; flex-direction: column; z-index: 95; overflow: hidden; }
.ai-panel.open { display: flex; }
.ai-head { background: linear-gradient(120deg, var(--navy), var(--navy-2)); color: #fff; padding: 14px 16px; display: flex; align-items: center; gap: 9px; }
.ai-head .x { margin-left: auto; background: none; border: none; color: #fff; font-size: 20px; cursor: pointer; }
.ai-msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { padding: 10px 13px; border-radius: 13px; font-size: 13.5px; max-width: 88%; }
.msg.bot { background: var(--surface-2); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.bot ul, .msg.bot ol { margin: 6px 0; padding-left: 20px; }
.msg.bot li { margin: 2px 0; }
.msg.bot code { background: rgba(255,255,255,.1); padding: 1px 5px; border-radius: 5px; font-size: 12px; }
.msg.bot strong { color: var(--gold-2); }
.msg.bot a { color: var(--accent); }
.msg.user { background: var(--accent); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.ai-suggest { display: flex; gap: 7px; flex-wrap: wrap; padding: 0 14px 10px; }
.ai-suggest .chip { font-size: 11.5px; }
.ai-input { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--border); }
.ai-input input { flex: 1; }
.ai-input button { background: var(--gold); color: #2a1d00; border: none; border-radius: 9px; padding: 0 15px; font-weight: 800; cursor: pointer; }

/* ---------- Footer ---------- */
footer { border-top: 1px solid var(--border); background: var(--surface); padding: 26px 18px; color: var(--muted); font-size: 13px; }
.footer-inner { max-width: 1320px; margin: 0 auto; display: flex; flex-wrap: wrap; gap: 20px; justify-content: space-between; }
.footer-inner h4 { color: var(--text); margin: 0 0 8px; font-size: 13px; }
.disclaimer { position: relative; background: rgba(241,196,15,.08); border: 1px solid rgba(241,196,15,.25); border-radius: 10px; padding: 12px 36px 12px 14px; margin-bottom: 18px; font-size: 12.5px; color: var(--gold-2); transition: padding .2s, background .2s; cursor: default; }
.disclaimer .disc-mini { display: none; }
.disclaimer.collapsed { padding: 8px 14px; cursor: pointer; background: rgba(241,196,15,.06); }
.disclaimer.collapsed .disc-full { display: none; }
.disclaimer.collapsed .disc-x { display: none; }
.disclaimer.collapsed .disc-mini { display: block; }
.disc-x { position: absolute; top: 6px; right: 8px; background: none; border: none; color: var(--gold-2); font-size: 18px; line-height: 1; cursor: pointer; opacity: .7; padding: 2px 6px; }
.disc-x:hover { opacity: 1; }
.loading { text-align: center; color: var(--muted); padding: 60px; font-size: 15px; }
.spin { display: inline-block; width: 18px; height: 18px; border: 3px solid var(--border); border-top-color: var(--gold); border-radius: 50%; animation: r 1s linear infinite; vertical-align: -3px; margin-right: 8px; }
@keyframes r { to { transform: rotate(360deg); } }
