:root {
  --bg: #f5f7f6;
  --panel: #ffffff;
  --ink: #15201d;
  --ink-2: #4a5a55;
  --ink-3: #82918c;
  --line: #e2e8e5;
  --brand: #0f6b5c;
  --brand-2: #0b5247;
  --brand-soft: #e3f2ee;
  --accent: #e8833a;
  --ok: #1e8a4c;
  --warn: #b7791f;
  --err: #c0392b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 30, 26, .06), 0 4px 16px rgba(16, 30, 26, .06);
  --sidebar: 220px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px; color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 14px; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }

/* Botones e inputs */
button, .btn {
  font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
button:hover { border-color: #c6d2ce; background: #fafcfb; }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--brand-2); }
button.accent { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.ghost { border-color: transparent; background: transparent; }
button.danger { color: var(--err); }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea {
  font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
input[type=checkbox] { width: auto; accent-color: var(--brand); }
label.f { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin: 10px 0 4px; }
textarea { min-height: 80px; resize: vertical; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

/* Layout */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; height: 100vh; }
.side { background: #0f201c; color: #cfe0db; display: flex; flex-direction: column; padding: 16px 10px; }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; color: #fff; padding: 4px 10px 18px; }
.logo .dot { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, #2bb59c, var(--accent)); }
.nav a { display: flex; align-items: center; gap: 10px; color: #cfe0db; padding: 9px 12px; border-radius: 8px; margin-bottom: 2px; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.nav a.on { background: rgba(43,181,156,.18); color: #fff; font-weight: 600; }
.side .pie { margin-top: auto; font-size: 12px; padding: 10px; border-top: 1px solid rgba(255,255,255,.08); }
.side .pie b { color: #fff; }
.main { overflow: auto; display: flex; flex-direction: column; min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; padding: 14px 22px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.content { padding: 18px 22px; flex: 1; min-height: 0; }
.banner { padding: 10px 22px; background: #fff4e5; color: #7a4b0c; border-bottom: 1px solid #f5d9ad; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.kpi .v { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.kpi .l { color: var(--ink-3); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }

/* Buscar */
.buscar { display: grid; grid-template-columns: 300px 1fr; gap: 16px; height: calc(100vh - 100px); }
.filtros { overflow: auto; }
.filtros .card { padding: 12px 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; padding: 4px 9px; border-radius: 999px; border: 1px solid var(--line); background: #fff; cursor: pointer; user-select: none; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip .x { margin-left: 4px; opacity: .7; }
.lista-mun { max-height: 160px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; margin-top: 6px; }
.lista-mun label { display: flex; gap: 6px; align-items: center; padding: 2px 0; font-size: 13px; }
.sugerencias { border: 1px solid var(--line); border-radius: 8px; margin-top: 4px; max-height: 200px; overflow: auto; background: #fff; }
.sugerencias div { padding: 6px 8px; cursor: pointer; font-size: 12px; }
.sugerencias div:hover { background: var(--brand-soft); }
.resultados { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; padding: 8px 12px; color: var(--ink-2); }
.tabs button.on { border-bottom-color: var(--brand); color: var(--ink); font-weight: 600; }
.panel-tab { flex: 1; min-height: 0; overflow: auto; }
#mapa { height: 100%; min-height: 420px; border-radius: var(--radius); border: 1px solid var(--line); }

table.t { width: 100%; border-collapse: collapse; background: var(--panel); }
table.t th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); padding: 8px 10px; border-bottom: 1px solid var(--line); background: #fafcfb; position: sticky; top: 0; }
table.t td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t tr:hover td { background: #fafcfb; }
table.t tr.click { cursor: pointer; }
.nombre { font-weight: 600; }
.sub { color: var(--ink-3); font-size: 12px; }
.ico { display: inline-flex; gap: 4px; }
.ico span { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--brand-soft); color: var(--brand-2); }
.ico span.no { background: #f1f3f2; color: #b3bdb9; }
.score { display: inline-block; min-width: 34px; text-align: center; font-weight: 700; padding: 2px 6px; border-radius: 6px; font-size: 12px; }
.s-hi { background: #dff3e7; color: #17663a; } .s-md { background: #fff1d6; color: #8a5a10; } .s-lo { background: #f1f3f2; color: #6b7773; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: #eef1f0; color: var(--ink-2); white-space: nowrap; }
.badge.b-ok { background: #dff3e7; color: #17663a; } .badge.b-err { background: #fbe3e0; color: #9c2b1f; } .badge.b-brand { background: var(--brand-soft); color: var(--brand-2); }
.barra { position: sticky; bottom: 0; background: var(--panel); border-top: 1px solid var(--line); padding: 10px; display: flex; gap: 10px; align-items: center; }
.paginacion { display: flex; gap: 6px; align-items: center; }

/* Barras de mercado */
.hbar { display: grid; grid-template-columns: 140px 1fr 70px; gap: 8px; align-items: center; margin: 4px 0; font-size: 13px; }
.hbar .b { height: 10px; background: var(--brand-soft); border-radius: 5px; overflow: hidden; }
.hbar .b i { display: block; height: 100%; background: var(--brand); border-radius: 5px; }
.hbar .n { text-align: right; font-variant-numeric: tabular-nums; }

/* Kanban */
.kanban { display: grid; grid-template-columns: repeat(7, minmax(210px, 1fr)); gap: 10px; overflow-x: auto; height: calc(100vh - 150px); }
.col { background: #eef2f0; border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; }
.col h3 { padding: 10px 12px 6px; margin: 0; display: flex; justify-content: space-between; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); }
.col .cards { padding: 6px; overflow: auto; flex: 1; min-height: 60px; }
.col.drop { outline: 2px dashed var(--brand); }
.kcard { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; margin-bottom: 6px; cursor: grab; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.kcard:hover { border-color: #b9c9c3; }
.kcard .nombre { font-size: 13px; }

/* Drawer */
.velo { position: fixed; inset: 0; background: rgba(10, 20, 18, .35); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: var(--panel); z-index: 41; box-shadow: -8px 0 30px rgba(0,0,0,.12); display: flex; flex-direction: column; }
.drawer .hd { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.drawer .bd { padding: 16px 18px; overflow: auto; flex: 1; }
.timeline .it { border-left: 2px solid var(--line); padding: 0 0 12px 12px; margin-left: 6px; position: relative; }
.timeline .it::before { content: ""; position: absolute; left: -6px; top: 3px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.timeline .it.sistema::before { background: #b3bdb9; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 4px 10px; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #15201d; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 60; box-shadow: var(--shadow); max-width: 90vw; }
.toast.err { background: var(--err); }
.vacio { text-align: center; padding: 40px 20px; color: var(--ink-3); }
.cargando { opacity: .55; pointer-events: none; }
.fuente { font-size: 11px; color: var(--ink-3); margin-top: 8px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { flex-direction: row; overflow-x: auto; padding: 8px; }
  .side .pie, .logo span { display: none; }
  .nav { display: flex; }
  .buscar { grid-template-columns: 1fr; height: auto; }
  .grid4 { grid-template-columns: 1fr 1fr; }
}
