/* Estructura de la app: sidebar, barra superior y contenedor principal.
   Breakpoints del panel: 600 (telefono), 1024 (tableta), 1280 (escritorio). */

#app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  background: var(--bg);
}

.main-column { display: flex; flex-direction: column; min-width: 0; }

/* ─── Sidebar ─── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  height: 100vh; position: sticky; top: 0;
  overflow-y: auto; overflow-x: hidden;
  padding: 1.1rem 0.75rem;
}

.sidebar-logo {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.2rem 0.5rem 1.4rem;
  color: var(--text-hi); text-decoration: none;
}
.sidebar-logo-mark { width: 34px; height: 34px; flex-shrink: 0; color: var(--accent); }
.sidebar-logo-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.sidebar-logo-name { font-weight: 700; font-size: 1.15rem; letter-spacing: 0.08em; }
.sidebar-logo-full { font-size: 0.68rem; color: var(--text-dim); white-space: nowrap; }

.sidebar-nav { display: flex; flex-direction: column; flex: 1; }
.nav-group { display: flex; flex-direction: column; gap: 2px; margin-bottom: 1.4rem; }
.nav-group.bottom { margin-top: auto; margin-bottom: 0; padding-top: 1rem; border-top: 1px solid var(--border); }

.nav-item {
  display: flex; align-items: center; gap: 0.7rem;
  min-height: 40px; padding: 0 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none;
  font-size: 0.88rem;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text-hi); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); font-weight: 600; }
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }
.nav-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ─── Barra superior ─── */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 0.75rem;
  height: var(--topbar-h); padding: 0 var(--gutter);
  background: rgba(10, 20, 32, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-spacer { flex: 1; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; flex-shrink: 0;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm);
  color: var(--text); cursor: pointer; position: relative;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text-hi); }
.icon-btn svg { width: 19px; height: 19px; }
.menu-btn { display: none; }

.status-pill {
  display: inline-flex; align-items: center; gap: 0.45rem;
  height: 30px; padding: 0 0.7rem;
  border: 1px solid var(--border); border-radius: 999px;
  font-size: 0.78rem; color: var(--text); white-space: nowrap;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--crit); box-shadow: 0 0 0 3px var(--crit-dim); flex-shrink: 0; }
.status-pill.on .status-dot { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-dim); }

.bell-count {
  position: absolute; top: 3px; right: 2px;
  min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px;
  background: var(--crit); color: #fff;
  font-size: 0.62rem; font-weight: 700; line-height: 17px; text-align: center;
}

.user-menu { position: relative; }
.user-menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 50;
  width: 230px; padding: 0.8rem;
  background: var(--surface-2); border: 1px solid var(--border-hi); border-radius: var(--radius);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}
.user-menu-name { color: var(--text-hi); font-weight: 600; }
.user-menu-role { color: var(--text-dim); font-size: 0.78rem; margin-bottom: 0.8rem; }
.user-menu-label { display: block; font-size: 0.72rem; color: var(--text-dim); margin-bottom: 0.3rem; }
.user-menu select {
  width: 100%; height: 38px; padding: 0 0.5rem; margin-bottom: 0.7rem;
  background: var(--bg); color: var(--text-hi);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: inherit; font-size: 0.85rem;
}
.user-menu-logout {
  width: 100%; height: 38px;
  background: transparent; color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: inherit; font-size: 0.85rem; cursor: pointer;
}
.user-menu-logout:hover { border-color: var(--crit); color: var(--crit); }

/* ─── Contenido ─── */
.main-content { flex: 1; min-width: 0; }
.view { padding: var(--gutter); max-width: 1480px; }

.view-header {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem;
  margin-bottom: 1.25rem;
}
.view-header h2 { font-size: 1.6rem; font-weight: 700; color: var(--text-hi); letter-spacing: -0.01em; }
.view-sub { color: var(--text-dim); font-size: 0.85rem; margin-top: 0.15rem; }

.nav-scrim { display: none; }

/* ─── Tableta y telefono: sidebar fuera del lienzo ─── */
@media (max-width: 1024px) {
  #app-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 70;
    width: min(var(--sidebar-w), 82vw);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }
  .nav-open .sidebar { transform: none; }
  .nav-open .nav-scrim {
    display: block; position: fixed; inset: 0; z-index: 60;
    background: rgba(0, 0, 0, 0.5);
  }
  .menu-btn { display: inline-flex; }
}

@media (max-width: 600px) {
  .status-pill .pill-text { display: none; }
  #source-pill { display: none; }
  .status-pill { width: 30px; padding: 0; justify-content: center; }
  .view-header h2 { font-size: 1.35rem; }
}

[dir="rtl"] .sidebar { border-right: none; border-left: 1px solid var(--border); }
[dir="rtl"] .user-menu-panel { right: auto; left: 0; }
[dir="rtl"] .bell-count { right: auto; left: 2px; }
@media (max-width: 1024px) {
  [dir="rtl"] .sidebar { left: auto; right: 0; transform: translateX(100%); }
  [dir="rtl"] .nav-open .sidebar { transform: none; }
}
