/* base.css v2 — layout y componentes base. Depende de tokens.css */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { background: var(--bg2); color: var(--txt); }

body {
  min-height: 100vh;
  font-family: var(--f-body);
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input, select, textarea { font: inherit; cursor: pointer; }
input, select, textarea { cursor: text; }
::selection { background: var(--rojo); color: #fff; }

/* ════════════════════════════════════
   APP SHELL — sidebar icónica + main
════════════════════════════════════ */
.app-shell {
  display: block;
  min-height: 100vh;
}

/* ── SIDEBAR ── */
.sidebar {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  gap: 6px;
  z-index: 20;
  overflow-y: auto;
}

.sidebar-logo {
  font-family: var(--f-display);
  font-size: 26px;
  letter-spacing: .04em;
  color: var(--txt);
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  width: 100%;
  text-align: center;
}
.sidebar-logo .o, .login-logo .o {
  color: #fff;
  text-shadow: 0 0 16px rgba(255,255,255,1), 0 0 48px rgba(255,255,255,.6), 0 0 100px rgba(255,255,255,.25);
}
.logo-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: rgba(255,255,255,.4); margin-left: 4px; vertical-align: middle; }

.sidebar-persona {
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 10px 0;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  flex: 1;
}

.nav-tab {
  width: 62px;
  height: 52px;
  border: 0;
  background: transparent;
  color: var(--txt2);
  border-radius: 10px;
  font-size: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  transition: color .14s, background .14s;
  cursor: pointer;
}
.nav-tab svg { width: 18px; height: 18px; }
.nav-tab:hover { color: var(--txt); background: rgba(255,255,255,.04); }
.nav-tab.active {
  color: #fff;
  background: linear-gradient(135deg,rgba(224,45,0,.22),rgba(224,45,0,.05));
  box-shadow: inset 0 0 0 1px var(--glow);
}

.sidebar-bottom {
  width: 100%;
  padding: 10px 12px 0;
  border-top: 1px solid var(--line);
}

/* ── MAIN AREA ── */
.main-area {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── TOPBAR ── */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 12px; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }

.topbar-search {
  max-width: 320px;
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 12px;
  color: var(--txt2);
  font-size: 13px;
  outline: none;
  transition: border-color .14s;
}
.topbar-search:focus { border-color: var(--rojo); color: var(--txt); }

.topbar-icon {
  position: relative;
  background: transparent;
  border: 1px solid var(--line2);
  color: var(--txt2);
  padding: 7px 11px;
  border-radius: 9px;
  font-size: 15px;
  transition: border-color .14s, color .14s;
}
.topbar-icon:hover { border-color: var(--rojo); color: var(--txt); }

.topbar-persona { display: flex; align-items: center; }

/* ── MAIN CONTENT ── */
.main-content {
  padding: 24px;
  flex: 1;
  max-width: 1360px;
  width: 100%;
  margin: 0 auto;
}

/* ════════════════════════════════════
   LOGIN OVERLAY (fallback v1 / PIN)
════════════════════════════════════ */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse 900px 400px at 50% 0%, rgba(224,45,0,.14), transparent 55%),
    var(--bg);
}
.login-overlay.hidden { display: none; }
.app-shell.hidden { display: none; }

.login-box {
  width: 100%;
  max-width: 780px;
  padding: 40px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.login-logo { text-align: center; }
.login-logo .logo-text {
  display: block;
  font-family: var(--f-display);
  font-size: 80px;
  line-height: .9;
  letter-spacing: .03em;
}
.login-logo .logo-sub {
  display: block;
  font-size: 11px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--txt3);
  margin-top: 8px;
}

.login-title {
  font-family: var(--f-display);
  font-size: 28px;
  letter-spacing: .04em;
  font-weight: 400;
  color: var(--txt2);
}

.login-personajes {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}
.login-persona-btn {
  cursor: pointer;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 180px;
  transition: border-color .16s, transform .16s, box-shadow .16s;
}
.login-persona-btn:hover {
  border-color: var(--rojo);
  box-shadow: 0 0 0 1px var(--glow), 0 0 40px -10px var(--glow);
  transform: translateY(-4px);
}

.login-pin-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 320px;
}
.login-pin-form.hidden { display: none; }
.login-selected-persona { display: flex; align-items: center; gap: 12px; }

.pin-label {
  font-size: 12px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--txt2);
}
.pin-inputs { display: flex; gap: 12px; }
.pin-digit {
  width: 50px;
  height: 60px;
  border: 2px solid var(--line2);
  border-radius: 12px;
  background: var(--card);
  color: var(--txt);
  font-size: 26px;
  text-align: center;
  outline: none;
  transition: border-color .14s;
}
.pin-digit:focus { border-color: var(--rojo); box-shadow: 0 0 0 3px rgba(224,45,0,.2); }
.login-error { color: var(--rojo-sem); font-size: 13px; }
.login-error.hidden { display: none; }

/* ════════════════════════════════════
   COMPONENTES COMUNES
════════════════════════════════════ */

/* Card base */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px;
}

/* Botones — UI grande por contrato */
.actbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--btn-h);       /* 44px */
  padding: 0 18px;
  border-radius: var(--r-lg);
  border: 0;
  font-family: var(--f-body);
  font-weight: 700;
  font-size: var(--btn-fz);       /* 14px */
  letter-spacing: .04em;
  transition: opacity .14s, transform .1s, box-shadow .14s;
  cursor: pointer;
  white-space: nowrap;
}
.actbtn svg { width: 18px; height: 18px; flex-shrink: 0; }
.actbtn:active { transform: scale(.97); }
.actbtn.primary {
  background: var(--rojo);
  color: #fff;
  box-shadow: 0 4px 16px rgba(224,45,0,.3);
}
.actbtn.primary:hover { opacity: .9; box-shadow: 0 6px 24px rgba(224,45,0,.45); }
.actbtn.ghost {
  background: transparent;
  border: 1.5px solid var(--line2);
  color: var(--txt);
}
.actbtn.ghost:hover { border-color: var(--rojo); color: #fff; }
.actbtn.large {
  min-height: var(--btn-h-lg);    /* 52px */
  padding: 0 24px;
  font-size: var(--btn-fz-lg);    /* 16px */
  border-radius: var(--r-xl);
}
.actbtn.small  { min-height: 32px; padding: 0 12px; font-size: 12px; border-radius: var(--r); }
.actbtn.w-full { width: 100%; }

/* Pills */
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 9px;
  border-radius: var(--r-full);
  border: 1px solid var(--line2);
  color: var(--txt2);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.pill.rojo     { border-color: rgba(224,45,0,.4);  background: rgba(224,45,0,.1);  color: #ff9b80; }
.pill.verde    { border-color: rgba(34,197,94,.4); background: rgba(34,197,94,.1); color: #86efac; }
.pill.amarillo { border-color: rgba(234,179,8,.4); background: rgba(234,179,8,.08); color: #fde68a; }
.pill.gris     { border-color: var(--line2); color: var(--txt2); }
.pill.ghost    { background: transparent; }

/* Dots semáforo */
.dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot.verde    { background: var(--verde);    box-shadow: 0 0 6px var(--verde); }
.dot.amarillo { background: var(--amarillo); box-shadow: 0 0 6px var(--amarillo); }
.dot.rojo     { background: var(--rojo-sem); box-shadow: 0 0 6px var(--rojo-sem); }
.dot.gris     { background: var(--txt3); }

/* Badge notificaciones (dentro de .topbar-icon) */
.notif-badge {
  position: absolute;
  top: -4px; right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 99px;
  background: var(--rojo);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.notif-badge.hidden { display: none; }
/* Compat: id="notif-badge" sin clase extra */
#notif-badge { position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 99px; background: var(--rojo); color: #fff; font-size: 10px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
#notif-badge.hidden { display: none; }

/* Alertas */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 10px 12px;
  border-radius: var(--r);
  font-size: 13px;
  line-height: 1.5;
}
.alert-icon { flex-shrink: 0; }
.alert.rojo     { background: rgba(255,59,48,.08);  border: 1px solid rgba(255,59,48,.25);  color: #ffb4ab; }
.alert.amarillo { background: rgba(234,179,8,.08);  border: 1px solid rgba(234,179,8,.25);  color: #fde68a; }
.alert.verde    { background: rgba(34,197,94,.08);  border: 1px solid rgba(34,197,94,.25);  color: #86efac; }
.alert.info     { background: rgba(96,165,250,.08); border: 1px solid rgba(96,165,250,.25); color: #93c5fd; }
.alert.bloqueada{ background: rgba(255,59,48,.08);  border: 1px solid rgba(255,59,48,.25);  color: #ffb4ab; }
.alert.instruccion{ background: rgba(234,179,8,.08); border: 1px solid rgba(234,179,8,.25); color: #fde68a; }

/* Métricas */
.metric { display: flex; flex-direction: column; gap: 3px; }
.metric-val { font-size: 26px; font-weight: 800; color: var(--txt); line-height: 1; }
.metric-val.rojo    { color: var(--rojo-sem); }
.metric-val.verde   { color: var(--verde); }
.metric-val.amarillo{ color: var(--amarillo); }
.metric-val.white   { color: var(--txt); }
.metric-label { font-size: 11px; color: var(--txt2); text-transform: uppercase; letter-spacing: .08em; }

/* Barras */
.bar { height: 5px; background: rgba(255,255,255,.06); border-radius: 4px; overflow: hidden; }
.bar.sm { height: 3px; }
.bar-fill { height: 100%; border-radius: 4px; background: var(--g-fuego); transition: width .3s; }
.bar-fill.verde    { background: var(--verde); }
.bar-fill.amarillo { background: var(--amarillo); }
.bar-fill.rojo     { background: var(--rojo-sem); }
.bar-fill.gris     { background: var(--txt3); }

/* Texto */
.txt-dim  { color: var(--txt2); }
.txt-xs   { font-size: 11px; }
.txt-sm   { font-size: 13px; }
.caps     { text-transform: uppercase; letter-spacing: .08em; }
.truncate { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.mt-sm  { margin-top: 8px; }
.mt-md  { margin-top: 16px; }
.mt-lg  { margin-top: 24px; }

/* Fade-in */
.fade-in { animation: fadeIn .22s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Bebas display helper */
.bebas { font-family: var(--f-display); font-weight: 400; letter-spacing: var(--ls-display); }

/* Lema */
.lema-controla {
  font-size: 9px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--txt3);
  white-space: nowrap;
}

/* ════════════════════════════════════
   RESPONSIVE
════════════════════════════════════ */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; --topbar-h: 48px; }

  .sidebar {
    flex-direction: row;
    width: 100%;
    height: auto;
    position: fixed;
    top: auto; bottom: 0;
    left: 0; right: 0;
    border-right: 0;
    border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
    justify-content: flex-start;
    gap: 0;
    background: rgba(8,8,8,.92);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    z-index: 50;
  }

  .sidebar-persona { display: none; }

  .sidebar-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    padding: 0;
    border-bottom: none;
    font-size: 0;
    cursor: pointer;
  }
  .sidebar-logo .logo-text,
  .sidebar-logo .logo-dot { display: none; }

  .sidebar-nav {
    flex-direction: row;
    flex: 1;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  .sidebar-nav::-webkit-scrollbar { display: none; }

  .nav-tab {
    width: auto;
    min-width: 56px;
    height: 44px;
    flex: 0 0 auto;
    font-size: 9px;
    gap: 2px;
    border-radius: 10px;
    padding: 0 6px;
    -webkit-tap-highlight-color: transparent;
  }
  .nav-tab svg { width: 20px; height: 20px; }

  .sidebar-bottom {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    flex-shrink: 0;
    padding: 0;
    border-top: none;
  }
  .sidebar-bottom .actbtn {
    width: 38px;
    min-height: 38px;
    padding: 0;
    border-radius: 10px;
    font-size: 0;
  }

  .sidebar-bottom .logout-text { display: none; }

  .main-area { margin-left: 0; padding-bottom: calc(62px + env(safe-area-inset-bottom, 0px)); }
  .main-content { padding: 14px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar-search { font-size: 13px; max-width: none; }
}
