/* ═══════════════════════════════════════════════════════════
   IBBQ LMS — layout.css
   Reset · Layout principal · Sidebar · Topbar · Page header
   Responsive · Accesibilidad
   Requiere: tokens.css
   ═══════════════════════════════════════════════════════════ */

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) var(--bg);
}
body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}
body::-webkit-scrollbar         { width: 8px; }
body::-webkit-scrollbar-track   { background: var(--bg); }
body::-webkit-scrollbar-thumb   {
  background: var(--border-strong);
  border-radius: 99px;
  border: 2px solid var(--bg);
}
body::-webkit-scrollbar-thumb:hover { background: var(--muted); }
a { color: var(--azul-light); text-decoration: none; }
a:hover { color: var(--azul); }
img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ── Layout principal ────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  transition: grid-template-columns var(--t-slow);
}
.layout.sidebar-collapsed {
  grid-template-columns: var(--sidebar-w-collapsed) 1fr;
}

.sidebar {
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  z-index: 200;
  transition: width var(--t-slow);
  width: var(--sidebar-w);
  flex-shrink: 0;
}
.layout.sidebar-collapsed .sidebar {
  width: var(--sidebar-w-collapsed);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10,22,40,0.5);
  z-index: 299;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.active { display: block; }

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

.content {
  flex: 1;
  padding: var(--sp-6);
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* ── Sidebar components (sb-*) ───────────────────────────── */
.sb-brand {
  padding: 0 16px;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--sb-border);
  flex-shrink: 0; overflow: hidden;
}
.sb-icon {
  width: 34px; height: 34px;
  background: linear-gradient(145deg, var(--azul-mid) 0%, var(--azul) 100%);
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background var(--t);
}
.sb-icon:hover {
  background: linear-gradient(145deg, var(--azul-light) 0%, var(--azul-mid) 100%);
}
.sb-name {
  font-family: 'Raleway', sans-serif;
  font-weight: 800; font-size: 13.5px; color: #fff;
  line-height: 1.2; white-space: nowrap; overflow: hidden;
  opacity: 1; transition: opacity var(--t);
}
.sb-name span {
  display: block; font-weight: 500; font-size: 10px;
  color: rgba(255,255,255,0.4); letter-spacing: 0.02em;
}
.layout.sidebar-collapsed .sb-name { opacity: 0; pointer-events: none; }

.sb-user {
  padding: 12px 14px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--sb-border);
  flex-shrink: 0; overflow: hidden;
  cursor: pointer; transition: background var(--t);
}
.sb-user:hover { background: var(--sidebar-hover); }
.sb-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--azul-mid);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Raleway', sans-serif; font-weight: 800;
  font-size: 12px; color: #fff; flex-shrink: 0;
  letter-spacing: 0.02em;
}
.sb-user-info { overflow: hidden; opacity: 1; transition: opacity var(--t); }
.layout.sidebar-collapsed .sb-user-info { opacity: 0; pointer-events: none; }
.sb-user-name {
  font-size: 12px; font-weight: 600; color: var(--sidebar-text-hi);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 148px;
}
.sb-user-rol { font-size: 10px; color: var(--sidebar-text); text-transform: capitalize; }

.sb-nav {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 10px 8px;
  scroll-behavior: smooth;
  scrollbar-width: thin; scrollbar-color: var(--sb-line) transparent;
}
.sb-nav::-webkit-scrollbar { width: 4px; }
.sb-nav::-webkit-scrollbar-track { background: transparent; }
.sb-nav::-webkit-scrollbar-thumb { background: var(--sb-line); border-radius: 99px; }

.sb-label {
  font-size: 9.5px; font-weight: 700; letter-spacing: 0.09em;
  color: rgba(255,255,255,0.25); padding: 14px 8px 4px;
  text-transform: uppercase; white-space: nowrap; overflow: hidden;
  transition: opacity var(--t);
}
.layout.sidebar-collapsed .sb-label { opacity: 0; }

.sb-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--r-sm);
  color: var(--sidebar-text); font-size: 13px; font-weight: 500;
  text-decoration: none;
  transition: background var(--t), color var(--t);
  margin-bottom: 1px; white-space: nowrap; overflow: hidden; position: relative;
}
.sb-item svg { flex-shrink: 0; width: 16px; height: 16px; }
.sb-item:hover { background: var(--sidebar-hover); color: var(--sidebar-text-hi); }
.sb-item.active { background: var(--sidebar-active); color: var(--sidebar-text-hi); }
.sb-item.active::before {
  content: ''; position: absolute; left: 0; top: 20%; bottom: 20%;
  width: 3px; background: var(--dorado); border-radius: 0 3px 3px 0;
}
.sb-item[data-tip] { position: relative; }
.layout.sidebar-collapsed .sb-item[data-tip]:hover::after {
  content: attr(data-tip); position: absolute;
  left: calc(var(--sidebar-w-collapsed) + 8px); top: 50%; transform: translateY(-50%);
  background: var(--text); color: #fff; font-size: 12px; font-weight: 500;
  padding: 5px 10px; border-radius: var(--r-sm); white-space: nowrap;
  pointer-events: none; z-index: 999; box-shadow: var(--shadow-md);
}
.sb-item-text { opacity: 1; transition: opacity var(--t); }
.layout.sidebar-collapsed .sb-item-text { opacity: 0; }

.sb-badge {
  margin-left: auto; background: var(--dorado); color: var(--navy);
  font-size: 9px; font-weight: 800; padding: 2px 6px; border-radius: 99px;
  flex-shrink: 0; transition: opacity var(--t);
}
.layout.sidebar-collapsed .sb-badge { opacity: 0; }
.sb-badge-red {
  margin-left: auto; background: var(--danger); color: #fff;
  font-size: 9px; font-weight: 800; padding: 2px 6px; border-radius: 99px;
  flex-shrink: 0; transition: opacity var(--t);
}
.layout.sidebar-collapsed .sb-badge-red { opacity: 0; }

.sb-collapse {
  padding: 10px 14px;
  border-top: 1px solid var(--sb-border);
  flex-shrink: 0;
}
.sb-collapse-btn {
  width: 100%; display: flex; align-items: center; gap: 8px;
  padding: 7px 8px; border-radius: var(--r-sm);
  background: transparent; border: none;
  color: rgba(255,255,255,0.35); font-size: 12px;
  cursor: pointer; transition: background var(--t), color var(--t);
  white-space: nowrap; overflow: hidden;
}
.sb-collapse-btn:hover { background: var(--sidebar-hover); color: rgba(255,255,255,0.7); }
.sb-collapse-btn svg { flex-shrink: 0; width: 16px; height: 16px; }
.sb-collapse-text { opacity: 1; transition: opacity var(--t); }
.layout.sidebar-collapsed .sb-collapse-text { opacity: 0; }

.sb-bottom { padding: 10px 8px 16px; border-top: 1px solid var(--sb-border); flex-shrink: 0; }
.sb-logout {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--r-sm);
  color: rgba(255,255,255,0.35); font-size: 13px; font-weight: 500;
  text-decoration: none; transition: background var(--t), color var(--t);
  white-space: nowrap; overflow: hidden;
}
.sb-logout svg { flex-shrink: 0; }
.sb-logout:hover { background: rgba(220,38,38,0.12); color: #fca5a5; }
.sb-logout-text { opacity: 1; transition: opacity var(--t); }
.layout.sidebar-collapsed .sb-logout-text { opacity: 0; }

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: none;
  box-shadow: 0 1px 0 var(--border), 0 2px 16px rgba(13,27,62,0.05);
  display: flex;
  align-items: center;
  padding: 0 var(--sp-6);
  gap: var(--sp-4);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}
.topbar-title {
  font-family: 'Raleway', sans-serif;
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-shrink: 0;
}
.topbar-notif {
  position: relative;
  width: 36px; height: 36px;
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  transition: background var(--t), color var(--t), border-color var(--t);
}
.topbar-notif:hover { background: var(--bg); color: var(--azul); border-color: var(--azul-xlight); }
.topbar-notif-dot {
  position: absolute; top: 6px; right: 7px;
  width: 7px; height: 7px;
  background: var(--danger); border-radius: 50%;
  border: 2px solid var(--surface);
}
.topbar-pill {
  font-family: 'Raleway', sans-serif;
  font-size: 10.5px; font-weight: 800; letter-spacing: .05em;
  color: var(--muted); background: var(--bg);
  border: 1px solid var(--border); padding: 5px 12px; border-radius: 99px;
}
.mobile-menu-btn {
  display: none;
  width: 36px; height: 36px;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: transparent;
  align-items: center; justify-content: center;
  color: var(--muted); cursor: pointer;
}

/* ── Page header ─────────────────────────────────────────── */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: var(--sp-6); flex-wrap: wrap;
}
.page-title {
  font-family: 'Raleway', sans-serif;
  font-weight: 800; font-size: 22px; color: var(--text); margin-bottom: 2px;
}
.page-subtitle { font-size: 13px; color: var(--muted); }
.page-header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page-header-left    { display: flex; flex-direction: column; gap: 2px; }
.page-actions        { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 1280px) {
  .insc-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 769px) and (max-width: 1024px) {
  :root { --sidebar-w: 210px; }
  .content         { padding: var(--sp-5); }
  .welcome-banner  { padding: 22px 24px; gap: 16px; }
  .wstat-num       { font-size: 22px; }
  .wstat           { padding: 12px 16px; }
  .stats-grid      { grid-template-columns: repeat(2, 1fr); }
  .grid-3          { grid-template-columns: 1fr 1fr; }
  .insc-grid       { grid-template-columns: repeat(2, 1fr); }
  .auth-card       { padding: 32px 28px; }
  .auth-right      { padding: 32px 24px; }
  .detail-grid     { grid-template-columns: 1fr; }
  .pago-detail-grid{ grid-template-columns: 1fr; }
}
@media (min-width: 769px) {
  .bottom-nav { display: none !important; }
}
@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0;
    height: 100vh; width: var(--sidebar-w) !important;
    transform: translateX(-100%);
    transition: transform var(--t-slow); z-index: 300;
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .mobile-menu-btn { display: flex; }
  .main { padding-bottom: 64px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .auth-layout { grid-template-columns: 1fr; }
  .auth-left   { display: none; }
  .content     { padding: var(--sp-4); }
  .welcome-banner { flex-direction: column; align-items: flex-start; }
  .welcome-stats  { width: 100%; }
  .stats-grid     { grid-template-columns: 1fr 1fr; }

  .bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0; height: 60px;
    background: var(--surface); border-top: 1px solid var(--border);
    display: flex; z-index: 200; box-shadow: 0 -4px 20px rgba(13,27,62,0.08);
  }
  .bottom-nav-item {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 3px; text-decoration: none;
    color: var(--muted); font-size: 10px; font-weight: 600;
    letter-spacing: 0.02em; transition: color var(--t); position: relative;
  }
  .bottom-nav-item svg { width: 20px; height: 20px; }
  .bottom-nav-item.active { color: var(--azul); }
  .bottom-nav-item.active::before {
    content: ''; position: absolute; top: 0; left: 20%; right: 20%;
    height: 2px; background: var(--azul); border-radius: 0 0 99px 99px;
  }
  .bottom-nav-badge {
    position: absolute; top: 6px; right: calc(50% - 18px);
    background: var(--danger); color: #fff;
    font-size: 8px; font-weight: 800;
    width: 14px; height: 14px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid var(--surface);
  }

  .page-title      { font-size: 19px; }
  .topbar-title    { font-size: 14px; }
  .welcome-text h2 { font-size: 18px; }
  .auth-card-title { font-size: 20px; }
  .stat-num        { font-size: 24px; }
  .wstat-num       { font-size: 22px; }
  .topbar          { padding: 0 var(--sp-4); }
  .topbar-pill     { display: none; }
  .page-header         { margin-bottom: var(--sp-4); align-items: flex-start; }
  .page-header-actions { width: 100%; justify-content: flex-end; }
  .page-actions        { width: 100%; justify-content: flex-end; }
  .card-body   { padding: 14px; }
  .card-hd, .card-header { padding: 12px 14px; flex-wrap: wrap; }
  .stat-card   { padding: 14px 16px; }
  .stat-icon   { width: 38px; height: 38px; }
  .welcome-banner { padding: 20px; }
  .welcome-stats  { justify-content: space-between; }
  th, td { padding: 10px 10px; font-size: 12px; }
  th     { font-size: 10px; }
  .form-row { grid-template-columns: 1fr; }
  .cfg-tabs { gap: 2px; }
  .cfg-tab  { padding: 7px 12px; font-size: 12px; }
  .auth-right        { padding: 20px 14px; }
  .auth-card         { padding: 24px 20px; border-radius: var(--r); max-width: 100%; box-shadow: var(--shadow-md); }
  .auth-card-subtitle{ margin-bottom: 20px; }
  .auth-logo-block   { margin-bottom: 28px; }
  .detail-grid       { grid-template-columns: 1fr; }
  .pago-detail-grid  { grid-template-columns: 1fr; }
  .page-header-actions .btn, .page-actions .btn { padding: 7px 12px; }
  .cfg-save-bar  { bottom: 70px; }
  .cfg-save-card { flex-direction: column; align-items: stretch; }
  .cfg-save-card .btn { width: 100%; justify-content: center; }
  .metodo-grid { grid-template-columns: 1fr 1fr; }
  .deuda-card  { flex-direction: column; align-items: flex-start; }
}
@media (max-width: 400px) {
  .auth-card        { padding: 20px 16px; }
  .auth-card-title  { font-size: 18px; }
  .stats-grid       { grid-template-columns: 1fr; }
  .welcome-stats    { flex-direction: column; gap: 0; }
  .wstat            { padding: 10px 16px; border-bottom: 1px solid var(--sb-line); }
  .wstat:last-child { border-bottom: none; }
  .wstat-sep        { display: none; }
  .metodo-grid      { grid-template-columns: 1fr; }
  .insc-grid        { grid-template-columns: 1fr; }
  .page-title       { font-size: 17px; }
  .btn-full         { font-size: 13px; padding: 11px 14px; }
  .topbar-right     { gap: var(--sp-2); }
  .card-hd, .card-header { padding: 10px 12px; }
  .card-body        { padding: 12px; }
}

/* ── Accesibilidad ───────────────────────────────────────── */
::selection { background: var(--azul-xlight); color: var(--azul); }
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--azul-light);
  outline-offset: 3px;
  border-radius: var(--r-sm);
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
