:root {
  --sidebar-w: 240px;
  --sidebar-w-collapsed: 64px;
  --sidebar-bg: #1f2a37;
  --sidebar-bg-hover: #283447;
  --sidebar-fg: #cbd5e1;
  --sidebar-fg-active: #fff;
  --sidebar-accent: #3b82f6;
  --topbar-h: 56px;
  --subnav-h: 48px;
  --content-bg: #f5f7fa;
}

html, body { height: 100%; }
body { background: var(--content-bg); }

/* ===========================================================
   Primary button takes the sidebar tone (more brand identity)
   =========================================================== */

.btn-primary {
  --bs-btn-bg:                  var(--sidebar-bg);
  --bs-btn-border-color:        var(--sidebar-bg);
  --bs-btn-hover-bg:            var(--sidebar-bg-hover);
  --bs-btn-hover-border-color:  var(--sidebar-bg-hover);
  --bs-btn-active-bg:           #131b25;
  --bs-btn-active-border-color: #131b25;
  --bs-btn-disabled-bg:         var(--sidebar-bg);
  --bs-btn-disabled-border-color: var(--sidebar-bg);
  --bs-btn-focus-shadow-rgb:    31, 42, 55;
}

/* ===========================================================
   Layout shell (sidebar + topbar + content)
   =========================================================== */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.app-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  margin-left: var(--sidebar-w);
  transition: margin-left .2s ease;
}

.app-shell.sidebar-collapsed .app-main { margin-left: var(--sidebar-w-collapsed); }

.app-content {
  padding: 1.5rem;
  flex: 1 1 auto;
}

/* ===========================================================
   Sidebar
   =========================================================== */

.app-sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: width .2s ease;
  overflow: hidden;
}
.app-shell.sidebar-collapsed .app-sidebar { width: var(--sidebar-w-collapsed); }

.sidebar-brand {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: 0 1rem;
  color: #fff;
  font-weight: 600;
  font-size: 1.05rem;
  border-bottom: 1px solid rgba(255,255,255,.06);
  white-space: nowrap;
}
.sidebar-brand-icon { font-size: 1.4rem; color: var(--sidebar-accent); flex: 0 0 auto; }
.sidebar-brand-text { transition: opacity .15s ease; }
.app-shell.sidebar-collapsed .sidebar-brand-text { opacity: 0; visibility: hidden; }

.sidebar-nav { flex: 1 1 auto; padding: .75rem 0; overflow-y: auto; }

.sidebar-item {
  display: flex;
  align-items: center;
  gap: .85rem;
  padding: .65rem 1rem;
  color: var(--sidebar-fg);
  text-decoration: none;
  font-size: .95rem;
  border-left: 3px solid transparent;
  white-space: nowrap;
}
.sidebar-item:hover { background: var(--sidebar-bg-hover); color: var(--sidebar-fg-active); }
.sidebar-item.is-active {
  background: var(--sidebar-bg-hover);
  color: var(--sidebar-fg-active);
  border-left-color: var(--sidebar-accent);
}
.sidebar-item i { font-size: 1.1rem; width: 1.2rem; text-align: center; flex: 0 0 auto; }
.sidebar-item-label { transition: opacity .15s ease; }
.app-shell.sidebar-collapsed .sidebar-item-label { opacity: 0; visibility: hidden; }

/* ===========================================================
   Topbar
   =========================================================== */

.app-topbar {
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: .75rem;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-toggle {
  background: transparent;
  border: 0;
  font-size: 1.4rem;
  color: #4b5563;
  padding: .25rem .5rem;
  border-radius: 6px;
  cursor: pointer;
}
.topbar-toggle:hover { background: #f3f4f6; }

.topbar-title { font-size: 1.05rem; font-weight: 600; margin: 0; color: #111827; }

.topbar-spacer { flex: 1 1 auto; }

.topbar-user-btn {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: transparent;
  border: 0;
  color: #374151;
}
.topbar-user-btn:hover, .topbar-user-btn:focus { background: #f3f4f6; }

.topbar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--sidebar-accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: .9rem;
}
.topbar-user-name { font-weight: 500; font-size: .95rem; }

/* ===========================================================
   Subnav (horizontal secondary navigation)
   =========================================================== */

.app-subnav {
  height: var(--subnav-h);
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: stretch;
  padding: 0 1rem;
  gap: .25rem;
  position: sticky;
  top: var(--topbar-h);
  z-index: 40;
}

.subnav-item {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: 0 .9rem;
  color: #4b5563;
  text-decoration: none;
  font-size: .9rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.subnav-item:hover { color: #111827; }
.subnav-item.is-active {
  color: var(--sidebar-accent);
  border-bottom-color: var(--sidebar-accent);
  font-weight: 600;
}
.subnav-item i { font-size: 1rem; }

/* Sub-sub-nav: segunda fila que aparece cuando el subnav agrupa items. */
.app-subsubnav {
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: stretch;
  padding: 0 1rem;
  gap: .25rem;
  min-height: 40px;
  position: sticky;
  top: calc(var(--topbar-h) + var(--subnav-h));
  z-index: 39;
}
.subsubnav-item {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: 0 .8rem;
  color: #6b7280;
  text-decoration: none;
  font-size: .85rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.subsubnav-item:hover { color: #111827; background: #fff; }
.subsubnav-item.is-active {
  color: var(--sidebar-accent);
  border-bottom-color: var(--sidebar-accent);
  font-weight: 600;
  background: #fff;
}
.subsubnav-item i { font-size: .95rem; }

/* ===========================================================
   Auth pages (login, establecer password, healthcheck)
   =========================================================== */

.auth-body {
  min-height: 100vh;
  position: relative;
  margin: 0;
}

.auth-bg {
  position: fixed;
  inset: 0;
  background-image: url('/assets/img/fondo_portada1.jpg');
  background-size: cover;
  background-position: center;
  background-color: #1e293b;
  z-index: -2;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, rgba(15,23,42,.72), rgba(15,23,42,.55));
  z-index: -1;
}

.auth-main {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

.auth-card {
  background: rgba(255,255,255,.97);
  backdrop-filter: blur(6px);
  width: 100%;
  max-width: 420px;
  padding: 2rem;
  border-radius: 14px;
  box-shadow: 0 25px 60px rgba(0,0,0,.35);
}

.auth-card-header { text-align: center; margin-bottom: 1.5rem; }
.auth-logo { font-size: 2.5rem; color: var(--sidebar-accent); }
.auth-title { font-size: 1.4rem; margin: .25rem 0 .15rem; color: #111827; font-weight: 700; }
.auth-subtitle { color: #6b7280; font-size: .9rem; margin: 0; }

.auth-card--wide { max-width: 720px; }
.auth-steps { padding-left: 1.2rem; }
.auth-steps li { margin-bottom: .25rem; }

.tfa-qr {
  display: inline-block;
  padding: .5rem;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
}
.tfa-qr img { display: block; width: 100%; height: auto; image-rendering: pixelated; }
.tfa-secret code {
  display: inline-block;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  padding: .35rem .6rem;
  border-radius: 6px;
  font-size: .85rem;
  letter-spacing: .04em;
}
.tfa-recovery {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: .75rem 1rem;
}
.tfa-recovery code { font-size: .9rem; }

/* ===========================================================
   Responsive
   =========================================================== */

/* ===========================================================
   Dropzone (subida de backups)
   =========================================================== */

.dropzone {
  background-color: #f8fafc;
  border-style: dashed !important;
  border-color: #cbd5e1 !important;
  transition: background-color .15s ease, border-color .15s ease;
}
.dropzone.is-drag-over {
  background-color: #e0ecff;
  border-color: var(--sidebar-accent) !important;
}
.dropzone .categoria-selection { word-break: break-all; }

@media (max-width: 768px) {
  .app-sidebar { transform: translateX(-100%); }
  .app-main { margin-left: 0; }
  .app-shell.sidebar-collapsed .app-main { margin-left: 0; }
  .app-shell.sidebar-mobile-open .app-sidebar { transform: translateX(0); width: var(--sidebar-w); }
  .app-shell.sidebar-mobile-open .sidebar-brand-text,
  .app-shell.sidebar-mobile-open .sidebar-item-label { opacity: 1; visibility: visible; }
}
