:root {
  --bg: #f6f3ed;
  --paper: #fffdf8;
  --panel: #ffffff;
  --ink: #181716;
  --muted: #736d64;
  --line: #ded8ce;
  --soft: #ebe5da;
  --gold: #9f7e3f;
  --green: #3f8f67;
  --red: #b7564b;
  --blue: #496f9f;
  --shadow: 0 18px 50px rgba(48, 40, 28, 0.12);
}

* { box-sizing: border-box; }
html {
  min-height: 100%;
  background: #151412;
}

/* Las reglas de clase de abajo (display: grid, block…) le ganan al
   `display: none` que el navegador aplica a [hidden]: sin este !important,
   esconder algo con el atributo no surte efecto. */
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select {
  font: inherit;
  font-size: 16px;
}

.sidebar {
  width: 280px;
  min-height: 100vh;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  position: sticky;
  top: 0;
  background: #151412;
  color: #f6f3ed;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  color: #e7c46f;
  font-weight: 800;
  font-size: 22px;
}

.brand-mark.admin-logo {
  border-radius: 999px;
  background: #f6f3ed;
  border-color: rgba(246, 243, 237, 0.42);
  color: #151412;
  font-family: Georgia, "Times New Roman", serif;
}

.admin-lockup {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.admin-lockup strong,
.admin-lockup span {
  display: block;
}

.admin-lockup strong {
  color: #151412;
  font-size: 19px;
  line-height: 1;
}

.admin-lockup span {
  margin-top: 3px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.brand strong { display: block; font-size: 18px; }
.brand span { display: block; color: #a9a199; font-size: 12px; margin-top: 2px; }

.nav { display: grid; gap: 6px; }

.nav-item {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  text-align: left;
  color: #d9d1c5;
  background: transparent;
  cursor: pointer;
}

.nav-item:hover,
.nav-item.active {
  color: #fff8ea;
  background: rgba(255, 255, 255, 0.08);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #a9a199;
  font-size: 12px;
  line-height: 1.4;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--green);
  flex: 0 0 auto;
}

.shell {
  min-width: 0;
  flex: 1;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--gold);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 800;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 34px; letter-spacing: -0.02em; }
h2 { margin-bottom: 4px; font-size: 18px; }
h3 { margin-bottom: 8px; font-size: 18px; }
p { color: var(--muted); line-height: 1.5; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

input[type="search"] {
  width: min(36vw, 420px);
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--paper);
  color: var(--ink);
}

button.primary,
button.secondary,
button.ghost {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 8px;
  cursor: pointer;
}

button.primary {
  border: 1px solid #151412;
  background: #151412;
  color: #fff8ea;
}

button.secondary {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
}

button.ghost {
  border: 0;
  background: transparent;
  color: var(--gold);
}

.section { display: none; }
.section.active { display: block; }

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 18px;
}

.metric span,
.metric small {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin: 8px 0 6px;
  font-size: 32px;
  letter-spacing: -0.03em;
}

.metric.attention strong { color: var(--red); }

.content-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 18px;
}

.span-2 { grid-column: span 1; }

.panel {
  padding: 18px;
  overflow: hidden;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--soft);
  font-size: 14px;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

.badge.success { background: #dcece2; color: var(--green); }
.badge.warning { background: #fff1c7; color: #8b6721; }
.badge.danger { background: #f5d9d5; color: var(--red); }
.badge.info { background: #dfe8f5; color: var(--blue); }

.risk-list,
.stack-list,
.timeline {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.risk-item,
.stack-list li,
.timeline li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-radius: 8px;
  background: var(--paper);
  border: 1px solid var(--soft);
}

.risk-item strong,
.stack-list strong {
  white-space: nowrap;
}

.board-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.chip {
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 999px;
  min-height: 34px;
  padding: 0 13px;
  cursor: pointer;
}

.chip.active {
  background: #151412;
  color: #fff8ea;
  border-color: #151412;
}

.kanban {
  display: grid;
  grid-template-columns: repeat(4, minmax(220px, 1fr));
  gap: 14px;
}

.column {
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  min-height: 420px;
}

.column h2 {
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.piece-card {
  padding: 12px;
  border: 1px solid var(--soft);
  border-radius: 8px;
  background: var(--panel);
  margin-top: 10px;
}

.piece-card strong { display: block; margin-bottom: 5px; }
.piece-card span { display: block; color: var(--muted); font-size: 13px; }

.lab-card {
  padding: 16px;
  border-radius: 10px;
  background: var(--paper);
  border: 1px solid var(--soft);
}

@media (max-width: 980px) {
  body {
    display: block;
    background: var(--bg);
  }
  .sidebar {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    width: 100%;
    height: auto;
    max-height: calc(72px + env(safe-area-inset-bottom));
    min-height: auto;
    padding: 10px max(14px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 -20px 44px rgba(21, 20, 18, 0.28);
  }
  .brand { flex: 0 0 auto; }
  .brand > div:last-child { display: none; }
  .brand-mark { width: 40px; height: 40px; font-size: 21px; }
  .nav {
    display: flex;
    flex: 1 1 auto;
    gap: 6px;
    overflow-x: auto;
    padding: 0 2px 2px;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav-item {
    flex: 0 0 auto;
    width: auto;
    min-height: 40px;
    padding: 0 13px;
    white-space: nowrap;
    text-align: center;
    border-radius: 999px;
  }
  .sidebar-footer { display: none; }
  .shell {
    padding: max(18px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) calc(92px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  }
  .topbar,
  .topbar-actions {
    display: grid;
    width: 100%;
  }
  .topbar { gap: 14px; margin-bottom: 18px; }
  h1 { font-size: 26px; }
  input[type="search"] { width: 100%; }
  .session {
    width: 100%;
    justify-content: space-between;
  }
  .metrics-grid,
  .content-grid,
  .kanban {
    grid-template-columns: 1fr;
  }
  .panel { overflow-x: auto; padding: 15px; border-radius: 12px; }
  .activation-panel table { min-width: 620px; }
  .activation-panel .cell-input {
    width: 160px;
    min-height: 42px;
    font-size: 16px;
    text-transform: uppercase;
  }
  .activation-panel .row-actions {
    flex-wrap: nowrap;
  }
  .panel-header {
    display: grid;
    gap: 12px;
  }
  table { min-width: 700px; }
  .metrics-grid { gap: 10px; }
  .metric { padding: 15px; }
  .ask {
    width: calc(100vw - 28px);
    max-width: 420px;
    padding: 22px;
  }
}

/* ─── Acceso propio del Control Center ─────────────────────────────────── */

body.locked { overflow: hidden; }

.gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 50% 18%, rgba(246, 243, 237, 0.13), transparent 30%),
    #151412;
}

.gate-card {
  width: min(400px, 100%);
  display: grid;
  gap: 8px;
  padding: 32px;
  border-radius: 16px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.gate-card .brand-mark { color: var(--gold); border-color: var(--line); margin-bottom: 4px; }
.gate-card .brand-mark.admin-logo {
  color: #151412;
  border-color: #151412;
  margin-bottom: 0;
}
.gate-card h1 { margin: 0; font-size: 24px; }
.gate-card p { margin: 0 0 12px; font-size: 14px; }

.gate-card label {
  margin-top: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.gate-card input {
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
  min-height: 46px;
}

.fixed-credential {
  min-height: 46px;
  display: flex;
  align-items: center;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(21, 20, 18, 0.04);
  color: #151412;
  font-size: 16px;
  font-weight: 700;
}

.gate-card input:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
.gate-card button { margin-top: 18px; padding: 12px; }

.gate-error:empty { display: none; }
.gate-error {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(183, 86, 75, 0.1);
  color: var(--red);
  font-size: 14px;
}

.session { display: flex; align-items: center; gap: 12px; }
.session span { font-size: 14px; font-weight: 600; }

/* ─── Estados de carga, vacío y error ──────────────────────────────────── */

.empty-cell { padding: 22px 4px; color: var(--muted); text-align: center; }
.empty-cell.error { color: var(--red); }
td .muted, .timeline .muted { color: var(--muted); font-size: 13px; font-weight: 400; }

/* Paso de código: oculta lo ya verificado sin sacarlo del formulario. */
.gate:not(.mfa) [for="gate-code"], .gate:not(.mfa) #gate-code { display: none; }
.gate.mfa #gate-email-label, .gate.mfa .fixed-credential, .gate.mfa #gate-email,
.gate.mfa [for="gate-password"], .gate.mfa #gate-password { display: none; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { width: 16px; height: 16px; accent-color: var(--gold); }
.switch span { font-weight: 700; }
.panel-note { margin: 14px 0 0; font-size: 13px; }

/* ─── Acciones sobre filas ─────────────────────────────────────────────── */

.ask::backdrop { background: rgba(21, 20, 18, 0.55); }

.ask {
  width: min(420px, 92vw);
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.ask h2 { margin: 0 0 6px; font-size: 20px; }
.ask p { margin: 0 0 14px; font-size: 14px; }
.ask label { display: block; margin-bottom: 6px; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.ask input[type="text"] { width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--ink); }
.ask-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.row-actions { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.row-actions select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); }

button.ghost.danger { color: var(--red); }
.cell-input { width: 110px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); }

.inline-form { display: grid; gap: 6px; }
.inline-form.wide { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); align-items: end; gap: 12px; margin-bottom: 22px; }
.inline-form label { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.inline-form input, .inline-form select { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--ink); }
.inline-form button { margin-top: 10px; }
.inline-form.wide button { margin-top: 0; }
.inline-form .gate-error { grid-column: 1 / -1; }

.panel-inner h3 { margin: 0 0 12px; font-size: 16px; }
.panel-inner.span-2 { grid-column: span 2; }

@media (max-width: 980px) {
  .panel-inner {
    min-width: 0;
    overflow-x: auto;
  }
  .panel-inner.span-2 { grid-column: span 1; }
  .inline-form.wide { grid-template-columns: 1fr; }
  .ask-actions { display: grid; }
  .ask-actions button { width: 100%; }
}

.link-cell { padding: 0; border: 0; background: none; color: inherit; text-align: left; cursor: pointer; font: inherit; }
.link-cell:hover strong { text-decoration: underline; }
