:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-glass: rgba(255, 255, 255, 0.78);
  --surface-active: #ffffff;
  --text: #111827;
  --muted: #64748b;
  --line: #dbe3ee;
  --line-strong: #cbd5e1;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --amber: #f59e0b;
  --amber-soft: #fef3c7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --violet: #7c3aed;
  --violet-soft: #ede9fe;
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
  --radius: 8px;
}

body[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1120;
  --surface: #111827;
  --surface-soft: #182235;
  --surface-glass: rgba(17, 24, 39, 0.84);
  --surface-active: #1f2937;
  --text: #f8fafc;
  --muted: #94a3b8;
  --line: #263349;
  --line-strong: #3b4a62;
  --blue: #60a5fa;
  --blue-dark: #93c5fd;
  --green: #4ade80;
  --green-soft: #123524;
  --amber: #f59e0b;
  --amber-soft: #422b0a;
  --red: #f87171;
  --red-soft: #3f1414;
  --violet: #a78bfa;
  --violet-soft: #2c214c;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html {
  scrollbar-gutter: stable;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.08), transparent 34%),
    linear-gradient(315deg, rgba(22, 163, 74, 0.08), transparent 36%),
    var(--bg);
  color: var(--text);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

body[data-theme="dark"] {
  background:
    linear-gradient(135deg, rgba(96, 165, 250, 0.14), transparent 34%),
    linear-gradient(315deg, rgba(74, 222, 128, 0.1), transparent 36%),
    var(--bg);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(calc(100% - 32px), 1680px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px 0 40px;
}

.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  min-height: 58px;
  border-bottom: 1px solid var(--line);
}

.brand-logo {
  width: 150px;
  height: auto;
  display: block;
  justify-self: start;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  justify-self: end;
  min-width: 0;
}

.app-nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-glass);
  padding: 4px;
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.06);
  justify-self: center;
}

.app-nav-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 0 13px;
  font-size: 0.88rem;
  font-weight: 850;
  line-height: 1;
  white-space: nowrap;
}

.app-nav-button.is-active {
  background: var(--surface-active);
  color: var(--text);
  box-shadow: 0 7px 16px rgba(15, 23, 42, 0.1);
}

.app-nav-button:focus {
  outline: 2px solid rgba(37, 99, 235, 0.22);
  outline-offset: 3px;
}

.today-pill,
.sync-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  padding: 8px 13px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 750;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
}

.today-pill {
  flex: 0 0 12.4rem;
}

.sync-pill {
  flex: 0 0 12.8rem;
}

.sync-pill[data-status="online"] {
  border-color: #bbf7d0;
  background: var(--green-soft);
  color: #166534;
}

.sync-pill[data-status="offline"],
.sync-pill[data-status="loading"] {
  background: var(--surface-soft);
}

.sync-pill[data-status="error"] {
  border-color: #fecaca;
  background: var(--red-soft);
  color: var(--red);
}

.auth-page {
  display: none;
  padding: 2rem 0;
}

.auth-page:not([hidden]) {
  display: block;
}

.auth-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
  max-width: 420px;
  margin: 0 auto;
}

.auth-intro {
  text-align: center;
}

.auth-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.auth-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.auth-tab {
  flex: 1;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 0.875rem;
  transition: background 0.15s, border-color 0.15s;
}

.auth-tab:hover {
  background: var(--surface-hover);
}

.auth-tab.is-active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}
.login-page {
  display: grid;
  min-height: calc(100vh - 160px);
  align-items: center;
  padding: 42px 0;
}

.login-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 460px);
  gap: 56px;
  align-items: center;
  width: min(100%, 1120px);
  margin: 0 auto;
}

.login-intro {
  min-width: 0;
}

.hero-wordmark {
  position: relative;
  display: inline-block;
  margin: 0;
  color: transparent;
  background:
    linear-gradient(90deg, #0f172a 0%, #1d4ed8 42%, #16a34a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  font-size: 6.2rem;
  font-weight: 950;
  line-height: 0.92;
  letter-spacing: 0;
}

.hero-wordmark::after {
  display: block;
  width: 156px;
  height: 8px;
  margin-top: 18px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--blue), var(--green));
  content: "";
}

#connectionMessage {
  max-width: 460px;
  margin: 28px 0 0;
  color: var(--muted);
  font-size: 1.12rem;
  font-weight: 700;
  line-height: 1.45;
}

.connection-form {
  display: grid;
  gap: 15px;
  min-width: 0;
  border-left: 1px solid var(--line);
  padding-left: 34px;
}

.connection-form label {
  position: relative;
  display: grid;
  gap: 8px;
  min-width: 0;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 750;
}

.school-hint {
  min-height: 1rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.35;
}

.login-alert {
  display: grid;
  gap: 4px;
  border: 1px solid #fecaca;
  border-left: 5px solid var(--red);
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(254, 242, 242, 0.96), rgba(255, 255, 255, 0.88));
  box-shadow: 0 14px 32px rgba(185, 28, 28, 0.1);
  padding: 14px 16px 14px 18px;
}

.login-alert[hidden] {
  display: none;
}

.login-alert strong {
  color: var(--red);
  font-size: 0.92rem;
  font-weight: 900;
  line-height: 1.25;
}

.login-alert span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 650;
  line-height: 1.4;
}

.login-alert[data-tone="info"] {
  border-color: #bfdbfe;
  border-left-color: var(--blue);
  background: linear-gradient(135deg, rgba(239, 246, 255, 0.96), rgba(255, 255, 255, 0.88));
  box-shadow: 0 14px 32px rgba(37, 99, 235, 0.1);
}

.login-alert[data-tone="info"] strong {
  color: var(--blue);
}

.school-results {
  position: absolute;
  z-index: 10;
  top: calc(100% + 8px);
  right: 0;
  left: 0;
  display: grid;
  gap: 6px;
}

.school-results:empty {
  display: none;
}

.school-option,
.selected-school {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 12px;
  color: var(--text);
  text-align: left;
  box-shadow: var(--shadow);
}

.school-option:hover,
.school-option:focus {
  border-color: var(--blue);
  outline: 3px solid rgba(37, 99, 235, 0.14);
}

.school-option strong,
.selected-school strong {
  display: block;
  font-size: 0.95rem;
  line-height: 1.25;
}

.school-option span,
.selected-school span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.35;
}

.connection-form input {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
  font-size: 0.98rem;
  font-weight: 650;
}

.connection-form input:focus {
  border-color: var(--blue);
  outline: 3px solid rgba(37, 99, 235, 0.14);
}

.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 42px;
  border-radius: var(--radius);
  padding: 0 15px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
}

.primary-button {
  border: 1px solid var(--blue);
  background: linear-gradient(135deg, var(--blue), var(--green));
  color: #ffffff;
}

.primary-button:hover {
  border-color: var(--blue-dark);
  filter: brightness(0.96);
}

.primary-button:disabled {
  cursor: progress;
  opacity: 0.72;
}

.secondary-button {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
}

.secondary-button:hover {
  background: var(--surface-soft);
}

.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.compact-button {
  min-height: 38px;
  padding: 0 13px;
}

.disconnect-button {
  flex: 0 0 8.2rem;
  min-height: 40px;
  border-color: #fecaca;
  border-radius: 999px;
  background: #fff7f7;
  color: #b91c1c;
  padding: 0 18px;
  box-shadow: 0 8px 18px rgba(185, 28, 28, 0.08);
}

.disconnect-button:hover,
.disconnect-button:focus {
  border-color: #fca5a5;
  background: #fee2e2;
  color: #991b1b;
  outline: none;
}

.home-page {
  display: grid;
  gap: 14px;
  padding-top: 28px;
}

.attendance-page {
  display: grid;
  gap: 16px;
  padding-top: 28px;
}

.attendance-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
}

.attendance-header h1 {
  margin: 6px 0 0;
  color: var(--text);
  font-size: clamp(2.2rem, 6vw, 4.3rem);
  line-height: 0.98;
  letter-spacing: 0;
}

.attendance-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 188px;
  align-items: center;
  gap: 10px;
  flex: 1 1 680px;
  max-width: 940px;
}

.attendance-period-toggle {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-glass);
  padding: 4px;
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.06);
}

.attendance-period-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 34px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-weight: 850;
  line-height: 1;
  text-align: center;
  cursor: pointer;
}

.attendance-period-button:hover {
  color: var(--text);
}

.attendance-period-button.is-active {
  background: var(--surface-active);
  color: var(--text);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
}

.attendance-refresh {
  position: relative;
  width: 188px;
  min-width: 188px;
  border-color: #bfdbfe;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  padding: 0 18px;
}

.attendance-refresh:disabled {
  cursor: progress;
  opacity: 0.88;
}

.attendance-refresh.is-loading::after {
  content: "";
  position: absolute;
  right: 16px;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: currentColor;
  animation: attendance-loading-pulse 0.9s ease-in-out infinite;
}

@keyframes attendance-loading-pulse {
  0%,
  100% {
    opacity: 0.28;
    transform: scale(0.72);
  }

  50% {
    opacity: 1;
    transform: scale(1);
  }
}

.attendance-unit-hint {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-glass);
  color: var(--muted);
  padding: 9px 14px;
  font-size: 0.84rem;
  font-weight: 850;
  line-height: 1.25;
}

.attendance-filter-bar {
  display: grid;
  grid-template-columns: minmax(220px, 1.3fr) minmax(180px, 0.85fr) minmax(180px, 0.85fr);
  gap: 10px;
  align-items: end;
}

.attendance-filter-field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.attendance-filter-field span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  text-transform: uppercase;
}

.attendance-filter-field input,
.attendance-filter-field select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  padding: 0 14px;
  font: inherit;
  font-weight: 800;
  line-height: 1;
  outline: none;
}

.attendance-filter-field input:focus,
.attendance-filter-field select:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 4px rgba(147, 197, 253, 0.22);
}

.attendance-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.attendance-stat,
.attendance-subject-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-glass);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.06);
}

.attendance-stat {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 15px;
}

.attendance-stat-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.attendance-stat span,
.attendance-metrics dt {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 850;
  text-transform: uppercase;
}

.attendance-percent-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  border-radius: 999px;
  background: #eff6ff;
  color: var(--blue);
  padding: 5px 8px;
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: none;
  line-height: 1;
}

.attendance-stat strong {
  color: var(--text);
  font-size: 1.7rem;
  line-height: 1;
}

.attendance-stat small {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
  line-height: 1.35;
}

.attendance-stat em {
  display: inline-flex;
  width: fit-content;
  border-radius: 999px;
  background: #fef3c7;
  color: #7c2d12;
  padding: 6px 10px;
  font-size: 0.78rem;
  font-style: normal;
  font-weight: 850;
  line-height: 1.1;
}

.attendance-subject-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.attendance-subject-card {
  display: grid;
  gap: 12px;
  min-width: 0;
  padding: 15px;
}

@keyframes critical-pulse {
  0%, 100% { box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.16), 0 0 0 4px rgba(239, 68, 68, 0.0), 0 14px 34px rgba(239, 68, 68, 0.12); }
  50% { box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.28), 0 0 0 6px rgba(239, 68, 68, 0.06), 0 14px 34px rgba(239, 68, 68, 0.12); }
}

.attendance-subject-card.is-critical {
  border-color: #ef4444;
  background:
    linear-gradient(180deg, rgba(254, 242, 242, 0.92), rgba(255, 255, 255, 0.98)),
    var(--surface-glass);
  box-shadow:
    0 0 0 1px rgba(239, 68, 68, 0.16),
    0 0 0 4px rgba(239, 68, 68, 0.0),
    0 14px 34px rgba(239, 68, 68, 0.12);
  animation: critical-pulse 3s ease-in-out infinite;
}

.attendance-subject-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
  min-width: 0;
}

.attendance-subject-head div {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.attendance-subject-head strong {
  color: var(--text);
  font-size: 1.35rem;
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.attendance-subject-head span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 750;
  line-height: 1.35;
}

.attendance-subject-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: fit-content;
  min-height: 26px;
  border: 1px solid #fca5a5;
  border-radius: 999px;
  background: #fef2f2;
  color: #b91c1c;
  padding: 0 10px;
  font-size: 0.74rem;
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.attendance-percent-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 70px;
  min-height: 38px;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 1.05rem;
  font-weight: 950;
  line-height: 1;
}

.attendance-percent-badge.is-critical {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fca5a5;
}

.attendance-subject-head b {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 70px;
  min-height: 38px;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 1.05rem;
  font-weight: 950;
  line-height: 1;
}

.attendance-progress {
  height: 10px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.attendance-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--green));
}

.attendance-subject-card.is-critical .attendance-progress {
  background: #fecaca;
}

.attendance-subject-card.is-critical .attendance-progress span {
  background: linear-gradient(90deg, #ef4444, #f97316);
}

.attendance-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.attendance-metrics div {
  display: grid;
  gap: 4px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 10px;
}

.attendance-metrics dd {
  display: grid;
  gap: 3px;
  margin: 0;
  color: var(--text);
  font-size: 0.96rem;
  font-weight: 850;
  line-height: 1.15;
}

.attendance-metrics dd small {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.2;
}

.attendance-metrics dd .attendance-late-note {
  color: #7c2d12;
}

.attendance-buffer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  min-width: 0;
  border-radius: 16px;
  background: #dcfce7;
  color: #166534;
  padding: 10px 12px;
}

.attendance-buffer span {
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1;
  text-transform: uppercase;
}

.attendance-buffer strong {
  min-width: 0;
  color: inherit;
  font-size: 0.86rem;
  font-weight: 900;
  line-height: 1.2;
  text-align: right;
  overflow-wrap: anywhere;
}

.attendance-buffer[data-tone="warning"] {
  background: #fef3c7;
  color: #7c2d12;
}

.attendance-buffer[data-tone="danger"] {
  background: #fee2e2;
  color: #991b1b;
}

.attendance-empty {
  grid-column: 1 / -1;
}

.settings-page {
  display: grid;
  gap: 16px;
  padding-top: 28px;
}

.settings-header {
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
}

.settings-header h1 {
  margin: 6px 0 0;
  color: var(--text);
  font-size: clamp(2.2rem, 6vw, 4.3rem);
  line-height: 0.98;
  letter-spacing: 0;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.settings-card {
  display: grid;
  gap: 18px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-glass);
  box-shadow: var(--shadow);
  padding: 18px;
}

.settings-card-copy {
  display: grid;
  gap: 7px;
}

.settings-card-copy span {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 850;
  text-transform: uppercase;
}

.settings-card-copy h2 {
  margin: 0;
  color: var(--text);
  font-size: 1.35rem;
  line-height: 1.1;
}

.settings-card-copy p {
  margin: 0;
  color: var(--muted);
  font-size: 0.94rem;
  font-weight: 650;
  line-height: 1.45;
}

.settings-toggle {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 4px;
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  padding: 4px;
}

.settings-toggle-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 0 14px;
  font: inherit;
  font-weight: 850;
  line-height: 1;
  white-space: nowrap;
}

.settings-toggle-button.is-active {
  background: var(--surface-active);
  color: var(--text);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.1);
}

.settings-toggle-button:focus {
  outline: 2px solid rgba(37, 99, 235, 0.28);
  outline-offset: 3px;
}

body[data-theme="dark"] .hero-wordmark {
  background: linear-gradient(90deg, #f8fafc 0%, #60a5fa 46%, #4ade80 100%);
  -webkit-background-clip: text;
  background-clip: text;
}

body[data-theme="dark"] .week-today-button,
body[data-theme="dark"] .attendance-refresh {
  background: #172554;
  color: #bfdbfe;
  border-color: #1d4ed8;
}

body[data-theme="dark"] .attendance-percent-chip {
  background: #172554;
  color: #bfdbfe;
}

body[data-theme="dark"] .attendance-buffer {
  background: #052e16;
  color: #bbf7d0;
}

body[data-theme="dark"] .attendance-buffer[data-tone="warning"] {
  background: #451a03;
  color: #fde68a;
}

body[data-theme="dark"] .attendance-buffer[data-tone="danger"] {
  background: #450a0a;
  color: #fecaca;
}

@keyframes critical-pulse-dark {
  0%, 100% { box-shadow: 0 0 0 1px rgba(248, 113, 113, 0.16), 0 0 0 4px rgba(248, 113, 113, 0.0), 0 14px 34px rgba(127, 29, 29, 0.28); }
  50% { box-shadow: 0 0 0 1px rgba(248, 113, 113, 0.28), 0 0 0 6px rgba(248, 113, 113, 0.06), 0 14px 34px rgba(127, 29, 29, 0.28); }
}

body[data-theme="dark"] .attendance-subject-card.is-critical {
  border-color: #b91c1c;
  background:
    linear-gradient(180deg, rgba(69, 10, 10, 0.82), rgba(24, 24, 27, 0.94)),
    var(--surface-glass);
  box-shadow:
    0 0 0 1px rgba(248, 113, 113, 0.16),
    0 0 0 4px rgba(248, 113, 113, 0.0),
    0 14px 34px rgba(127, 29, 29, 0.28);
  animation: critical-pulse-dark 3s ease-in-out infinite;
}

body[data-theme="dark"] .attendance-subject-status {
  border-color: #7f1d1d;
  background: #450a0a;
  color: #fecaca;
}

body[data-theme="dark"] .attendance-percent-badge {
  background: #172554;
  color: #bfdbfe;
}

body[data-theme="dark"] .attendance-percent-badge.is-critical {
  background: #450a0a;
  color: #fecaca;
  border-color: #7f1d1d;
}

body[data-theme="dark"] .attendance-subject-card.is-critical .attendance-progress {
  background: #451a1a;
}

body[data-theme="dark"] .disconnect-button {
  background: #3f1414;
  border-color: #7f1d1d;
  color: #fecaca;
}

body[data-theme="dark"] .login-alert {
  background: linear-gradient(135deg, rgba(127, 29, 29, 0.34), rgba(15, 23, 42, 0.88));
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.24);
}

body[data-theme="dark"] .login-alert[data-tone="info"] {
  background: linear-gradient(135deg, rgba(30, 64, 175, 0.28), rgba(15, 23, 42, 0.88));
}

body[data-theme="dark"] .test-filter-knob {
  background: #f8fafc;
}

.schedule-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  padding-bottom: 8px;
}

.title-mode-group {
  display: grid;
  flex: 1 1 560px;
  gap: 10px;
  min-width: min(100%, 520px);
}

.title-mode-row {
  width: min(100%, 760px);
}

.plan-mode-toggle {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  width: min(100%, 760px);
  min-height: 68px;
  border: 1px solid #d8e2ef;
  border-radius: 999px;
  background: var(--surface-glass);
  box-shadow: 0 16px 34px rgba(15, 23, 42, 0.08);
  padding: 6px;
  isolation: isolate;
}

.plan-mode-indicator {
  position: absolute;
  top: 6px;
  bottom: 6px;
  left: 6px;
  width: calc(50% - 6px);
  border-radius: 999px;
  background: linear-gradient(135deg, #0f172a, #1e3a8a);
  box-shadow: 0 10px 24px rgba(30, 58, 138, 0.22);
  transition: transform 180ms ease, background 180ms ease, box-shadow 180ms ease;
  z-index: -1;
}

.plan-mode-toggle[data-mode="absence"] .plan-mode-indicator {
  background: linear-gradient(135deg, #b91c1c, #dc2626);
  box-shadow: 0 10px 24px rgba(220, 38, 38, 0.22);
  transform: translateX(100%);
}

.plan-mode-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 56px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 1.12rem;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1;
  padding: 0 22px;
  text-align: center;
  transition: color 160ms ease, opacity 160ms ease;
}

.plan-mode-button.is-active {
  color: #ffffff;
}

.plan-mode-button:focus {
  outline: 2px solid rgba(37, 99, 235, 0.34);
  outline-offset: 4px;
}

.plan-mode-button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

.plan-mode-toggle.is-disabled {
  box-shadow: none;
}

.week-switcher {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  justify-self: center;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-glass);
  color: var(--muted);
  font-size: 1.55rem;
  font-weight: 850;
  line-height: 1;
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.07);
}

.icon-button:hover,
.icon-button:focus {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.week-nav-button {
  display: inline-grid;
  place-items: center;
  font-size: 0;
  line-height: 0;
}

.chevron-icon {
  display: block;
  width: 10px;
  height: 10px;
  border-top: 3px solid currentColor;
  border-right: 3px solid currentColor;
  border-radius: 2px;
}

.week-nav-button.is-prev .chevron-icon {
  transform: translateX(2px) rotate(-135deg);
}

.week-nav-button.is-next .chevron-icon {
  transform: translateX(-2px) rotate(45deg);
}

.week-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 228px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-glass);
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 850;
  line-height: 1;
  padding: 0 18px;
  text-align: center;
  white-space: nowrap;
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.07);
}

.week-today-button {
  min-height: 42px;
  border-color: #bfdbfe;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  padding: 0 18px;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.08);
}

.week-today-button:hover,
.week-today-button:focus {
  border-color: #93c5fd;
  background: #dbeafe;
  color: #1e3a8a;
  outline: none;
}

.eyebrow,
.muted-label,
.control-label,
.day-short {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.home-view {
  display: grid;
  gap: 14px;
}

.controls-band {
  display: grid;
  grid-template-columns: minmax(300px, auto) minmax(360px, 1fr) auto;
  align-items: end;
  gap: 14px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
}

.control-group {
  display: grid;
  gap: 7px;
}

.control-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  justify-self: end;
}

.day-view-toggle {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(138px, 1fr));
  gap: 4px;
  width: min(100%, 430px);
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-glass);
  padding: 4px;
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.06);
}

.day-view-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 0 14px;
  font: inherit;
  font-weight: 850;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background 160ms ease,
    color 160ms ease,
    box-shadow 160ms ease;
}

.day-view-button:hover,
.day-view-button:focus {
  color: var(--text);
  outline: none;
}

.day-view-button.is-active {
  background: var(--surface-active);
  color: var(--text);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.1);
}

.test-filter-toggle {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-glass);
  padding: 5px 14px 5px 7px;
  color: var(--text);
  font-weight: 850;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.07);
}

.test-filter-toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.test-filter-switch {
  position: relative;
  width: 52px;
  height: 30px;
  flex: 0 0 52px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: #e2e8f0;
  transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.test-filter-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 5px 12px rgba(15, 23, 42, 0.18);
  transition: transform 160ms ease;
}

.test-filter-toggle input:checked + .test-filter-switch {
  border-color: #93c5fd;
  background: linear-gradient(135deg, var(--blue), var(--green));
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.16);
}

.test-filter-toggle input:checked + .test-filter-switch .test-filter-knob {
  transform: translateX(22px);
}

.test-filter-toggle input:focus-visible + .test-filter-switch {
  outline: 3px solid rgba(37, 99, 235, 0.18);
  outline-offset: 3px;
}

.schedule-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.legend-label {
  margin-right: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-glass);
  padding: 0 10px;
  color: var(--text);
  line-height: 1;
  text-align: center;
}

.legend-item i {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #22c55e;
}

.legend-item[data-type="exam"] i {
  background: var(--violet);
}

.legend-item[data-type="substitution"] i {
  background: #2563eb;
}

.legend-item[data-type="cancelled"] i {
  background: #94a3b8;
}

.schedule-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.schedule-workspace.has-absence-panel {
  grid-template-columns: minmax(0, 1fr) minmax(280px, 330px);
}

.absence-panel {
  display: grid;
  gap: 12px;
  align-content: start;
  max-height: 640px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
  padding: 12px;
  overflow: auto;
}

.absence-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  justify-content: flex-start;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
}

.absence-panel .absence-controls {
  align-items: stretch;
  flex-direction: column;
  gap: 10px;
  border-top: 0;
  padding-top: 0;
}

.select-control {
  display: grid;
  gap: 7px;
  min-width: 210px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
}

.select-control select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--text);
  padding: 0 12px;
  font: inherit;
  font-size: 0.94rem;
  font-weight: 800;
  text-transform: none;
}

.absence-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.absence-panel .absence-summary {
  grid-template-columns: 1fr;
}

.absence-stat {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.76);
  padding: 14px;
}

.absence-stat span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
}

.absence-stat strong {
  color: var(--text);
  font-size: 1.6rem;
  line-height: 1;
}

.absence-stat small {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.absence-list {
  display: grid;
  gap: 10px;
}

.absence-item {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-left: 4px solid #ef4444;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.8);
  padding: 12px;
  cursor: pointer;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.absence-panel .absence-item {
  grid-template-columns: 1fr;
  align-items: start;
}

.absence-item:hover,
.absence-item:focus-visible {
  border-color: #93c5fd;
  box-shadow: 0 14px 28px rgba(37, 99, 235, 0.12);
  outline: none;
  transform: translateY(-1px);
}

.absence-item.is-selected {
  border-color: #2563eb;
  box-shadow:
    0 0 0 3px rgba(37, 99, 235, 0.12),
    0 14px 28px rgba(37, 99, 235, 0.12);
}

.absence-item[data-status="excused"] {
  border-left-color: #22c55e;
}

.absence-item[data-kind="late"] {
  border-left-color: #f59e0b;
}

.absence-date,
.absence-body {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.absence-date strong,
.absence-body strong {
  color: var(--text);
  font-size: 0.98rem;
  line-height: 1.2;
}

.absence-date span,
.absence-body span,
.absence-note {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1.35;
}

.absence-note {
  margin: 0;
  overflow-wrap: anywhere;
}

.absence-status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  background: #fee2e2;
  color: #991b1b;
  padding: 0 10px;
  font-size: 0.78rem;
  font-weight: 850;
  white-space: nowrap;
}

.absence-status[data-status="excused"] {
  background: #dcfce7;
  color: #166534;
}

.absence-status[data-status="late"] {
  background: #fef3c7;
  color: #92400e;
}

.absence-empty {
  background: rgba(255, 255, 255, 0.76);
}

.schedule-grid {
  display: block;
  min-height: 640px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #eef4f9;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0;
}

.lesson-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  height: 24px;
  border-radius: 999px;
  background: #e0f2fe;
  color: #075985;
  font-size: 0.72rem;
  font-weight: 850;
}

.timetable-board {
  --time-width: 76px;
  --row-height: 74px;
  --day-min-width: 220px;
  display: grid;
  grid-template-columns: var(--time-width) repeat(var(--day-count), minmax(var(--day-min-width), 1fr));
  grid-template-rows: 96px repeat(var(--period-count), var(--row-height));
  min-width: calc(var(--time-width) + var(--day-count) * var(--day-min-width));
  position: relative;
}

.schedule-workspace.has-absence-panel .timetable-board {
  --day-min-width: 190px;
}

.time-corner,
.timetable-day-heading {
  position: sticky;
  top: 0;
  z-index: 5;
  border-bottom: 1px solid var(--line-strong);
  background: rgba(248, 250, 252, 0.96);
}

.time-corner {
  left: 0;
  display: grid;
  place-items: center;
  border-right: 1px solid var(--line-strong);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
  text-transform: uppercase;
}

.timetable-day-heading {
  display: grid;
  align-content: start;
  grid-template-rows: auto auto;
  gap: 7px;
  min-width: 0;
  border-right: 1px solid var(--line);
  padding: 9px 10px;
}

.timetable-day-heading.is-focused-absence-day {
  background: linear-gradient(180deg, #eff6ff, #ffffff 74%);
  box-shadow: inset 0 0 0 2px rgba(37, 99, 235, 0.24);
}

.day-metrics {
  --day-chip-width: 96px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
  min-width: 0;
}

.lesson-count,
.absence-day-chip,
.late-day-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 min(var(--day-chip-width), 100%);
  width: min(var(--day-chip-width), 100%);
  min-height: 24px;
  border-radius: 999px;
  padding: 0 8px;
  font-size: 0.68rem;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
}

.lesson-count.is-event {
  background: #dcfce7;
  color: #166534;
}

.absence-day-chip {
  background: var(--red);
  color: #ffffff;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 8px 18px rgba(220, 38, 38, 0.22);
}

.late-day-chip {
  background: var(--amber);
  color: #451a03;
  box-shadow: 0 8px 18px rgba(245, 158, 11, 0.18);
}

.timetable-day-title {
  min-width: 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 850;
  overflow: visible;
  text-overflow: clip;
  white-space: nowrap;
}

.time-slot,
.period-cell {
  border-right: 1px solid #d3dde8;
  border-bottom: 1px solid #d3dde8;
}

.time-slot {
  position: sticky;
  left: 0;
  z-index: 4;
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  gap: 4px;
  align-items: start;
  background: #eef4f9;
  color: var(--muted);
  padding: 7px 6px;
  font-size: 0.72rem;
  line-height: 1.28;
}

.time-slot strong {
  color: #64748b;
  font-size: 0.95rem;
  font-weight: 700;
}

.period-cell {
  min-width: 0;
  background: rgba(255, 255, 255, 0.5);
}

.period-cell.is-focused-absence-day {
  background:
    linear-gradient(180deg, rgba(37, 99, 235, 0.06), rgba(255, 255, 255, 0.26)),
    rgba(255, 255, 255, 0.5);
}

.period-cell.is-today {
  background: rgba(191, 219, 254, 0.62);
}

.period-cell.has-absence {
  background:
    repeating-linear-gradient(
      -45deg,
      rgba(220, 38, 38, 0.24) 0,
      rgba(220, 38, 38, 0.24) 8px,
      rgba(254, 226, 226, 0.78) 8px,
      rgba(254, 226, 226, 0.78) 16px
    );
  box-shadow: inset 0 0 0 2px rgba(220, 38, 38, 0.32);
}

.period-cell.has-late {
  background:
    linear-gradient(135deg, rgba(254, 243, 199, 0.76), rgba(255, 251, 235, 0.72)),
    rgba(255, 255, 255, 0.5);
  box-shadow: inset 0 0 0 2px rgba(245, 158, 11, 0.3);
}

.period-cell.has-absence.has-late {
  background:
    repeating-linear-gradient(
      -45deg,
      rgba(220, 38, 38, 0.24) 0,
      rgba(220, 38, 38, 0.24) 8px,
      rgba(254, 226, 226, 0.78) 8px,
      rgba(254, 226, 226, 0.78) 16px
    );
  box-shadow:
    inset 0 0 0 2px rgba(220, 38, 38, 0.32),
    inset 0 0 0 4px rgba(245, 158, 11, 0.24);
}

.timetable-lesson {
  z-index: 3;
  position: relative;
  align-self: stretch;
  display: grid;
  align-content: start;
  gap: 2px;
  width: calc((100% / var(--lane-count)) - 10px);
  min-width: 0;
  max-width: calc(100% - 8px);
  margin: 4px;
  margin-left: calc((100% / var(--lane-count)) * var(--lane) + 4px);
  border: 1px solid rgba(34, 197, 94, 0.28);
  border-left: 4px solid #22c55e;
  border-radius: 5px;
  background: #dcfce7;
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.12);
  cursor: pointer;
  overflow: hidden;
  padding: 8px 8px 7px;
  text-align: left;
}

.timetable-lesson:hover,
.timetable-lesson:focus {
  outline: 3px solid rgba(37, 99, 235, 0.18);
  outline-offset: -2px;
}

.timetable-lesson.is-focused-absence-day {
  box-shadow:
    inset 0 0 0 2px rgba(37, 99, 235, 0.12),
    0 12px 22px rgba(37, 99, 235, 0.12);
}

.timetable-lesson[data-type="exam"] {
  border-color: rgba(124, 58, 237, 0.36);
  border-left-color: var(--violet);
  background: var(--violet-soft);
}

.timetable-lesson[data-type="project"] {
  border-color: rgba(245, 158, 11, 0.42);
  border-left-color: #f59e0b;
  background: #fef3c7;
}

.timetable-lesson[data-type="sport"] {
  border-left-color: #16a34a;
  background: #dff7eb;
}

.timetable-lesson[data-type="substitution"] {
  border-color: rgba(37, 99, 235, 0.34);
  border-left-color: #2563eb;
  background: #dbeafe;
}

.timetable-lesson[data-type="cancelled"] {
  border-color: rgba(148, 163, 184, 0.46);
  border-left-color: #94a3b8;
  background: #e5e7eb;
  opacity: 0.75;
}

.timetable-lesson[data-type="cancelled"] .lesson-time,
.timetable-lesson[data-type="cancelled"] .lesson-title,
.timetable-lesson[data-type="cancelled"] .lesson-meta {
  text-decoration-line: line-through;
  text-decoration-thickness: 2px;
  text-decoration-color: rgba(51, 65, 85, 0.55);
  text-decoration-skip-ink: auto;
}

.timetable-lesson.has-absence {
  border: 2px solid rgba(185, 28, 28, 0.76);
  border-left: 8px solid #b91c1c;
  background:
    linear-gradient(135deg, rgba(254, 202, 202, 0.98), rgba(255, 241, 242, 0.94)),
    #fee2e2;
  box-shadow: 0 16px 28px rgba(185, 28, 28, 0.24);
}

.timetable-lesson.has-late {
  border-color: rgba(245, 158, 11, 0.58);
  border-left-color: #f59e0b;
  background:
    linear-gradient(135deg, rgba(254, 243, 199, 0.98), rgba(255, 251, 235, 0.94)),
    #fef3c7;
}

.timetable-lesson.has-absence.has-late {
  border: 2px solid rgba(185, 28, 28, 0.76);
  border-left: 8px solid #b91c1c;
  background:
    linear-gradient(135deg, rgba(254, 202, 202, 0.98), rgba(255, 241, 242, 0.94)),
    #fee2e2;
}

.lesson-time {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  line-height: 1.25;
}

.lesson-card-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 5px;
  align-items: start;
  min-width: 0;
}

.lesson-card-header .lesson-time {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lesson-title {
  min-width: 0;
  margin: 0;
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.12;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.lesson-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  justify-self: start;
  max-width: 82px;
  min-height: 18px;
  border-radius: 999px;
  padding: 0 6px;
  background: #e0f2fe;
  color: #075985;
  font-size: 0.6rem;
  font-weight: 850;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lesson-badge[data-type="exam"] {
  background: #ddd6fe;
  color: #4c1d95;
}

.lesson-badge[data-type="project"] {
  background: #fde68a;
  color: #92400e;
}

.lesson-badge[data-type="substitution"] {
  background: #bfdbfe;
  color: #1e3a8a;
}

.lesson-badge[data-type="cancelled"] {
  background: #cbd5e1;
  color: #334155;
}

.lesson-badge[data-type="event"] {
  background: #bbf7d0;
  color: #166534;
}

.lesson-status-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: min(88px, calc(100% - 18px));
  min-height: 18px;
  border-radius: 999px;
  padding: 0 7px;
  font-size: 0.56rem;
  font-weight: 900;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.lesson-absence-badge {
  background: var(--red);
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(220, 38, 38, 0.22);
}

.lesson-late-badge {
  background: var(--amber);
  color: #451a03;
  box-shadow: 0 8px 18px rgba(245, 158, 11, 0.18);
}

.timetable-lesson.has-absence.has-late .lesson-late-badge {
  top: 27px;
}

.timetable-lesson.has-absence .lesson-card-header,
.timetable-lesson.has-late .lesson-card-header {
  padding-right: 66px;
}

.lesson-meta {
  display: block;
  margin: 0;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 650;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.free-day-panel {
  z-index: 2;
  display: grid;
  place-items: center;
  margin: 12px;
  border: 1px dashed #93c5fd;
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(219, 234, 254, 0.88), rgba(248, 250, 252, 0.82));
  color: #1e3a8a;
  text-align: center;
}

.free-day-panel.is-focused-absence-day,
.day-event-panel.is-focused-absence-day {
  box-shadow:
    inset 0 0 0 2px rgba(37, 99, 235, 0.2),
    0 18px 32px rgba(37, 99, 235, 0.12);
}

.free-day-panel strong {
  display: block;
  color: #0f172a;
  font-size: 1.9rem;
  line-height: 1.1;
}

.free-day-panel span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 750;
}

.day-event-panel {
  z-index: 3;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  margin: 12px;
  border: 1px solid rgba(34, 197, 94, 0.34);
  border-left: 5px solid #22c55e;
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(220, 252, 231, 0.96), rgba(240, 253, 244, 0.88)),
    #dcfce7;
  color: #166534;
  text-align: center;
  box-shadow: 0 16px 32px rgba(22, 163, 74, 0.16);
  cursor: pointer;
}

.day-event-panel:hover,
.day-event-panel:focus {
  outline: 3px solid rgba(34, 197, 94, 0.22);
  outline-offset: -2px;
}

.day-event-panel strong {
  display: block;
  color: #052e16;
  font-size: 1.85rem;
  line-height: 1.05;
}

.day-event-panel span {
  display: block;
  max-width: 86%;
  color: #166534;
  font-size: 0.95rem;
  font-weight: 850;
  line-height: 1.25;
}

.current-time-marker {
  z-index: 9;
  position: relative;
  pointer-events: none;
}

.current-time-line,
.current-time-arrow,
.current-time-label {
  position: absolute;
  top: calc(var(--marker-offset) * var(--row-height));
}

.current-time-line {
  right: 4px;
  left: 0;
  height: 2px;
  border-radius: 999px;
  background: #ef4444;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.12);
  transform: translateY(-1px);
}

.current-time-arrow {
  left: -2px;
  width: 0;
  height: 0;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 10px solid #ef4444;
  filter: drop-shadow(0 2px 4px rgba(15, 23, 42, 0.2));
  transform: translate(-7px, -50%);
}

.current-time-label {
  right: 8px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: calc(100% - 24px);
  border: 1px solid rgba(239, 68, 68, 0.28);
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.16);
  color: var(--text);
  padding: 5px 9px;
  font-size: 0.72rem;
  font-weight: 850;
  transform: translateY(-50%);
}

.current-time-label strong {
  color: #b91c1c;
  font-weight: 950;
}

.current-time-label span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  grid-column: 1 / -1;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 30px 18px;
  color: var(--muted);
  text-align: center;
  font-weight: 750;
}

.lesson-dialog {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.36);
  padding: 24px;
}

.lesson-dialog-panel {
  position: relative;
  width: min(100%, 460px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.24);
  padding: 24px;
}

.lesson-dialog-panel h2 {
  margin: 4px 44px 18px 0;
  color: var(--text);
  font-size: 1.8rem;
  line-height: 1.12;
}

.dialog-close {
  position: absolute;
  top: 14px;
  right: 14px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  font-size: 1.3rem;
}

.lesson-detail-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.lesson-detail-list div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 10px;
}

.lesson-detail-list dt {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  text-transform: uppercase;
}

.lesson-detail-list dd {
  margin: 0;
  color: var(--text);
  font-weight: 800;
  overflow-wrap: anywhere;
}

.lesson-dialog-info {
  margin: 14px 0 0;
  border-left: 4px solid var(--blue);
  border-radius: 5px;
  background: #eff6ff;
  color: #1e3a8a;
  padding: 10px 12px;
  font-size: 0.94rem;
  font-weight: 650;
  line-height: 1.4;
}

@media (max-width: 1400px) {
  .schedule-workspace.has-absence-panel {
    grid-template-columns: 1fr;
  }

  .schedule-workspace.has-absence-panel .timetable-board {
    --day-min-width: 220px;
  }

  .absence-panel {
    max-height: none;
  }
}

@media (max-width: 1180px) {
  .controls-band {
    grid-template-columns: 1fr;
  }

  .attendance-summary-grid,
  .attendance-subject-list,
  .settings-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .attendance-search-field {
    grid-column: 1 / -1;
  }

  .week-switcher,
  .control-actions {
    justify-self: stretch;
  }

  .week-switcher {
    justify-content: center;
  }

  .control-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 900px) {
  .topbar,
  .schedule-topbar {
    display: flex;
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    align-items: stretch;
    flex-direction: column;
    justify-content: flex-start;
    width: 100%;
  }

  .app-nav {
    width: 100%;
  }

  .app-nav-button {
    flex: 1;
  }

  .attendance-header {
    align-items: start;
    flex-direction: column;
  }

  .attendance-actions {
    grid-template-columns: minmax(0, 1fr) 188px;
    width: 100%;
    max-width: 720px;
  }

  .attendance-period-toggle {
    width: 100%;
  }

  .login-layout {
    grid-template-columns: 1fr;
    gap: 32px;
  }

  .connection-form {
    max-width: 560px;
    border-left: 0;
    border-top: 1px solid var(--line);
    padding-top: 26px;
    padding-left: 0;
  }

  .hero-wordmark {
    font-size: 5rem;
  }

  .week-switcher {
    width: 100%;
    justify-content: space-between;
  }

  .title-mode-group,
  .title-mode-row,
  .plan-mode-toggle {
    width: 100%;
  }

  .week-label {
    min-width: 0;
    flex: 1;
  }

  .schedule-workspace.has-absence-panel {
    grid-template-columns: 1fr;
  }

  .absence-panel {
    max-height: none;
  }

  .absence-summary {
    grid-template-columns: 1fr;
  }

  .attendance-summary-grid,
  .attendance-subject-list,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .attendance-filter-bar {
    grid-template-columns: 1fr;
  }

  .attendance-search-field {
    grid-column: auto;
  }

  .absence-item {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .absence-status {
    justify-self: start;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(calc(100% - 40px), 1320px);
    padding-top: 14px;
  }

  .today-pill,
  .sync-pill,
  .compact-button {
    width: 100%;
    text-align: center;
  }

  .attendance-actions {
    grid-template-columns: 1fr;
    max-width: none;
  }

  .attendance-refresh {
    width: 100%;
    min-width: 0;
  }

  .attendance-metrics {
    grid-template-columns: 1fr;
  }

  .week-today-button {
    width: auto;
  }

  .login-page {
    align-items: start;
    min-height: auto;
    padding: 28px 0;
  }

  .hero-wordmark {
    font-size: 3.6rem;
  }

  .hero-wordmark::after {
    width: 118px;
    height: 7px;
    margin-top: 14px;
  }

  #connectionMessage {
    margin-top: 22px;
    font-size: 1rem;
  }

  .school-results {
    position: static;
  }

  .controls-band {
    align-items: stretch;
    flex-direction: column;
  }

  .control-actions {
    justify-content: stretch;
  }

  .absence-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .select-control {
    min-width: 0;
  }

  .schedule-legend {
    align-items: stretch;
    flex-direction: column;
  }

  .legend-label,
  .legend-item {
    width: 100%;
  }

  .week-switcher {
    flex-wrap: wrap;
  }

  .icon-button {
    flex: 0 0 38px;
  }

  .week-label {
    order: -1;
    flex: 1 0 100%;
    min-height: 42px;
    padding: 0 4px;
  }

  .plan-mode-toggle {
    min-height: 62px;
  }

  .plan-mode-button {
    min-height: 50px;
    font-size: 0.96rem;
    padding: 0 10px;
  }

  .day-view-toggle,
  .attendance-period-toggle,
  .test-filter-toggle {
    width: 100%;
  }

  .attendance-period-toggle {
    grid-template-columns: 1fr;
    border-radius: 22px;
  }

  .day-view-toggle {
    grid-template-columns: 1fr;
    border-radius: 22px;
  }

  .day-view-button {
    min-height: 42px;
  }

  .test-filter-toggle {
    justify-content: center;
  }

  .schedule-grid {
    min-height: 560px;
  }

  .lesson-dialog {
    padding: 16px;
  }

  .lesson-dialog-panel {
    padding: 20px;
  }

  .lesson-detail-list {
    grid-template-columns: 1fr;
  }
}

/* === Footer === */
.app-footer {
  padding: 1.5rem 1rem 1rem;
  text-align: center;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

.footer-links {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
}

.footer-link {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  transition: color 0.2s, background 0.2s;
}

.footer-link:hover,
.footer-link:focus-visible {
  color: var(--text-primary);
  background: var(--surface-hover);
}

/* === Legal overlays === */
.legal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.legal-panel {
  background: var(--surface-primary);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 560px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 2rem;
  position: relative;
}

.legal-panel h1 {
  font-size: 1.25rem;
  margin-bottom: 1.5rem;
}

.legal-panel .dialog-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
}

.legal-info {
  margin-bottom: 1.5rem;
}

.legal-info dt {
  font-weight: 600;
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.legal-info dd {
  margin: 0.25rem 0 0;
  font-size: 0.95rem;
}

.legal-section {
  margin-bottom: 1.25rem;
}

.legal-section h2 {
  font-size: 1rem;
  margin-bottom: 0.5rem;
}

.legal-section p,
.legal-list {
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-secondary);
}

.legal-list {
  list-style: disc;
  padding-left: 1.25rem;
}

.legal-list li {
  margin-bottom: 0.5rem;
}

.legal-note {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

.legal-warning {
  color: #991b1b;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.18);
  border-radius: 10px;
  padding: 0.85rem 0.95rem;
  margin-top: 1rem;
}

/* === Cookie banner === */
.cookie-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 90;
  background: var(--surface-primary);
  border-top: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
}

.cookie-banner p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  max-width: 480px;
}

.cookie-accept {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.5rem 1.25rem;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}

.cookie-accept:hover,
.cookie-accept:focus-visible {
  opacity: 0.9;
}

/* === Settings data card === */
.settings-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.settings-button {
  background: var(--surface-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s;
}

.settings-button:hover {
  background: var(--surface-hover);
}

.settings-button.is-danger {
  color: var(--red);
  border-color: var(--red);
  background: transparent;
}

.settings-button.is-danger:hover {
  background: var(--red);
  color: #fff;
}
