:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --subtle: #f5f5f5;
  --hover: #f4f4f5;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --text: #18181b;
  --text-2: #52525b;
  --text-3: #71717a;
  --accent: #0f766e;
  --ok: #15803d; --ok-bg: #f0fdf4; --ok-bd: #bbf7d0;
  --warn: #a16207; --warn-bg: #fefce8; --warn-bd: #fde68a;
  --late: #c2410c; --late-bg: #fff7ed; --late-bd: #fed7aa;
  --bad: #b91c1c; --bad-bg: #fef2f2; --bad-bd: #fecaca;
  --info: #1d4ed8; --info-bg: #eff6ff; --info-bd: #bfdbfe;
  --vip: #6d28d9; --vip-bg: #f5f3ff; --vip-bd: #ddd6fe;
  --radius: 8px;
}
* { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; }
body {
  margin: 0;
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 13.5px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }
button { font: inherit; color: inherit; }
svg.i { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Estructura ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 14px 10px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 14px; padding: 4px 8px 16px; letter-spacing: -.01em; }
.brand-mark {
  display: grid; place-items: center; width: 24px; height: 24px; border-radius: 6px;
  background: var(--text); color: #fff; font-size: 11px; font-weight: 700; letter-spacing: .02em;
}
.brand-lg { justify-content: center; font-size: 15px; padding: 0 0 6px; }
.nav-label { font-size: 11.5px; font-weight: 500; color: var(--text-3); padding: 12px 8px 4px; }
.nav { display: flex; flex-direction: column; gap: 1px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  border: 0; background: transparent; color: var(--text-2);
  padding: 7px 8px; border-radius: 6px; cursor: pointer; text-align: left; font-weight: 500;
}
.nav-item:hover, .nav-item.active { background: var(--hover); color: var(--text); }
.nav-item.active svg.i { color: var(--accent); }
.nav-count { margin-left: auto; font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.nav-count:empty { display: none; }
.nav-count.alert { color: var(--bad); font-weight: 600; }
.sidebar-foot { border-top: 1px solid var(--border); padding: 12px 8px 2px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sidebar-foot .who { font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.content { min-width: 0; }
.page-head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 16px 32px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.page-head h1 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -.01em; }
.page-head p { margin: 2px 0 0; font-size: 12.5px; color: var(--text-3); }
.view { padding: 24px 32px 48px; max-width: 1320px; }
.muted-text { color: var(--text-2); }
.muted { color: var(--text-3); font-size: 12.5px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 500; font-size: 13px;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--hover); border-color: var(--border-strong); }
.btn.primary { background: var(--text); border-color: var(--text); color: #fff; }
.btn.primary:hover { background: #3f3f46; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger:hover { background: #991b1b; }
.btn.block { width: 100%; height: 38px; }
.btn.icon { width: 32px; padding: 0; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, .nav-item:focus-visible, .tab:focus-visible, .metric:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- Métricas ---------- */
.metrics {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.metric {
  padding: 14px 18px; border: 0; border-right: 1px solid var(--border); background: transparent;
  text-align: left; display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.metric:last-child { border-right: 0; }
button.metric { cursor: pointer; }
button.metric:hover { background: var(--subtle); }
.metric-label { font-size: 12.5px; color: var(--text-2); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.metric-value { font-size: 22px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.3; }
.metric-value.bad { color: var(--bad); }
.metric-value.late { color: var(--late); }
.metric-hint { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex: none; }
.dot.ok { background: #22c55e; } .dot.warn { background: #eab308; } .dot.late { background: #f97316; }
.dot.bad { background: #ef4444; } .dot.info { background: #3b82f6; } .dot.vip { background: #8b5cf6; }
.section { margin-top: 28px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.section-head h2 { margin: 0; font-size: 13.5px; font-weight: 600; }
.section-head > div { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.billing-head { align-items: center; gap: 12px; }
.billing-head .btn { flex: none; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ---------- Paneles ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.panel-head { min-height: 46px; padding: 7px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.panel-head h3 { margin: 0; font-size: 13.5px; font-weight: 600; }
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: 0; }
.list-row .main { font-weight: 500; }
.list-row .sub { font-size: 12px; color: var(--text-3); }

/* ---------- Filtros ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.search-wrap { position: relative; flex: 1 1 280px; max-width: 420px; }
.search-wrap svg.i { position: absolute; left: 10px; top: 8px; color: var(--text-3); }
.search {
  width: 100%; height: 32px; padding: 0 10px 0 32px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); font: inherit;
}
input:focus, textarea:focus, select:focus { outline: 2px solid #99f6e4; outline-offset: -1px; border-color: var(--accent); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 8px 0 16px; overflow-x: auto; scrollbar-width: none; }
.tab {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  border: 0; background: transparent; padding: 9px 10px; margin-bottom: -1px;
  color: var(--text-2); font-weight: 500; cursor: pointer; border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--text); }
.tab .n { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.tab.alert .n { color: var(--bad); font-weight: 600; }
.segmented { display: inline-flex; padding: 2px; border-radius: 7px; background: var(--hover); }
.segmented button { border: 0; background: transparent; height: 28px; padding: 0 10px; border-radius: 5px; cursor: pointer; font-weight: 500; color: var(--text-2); }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--border); }

/* ---------- Tablas ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
th { font-size: 12px; font-weight: 500; color: var(--text-3); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fcfcfc; }
td:first-child { white-space: normal; }
td .main { font-weight: 500; }
td:first-child .main { overflow-wrap: break-word; min-width: 200px; }
.tnum { font-variant-numeric: tabular-nums; }
td .sub { font-size: 12px; color: var(--text-3); margin-top: 1px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-foot { padding: 10px 14px; color: var(--text-3); font-size: 12px; border-top: 1px solid var(--border); }
/* La columna de acciones queda fija a la derecha aunque la tabla tenga scroll. */
th:last-child, td:last-child { position: sticky; right: 0; background: var(--surface); z-index: 1; }
tbody tr:hover td:last-child { background: #fcfcfc; }
td:last-child:has(details[open]) { z-index: 40; }

/* ---------- Estados ---------- */
.badge {
  display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 5px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
  background: var(--subtle); color: var(--text-2); border: 1px solid var(--border);
}
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-bd); }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-bd); }
.badge.late { background: var(--late-bg); color: var(--late); border-color: var(--late-bd); }
.badge.bad { background: var(--bad-bg); color: var(--bad); border-color: var(--bad-bd); }
.badge.info { background: var(--info-bg); color: var(--info); border-color: var(--info-bd); }
.badge.vip { background: var(--vip-bg); color: var(--vip); border-color: var(--vip-bd); }
.kind { font-size: 12.5px; color: var(--text-2); display: inline-flex; align-items: center; gap: 6px; }
.kind svg.i { width: 14px; height: 14px; color: var(--text-3); }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; letter-spacing: .02em; }

/* ---------- Acciones ---------- */
.row-actions { display: flex; gap: 6px; align-items: center; justify-content: flex-end; }
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-list {
  position: fixed; z-index: 50; width: 232px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .08), 0 1px 2px rgba(0, 0, 0, .04);
  padding: 4px; display: flex; flex-direction: column;
}
.menu-list button { border: 0; background: transparent; text-align: left; padding: 7px 9px; border-radius: 5px; cursor: pointer; }
.menu-list button:hover { background: var(--hover); }
.menu-list button.danger-text { color: var(--bad); }

/* ---------- Formularios ---------- */
.form-panel { padding: 16px; margin-bottom: 20px; }
.form-panel h3 { margin: 0 0 12px; font-size: 13.5px; font-weight: 600; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.field input, .field textarea, .field select, #dialog-input {
  font: inherit; color: var(--text); height: 32px; padding: 0 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface);
}
.field textarea { height: auto; padding: 8px 10px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .span-2 { grid-column: span 2; }
.checkbox { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.checkbox input { height: auto; }
.callout { padding: 14px 16px; margin-bottom: 20px; display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.callout pre { margin: 6px 0 0; font-size: 15px; line-height: 1.6; }

/* ---------- Vacíos y avisos ---------- */
.empty { color: var(--text-3); padding: 40px 16px; text-align: center; }
.empty strong { display: block; color: var(--text); font-weight: 500; margin-bottom: 2px; }
.error { color: var(--bad); margin-top: 12px; }
.skeleton { height: 76px; border-radius: var(--radius); background: var(--hover); }

.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--text); color: #fff; padding: 9px 14px; border-radius: 7px; font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .15); max-width: 360px;
}
.toast.error { background: var(--bad); }

.dialog { border: 1px solid var(--border); border-radius: 10px; padding: 0; width: min(420px, calc(100vw - 32px)); box-shadow: 0 16px 48px rgba(0, 0, 0, .18); color: var(--text); }
.dialog::backdrop { background: rgba(24, 24, 27, .35); }
.dialog form { padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.dialog h3 { margin: 0; font-size: 15px; font-weight: 600; }
.dialog p { margin: 0; color: var(--text-2); white-space: pre-line; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* ---------- Login ---------- */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { background: var(--surface); padding: 28px; border-radius: 10px; border: 1px solid var(--border); max-width: 360px; width: 100%; }
.login-card h2 { margin: 14px 0 2px; font-size: 18px; font-weight: 600; text-align: center; }
.login-card > .muted-text { text-align: center; margin: 0; color: var(--text-3); }
.login-form { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }
.login-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.login-form input { height: 36px; padding: 0 10px; border: 1px solid var(--border); border-radius: 6px; font: inherit; }

/* ---------- Tutoriales ---------- */
.tutorial-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.tutorial-card { overflow: hidden; }
.tutorial-thumb { position: relative; aspect-ratio: 16 / 9; background: var(--hover); border-bottom: 1px solid var(--border); }
.tutorial-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tutorial-thumb .badge { position: absolute; top: 8px; left: 8px; }
.tutorial-body { padding: 12px 14px 14px; }
.tutorial-body h4 { margin: 2px 0 4px; font-size: 13.5px; font-weight: 600; }
.tutorial-body p { margin: 0 0 6px; color: var(--text-2); font-size: 12.5px; }
.tutorial-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.cat { font-size: 12px; color: var(--text-3); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: sticky; z-index: 30; height: auto; flex-direction: row; align-items: center; gap: 6px; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--border); overflow-x: auto; }
  .sidebar .brand { padding: 0; }
  .sidebar .brand span:last-child, .nav-label, .sidebar-foot .who { display: none; }
  .nav { flex-direction: row; gap: 2px; }
  .nav-item { white-space: nowrap; width: auto; }
  .nav-item .lbl { display: none; }
  .nav-item.active .lbl { display: inline; }
  .sidebar-foot { border: 0; padding: 0; }
  .page-head { padding: 14px 16px; }
  .view { padding: 16px 16px 40px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric { border-bottom: 1px solid var(--border); }
  .metric:nth-child(2n) { border-right: 0; }
  .grid-2, .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
}

/* Textos de confirmación con varias líneas (por ejemplo, al eliminar una cuenta). */
#dialog-text { white-space: pre-line; }
