:root {
  --page: #f3f6f8;
  --surface: #ffffff;
  --surface-subtle: #f7f9fa;
  --surface-strong: #eaf0f3;
  --text: #10212b;
  --text-soft: #29404d;
  --muted: #60737e;
  --border: #d9e1e5;
  --border-strong: #a9b8c0;
  --navy: #0b3f5d;
  --navy-dark: #082f46;
  --primary: #007e78;
  --primary-hover: #006862;
  --primary-soft: #dff3f1;
  --success: #167653;
  --success-soft: #e3f4ec;
  --warning: #9a5b00;
  --warning-soft: #fff1d6;
  --danger: #b23845;
  --danger-soft: #fbe8ea;
  --info: #246a8d;
  --info-soft: #e1f0f7;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --topbar-height: 76px;
  --sidebar-width: 292px;
  --overlay-shadow: 0 24px 64px rgba(8, 47, 70, 0.2);
}

* {
  scrollbar-color: #a9b8c0 transparent;
  scrollbar-width: thin;
}

html {
  background: var(--page);
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  overflow-x: hidden;
  background: var(--page);
  color: var(--text);
  font-family: "Manrope", "Segoe UI Variable Text", "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  padding-bottom: 0;
}

html.sidebar-open,
body.sidebar-open {
  overflow: hidden;
  overscroll-behavior: none;
}

h1,
h2,
h3,
strong {
  letter-spacing: -0.02em;
}

h1 {
  font-size: clamp(1.35rem, 4.6vw, 1.75rem);
  font-weight: 800;
}

h2 {
  font-size: clamp(1.18rem, 4vw, 1.48rem);
  font-weight: 750;
}

h3 {
  font-size: 1rem;
  font-weight: 700;
}

.skip-link {
  position: fixed;
  z-index: 1000;
  top: 10px;
  left: 10px;
  transform: translateY(-150%);
  border-radius: var(--radius-sm);
  background: var(--navy-dark);
  color: #fff;
  padding: 10px 14px;
  font-weight: 700;
  text-decoration: none;
}

.skip-link:focus {
  transform: translateY(0);
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.button,
.icon-button,
.text-button {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(0, 126, 120, 0.32);
  outline-offset: 2px;
}

input,
select,
textarea {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
}

input,
select {
  min-height: 46px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 126, 120, 0.1);
}

input::placeholder,
textarea::placeholder {
  color: #75858e;
}

.input-icon-button {
  width: 44px;
  min-width: 44px;
  height: 44px;
}

.forgot-button,
#registerBtn {
  min-height: 44px;
  padding: 8px 4px;
}

.button {
  min-height: 44px;
  gap: 8px;
  border-radius: var(--radius-sm);
  padding: 0 16px;
  font-size: 0.88rem;
  font-weight: 750;
  letter-spacing: -0.01em;
  transition: transform 140ms ease, background-color 140ms ease, border-color 140ms ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button:active:not(:disabled) {
  transform: translateY(0);
}

.button-primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.button-primary:hover:not(:disabled) {
  border-color: var(--primary-hover);
  background: var(--primary-hover);
}

.button-secondary,
.button-google,
.button-quiet {
  border-color: var(--border);
  background: #fff;
  color: var(--text-soft);
}

.button-secondary:hover:not(:disabled),
.button-google:hover:not(:disabled),
.button-quiet:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--surface-subtle);
}

.text-button {
  color: var(--primary-hover);
  font-weight: 750;
  text-underline-offset: 3px;
}

.icon-button {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text-soft);
}

.icon-button:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--surface-subtle);
  color: var(--navy);
}

/* Acceso */

.auth-view {
  min-height: 100dvh;
  align-items: start;
  border-top: 5px solid var(--navy);
  background: #fff;
  padding: max(22px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
}

.auth-access {
  width: min(440px, 100%);
  min-height: auto;
  padding: 0;
}

.auth-card {
  width: 100%;
  border: 0;
  border-radius: 0;
  background: #fff;
  box-shadow: none;
  padding: 0;
}

.auth-institution {
  gap: 11px;
  border-bottom: 1px solid var(--border);
  padding: 0 0 17px;
}

.brand-logo {
  width: 29px;
  height: 38px;
  flex-basis: 29px;
  object-fit: contain;
}

.auth-institution > span,
.brand-lockup > span {
  display: grid;
  gap: 1px;
}

.auth-institution strong,
.brand-lockup strong {
  color: var(--navy-dark);
  font-size: 0.92rem;
  font-weight: 800;
}

.auth-institution small,
.brand-lockup small {
  color: var(--muted);
  font-size: 0.76rem;
}

.auth-heading {
  margin: 24px 0 20px;
}

.auth-heading h2 {
  color: var(--navy-dark);
  font-size: clamp(1.6rem, 7vw, 2rem);
  font-weight: 800;
  line-height: 1.15;
}

.auth-heading > p:last-child {
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.9rem;
}

.auth-form {
  gap: 14px;
}

.form-field {
  gap: 6px;
}

.form-field > span:first-child,
.color-field legend {
  color: var(--text-soft);
  font-size: 0.82rem;
  font-weight: 750;
}

.color-field {
  display: grid;
}

.input-shell input {
  min-height: 48px;
  padding-right: 46px;
}

.input-shell > svg {
  color: var(--muted);
}

.forgot-button {
  min-height: 44px;
  margin-top: -3px;
  font-size: 0.8rem;
}

.button-full {
  min-height: 48px;
}

.auth-divider {
  margin: 2px 0;
  color: var(--muted);
  font-size: 0.76rem;
}

.register-copy {
  margin-top: 14px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
  color: var(--muted);
  font-size: 0.8rem;
}

.google-logo {
  width: 20px;
  height: 20px;
}

/* Navegación y estructura */

.app-shell {
  min-height: 100dvh;
  background: var(--page);
}

.app-content {
  min-width: 0;
}

.app-sidebar {
  z-index: 120;
  width: min(88vw, 320px);
  border-right: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  box-shadow: 18px 0 48px rgba(8, 47, 70, 0.18);
}

.sidebar-backdrop {
  z-index: 110;
  background: rgba(8, 31, 45, 0.52);
}

.sidebar-brand {
  min-height: 74px;
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
}

.sidebar-section-heading {
  min-height: 52px;
  padding: 15px 14px 8px 18px;
  color: var(--text-soft);
  font-size: 0.78rem;
  font-weight: 800;
}

.sidebar-add-button {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  color: var(--primary-hover);
  padding: 0 11px;
  font-size: 0.76rem;
  font-weight: 800;
}

.sidebar-search {
  margin: 2px 12px 12px;
}

.sidebar-search input {
  min-height: 43px;
  border-color: transparent;
  background: var(--surface-strong);
  font-size: 0.84rem;
}

.subject-list {
  gap: 5px;
  padding: 0 10px 14px;
}

.subject-item {
  min-height: 66px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 11px 10px 15px;
}

.subject-item:hover {
  background: var(--surface-subtle);
}

.subject-item.active {
  border-color: #b7dcd8;
  background: var(--primary-soft);
  color: var(--navy-dark);
}

.subject-item.active::before {
  top: 12px;
  bottom: 12px;
  left: 5px;
  width: 3px;
  border-radius: 3px;
  background: var(--primary);
}

.subject-copy strong {
  font-size: 0.87rem;
  font-weight: 800;
}

.subject-copy small {
  color: var(--muted);
  font-size: 0.75rem;
}

.sidebar-account {
  min-height: 74px;
  border-top: 1px solid var(--border);
  background: var(--surface-subtle);
  padding: 10px 12px;
}

.user-avatar,
.student-avatar {
  border: 1px solid #c8d6dc;
  border-radius: 50%;
  background: #edf3f5;
  color: var(--navy);
  font-weight: 800;
}

.account-copy strong {
  font-size: 0.84rem;
  font-weight: 800;
}

.account-copy small {
  color: var(--muted);
  font-size: 0.75rem;
}

.topbar {
  position: sticky;
  z-index: 70;
  top: 0;
  min-height: var(--topbar-height);
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
  padding: 9px 12px;
}

.topbar-context {
  min-width: 0;
}

.topbar-context > div {
  min-width: 0;
}

.topbar-context h1 {
  max-width: 62vw;
  margin-top: 1px;
  overflow: hidden;
  color: var(--navy-dark);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.context-label {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  flex-wrap: nowrap;
  gap: 6px;
}

.topbar-actions .compact-action {
  width: 42px;
  min-width: 42px;
  padding: 0;
}

.topbar-actions .compact-action span {
  display: none;
}

.workspace-shell {
  width: 100%;
  max-width: 1520px;
  margin: 0 auto;
  padding: 0 12px calc(96px + env(safe-area-inset-bottom));
}

.workspace-tabs {
  position: fixed;
  z-index: 90;
  top: auto;
  right: 0;
  bottom: 0;
  left: 0;
  min-height: calc(68px + env(safe-area-inset-bottom));
  align-items: flex-start;
  gap: 0;
  border: 0;
  border-top: 1px solid var(--border);
  background: #fff;
  box-shadow: 0 -8px 28px rgba(8, 47, 70, 0.1);
  padding: 6px 5px calc(5px + env(safe-area-inset-bottom));
}

.tab-button {
  min-width: 0;
  min-height: 56px;
  flex: 1;
  flex-direction: column;
  gap: 3px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  padding: 5px 2px;
  font-size: 0.75rem;
  font-weight: 700;
}

.tab-button svg {
  display: block;
  width: 20px;
  height: 20px;
}

.tab-button:hover {
  background: var(--surface-subtle);
  color: var(--text-soft);
}

.tab-button.active {
  background: var(--primary-soft);
  color: var(--primary-hover);
}

.tab-button::after {
  display: none;
}

.workspace-page {
  padding-top: 18px;
  scroll-margin-top: calc(var(--topbar-height) + 12px);
}

.workspace-page:focus {
  outline: none;
}

.welcome-state {
  width: min(540px, 100%);
  min-height: 0;
  justify-items: start;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: #fff;
  box-shadow: 0 14px 42px rgba(8, 47, 70, 0.08);
  margin: 28px auto;
  padding: 28px;
  text-align: left;
}

.welcome-state h2 {
  color: var(--navy-dark);
}

.welcome-state > p:not(.empty-state-context) {
  margin: 7px 0 20px;
  color: var(--muted);
  font-size: 0.88rem;
}

.empty-state-context {
  margin-bottom: 5px;
  color: var(--primary-hover);
  font-size: 0.75rem;
  font-weight: 800;
}

/* Resumen */

.teacher-focus {
  display: grid;
  gap: 16px;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 2px 0 18px;
}

.teacher-focus h2 {
  color: var(--navy-dark);
  font-size: 1.28rem;
}

.teacher-focus p {
  max-width: 620px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.84rem;
}

.quick-actions {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.quick-action,
.quick-action:first-child {
  width: 100%;
  min-height: 46px;
  justify-content: center;
}

.quick-action:first-child {
  grid-column: 1 / -1;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fff;
  box-shadow: 0 10px 30px rgba(8, 47, 70, 0.05);
  margin-top: 0;
}

.stat-card,
.stat-card:first-child,
.stat-card:nth-child(3),
.stat-card:nth-child(4) {
  min-height: 112px;
  border: 0;
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
  background: #fff;
  padding: 17px;
}

.stat-card:nth-child(odd) {
  border-left: 0;
}

.stat-card:nth-child(-n + 2) {
  border-top: 0;
}

.stat-copy {
  gap: 2px;
}

.stat-copy small {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.stat-copy strong {
  margin-top: 5px;
  color: var(--navy-dark);
  font-size: 1.75rem;
  font-weight: 800;
}

.stat-copy > span {
  color: var(--muted);
  font-size: 0.75rem;
}

.overview-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 12px;
}

.surface-section,
.data-surface,
.history-panel {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fff;
  box-shadow: 0 10px 30px rgba(8, 47, 70, 0.04);
}

.surface-section {
  padding: 18px;
}

.section-heading h2 {
  color: var(--navy-dark);
  font-size: 1rem;
  font-weight: 800;
}

.subtle-badge,
.save-status,
.toolbar-note,
.autosave-note {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
  font-size: 0.75rem;
  font-weight: 650;
}

.stacked-progress,
.mini-progress {
  height: 7px;
  border-radius: 7px;
  background: #e7edef;
}

.stacked-progress span,
.mini-progress span {
  border-radius: 7px;
}

.progress-legend {
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--muted);
  font-size: 0.75rem;
}

.compact-row {
  min-height: 62px;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 8px 0;
}

.compact-row:last-child {
  border-bottom: 0;
}

.compact-row-copy strong,
.attendance-ring-copy strong {
  font-size: 0.82rem;
}

.compact-row-copy small,
.attendance-ring-copy span {
  color: var(--muted);
  font-size: 0.75rem;
}

.attendance-ring-row {
  min-height: 76px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  padding: 14px;
}

.attendance-ring {
  color: var(--primary-hover);
  font-size: 1.35rem;
  font-weight: 800;
}

/* Páginas de trabajo */

.page-heading {
  min-height: auto;
  align-items: stretch;
  gap: 14px;
  border-bottom: 0;
  margin-bottom: 14px;
  padding-bottom: 0;
}

.page-heading h2 {
  color: var(--navy-dark);
  font-size: 1.28rem;
}

.page-heading > div:first-child > p:last-child {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.8rem;
}

.page-heading-actions {
  width: 100%;
}

.page-heading-actions .button,
.page-heading > .button {
  width: 100%;
}

.data-toolbar {
  min-height: auto;
  align-items: stretch;
  gap: 9px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-subtle);
  padding: 10px;
}

.search-control {
  width: 100%;
}

.search-control input {
  width: 100%;
  min-height: 44px;
  background: #fff;
  font-size: 0.82rem;
}

.select-control {
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.76rem;
}

.select-control select {
  min-height: 42px;
}

.toolbar-actions,
.gradebook-help {
  width: 100%;
  justify-content: stretch;
}

.toolbar-actions .button {
  flex: 1;
}

.table-wrap,
.gradebook-wrap {
  overflow: visible;
  background: var(--page);
}

.students-table,
.gradebook-table,
.students-table tbody,
.gradebook-table tbody {
  display: block;
  width: 100%;
}

.students-table thead,
.gradebook-table thead {
  display: none;
}

.students-table tr,
.gradebook-table .gradebook-row {
  display: block;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fff;
  box-shadow: 0 8px 24px rgba(8, 47, 70, 0.04);
  margin: 10px;
}

.students-table td,
.gradebook-table td {
  display: flex;
  width: 100%;
  min-height: 44px;
  height: auto;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: #fff;
  padding: 10px 13px;
  text-align: right;
}

.students-table td:last-child,
.gradebook-table td:last-child {
  border-bottom: 0;
}

.students-table td::before,
.gradebook-table .grade-cell::before,
.gradebook-table .grade-summary::before {
  content: attr(data-label);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-align: left;
}

.students-table td:first-child,
.gradebook-table td:first-child {
  justify-content: flex-start;
  background: var(--surface-subtle);
  text-align: left;
}

.students-table td:first-child::before,
.gradebook-table td:first-child::before {
  display: none;
}

.gradebook-table .grade-cell,
.gradebook-table .grade-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.student-cell {
  min-width: 0;
}

.student-avatar {
  width: 36px;
  height: 36px;
  flex-basis: 36px;
  font-size: 0.75rem;
}

.student-primary {
  min-width: 0;
}

.student-primary strong {
  overflow: hidden;
  font-size: 0.82rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.student-primary small,
.grade-progress small {
  color: var(--muted);
  font-size: 0.75rem;
}

.gradebook-input {
  width: 92px;
  min-height: 42px;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 750;
  text-align: center;
}

.gradebook-input.dirty {
  border-color: var(--warning);
  background: var(--warning-soft);
}

.gradebook-table .gradebook-row:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 126, 120, 0.12);
}

.status-badge {
  min-height: 28px;
  border: 0;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 0.75rem;
  font-weight: 800;
}

.status-badge.approved {
  background: var(--success-soft);
  color: var(--success);
}

.status-badge.risk {
  background: var(--danger-soft);
  color: var(--danger);
}

.status-badge.pending {
  background: var(--surface-strong);
  color: var(--muted);
}

.row-actions {
  margin-left: auto;
}

.row-actions .icon-button {
  min-height: 44px;
  height: 44px;
}

#goToAttendanceBtn {
  min-height: 44px;
  padding: 8px 10px;
}

.inline-empty-state {
  min-height: 220px;
  background: #fff;
  color: var(--muted);
}

/* Asistencia */

.attendance-page-heading {
  gap: 14px;
}

.date-navigation {
  display: grid;
  width: 100%;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  gap: 7px;
}

.date-navigation #todayBtn,
.period-control {
  grid-column: 1 / -1;
}

.period-control {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  border-left: 0;
  margin-left: 0;
  padding-left: 0;
}

.period-control select {
  width: 100%;
}

.attendance-stats {
  display: grid;
  min-height: auto;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fff;
  margin-bottom: 12px;
  padding: 12px;
  font-size: 0.75rem;
}

.attendance-pending {
  grid-column: 1 / -1;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.attendance-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.attendance-list {
  padding: 0;
}

.attendance-row {
  display: grid;
  min-height: 0;
  gap: 12px;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: #fff;
  padding: 14px 12px;
}

.attendance-row:last-child {
  border-bottom: 0;
}

.attendance-student-copy strong {
  font-size: 0.82rem;
  font-weight: 800;
}

.attendance-student-copy small {
  color: var(--muted);
  font-size: 0.75rem;
}

.attendance-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  border: 0;
}

.attendance-button {
  min-height: 44px;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  font-size: 0.75rem;
  font-weight: 700;
}

.attendance-button.active {
  border-color: currentColor;
  background: #fff;
  box-shadow: inset 0 0 0 1px currentColor;
}

.history-panel > .section-heading {
  min-height: 58px;
  border-bottom: 1px solid var(--border);
  padding: 10px 13px;
}

.history-item {
  min-height: 66px;
  border-radius: 0;
}

.history-item.active {
  background: var(--primary-soft);
  box-shadow: inset 3px 0 0 var(--primary);
}

/* Modales */

.modal-backdrop {
  background: rgba(8, 31, 45, 0.58);
}

.modal-dialog {
  max-height: min(92dvh, 900px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--overlay-shadow);
}

.modal-header {
  min-height: 64px;
  border-bottom: 1px solid var(--border);
  background: #fff;
  padding: 12px 15px;
}

.modal-header h2 {
  color: var(--navy-dark);
  font-size: 1.18rem;
  font-weight: 800;
}

.modal-form {
  gap: 18px;
  padding: 16px 15px;
}

.form-grid,
.rounding-controls,
.period-weights-grid {
  grid-template-columns: 1fr;
  gap: 13px;
}

.rounding-settings,
.period-weights-field {
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
  padding: 14px;
}

.rounding-settings-heading {
  align-items: flex-start;
  gap: 10px;
}

.rounding-example,
.period-weight-total {
  border: 0;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-hover);
  padding: 5px 9px;
  font-size: 0.75rem;
  font-weight: 800;
}

.acta-weight-note {
  border: 0;
  border-left: 3px solid var(--primary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--info-soft);
  font-size: 0.78rem;
}

.modal-footer {
  position: sticky;
  z-index: 5;
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  border-top: 1px solid var(--border);
  background: #fff;
  padding: 12px 15px calc(12px + env(safe-area-inset-bottom));
}

.modal-footer .danger-left {
  grid-column: 1 / -1;
}

.modal-form > .modal-footer {
  margin: 0 -15px -16px;
}

.toast {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--overlay-shadow);
}

@media (min-width: 540px) {
  .quick-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .page-heading-actions,
  .page-heading > .button {
    width: auto;
  }

  .page-heading-actions .button {
    width: auto;
  }

  .data-toolbar {
    flex-direction: row;
    align-items: center;
  }

  .search-control {
    width: min(340px, 100%);
  }

  .toolbar-actions,
  .gradebook-help {
    width: auto;
  }

  .attendance-actions {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (min-width: 701px) {
  :root {
    --topbar-height: 82px;
  }

  .auth-view {
    place-items: center;
    background: var(--page);
    padding: 42px 24px;
  }

  .auth-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 70px rgba(8, 47, 70, 0.1);
    padding: 34px 36px;
  }

  .auth-heading {
    margin-top: 28px;
  }

  .workspace-shell {
    padding: 0 24px 48px;
  }

  .workspace-tabs {
    position: sticky;
    z-index: 60;
    top: var(--topbar-height);
    min-height: 58px;
    align-items: stretch;
    gap: 4px;
    border: 0;
    border-bottom: 1px solid var(--border);
    background: rgba(243, 246, 248, 0.96);
    box-shadow: none;
    padding: 7px 0;
  }

  .tab-button {
    min-height: 44px;
    flex: 0 0 auto;
    flex-direction: row;
    gap: 7px;
    padding: 0 15px;
    font-size: 0.82rem;
  }

  .tab-button svg {
    width: 18px;
    height: 18px;
  }

  .workspace-page {
    padding-top: 24px;
  }

  .teacher-focus {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    padding-bottom: 20px;
  }

  .quick-actions {
    width: auto;
  }

  .quick-action,
  .quick-action:first-child {
    grid-column: auto;
    width: auto;
  }

  .stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .stat-card,
  .stat-card:first-child,
  .stat-card:nth-child(3),
  .stat-card:nth-child(4) {
    min-height: 118px;
    border-top: 0;
    border-left: 1px solid var(--border);
    padding: 20px;
  }

  .stat-card:first-child {
    border-left: 0;
  }

  .page-heading {
    min-height: 66px;
    flex-direction: row;
    align-items: flex-end;
    justify-content: space-between;
  }

  .data-toolbar {
    min-height: 66px;
    padding: 10px 12px;
  }

  .students-table,
  .gradebook-table {
    display: table;
  }

  .students-table tbody,
  .gradebook-table tbody {
    display: table-row-group;
  }

  .students-table thead,
  .gradebook-table thead {
    display: table-header-group;
  }

  .students-table tr,
  .gradebook-table .gradebook-row {
    display: table-row;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    margin: 0;
  }

  .students-table th,
  .gradebook-table th {
    height: 50px;
    border-bottom: 1px solid var(--border-strong);
    background: var(--surface-strong);
    color: var(--text-soft);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.03em;
    text-transform: uppercase;
  }

  .students-table td,
  .gradebook-table td {
    display: table-cell;
    width: auto;
    height: 66px;
    border-bottom: 1px solid var(--border);
    background: #fff;
    padding: 10px 12px;
    text-align: left;
  }

  .gradebook-table .grade-cell,
  .gradebook-table .grade-summary {
    display: table-cell;
  }

  .students-table td::before,
  .gradebook-table .grade-cell::before,
  .gradebook-table .grade-summary::before {
    display: none;
  }

  .table-wrap,
  .gradebook-wrap {
    contain: inline-size;
    overflow-x: auto;
    background: #fff;
  }

  .attendance-page-heading {
    align-items: flex-start;
  }

  .date-navigation {
    width: auto;
    grid-template-columns: 42px 160px 42px auto;
  }

  .date-navigation #todayBtn {
    grid-column: auto;
  }

  .period-control {
    grid-column: 1 / -1;
  }

  .attendance-stats {
    display: flex;
    min-height: 54px;
    align-items: center;
    gap: 18px;
    margin-bottom: 0;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    font-size: 0.78rem;
  }

  .attendance-pending {
    grid-column: auto;
    border-top: 0;
    border-left: 1px solid var(--border);
    margin-left: auto;
    padding-top: 0;
    padding-left: 16px;
  }

  .attendance-row {
    grid-template-columns: minmax(210px, 1fr) auto;
    align-items: center;
    padding: 12px 14px;
  }

  .attendance-button {
    min-width: 94px;
  }

  .modal-dialog {
    border-radius: var(--radius-lg);
  }

  .modal-form {
    padding: 20px;
  }

  .form-grid,
  .rounding-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .period-weights-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .modal-footer {
    display: flex;
    padding: 14px 20px;
  }

  .modal-form > .modal-footer {
    margin: 0 -20px -20px;
  }

  .modal-footer .danger-left {
    grid-column: auto;
  }
}

@media (min-width: 981px) {
  .app-sidebar {
    width: var(--sidebar-width);
    box-shadow: none;
  }

  .sidebar-brand {
    min-height: var(--topbar-height);
    padding: 15px 20px;
  }

  .topbar {
    padding: 12px 28px;
  }

  .topbar-context h1 {
    max-width: none;
  }

  .topbar-actions .compact-action {
    width: auto;
    min-width: 0;
    padding: 0 14px;
  }

  .topbar-actions .compact-action span {
    display: inline;
  }

  .workspace-shell {
    padding-right: 28px;
    padding-left: 28px;
  }

  .overview-grid {
    grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.75fr);
    gap: 16px;
    margin-top: 16px;
  }

  .attendance-layout {
    grid-template-columns: minmax(0, 1fr) 330px;
    gap: 16px;
  }

  .period-control {
    grid-column: auto;
    grid-template-columns: auto 140px;
    border-left: 1px solid var(--border);
    margin-left: 3px;
    padding-left: 10px;
  }
}

@media (min-width: 1240px) {
  .workspace-shell {
    padding-right: 36px;
    padding-left: 36px;
  }

  .teacher-focus h2 {
    font-size: 1.5rem;
  }

  .stat-card,
  .stat-card:first-child,
  .stat-card:nth-child(3),
  .stat-card:nth-child(4) {
    padding: 22px 24px;
  }
}

@media (max-width: 370px) {
  .topbar-actions #exportBtn {
    display: none;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stat-card,
  .stat-card:first-child,
  .stat-card:nth-child(2),
  .stat-card:nth-child(3),
  .stat-card:nth-child(4) {
    border-top: 1px solid var(--border);
    border-left: 1px solid var(--border);
  }

  .stat-card:nth-child(odd) {
    border-left: 0;
  }

  .stat-card:nth-child(-n + 2) {
    border-top: 0;
  }
}

/* Piso tipográfico y táctil: ninguna ayuda visual baja de 12 px. */
.subject-copy small,
.account-copy small,
.context-label,
.topbar-context .context-label,
.tab-button,
.stat-copy small,
.stat-copy > span,
.subtle-badge,
.save-status,
.toolbar-note,
.autosave-note,
.progress-legend,
.compact-row-copy small,
.attendance-ring-copy span,
.select-control,
.students-table td::before,
.gradebook-table .grade-cell::before,
.gradebook-table .grade-summary::before,
.user-avatar,
.student-avatar,
.student-primary small,
.grade-progress small,
.status-badge,
.attendance-stats,
.attendance-student-copy small,
.attendance-button,
.history-copy small,
.history-rate,
.history-empty,
.rounding-example,
.period-weight-total,
.acta-weight-note,
.students-table th,
.gradebook-table th {
  font-size: 0.75rem;
}

.icon-button {
  width: 44px;
  min-width: 44px;
  height: 44px;
  flex-basis: 44px;
}

@media (max-width: 700px) {
  .topbar-actions .compact-action {
    width: 44px;
    min-width: 44px;
    height: 44px;
    flex-basis: 44px;
  }

}

@media (min-width: 701px) and (max-width: 980px) {
  .teacher-focus {
    grid-template-columns: 1fr;
  }

  .students-table {
    min-width: 700px;
  }

  .topbar-actions .compact-action {
    width: 44px;
    min-width: 44px;
    height: 44px;
  }
}

@media (min-width: 981px) and (max-width: 1099px) {
  .mobile-only {
    display: inline-grid !important;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(var(--sidebar-width), calc(100vw - 56px));
    transform: translateX(-102%);
    transition: transform 160ms ease;
  }

  .app-sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    z-index: 110;
    inset: 0;
  }

  .app-content {
    width: 100%;
    margin-left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* Blindaje responsive para teléfonos y ventanas de poca altura. */
@media (max-width: 700px) {
  :root {
    --topbar-height: 68px;
    --mobile-nav-height: calc(68px + env(safe-area-inset-bottom));
  }

  html,
  body,
  .app-shell,
  .app-content,
  .workspace-shell,
  #subjectWorkspace,
  .workspace-page,
  .data-surface,
  .table-wrap {
    max-width: 100%;
  }

  .topbar {
    min-width: 0;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-right: max(10px, env(safe-area-inset-right));
    padding-left: max(10px, env(safe-area-inset-left));
  }

  .topbar-context {
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
  }

  .topbar-context > div {
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
  }

  .topbar-context h1 {
    max-width: 100%;
  }

  .topbar-actions {
    min-width: 0;
    flex: 0 0 auto;
  }

  .topbar-actions #editSubjectBtn,
  .topbar-actions .compact-action {
    width: 44px;
    min-width: 44px;
    height: 44px;
    flex: 0 0 44px;
  }

  .forgot-button,
  .sidebar-add-button,
  .sidebar-search input,
  .text-button,
  .input-icon-button,
  .gradebook-input,
  .attendance-button,
  .select-control select,
  .period-control select,
  #gradesPage .page-heading-actions .button {
    min-height: 44px;
  }

  .input-icon-button,
  .toast-close,
  .color-swatch {
    width: 44px;
    min-width: 44px;
    height: 44px;
  }

  .workspace-shell {
    padding-right: max(10px, env(safe-area-inset-right));
    padding-bottom: calc(var(--mobile-nav-height) + 28px);
    padding-left: max(10px, env(safe-area-inset-left));
  }

  .workspace-tabs {
    right: 0;
    bottom: 0;
    left: 0;
    min-height: var(--mobile-nav-height);
    padding-right: max(4px, env(safe-area-inset-right));
    padding-bottom: max(5px, env(safe-area-inset-bottom));
    padding-left: max(4px, env(safe-area-inset-left));
  }

  .tab-button {
    overflow: hidden;
    line-height: 1.15;
    text-align: center;
  }

  .tab-button svg {
    flex: 0 0 auto;
  }

  .page-heading,
  .page-heading-actions,
  .data-toolbar,
  .toolbar-actions,
  .gradebook-help,
  .attendance-page-heading,
  .attendance-student,
  .attendance-actions {
    min-width: 0;
    max-width: 100%;
  }

  .search-control,
  .select-control,
  .date-navigation,
  .period-control,
  .data-toolbar > .button,
  .attendance-toolbar .toolbar-actions,
  .attendance-toolbar .toolbar-actions .button {
    width: 100%;
    min-width: 0;
  }

  .date-navigation {
    grid-template-columns: 44px minmax(0, 1fr) 44px;
  }

  .date-navigation input[type="date"] {
    width: 100%;
    min-width: 0;
  }

  .toolbar-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px;
  }

  .attendance-toolbar .toolbar-actions .icon-button {
    width: 44px;
    min-width: 44px;
  }

  .attendance-student-copy,
  .student-primary,
  .compact-row-copy,
  .history-copy {
    min-width: 0;
  }

  .attendance-student-copy strong,
  .attendance-student-copy small,
  .student-primary strong,
  .student-primary small,
  .compact-row-copy strong,
  .compact-row-copy small,
  .history-copy strong,
  .history-copy small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #gradesPage:has(#gradebookStatus.dirty) #saveGradesBtn {
    position: fixed;
    z-index: 75;
    top: max(10px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    bottom: auto;
    left: auto;
    width: 104px;
    min-width: 104px;
    padding: 0 12px;
    font-size: 0;
    box-shadow: 0 8px 22px rgba(8, 47, 70, 0.2);
  }

  #gradesPage:has(#gradebookStatus.dirty) #saveGradesBtn svg {
    margin: 0;
  }

  #gradesPage:has(#gradebookStatus.dirty) #saveGradesBtn::after {
    content: "Guardar";
    font-size: 0.78rem;
  }

  body:has(#gradesPage:not([hidden]) #gradebookStatus.dirty) #subjectActions {
    display: none;
  }

  body:has(#gradesPage:not([hidden]) #gradebookStatus.dirty) .topbar {
    padding-right: max(122px, calc(112px + env(safe-area-inset-right)));
  }

  .modal {
    align-items: end;
    padding: env(safe-area-inset-top) 0 0;
  }

  .modal-dialog,
  .modal-dialog-wide,
  .modal-dialog-subject,
  .modal-dialog-small {
    width: 100%;
    max-width: 100%;
    max-height: calc(100dvh - env(safe-area-inset-top));
    overscroll-behavior: contain;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
  }

  .modal-header {
    top: 0;
    min-width: 0;
    padding-right: max(12px, env(safe-area-inset-right));
    padding-left: max(15px, env(safe-area-inset-left));
  }

  .modal-header > div {
    min-width: 0;
  }

  .modal-header h2 {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .modal-form {
    min-width: 0;
    padding-right: max(15px, env(safe-area-inset-right));
    padding-left: max(15px, env(safe-area-inset-left));
  }

  .modal-footer {
    padding-right: max(15px, env(safe-area-inset-right));
    padding-left: max(15px, env(safe-area-inset-left));
  }

  .toast-region {
    right: max(10px, env(safe-area-inset-right));
    bottom: calc(var(--mobile-nav-height) + 10px);
    left: max(10px, env(safe-area-inset-left));
    width: auto;
  }

  .toast {
    width: 100%;
    max-width: none;
  }
}

@media (max-width: 374px) {
  .topbar {
    gap: 6px;
    padding-right: 8px;
    padding-left: 8px;
  }

  .topbar-context {
    gap: 7px;
  }

  .topbar-actions {
    gap: 4px;
  }

  .topbar-actions #editSubjectBtn,
  .topbar-actions .compact-action {
    width: 44px;
    min-width: 44px;
    height: 44px;
    flex-basis: 44px;
  }

  .topbar-actions #exportBtn {
    display: none;
  }

  .context-label {
    display: none;
  }

  .tab-button {
    padding-right: 0;
    padding-left: 0;
    font-size: 0.72rem;
  }

  .teacher-focus,
  .surface-section,
  .data-toolbar,
  .attendance-stats,
  .rounding-settings,
  .period-weights-field {
    padding-right: 11px;
    padding-left: 11px;
  }

  .quick-actions {
    grid-template-columns: 1fr;
  }

  .quick-action:first-child {
    grid-column: auto;
  }

  .attendance-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .modal-footer {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .modal-footer .danger-left {
    grid-column: 1 / -1;
  }
}

@media (max-width: 700px) and (max-height: 520px) and (orientation: landscape) {
  :root {
    --topbar-height: 58px;
    --mobile-nav-height: calc(58px + env(safe-area-inset-bottom));
  }

  .topbar {
    min-height: var(--topbar-height);
    padding-top: 5px;
    padding-bottom: 5px;
  }

  .context-label {
    font-size: 0.7rem;
  }

  .workspace-tabs {
    min-height: var(--mobile-nav-height);
    padding-top: 3px;
  }

  .tab-button {
    min-height: 48px;
    flex-direction: row;
    justify-content: center;
    font-size: 0;
  }

  .modal-dialog,
  .modal-dialog-wide,
  .modal-dialog-subject,
  .modal-dialog-small {
    max-height: 100dvh;
    border-radius: 0;
  }
}

@media (hover: none) {
  .button:hover:not(:disabled) {
    transform: none;
  }

  .button-primary:hover:not(:disabled) {
    border-color: var(--primary);
    background: var(--primary);
  }

  .button-secondary:hover:not(:disabled),
  .button-google:hover:not(:disabled),
  .button-quiet:hover:not(:disabled),
  .icon-button:hover:not(:disabled) {
    border-color: var(--border);
    background: #fff;
    color: var(--text-soft);
  }

  .tab-button:not(.active):hover {
    background: transparent;
    color: var(--muted);
  }
}
