.btn-back-pcbsystem {
  position: absolute;
  top: 20px;
  left: 20px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 12px;
  color: white;
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  transition: all 0.25s ease;
  z-index: 100;
}

.btn-back-pcbsystem:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: translateX(-2px);
}

@media (max-width: 980px) {
  .btn-back-pcbsystem {
    position: fixed;
    top: 20px;
    left: 12px;
    z-index: 1000;
  }
}

:root {
  --bg: #f4f7fb;
  --bg-soft: #eef3f9;
  --surface: rgba(255, 255, 255, 0.88);
  --surface-solid: #ffffff;
  --surface-2: #f8fbff;
  --text: #162033;
  --muted: #62708a;
  --border: rgba(18, 40, 76, 0.1);
  --primary: #1d4ed8;
  --primary-2: #2563eb;
  --primary-soft: rgba(37, 99, 235, 0.12);
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --info: #2563eb;
  --purple: #7c3aed;
  --gray: #6b7280;
  --shadow: 0 20px 45px rgba(15, 23, 42, 0.12);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 12px;
}

body.dark {
  --bg: #0b1220;
  --bg-soft: #121b2d;
  --surface: rgba(15, 23, 42, 0.92);
  --surface-solid: #0f172a;
  --surface-2: #172235;
  --text: #e7edf8;
  --muted: #96a3bb;
  --border: rgba(148, 163, 184, 0.16);
  --primary-soft: rgba(59, 130, 246, 0.18);
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: 'Inter', sans-serif;
  background: radial-gradient(circle at top left, rgba(37,99,235,0.16), transparent 30%), var(--bg);
  color: var(--text);
  overflow-x: hidden; /* Cambiado a hidden para evitar scroll horizontal por texto largo */
}

/* Overlay para sidebar en móvil */
.sidebar-overlay {
  display: none;
}

@media (max-width: 980px) {
  .sidebar-overlay {
    display: block;
  }
}

/* Evitar overflow horizontal en todo el sitio */
html, .app-shell, .main-panel, .content-area, .section-block {
  max-width: 100%;
  overflow-x: visible;
  min-width: 0; /* Permite que los contenedores flex/grid se encojan */
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.loader-overlay {
  position: fixed; inset: 0; background: rgba(10, 17, 30, 0.52); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center; z-index: 9999;
  transition: opacity .35s ease, visibility .35s ease;
}
.loader-overlay.hidden { 
  opacity: 0; 
  visibility: hidden; 
  transition: opacity .15s ease, visibility .15s ease;
}
.loader-card {
  background: var(--surface-solid); padding: 28px; border-radius: 24px; box-shadow: var(--shadow);
  text-align: center; width: min(92vw, 360px); border: 1px solid var(--border);
}
.spinner {
  width: 54px; height: 54px; border-radius: 50%; margin: 0 auto 12px;
  border: 4px solid rgba(37,99,235,.15); border-top-color: var(--primary); animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg);} }
@keyframes fadeUp { from {opacity:0; transform: translateY(14px);} to {opacity:1; transform: translateY(0);} }
.fade-in { animation: fadeUp .55s ease both; }

.auth-body { min-height: 100vh; }
.auth-layout {
  min-height: 100vh; display: grid; grid-template-columns: 1.1fr .9fr;
  position: relative;
}
.auth-left {
  padding: 56px;
  padding-top: 80px; color: white;
  background:
    linear-gradient(135deg, rgba(2,6,23,.7), rgba(29,78,216,.7)),
    linear-gradient(120deg, #163985, #2563eb 55%, #1e40af);
  display: flex; flex-direction: column; justify-content: space-between;
}
.brand-block { max-width: 640px; display: flex; gap: 18px; align-items: flex-start; }
.brand-icon {
  width: 74px; height: 74px; display: grid; place-items: center; font-size: 1.8rem;
  border-radius: 22px; background: rgba(255,255,255,.15); backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,.18); flex-shrink: 0;
}
.brand-icon.small { width: 54px; height: 54px; border-radius: 16px; font-size: 1.25rem; }
.eyebrow {
  display: inline-block; font-size: .78rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
  font-weight: 700; margin-bottom: 8px;
}
.auth-left .eyebrow { color: rgba(255,255,255,.75); }
.brand-block h1 { margin: 0 0 12px; font-size: clamp(2rem, 4vw, 3.5rem); line-height: 1.05; word-break: break-word; }
.brand-block p { margin: 0; font-size: 1.05rem; color: rgba(255,255,255,.85); max-width: 620px; word-break: break-word; }
.hero-cards { display: grid; gap: 16px; margin-top: 32px; }
.glass {
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.16); backdrop-filter: blur(12px);
}
.hero-card {
  display: flex; gap: 16px; align-items: flex-start; padding: 18px 20px; border-radius: 20px;
}
.hero-card i { font-size: 1.25rem; margin-top: 4px; }
.hero-card h3 { margin: 0 0 4px; word-break: break-word; }
.hero-card p { margin: 0; color: rgba(255,255,255,.8); word-break: break-word; }

.auth-right {
  display: flex; align-items: center; justify-content: center; padding: 34px;
}
.auth-card {
  width: min(100%, 520px); background: var(--surface); backdrop-filter: blur(18px); border: 1px solid var(--border);
  border-radius: var(--radius-xl); box-shadow: var(--shadow); padding: 30px;
}
.auth-header h2 { margin: 0 0 8px; font-size: 2rem; word-break: break-word; }
.auth-header p { margin: 0; color: var(--muted); word-break: break-word; }
.auth-form { margin-top: 24px; display: grid; gap: 18px; }
.role-switch {
  display: grid; grid-template-columns: 1fr 1fr; background: var(--bg-soft); padding: 6px; border-radius: 16px;
}
.role-btn {
  border: none; background: transparent; border-radius: 12px; padding: 14px 12px; color: var(--muted); font-weight: 700;
  white-space: normal; /* Corregido */
}
.role-btn.active { background: var(--surface-solid); color: var(--primary); box-shadow: 0 8px 20px rgba(37,99,235,.12); }
.field { display: grid; gap: 8px; }
.field span { font-weight: 600; word-break: break-word; }
.input-wrap {
  display: flex; align-items: center; gap: 10px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 16px; padding: 0 14px;
}
.input-wrap i { color: var(--muted); }
.input-wrap input { width: 100%; border: none; background: transparent; outline: none; padding: 15px 0; color: var(--text); }
.icon-btn { border: none; background: transparent; color: var(--muted); }
.demo-box {
  background: linear-gradient(180deg, var(--bg-soft), transparent); border: 1px dashed var(--border); border-radius: 18px; padding: 16px;
}
.demo-box h4 { margin: 0 0 8px; word-break: break-word; }
.demo-box p { margin: 4px 0; color: var(--muted); word-break: break-word; }
code { background: var(--primary-soft); color: var(--primary); padding: 2px 8px; border-radius: 8px; word-break: break-all; }
.error-text { min-height: 20px; margin: 0; color: var(--danger); font-weight: 600; word-break: break-word; }

/* Mensajes de autenticación */
.auth-message {
  padding: 14px 16px;
  border-radius: 14px;
  margin-bottom: 18px;
  font-weight: 600;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: fadeUp .3s ease;
  word-break: break-word; /* Corregido */
}

.auth-message.error {
  background: rgba(220, 38, 38, 0.12);
  color: var(--danger);
  border: 1px solid rgba(220, 38, 38, 0.25);
}

.auth-message.success {
  background: rgba(22, 163, 74, 0.12);
  color: var(--success);
  border: 1px solid rgba(22, 163, 74, 0.25);
}

.auth-message.loading {
  background: rgba(37, 99, 235, 0.12);
  color: var(--primary);
  border: 1px solid rgba(37, 99, 235, 0.25);
}

.auth-message.warning {
  background: rgba(217, 119, 6, 0.12);
  color: var(--warning);
  border: 1px solid rgba(217, 119, 6, 0.25);
}

.auth-message i { font-size: 1.1rem; flex-shrink: 0; }

.auth-message.hidden { display: none !important; }

@media (max-width: 540px) {
  .auth-message {
    padding: 12px;
    font-size: 0.85rem;
    border-radius: 12px;
  }
}

/* Info box */
.info-box {
  background: linear-gradient(180deg, var(--bg-soft), transparent);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
}

@media (max-width: 540px) {
  .info-box {
    padding: 12px;
    border-radius: 12px;
  }
  
  .info-box h4 {
    font-size: 0.85rem;
  }
  
  .info-box p {
    font-size: 0.8rem;
  }
}

.info-box h4 {
  margin: 0 0 8px;
  font-size: 0.9rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  word-break: break-word;
}

.info-box h4 i { color: var(--primary); flex-shrink: 0; }

.info-box p {
  margin: 4px 0;
  color: var(--muted);
  font-size: 0.85rem;
  word-break: break-word;
}

.info-box code {
  background: var(--primary-soft);
  color: var(--primary);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.8rem;
}

/* Ajustes para tablas - evitar scroll horizontal */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

.table-wrap table {
  min-width: 100%;
  width: 100%;
  table-layout: auto;
}

/* Ocultar columnas menos importantes en pantallas pequeñas */
@media (max-width: 1400px) {
  table .hide-1400,
  table td.hide-1400,
  table th.hide-1400 {
    display: none;
  }
}

@media (max-width: 1100px) {
  table .hide-1100,
  table td.hide-1100,
  table th.hide-1100 {
    display: none;
  }
}

/* Melhorar scroll horizontal */
@media (max-width: 768px) {
  .table-wrap {
    margin: 0 -14px;
    padding: 0 14px;
  }
  
  table {
    font-size: 0.75rem;
  }
  
  thead th, tbody td {
    padding: 8px 6px;
  }
}

/* Input con error */
.input-wrap.error {
  border-color: var(--danger) !important;
  background: rgba(220, 38, 38, 0.06);
}

.input-wrap.error i {
  color: var(--danger);
}

/* Input con éxito */
.input-wrap.success {
  border-color: var(--success) !important;
  background: rgba(22, 163, 74, 0.06);
}

.input-wrap.success i {
  color: var(--success);
}

/* Botón deshabilitado */
.btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none !important;
}

.btn.btn-loading {
  pointer-events: none;
}

.btn.btn-loading .btn-text {
  display: none;
}

.btn.btn-loading .btn-spinner {
  display: inline-block !important;
}

.btn-spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.btn {
  border: none; border-radius: 16px; padding: 13px 18px; display: inline-flex; align-items: center; justify-content: center;
  gap: 10px; font-weight: 700; transition: .25s ease; text-decoration: none;
  word-break: break-word; /* Corregido */
  text-align: center;
}
.btn:hover { transform: translateY(-1px); }
.btn-full { width: 100%; }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: white; box-shadow: 0 14px 30px rgba(37,99,235,.22); }
.btn-soft { background: var(--primary-soft); color: var(--primary); }
.btn-danger { background: rgba(220,38,38,.12); color: var(--danger); }
.btn-success { background: rgba(22,163,74,.12); color: var(--success); }
.btn-warning { background: rgba(217,119,6,.12); color: var(--warning); }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-sm { padding: 10px 12px; border-radius: 12px; font-size: .88rem; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
  width: 100%;
  max-width: 100%;
}

.sidebar {
  background: linear-gradient(180deg, #0f172a, #13213d 55%, #0f172a);
  color: white;
  padding: 22px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
  z-index: 200;
  scrollbar-width: thin;
}
.sidebar::-webkit-scrollbar {
  width: 8px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar-top {
  flex-shrink: 0;
}

.sidebar-bottom {
  margin-top: auto;
  flex-shrink: 0;
}
.brand-mini { 
  display: flex; 
  gap: 12px; 
  align-items: center; 
  min-width: 0;
}
.brand-mini h2 { 
  margin: 0; 
  white-space: normal; /* Corregido de nowrap */
  word-break: break-word;
}
.brand-mini p { 
  margin: 2px 0 0; 
  color: rgba(255,255,255,.7); 
  white-space: normal; /* Corregido de nowrap */
  word-break: break-word;
}
.sidebar-top { 
  display: flex; 
  align-items: center; 
  justify-content: space-between; 
  min-width: 0;
}
.mobile-close, .menu-btn {
  display: inline-flex; align-items: center; justify-content: center; border: none; background: rgba(37,99,235,.12); color: var(--primary); width: 42px; height: 42px; border-radius: 12px; cursor: pointer;
}
.nav-menu { 
  display: grid; 
  gap: 8px; 
  width: 100%;
}
.nav-link {
  color: rgba(255,255,255,.8);
  padding: 14px 14px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  width: 100%;
  min-width: 0;
  flex-shrink: 0;
  white-space: normal; /* Corregido: permite saltos de línea */
  word-break: break-word;
}
.nav-link i {
  flex-shrink: 0;
}

.nav-link span,
.nav-link strong,
.nav-link p {
  min-width: 0;
  word-break: break-word;
}
.nav-link:hover, .nav-link.active { background: rgba(255,255,255,.1); color: white; }
.sidebar-bottom { margin-top: auto; display: grid; gap: 10px; }
.main-panel { 
  display: flex; 
  flex-direction: column; 
  min-width: 0; 
  overflow-x: visible;
}
.topbar {
  position: sticky; top: 0; z-index: 50; display: flex; justify-content: space-between; align-items: center; gap: 20px;
  background: rgba(244,247,251,.7); backdrop-filter: blur(14px); border-bottom: 1px solid var(--border); padding: 22px 28px;
  flex-wrap: wrap;
  box-sizing: border-box;
}
body.dark .topbar { background: rgba(11,18,32,.7); }
.topbar-left { display: flex; align-items: center; gap: 16px; min-width: 0; }
.topbar-left h1 { margin: 0; font-size: clamp(1.3rem, 2vw, 1.9rem); word-break: break-word; }
.topbar-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.user-chip {
  display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--border); padding: 10px 14px;
  border-radius: 16px; box-shadow: var(--shadow); min-width: 0;
}
.user-chip i { color: var(--primary); flex-shrink: 0; }
.user-chip strong { display: block; word-break: break-word; font-size: 0.9rem; }
.user-chip span { color: var(--muted); font-size: .9rem; word-break: break-word; }
.content-area { 
  padding: 28px; 
  display: grid; 
  gap: 26px; 
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
}
.section-block { display: grid; gap: 18px; min-width: 0; }
.section-title-row { display: flex; align-items: end; justify-content: space-between; gap: 14px; min-width: 0; }
.section-title-row.wrap { flex-wrap: wrap; }
.section-title-row h2 { margin: 0; font-size: 1.6rem; word-break: break-word; }
.toolbar { display: flex; gap: 12px; flex-wrap: wrap; }
.toolbar input, .toolbar select,
.field input, .field select, .field textarea {
  width: 100%; background: var(--surface-solid); border: 1px solid var(--border); color: var(--text); outline: none;
  padding: 14px 15px; border-radius: 14px;
}
.field textarea { resize: vertical; min-height: 110px; }
.helper { color: var(--muted); word-break: break-word; }
.card, .table-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); backdrop-filter: blur(16px); min-width: 0;
}
.card { padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.card-head h3 { margin: 0; word-break: break-word; }
.split-layout { display: grid; grid-template-columns: 1.2fr .8fr; gap: 20px; }
.chart-layout { grid-template-columns: 1fr 1fr; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.field-full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 18px; }
.preview-content {
  min-height: 440px; background: linear-gradient(180deg, var(--bg-soft), transparent); border: 1px dashed var(--border);
  border-radius: 18px; padding: 18px; word-break: break-word;
}
.empty-preview { display: grid; place-items: center; text-align: center; color: var(--muted); }
.empty-preview i { font-size: 2.8rem; margin-bottom: 8px; }
.preview-list { display: grid; gap: 12px; }
.preview-item {
  display: flex; align-items: start; justify-content: space-between; gap: 12px; padding: 12px 14px; border-radius: 14px;
  background: var(--surface-solid); border: 1px solid var(--border); min-width: 0;
}
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.teacher-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat-card {
  background: linear-gradient(180deg, var(--surface), rgba(255,255,255,.55)); border: 1px solid var(--border);
  border-radius: 20px; padding: 18px; box-shadow: var(--shadow); overflow: hidden; position: relative; min-width: 0;
}
body.dark .stat-card { background: linear-gradient(180deg, rgba(15,23,42,.92), rgba(23,34,53,.85)); }
.stat-card::after {
  content: ''; position: absolute; right: -20px; top: -20px; width: 80px; height: 80px; border-radius: 50%; background: var(--primary-soft);
}
.stat-card h4 { margin: 0 0 8px; color: var(--muted); font-size: .92rem; word-break: break-word; }
.stat-card .value { font-size: 2rem; font-weight: 800; word-break: break-all; }
.stat-card .meta { color: var(--muted); font-size: .9rem; word-break: break-word; }
.table-card { padding: 8px; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: auto; }
thead th {
  text-align: left; padding: 16px 14px; color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .06em;
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 16px 14px; border-bottom: 1px solid var(--border); vertical-align: top; word-break: break-word; }
tbody tr:hover { background: rgba(37,99,235,.04); }
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700;
  white-space: normal; /* Corregido */
  text-align: center;
}
.badge.pendiente { background: rgba(217,119,6,.13); color: var(--warning); }
.badge.en-proceso { background: rgba(37,99,235,.13); color: var(--info); }
.badge.impreso { background: rgba(124,58,237,.14); color: var(--purple); }
.badge.listo-para-recoger { background: rgba(22,163,74,.13); color: var(--success); }
.badge.entregado { background: rgba(107,114,128,.16); color: var(--gray); }
.badge.cancelado { background: rgba(220,38,38,.13); color: var(--danger); }
.urgency {
  display: inline-flex; align-items: center; gap: 6px; font-weight: 700; border-radius: 999px; padding: 7px 10px; font-size: .8rem;
  white-space: normal;
}
.urgency.baja { background: rgba(22,163,74,.12); color: var(--success); }
.urgency.media { background: rgba(37,99,235,.12); color: var(--info); }
.urgency.alta { background: rgba(220,38,38,.12); color: var(--danger); }
.action-stack { display: flex; flex-wrap: wrap; gap: 8px; }
.timeline { display: grid; gap: 14px; }
.timeline-item {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 16px 18px; box-shadow: var(--shadow);
  word-break: break-word;
}
.timeline-item h4 { margin: 0 0 6px; }
.timeline-item p, .timeline-item small { margin: 0; color: var(--muted); }
.notifications-list { display: grid; gap: 12px; }
.note-item {
  display: flex; gap: 14px; align-items: flex-start; padding: 16px; border-radius: 18px; background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow); word-break: break-word;
}
.note-item i { color: var(--primary); margin-top: 4px; flex-shrink: 0; }
.note-item h4 { margin: 0 0 4px; }
.note-item p { margin: 0; color: var(--muted); }
.inline-files { display: grid; gap: 6px; }
.file-tag {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 12px; background: var(--primary-soft); color: var(--primary);
  font-weight: 600; font-size: .88rem; word-break: break-all;
}

.file-tag .btn-download-file {
  background: transparent;
  border: none;
  color: var(--primary);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  margin-left: 4px;
  transition: background 0.2s;
  flex-shrink: 0;
}

.file-tag .btn-download-file:hover {
  background: rgba(37, 99, 235, 0.2);
}

/* Preview de archivos del maestro */
.files-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 8px;
}

.file-preview-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-align: center;
}

.file-preview-image {
  max-width: 100%;
  max-height: 80px;
  border-radius: 6px;
  object-fit: contain;
}

.file-preview-icon {
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 10px;
  font-size: 1.5rem;
  margin-bottom: 6px;
}

.file-preview-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
}

.file-preview-info strong {
  font-size: 0.75rem;
  word-break: break-all;
}

.file-preview-info span {
  font-size: 0.7rem;
  color: var(--muted);
}

@media (max-width: 540px) {
  .files-preview-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
.muted { color: var(--muted); }
.empty-state {
  background: var(--surface); border: 1px dashed var(--border); border-radius: 18px; padding: 20px; text-align: center; color: var(--muted);
  word-break: break-word;
}
.modal-overlay {
  position: fixed; inset: 0; background: rgba(2,6,23,.55); display: grid; place-items: center; z-index: 1100; padding: 18px;
}
.modal-card {
  width: min(100%, 650px); background: var(--surface-solid); border: 1px solid var(--border); border-radius: 24px; box-shadow: var(--shadow); padding: 22px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.modal-head h3 { margin: 0; word-break: break-word; }
.toast-container {
  position: fixed; top: 18px; right: 18px; z-index: 1300; display: grid; gap: 10px; width: min(92vw, 360px);
}
.toast {
  background: var(--surface-solid); border: 1px solid var(--border); box-shadow: var(--shadow); border-left: 5px solid var(--primary);
  border-radius: 16px; padding: 14px 16px; animation: fadeUp .25s ease; word-break: break-word;
}
.toast.success { border-left-color: var(--success); }
.toast.warning { border-left-color: var(--warning); }
.toast.danger { border-left-color: var(--danger); }
.canvas-empty { color: var(--muted); text-align: center; padding: 28px; word-break: break-word; }

/* Laptop y Desktop - Ajustes óptimos para pantallas grandes */
@media (min-width: 1201px) {
  .app-shell {
    max-width: 100%;
  }
  
  .content-area {
    padding: 24px;
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
  }
  
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
  }
  
  .split-layout {
    grid-template-columns: 1.5fr 1fr;
  }
  
  /* Ajustar tablas para que quepan */
  .table-wrap {
    overflow-x: auto; /* Cambiado de hidden para permitir scroll si el texto es muy largo */
  }
  
  table {
    min-width: auto;
    font-size: 0.85rem;
  }
  
  thead th, tbody td {
    padding: 12px 8px;
  }
}

/* Pantallas muy grandes - limitar ancho máximo */
@media (min-width: 1600px) {
  .app-shell {
    max-width: 1800px;
    margin: 0 auto;
  }
  
  .content-area {
    max-width: 1700px;
  }
}

/* Tablet Landscape y Laptop pequeña */
@media (max-width: 1200px) {
  .stats-grid, .teacher-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split-layout, .chart-layout { grid-template-columns: 1fr; }
  .content-area { padding: 24px; }
}

/* Tablet Portrait */
@media (max-width: 980px) {
  .auth-left {
    padding-top: 56px;
  }
  .auth-layout { grid-template-columns: 1fr; }
  .auth-left { display: none; }
  .app-shell { 
    grid-template-columns: 1fr; 
    padding-left: 0;
  }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: min(85vw, 300px); transform: translateX(-100%);
    transition: transform .28s ease; z-index: 1200;
  }
  .sidebar.show { transform: translateX(0); }
  .mobile-close, .menu-btn { display: inline-grid; place-items: center; }
  .content-area, .topbar { padding-left: 18px; padding-right: 18px; }
  .section-title-row { flex-direction: column; align-items: flex-start; }
  .card-head { flex-direction: column; align-items: flex-start; }
  .table-wrap { margin: 0 -20px; padding: 0 20px; overflow-x: auto; }
  .main-panel { margin-left: 0; }
}

/* Tablets pequeñas y Large Phones */
@media (max-width: 768px) {
  .auth-card { padding: 20px; border-radius: 18px; }
  .auth-header h2 { font-size: 1.5rem; }
  .form-grid { grid-template-columns: 1fr; }
  .stats-grid, .teacher-stats { grid-template-columns: 1fr; }
  .topbar { 
    flex-wrap: wrap; 
    padding: 14px;
    gap: 10px;
  }
  .topbar-left h1 { font-size: 1.2rem; }
  .toolbar { width: 100%; flex-direction: column; }
  .toolbar input, .toolbar select { flex: 1 1 100%; width: 100%; }
  .form-actions { grid-template-columns: 1fr; }
  .content-area { padding: 14px; gap: 16px; }
  .stat-card { padding: 12px; }
  .stat-card .value { font-size: 1.4rem; }
  .brand-block { flex-direction: column; gap: 12px; }
  .brand-icon { width: 50px; height: 50px; font-size: 1.2rem; }
  .brand-block h1 { font-size: 1.6rem; }
  .role-switch { grid-template-columns: 1fr; gap: 6px; }
  .role-btn { padding: 12px; }
  .input-wrap { padding: 0 12px; }
  .input-wrap input { padding: 12px 0; font-size: 1rem; }
  .btn { padding: 12px 16px; min-height: 48px; font-size: 0.95rem; }
  .user-chip { padding: 8px 12px; }
  .user-chip strong { font-size: 0.9rem; }
  .user-chip span { font-size: 0.8rem; }
  table { font-size: 0.8rem; }
  thead th { padding: 10px 8px; }
  tbody td { padding: 10px 8px; }
  .badge { padding: 4px 7px; font-size: 0.7rem; }
  .timeline-item { padding: 12px; }
  .note-item { padding: 10px; }
  .modal-card { padding: 14px; border-radius: 16px; }
  .toast-container { width: min(95vw, 320px); right: 8px; top: 8px; }
  .hero-cards { gap: 12px; }
  .hero-card { padding: 12px; border-radius: 14px; }
}

/* Smartphones */
@media (max-width: 540px) {
  :root {
    --radius-xl: 20px;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 10px;
  }
  
  body { font-size: 14px; }
  
  .auth-card {
    padding: 18px;
    border-radius: 18px;
    margin: 12px;
  }
  
  .auth-header h2 { font-size: 1.4rem; }
  .auth-header p { font-size: 0.9rem; }
  .auth-form { gap: 14px; margin-top: 18px; }
  
  .field span { font-size: 0.9rem; }
  .field input, .field select, .field textarea {
    padding: 12px;
    font-size: 1rem;
  }
  
  .demo-box { padding: 12px; }
  .demo-box h4 { font-size: 0.95rem; }
  .demo-box p { font-size: 0.85rem; }
  
  .btn { 
    padding: 14px 16px; 
    min-height: 50px;
    font-size: 0.95rem;
    border-radius: 14px;
  }
  
  .topbar {
    padding: 12px;
    gap: 10px;
  }
  
  .topbar-left h1 { font-size: 1.1rem; }
  .topbar-right { gap: 8px; }
  
  .user-chip {
    padding: 6px 10px;
    border-radius: 12px;
    gap: 8px;
  }
  
  .menu-btn {
    width: 38px;
    height: 38px;
    font-size: 1.2rem;
  }
  
  .content-area {
    padding: 12px;
    gap: 14px;
  }
  
  .section-title-row h2 { font-size: 1.3rem; }
  
  .card {
    padding: 14px;
    border-radius: 16px;
  }
  
  .card-head {
    margin-bottom: 12px;
    gap: 10px;
  }
  
  .stat-card {
    padding: 12px;
    border-radius: 16px;
  }
  
  .stat-card .value { font-size: 1.4rem; }
  .stat-card h4 { font-size: 0.8rem; }
  
  .toolbar {
    gap: 8px;
  }
  
  .form-actions {
    gap: 10px;
    margin-top: 14px;
  }
  
  .btn-sm {
    padding: 8px 10px;
    font-size: 0.8rem;
  }
  
  /* Tablas responsive */
  .table-card {
    padding: 4px;
    border-radius: 14px;
  }
  
  table {
    min-width: 600px;
    font-size: 0.8rem;
  }
  
  thead th {
    padding: 10px 8px;
    font-size: 0.7rem;
  }
  
  tbody td {
    padding: 10px 8px;
  }
  
  .badge {
    padding: 4px 7px;
    font-size: 0.7rem;
  }
  
  .action-stack {
    flex-direction: column;
  }
  
  .timeline {
    gap: 10px;
  }
  
  .timeline-item {
    padding: 12px;
    border-radius: 14px;
  }
  
  .timeline-item h4 { font-size: 0.95rem; }
  
  .note-item {
    padding: 10px;
    border-radius: 14px;
    flex-direction: column;
    gap: 8px;
  }
  
  .file-tag {
    padding: 6px 8px;
    font-size: 0.8rem;
  }
  
  .modal-card {
    padding: 14px;
    border-radius: 16px;
    margin: 8px;
  }
  
  .modal-head h3 { font-size: 1.1rem; }
  
  .toast {
    padding: 12px;
    border-radius: 12px;
  }
  
  .preview-content {
    padding: 12px;
    min-height: 300px;
  }
  
  .hero-card {
    padding: 14px;
    border-radius: 14px;
  }
  
  .hero-card h3 { font-size: 1rem; }
  .hero-card p { font-size: 0.85rem; }
  
  /* Ocultar sidebar en móvil completamente */
  .sidebar {
    width: 85vw;
    padding: 16px;
  }
  
  .nav-link {
    padding: 12px;
    font-size: 0.9rem;
  }
  
  .brand-mini h2 { font-size: 1.1rem; }
  .brand-mini p { font-size: 0.75rem; }
  
  /* Loader responsive */
  .loader-card {
    padding: 20px;
    border-radius: 18px;
  }
  
  .spinner {
    width: 44px;
    height: 44px;
  }
}

/* Smartphones pequeños */
@media (max-width: 380px) {
  .auth-card {
    padding: 14px;
    margin: 8px;
    border-radius: 16px;
  }
  
  .auth-header h2 { font-size: 1.25rem; }
  
  .btn {
    padding: 12px 14px;
    min-height: 46px;
    font-size: 0.9rem;
  }
  
  .topbar-left h1 { font-size: 1rem; }
  
  .stat-card .value { font-size: 1.25rem; }
  
  .section-title-row h2 { font-size: 1.15rem; }
  
  table {
    min-width: 500px;
  }
}
@media (min-width: 981px) {
  .main-panel {
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
  }
}
/* ================================================
   MEDIA QUERIES RESPONSIVE
   ================================================ */

/* Tablet Portrait (768px - 979px) - Sidebar visible como en desktop */
@media (min-width: 768px) and (max-width: 979px) {
  .app-shell {
    display: grid !important;
    grid-template-columns: 240px 1fr;
  }

  .sidebar {
    position: sticky !important;
    left: 0;
    top: 0;
    transform: translateX(0) !important;
    width: 240px;
  }

  .sidebar-overlay {
    display: none !important;
  }

  .main-panel {
    margin-left: 0;
  }

  .menu-btn,
  .mobile-close {
    display: none !important;
  }

  .content-area {
    padding: 16px;
  }
}

/* Smartphones (menor a 768px) - Menú hamburguesa */
@media (max-width: 767px) {
  .app-shell {
    display: block !important;
    min-height: 100vh;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  /* Sidebar como menú lateral */
  .sidebar {
    position: fixed !important;
    left: 0;
    top: 0;
    bottom: 0;
    width: 280px;
    max-width: 85%;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 1200;
    display: flex !important;
    overflow-y: auto;
  }

  .sidebar.show {
    transform: translateX(0);
  }

  /* Overlay */
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1100;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease;
    display: block !important;
  }

  .sidebar-overlay.show {
    opacity: 1;
    visibility: visible;
  }

  /* Botón menú */
  .menu-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: var(--primary-soft);
    border: none;
    color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
  }

  .main-panel {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100%;
    padding: 0;
  }

  /* Topbar para smartphone */
  .topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 12px !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    justify-content: space-between !important;
    align-items: center !important;
    gap: 8px !important;
    background: var(--surface) !important;
    border-bottom: 1px solid var(--border);
    width: 100% !important;
    box-sizing: border-box;
  }

  .topbar-left {
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
    min-width: 0;
    flex: 1;
  }

  .topbar-left h1 {
    font-size: 0.95rem !important;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
  }

  .eyebrow {
    display: none !important;
  }

  .topbar-right {
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
  }

  .user-chip {
    padding: 6px 8px !important;
    min-width: auto;
  }

  .user-chip > i {
    margin: 0;
    font-size: 1rem;
  }

  .user-chip > div {
    display: none !important;
  }

  .menu-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    background: var(--primary-soft);
    border: none;
    color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
  }

  .mobile-close {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    cursor: pointer;
  }

  /* Contenido principal */
  .content-area {
    padding: 12px !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
    overflow-x: hidden;
  }

  .section-block {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
  }

  /* Ajustes para smartphone */
  .split-layout,
  .chart-layout {
    grid-template-columns: 1fr !important;
  }

  .form-grid {
    grid-template-columns: 1fr !important;
  }

  .stats-grid,
  .teacher-stats {
    grid-template-columns: 1fr !important;
    gap: 10px;
  }

  /* Tarjetas */
  .card {
    padding: 12px !important;
    border-radius: 12px !important;
    margin-bottom: 10px;
  }

  .card-head {
    margin-bottom: 10px;
  }

  .card-head h3 {
    font-size: 1rem;
  }

  /* Tablas */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 500px;
    font-size: 0.75rem;
  }

  thead th,
  tbody td {
    padding: 8px 6px;
    white-space: nowrap;
  }

  /* Toolbar */
  .toolbar {
    flex-direction: column;
    gap: 8px;
    width: 100%;
  }

  .toolbar input,
  .toolbar select {
    width: 100%;
    min-width: 0;
  }

  /* Botones */
  .btn {
    padding: 10px 14px;
    font-size: 0.85rem;
    min-height: 40px;
  }

  .btn-sm {
    padding: 5px 8px;
    font-size: 0.7rem;
  }

  /* Formularios */
  .form-grid {
    gap: 12px;
  }

  .field-full {
    grid-column: 1;
  }

  .input-wrap {
    padding: 0 10px;
  }

  .field input,
  .field select,
  .field textarea {
    padding: 10px;
    font-size: 14px;
  }

  /* Estadísticas */
  .stat-card {
    padding: 10px;
    border-radius: 12px;
  }

  .stat-card h4 {
    font-size: 0.7rem;
  }

  .stat-card .value {
    font-size: 1.2rem;
  }

  /* Títulos de sección */
  .section-title-row h2 {
    font-size: 1.1rem;
  }

  /* Badge y pills */
  .status-pill,
  .priority-pill,
  .badge {
    padding: 3px 6px;
    font-size: 0.65rem;
  }

  /* Admin actions */
  .admin-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
  }
}