:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f4f8);
  --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #181c24);
  --hint: var(--tg-theme-hint-color, #707887);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --border: rgba(128, 138, 156, 0.16);
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.04);

  --mark-5-bg: rgba(22, 163, 74, 0.16);
  --mark-5-fg: #15803d;
  --mark-4-bg: rgba(37, 99, 235, 0.15);
  --mark-4-fg: #1d4ed8;
  --mark-3-bg: rgba(217, 119, 6, 0.16);
  --mark-3-fg: #b45309;
  --mark-2-bg: rgba(220, 38, 38, 0.16);
  --mark-2-fg: #b91c1c;
  --danger: #dc2626;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-secondary-bg-color, #12151c);
    --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #1c202a));
    --text: var(--tg-theme-text-color, #f3f5f8);
    --hint: var(--tg-theme-hint-color, #8e98ab);
    --border: rgba(255, 255, 255, 0.08);
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.25);

    --mark-5-bg: rgba(34, 197, 94, 0.22);
    --mark-5-fg: #4ade80;
    --mark-4-bg: rgba(59, 130, 246, 0.22);
    --mark-4-fg: #60a5fa;
    --mark-3-bg: rgba(245, 158, 11, 0.22);
    --mark-3-fg: #fbbf24;
    --mark-2-bg: rgba(239, 68, 68, 0.24);
    --mark-2-fg: #f87171;
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.screen {
  min-height: 100vh;
  padding: 20px 16px;
}

.center-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.muted-text {
  color: var(--hint);
  font-size: 13px;
  margin: 0;
}

/* Auth Screen */
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px 20px;
  box-shadow: var(--shadow);
}

.auth-logo {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: rgba(36, 129, 204, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin: 0 auto 12px;
}

.auth-title {
  margin: 0;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
}

.auth-subtitle {
  margin: 4px 0 18px;
  text-align: center;
  color: var(--hint);
  font-size: 13px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--hint);
  margin-top: 4px;
}

.text-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
}

.text-input:focus {
  border-color: var(--accent);
}

.password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.password-wrap .text-input {
  padding-right: 44px;
}

.icon-inside-btn {
  position: absolute;
  right: 8px;
  border: none;
  background: transparent;
  color: var(--hint);
  font-size: 17px;
  padding: 6px;
  cursor: pointer;
}

.primary-btn, .secondary-btn, .danger-btn {
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 13px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.primary-btn {
  margin-top: 8px;
  background: var(--accent);
  color: var(--accent-text);
}

.secondary-btn {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.danger-btn {
  background: rgba(220, 38, 38, 0.12);
  color: var(--danger);
}

.primary-btn:active, .secondary-btn:active, .danger-btn:active {
  transform: scale(0.985);
  opacity: 0.9;
}

.primary-btn:disabled, .secondary-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.alert-error {
  background: rgba(220, 38, 38, 0.12);
  color: var(--danger);
  border: 1px solid rgba(220, 38, 38, 0.25);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 12px;
}

.auth-hint {
  margin: 16px 0 0;
  font-size: 12px;
  color: var(--hint);
  text-align: center;
}

/* App Shell */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.top-bar-info {
  min-width: 0;
}

.header-title {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-subtitle {
  font-size: 12px;
  color: var(--hint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn.spinning {
  animation: spin 0.8s linear infinite;
}

.main-content {
  flex: 1;
  padding: 12px 14px calc(78px + env(safe-area-inset-bottom, 0px));
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
}

.content-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
}

/* Schedule Toolbar & Day Strip */
.week-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
}

.nav-arrow-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.week-center {
  flex: 1;
  text-align: center;
}

.week-label {
  font-size: 14px;
  font-weight: 700;
}

.week-actions {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 6px;
}

.chip-btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.chip-btn.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}

.day-strip {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 12px;
}

.day-pill {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  position: relative;
}

.day-pill-wd {
  font-size: 11px;
  color: var(--hint);
  font-weight: 600;
}

.day-pill-num {
  font-size: 14px;
  font-weight: 700;
}

.day-pill-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0;
}

.day-pill.has-lessons .day-pill-dot {
  opacity: 0.75;
}

.day-pill.today {
  border-color: var(--accent);
}

.day-pill.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}

.day-pill.active .day-pill-wd {
  color: rgba(255, 255, 255, 0.85);
}

.day-pill.active .day-pill-dot {
  background: var(--accent-text);
}

.day-heading {
  font-size: 14px;
  font-weight: 700;
  color: var(--hint);
  margin: 6px 2px 2px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--bg);
  color: var(--hint);
}

/* Lesson Card */
.lesson-card {
  display: flex;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.lesson-card.window-card {
  opacity: 0.65;
  padding: 9px 14px;
  border-style: dashed;
}

.time-rail {
  width: 48px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  border-right: 2px solid rgba(36, 129, 204, 0.35);
  padding-right: 10px;
}

.time-start {
  font-size: 13px;
  font-weight: 700;
}

.time-end {
  font-size: 11px;
  color: var(--hint);
}

.lesson-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.lesson-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.lesson-name {
  font-size: 15px;
  font-weight: 700;
  word-break: break-word;
}

.lesson-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12px;
  color: var(--hint);
}

.meta-pill {
  background: var(--bg);
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 12px;
}

.marks-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.mark-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
  background: var(--bg);
  color: var(--text);
}

.mark-5 { background: var(--mark-5-bg); color: var(--mark-5-fg); }
.mark-4 { background: var(--mark-4-bg); color: var(--mark-4-fg); }
.mark-3 { background: var(--mark-3-bg); color: var(--mark-3-fg); }
.mark-2 { background: var(--mark-2-bg); color: var(--mark-2-fg); }

.lesson-extra {
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}

.extra-label {
  font-weight: 600;
  color: var(--hint);
  margin-right: 4px;
}

.absence-pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(217, 119, 6, 0.16);
  color: var(--mark-3-fg);
  align-self: flex-start;
}

/* Grades Tab */
.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 12px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--hint);
  border-radius: 9px;
  padding: 8px 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--accent);
  color: var(--accent-text);
}

.gpa-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, var(--accent), #1b65a6);
  color: #ffffff;
  border-radius: 16px;
  padding: 16px 18px;
}

.gpa-label {
  font-size: 13px;
  opacity: 0.9;
}

.gpa-sub {
  font-size: 12px;
  opacity: 0.8;
  margin-top: 2px;
}

.gpa-value {
  font-size: 30px;
  font-weight: 800;
}

.subject-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 13px 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.subject-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.subject-name {
  font-size: 15px;
  font-weight: 700;
}

.avg-badge {
  flex-shrink: 0;
  min-width: 48px;
  text-align: center;
  border-radius: 10px;
  padding: 4px 8px;
  font-size: 14px;
  font-weight: 800;
  background: var(--bg);
}

.subject-marks {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.subject-absences {
  margin-top: 6px;
  font-size: 12px;
  color: var(--hint);
}

.subject-details {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.detail-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
}

.detail-date {
  color: var(--hint);
}

.term-strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.att-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.att-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.att-row:first-child {
  padding-top: 0;
}

/* Profile & Switches */
.section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--hint);
  margin: 4px 4px 0;
}

.kv-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.kv-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.kv-row:first-child {
  padding-top: 0;
}

.kv-key {
  color: var(--hint);
}

.kv-val {
  font-weight: 600;
  text-align: right;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.switch-row:last-child {
  border-bottom: none;
}

.switch-title {
  font-size: 14px;
  font-weight: 600;
}

.switch-desc {
  font-size: 12px;
  color: var(--hint);
}

.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background: rgba(128, 138, 156, 0.35);
  border-radius: 999px;
  transition: 0.2s;
}

.slider::before {
  content: "";
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background: #ffffff;
  border-radius: 50%;
  transition: 0.2s;
}

.switch input:checked + .slider {
  background: var(--accent);
}

.switch input:checked + .slider::before {
  transform: translateX(20px);
}

.student-option {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.student-option.active {
  border-color: var(--accent);
  background: rgba(36, 129, 204, 0.12);
}

.btn-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Empty & Skeleton */
.empty-card {
  text-align: center;
  padding: 28px 16px;
  color: var(--hint);
  font-size: 14px;
}

.skeleton {
  height: 76px;
  border-radius: 14px;
  background: linear-gradient(
    90deg,
    var(--surface) 25%,
    var(--border) 50%,
    var(--surface) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
}

.nav-btn {
  border: none;
  background: transparent;
  color: var(--hint);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 0;
  cursor: pointer;
}

.nav-btn.active {
  color: var(--accent);
}

.nav-icon {
  font-size: 19px;
  line-height: 1.1;
}

.nav-text {
  font-size: 11px;
  font-weight: 600;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: rgba(24, 28, 36, 0.92);
  color: #ffffff;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  max-width: calc(100vw - 32px);
  text-align: center;
  z-index: 50;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
