:root {
  --bg: #07090d;
  --bg-2: #0b0e14;
  --panel: #11151e;
  --panel-2: #161b26;
  --border: #222a39;
  --border-soft: #1a212e;
  --text: #eef1f6;
  --muted: #8a93a6;
  --muted-2: #5e6679;
  --accent: #6366f1;
  --accent-2: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.35);
  --success: #34d399;
  --danger: #f87171;
  --warn: #fbbf24;
  --radius: 16px;
  --radius-sm: 11px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.sm { font-size: 0.82rem; }
.num { text-align: right; font-family: 'JetBrains Mono', monospace; font-variant-numeric: tabular-nums; }
.error { color: var(--danger); font-size: 0.85rem; margin-top: 10px; }
.block { width: 100%; }
.field-label { display: block; font-size: 0.8rem; color: var(--muted); margin: 16px 0 0; font-weight: 500; }

/* brand */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.06rem; letter-spacing: -0.02em; }
.brand-lg { font-size: 1.3rem; margin-bottom: 6px; }
.orb {
  width: 12px; height: 12px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, var(--accent-2), var(--accent));
  box-shadow: 0 0 0 4px var(--accent-glow), 0 0 18px var(--accent-glow);
  flex: none;
}

/* buttons */
.btn {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: 10px 17px; border-radius: var(--radius-sm); font: inherit; font-weight: 600;
  cursor: pointer; transition: all .15s ease; display: inline-flex; align-items: center; gap: 7px;
  justify-content: center;
}
.btn:hover { border-color: #34405a; background: #1b2230; }
.btn.sm { padding: 7px 13px; font-size: 0.82rem; }
.btn.primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  border-color: transparent; color: white; box-shadow: 0 4px 14px -4px var(--accent-glow);
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }

input, select {
  width: 100%; background: var(--bg-2); border: 1px solid var(--border); color: var(--text);
  padding: 12px 14px; border-radius: var(--radius-sm); font: inherit; margin-top: 7px;
  transition: border-color .15s;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
select { width: auto; margin-top: 0; cursor: pointer; }

/* gate */
.gate {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: radial-gradient(900px 500px at 50% -5%, rgba(99,102,241,0.12), transparent), var(--bg);
}
.gate-card {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--border); border-radius: 20px;
  padding: 38px; width: 380px; box-shadow: 0 40px 90px rgba(0,0,0,0.55);
}
.gate-card p { margin-bottom: 6px; }
.gate-card .btn { margin-top: 18px; }

/* layout */
.layout { display: grid; grid-template-columns: 244px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--bg-2); border-right: 1px solid var(--border-soft);
  padding: 24px 18px; display: flex; flex-direction: column; gap: 26px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { padding: 0 8px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 13px; border-radius: 10px;
  background: transparent; border: none; color: var(--muted); font: inherit; font-weight: 600;
  font-size: 0.92rem; cursor: pointer; transition: all .15s; text-align: left;
}
.nav-item svg { width: 19px; height: 19px; flex: none; }
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active { background: var(--panel-2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }

/* main */
.main { padding: 32px 40px; max-width: 1180px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 28px; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 1.55rem; font-weight: 700; letter-spacing: -0.02em; }
.page-head .muted { margin-top: 3px; text-transform: capitalize; }
.controls { display: flex; gap: 10px; align-items: center; }
.section-head { margin: 6px 0 16px; }
.section-head h2 { font-size: 1.05rem; font-weight: 650; }

/* kpis */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 36px; }
.kpi {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 20px;
  position: relative; overflow: hidden;
}
.kpi .ic {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  background: var(--panel-2); color: var(--accent-2); margin-bottom: 16px;
}
.kpi .ic svg { width: 20px; height: 20px; }
.kpi .label { color: var(--muted); font-size: 0.82rem; font-weight: 500; }
.kpi .value { font-family: 'JetBrains Mono', monospace; font-size: 2.1rem; font-weight: 700; margin-top: 6px; letter-spacing: -0.03em; }
.kpi .sub { color: var(--muted-2); font-size: 0.76rem; margin-top: 5px; }
.kpi.hero { background: linear-gradient(150deg, rgba(99,102,241,0.18), var(--bg-2) 70%); border-color: rgba(99,102,241,0.3); }
.kpi.hero .ic { background: var(--accent); color: white; }
.kpi.hero .value { color: #fff; }

/* apps grid */
.apps-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 16px; }
.app-card {
  background: var(--panel); border: 1px solid var(--border-soft); border-radius: var(--radius);
  padding: 20px; transition: border-color .15s, transform .15s;
}
.app-card:hover { border-color: var(--border); transform: translateY(-2px); }
.app-card .top { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.avatar {
  width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center;
  font-weight: 700; font-size: 1.05rem; color: #fff; flex: none;
  background: linear-gradient(140deg, var(--accent-2), var(--accent));
}
.app-card .name { font-weight: 650; font-size: 1.02rem; }
.pill { font-size: 0.7rem; font-weight: 600; padding: 3px 9px; border-radius: 999px; display: inline-flex; align-items: center; gap: 5px; margin-top: 3px; }
.pill.on { color: var(--success); background: rgba(52,211,153,0.1); }
.pill.off { color: var(--muted); background: var(--panel-2); }
.pill .d { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.app-card .consumed { font-family: 'JetBrains Mono', monospace; font-size: 1.9rem; font-weight: 700; letter-spacing: -0.02em; }
.app-card .consumed small { font-size: 0.8rem; color: var(--muted); font-weight: 500; margin-left: 6px; font-family: 'Inter'; }
.bar { height: 8px; background: var(--bg); border-radius: 999px; margin-top: 14px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 999px; transition: width .5s ease; }
.bar > span.warn { background: linear-gradient(90deg, #f59e0b, var(--warn)); }
.bar > span.full { background: linear-gradient(90deg, #dc2626, var(--danger)); }
.quota-label { color: var(--muted); font-size: 0.8rem; margin-top: 9px; }
.app-card .actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border-soft); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: rgba(248,113,113,0.12); border-color: rgba(248,113,113,0.4); }

/* status pills (timbres) */
.st { font-size: 0.73rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.st-on { color: var(--success); background: rgba(52,211,153,0.12); }
.st-off { color: var(--muted); background: var(--panel-2); }
.st-err { color: var(--danger); background: rgba(248,113,113,0.12); }
.st-warn { color: var(--warn); background: rgba(251,191,36,0.12); }

.pending-banner { background: rgba(251,191,36,0.1); border: 1px solid rgba(251,191,36,0.35); color: var(--warn); padding: 13px 16px; border-radius: 12px; margin-bottom: 16px; font-size: 0.9rem; }
.empty { color: var(--muted); padding: 30px; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); }

/* panel + table */
.panel { background: var(--panel); border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 8px 6px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 16px; text-align: left; border-bottom: 1px solid var(--border-soft); font-size: 0.92rem; }
tbody tr:last-child td { border-bottom: none; }
th { color: var(--muted); font-weight: 600; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.05em; }
tbody tr:hover { background: var(--panel-2); }
td.num, th.num { text-align: right; font-family: 'JetBrains Mono', monospace; }

/* modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(4,6,10,0.7); backdrop-filter: blur(4px); display: grid; place-items: center; z-index: 20; padding: 20px; }
.modal { background: linear-gradient(180deg, var(--panel), var(--bg-2)); border: 1px solid var(--border); border-radius: 20px; padding: 30px; width: 440px; position: relative; box-shadow: 0 40px 90px rgba(0,0,0,0.6); }
.modal h3 { margin-bottom: 6px; font-size: 1.2rem; }
.modal-x { position: absolute; top: 18px; right: 18px; background: none; border: none; color: var(--muted); font-size: 1.1rem; cursor: pointer; line-height: 1; }
.modal-x:hover { color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.key-result { text-align: center; }
.key-ok { color: var(--success); font-weight: 700; font-size: 1.15rem; margin-bottom: 14px; }
.key-result p { text-align: left; }
.key-box { display: flex; gap: 8px; align-items: center; margin: 12px 0 20px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 13px; }
.key-box code { font-family: 'JetBrains Mono', monospace; font-size: 0.82rem; color: var(--accent-2); word-break: break-all; flex: 1; text-align: left; }

/* badge */
.badge { font-size: 0.7rem; font-weight: 600; padding: 6px 11px; border-radius: 8px; border: 1px solid var(--border); text-align: center; letter-spacing: 0.03em; }
.badge.mock { color: var(--warn); border-color: rgba(251,191,36,0.3); background: rgba(251,191,36,0.07); }
.badge.real { color: var(--success); border-color: rgba(52,211,153,0.3); background: rgba(52,211,153,0.07); }

/* toast */
.toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--border); padding: 13px 22px; border-radius: 12px; box-shadow: 0 16px 50px rgba(0,0,0,0.5); z-index: 30; font-size: 0.9rem; font-weight: 500; }
.toast.ok { border-color: rgba(52,211,153,0.4); }
.toast.err { border-color: rgba(248,113,113,0.4); }

@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; }
  .nav { flex-direction: row; }
  .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; }
  .main { padding: 24px 20px; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}

/* ===== Tema claro (modo día) ===== */
body.light {
  --bg: #eef0f4;
  --bg-2: #ffffff;
  --panel: #ffffff;
  --panel-2: #f3f5f9;
  --border: #d4d9e2;
  --border-soft: #e7eaf0;
  --text: #1a2230;
  --muted: #5a6373;
  --muted-2: #8b94a4;
  --accent: #6366f1;
  --accent-2: #4f46e5;
  --accent-glow: rgba(99, 102, 241, 0.22);
}
body.light .btn:not(.primary):hover { background: var(--panel-2); border-color: var(--border); }
body.light .kpi.hero { background: linear-gradient(150deg, rgba(99,102,241,0.14), var(--bg-2) 70%); }
body.light .kpi.hero .value { color: var(--accent-2); }
body.light .gate-card,
body.light .modal { box-shadow: 0 20px 60px rgba(40, 50, 90, 0.18); }
body.light .toast { box-shadow: 0 16px 50px rgba(40, 50, 90, 0.18); }
body.light .nav-item.active { box-shadow: inset 2px 0 0 var(--accent); }
