:root {
  --bg: #0e0f11;
  --panel: #16171a;
  --panel-2: #1c1d21;
  --line: #26272c;
  --grid: #24252a;
  --text: #ececee;
  --muted: #8b8d96;
  --accent: #5b8cff;
  --up: #4ade80;
  --c-fb: #5b8cff;
  --c-ig: #e05db0;
  --c-ads: #f0a429;
  --c-spend: #49c5b6;
  --c-li: #2d9cdb;
  --c-g: #8bc34a;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
h1, h2, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
.muted { color: var(--muted); margin: 2px 0 0; font-size: 13px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.up { color: var(--up); }
.flat { color: var(--muted); }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; padding: 0 6px; }
.brand strong { display: block; font-size: 13.5px; line-height: 1.25; }
.brand small { color: var(--muted); font-size: 12px; }
.logo { flex: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #fff; font: 600 11.5px var(--mono); letter-spacing: 0.02em; }
.logo.big { width: 46px; height: 46px; font-size: 14px; border-radius: 12px; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: #c9cad0; }
nav a:hover { background: var(--panel-2); }
nav a.on { background: var(--panel-2); color: var(--text); }
nav a i, .kpi-label i, .ch i, .legend i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex: none; }
.nav-h { margin: 14px 10px 4px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.side-foot { margin-top: auto; padding: 0 8px; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; }
.side-foot strong { color: var(--text); font-weight: 500; }

.main { padding: 26px 32px 40px; display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.top { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.actions { display: flex; gap: 8px; }
.select { position: relative; display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 0 10px; color: var(--muted); }
.select select { appearance: none; background: transparent; border: 0; color: var(--text); font: inherit; padding: 8px 18px 8px 0; cursor: pointer; }
.select::after { content: "▾"; position: absolute; right: 10px; pointer-events: none; font-size: 11px; }
.select option { background: var(--panel); }
.iconbtn { display: flex; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 9px; padding: 0 12px; font: inherit; cursor: pointer; }
.iconbtn:hover, .select:hover { border-color: #3a3b42; }

.banner { background: color-mix(in srgb, var(--accent) 12%, var(--panel)); border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line)); border-radius: 10px; padding: 10px 14px; font-size: 13px; }
.banner.warn { background: #241d10; border-color: #4a3816; }
.banner summary { cursor: pointer; }
.banner ul { margin: 8px 0 0; padding-left: 18px; color: #d8c7a3; font-family: var(--mono); font-size: 12px; }

/* ---------- cards ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; }
.card-h { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; gap: 12px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.kpi { display: flex; flex-direction: column; gap: 6px; }
.kpi-label { display: flex; align-items: center; gap: 8px; color: #c4c5cc; font-size: 13.5px; }
.kpi-value { font: 600 30px/1.15 var(--mono); letter-spacing: -0.02em; margin: 4px 0 2px; }
.sub { color: var(--muted); font-size: 12px; }
.sub b { font-weight: 500; padding: 1px 6px; border-radius: 6px; background: #1d2a21; margin-right: 4px; }
.sub b.flat { background: var(--panel-2); }

.lectura { border-left: 3px solid var(--accent); }
.pill { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; text-transform: capitalize; }
.md { max-width: 76ch; color: #d9dae0; font-size: 14.5px; }
.md p { margin: 0 0 10px; }
.md ul { margin: 0 0 10px; padding-left: 18px; }
.md li { margin: 4px 0; }
.md strong { color: var(--text); }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs button { background: transparent; border: 1px solid var(--line); color: #c4c5cc; padding: 4px 12px; border-radius: 8px; font: inherit; font-size: 13px; cursor: pointer; }
.tabs button.on { border-color: var(--accent); color: var(--text); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.chart { margin-left: -8px; }
.legend { display: flex; justify-content: center; gap: 18px; margin-top: 8px; font-size: 12.5px; color: #c4c5cc; }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { border-radius: 2px; }

.table-wrap { overflow-x: auto; margin: 0 -20px -18px; }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th { text-align: right; font-weight: 500; font-size: 11.5px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); padding: 10px 20px; border-bottom: 1px solid var(--line); }
td { text-align: right; padding: 13px 20px; border-bottom: 1px solid var(--line); font-family: var(--mono); font-size: 13px; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
tr:last-child td { border-bottom: 0; }
td.name { font-family: inherit; white-space: normal; }
td small { font-size: 11.5px; }
.ch { display: flex; align-items: center; gap: 8px; font-family: Inter, system-ui, sans-serif; font-size: 14px; }
.tag { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; }
.bar { margin-top: 8px; height: 3px; width: 160px; background: var(--panel-2); border-radius: 2px; overflow: hidden; }
.bar span { display: block; height: 100%; }

.posts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.post { display: flex; flex-direction: column; gap: 8px; }
.thumb { aspect-ratio: 4 / 5; border-radius: 10px; overflow: hidden; background: var(--panel-2); display: grid; place-items: center; color: var(--muted); font-size: 12px; border: 1px solid var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.post p { margin: 0; font-size: 13px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.post small { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.post:hover p { text-decoration: underline; }

.foot { color: var(--muted); font-size: 12px; text-align: center; padding-top: 6px; }

/* ---------- login / admin ---------- */
.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(380px, 100%); display: flex; flex-direction: column; gap: 12px; padding: 28px; }
.login.wide { width: min(560px, 100%); }
.login input { background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; color: var(--text); font: inherit; }
.login input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.login button { background: var(--accent); color: #fff; border: 0; border-radius: 9px; padding: 10px; font: 500 14px Inter, sans-serif; cursor: pointer; }
.err { color: #f08a8a; margin: 0; font-size: 13px; }
.clients { list-style: none; padding: 0; margin: 6px 0 0; display: flex; flex-direction: column; gap: 8px; }
.clients li { display: flex; align-items: center; gap: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; }
.clients a { flex: 1; font-weight: 500; }
.clients a:hover { text-decoration: underline; }
.clients code { color: var(--muted); font: 12px var(--mono); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .posts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; align-items: center; justify-content: space-between; padding: 14px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .side nav, .side-foot { display: none; }
  .main { padding: 18px 16px 32px; }
  .top { flex-direction: column; align-items: stretch; }
  .kpi-value { font-size: 24px; }
  .table-wrap { margin: 0 -20px -18px; }
}

/* ---------- PDF (imprimir) ---------- */
@media print {
  :root { --bg: #fff; --panel: #fff; --panel-2: #f2f2f4; --line: #e3e3e8; --grid: #ececf0; --text: #111; --muted: #666; color-scheme: light; }
  .shell { grid-template-columns: 1fr; }
  .side nav, .side-foot, .actions, .tabs, .banner { display: none !important; }
  .side { position: static; height: auto; border: 0; padding: 0 0 8px; }
  .main { padding: 0; }
  .card { break-inside: avoid; }
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .posts { grid-template-columns: repeat(4, 1fr); }
  .md { color: #222; }
}

/* ---------- PHP: extras ---------- */
.chart { position: relative; height: 280px; margin-left: 0; }
.side-foot .back { color: var(--text); margin-bottom: 14px; font-size: 13px; }
.side-foot .back:hover { text-decoration: underline; }
.admin { width: min(920px, 100%); margin: 0 auto; padding: 32px 16px 60px; display: flex; flex-direction: column; gap: 18px; }
.admin-top { display: flex; align-items: center; gap: 12px; }
.admin-top h1 { flex: 1; }
.admin-top a { color: var(--muted); font-size: 13px; }
.admin h2 { margin-bottom: 4px; }
.admin form.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.admin input[type=text], .admin input[type=password], .admin input[type=month], .admin select, .admin textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 9px 12px; color: var(--text); font: inherit; }
.admin input:focus, .admin select:focus, .admin textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.admin textarea { width: 100%; min-height: 180px; resize: vertical; line-height: 1.5; }
.admin .grow { flex: 1; min-width: 220px; }
.btn { background: var(--accent); color: #fff; border: 0; border-radius: 9px; padding: 9px 14px; font: 500 14px Inter, sans-serif; cursor: pointer; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.chk { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 13px; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.status i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); }
.status.ok i { background: var(--up); }
.status.no i { background: #f0a429; }
.flash { background: #15241a; border: 1px solid #23452e; border-radius: 10px; padding: 10px 14px; font-size: 13px; }
.client-row { display: grid; grid-template-columns: 220px 1fr; gap: 14px; padding: 14px 0; border-top: 1px solid var(--line); }
.client-row:first-of-type { border-top: 0; }
.client-row .who { display: flex; gap: 10px; align-items: center; }
.client-row .who a { font-weight: 500; }
.client-row .who a:hover { text-decoration: underline; }
.client-row .who small { display: block; color: var(--muted); font: 11.5px var(--mono); }
.checks td, .checks th { font-family: inherit; text-align: left; white-space: normal; }
.help { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.help code { font: 12px var(--mono); color: var(--text); }
@media (max-width: 700px) { .client-row { grid-template-columns: 1fr; } }
.legal .md { max-width: none; }
.legal .md h4 { margin: 18px 0 6px; font-size: 15px; color: var(--text); }
.legal .md a { color: var(--text); text-decoration: underline; }
