/* ═══════════════════════════════════════════════════════════════
   DESIGN TOKENS — Material Design 3 + Apple HIG aligned
   ═══════════════════════════════════════════════════════════════ */
:root {
  /* — MD3 Color Roles — */
  --md-primary:            #4F46E5;   /* Indigo 500 */
  --md-on-primary:         #FFFFFF;
  --md-primary-container:  #E8E6FD;   /* Indigo 50  */
  --md-on-primary-container:#1A148C;  /* Indigo 900 */
  --md-secondary:          #625B71;
  --md-on-secondary:       #FFFFFF;
  --md-secondary-container:#E8DEF8;
  --md-on-secondary-container:#1D192B;

  /* — Surface & Background — */
  --md-background:         #FAFAFF;
  --md-surface:            #FAFAFF;
  --md-surface-variant:    #F0EFF9;
  --md-surface-1:          #F4F3FF;   /* +5% primary tint */
  --md-surface-2:          #EEEEFF;   /* +8% primary tint */
  --md-on-surface:         #1C1B1F;
  --md-on-surface-variant: #49454F;
  --md-on-surface-muted:   #79747E;
  --md-outline:            #79747E;
  --md-outline-variant:    #CAC4D0;

  /* — Semantic Colors — */
  --md-error:              #B3261E;
  --md-error-container:    #F9DEDC;
  --md-on-error-container: #410E0B;
  --md-success:            #146C2E;
  --md-success-container:  #C8F0D2;
  --md-on-success-container:#002111;
  --md-warning:            #8B4000;
  --md-warning-container:  #FFDCC5;
  --md-on-warning-container:#301400;

  /* — MD3 Elevation — */
  --elev-0:  0px 0px 0px rgba(0,0,0,0);
  --elev-1:  0px 1px 2px rgba(0,0,0,.07), 0px 1px 3px 1px rgba(0,0,0,.05);
  --elev-2:  0px 1px 2px rgba(0,0,0,.05), 0px 2px 6px 2px rgba(0,0,0,.06);
  --elev-3:  0px 1px 3px rgba(0,0,0,.08), 0px 4px 8px 3px rgba(0,0,0,.06);

  /* — Shape — MD3 shape scale */
  --shape-none:       0px;
  --shape-xs:         4px;
  --shape-sm:         8px;
  --shape-md:         12px;
  --shape-lg:         16px;
  --shape-xl:         20px;
  --shape-2xl:        28px;
  --shape-full:       9999px;

  /* — Spacing — 4dp grid */
  --sp-1:  4px;
  --sp-2:  8px;
  --sp-3:  12px;
  --sp-4:  16px;
  --sp-5:  20px;
  --sp-6:  24px;

  /* — Typography scale — */
  --type-display-large:   57px;
  --type-display-medium:  45px;
  --type-display-small:   36px;
  --type-headline-large:  32px;
  --type-headline-medium: 28px;
  --type-headline-small:  24px;
  --type-title-large:     22px;
  --type-title-medium:    16px;
  --type-title-small:     14px;
  --type-label-large:     14px;
  --type-label-medium:    12px;
  --type-label-small:     11px;
  --type-body-large:      16px;
  --type-body-medium:     14px;
  --type-body-small:      12px;

  /* — Navigation — */
  --nav-height:  80px;
  --bar-height:  64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── Dark Mode (Midnight Blue / OLED) ── */
[data-theme='dark'] {
  --md-primary:            #A5B4FC;   /* Indigo 300 */
  --md-on-primary:         #1E1B4B;   /* Indigo 950 */
  --md-primary-container:  #312E81;   /* Indigo 900 */
  --md-on-primary-container:#E0E7FF;  /* Indigo 100 */
  
  --md-background:         #020617;   /* Slate 950 */
  --md-surface:            #020617;
  --md-surface-variant:    #1E293B;   /* Slate 800 */
  --md-surface-1:          #0F172A;   /* Slate 900 */
  --md-surface-2:          #1E293B;
  
  --md-on-surface:         #F8FAFC;   /* Slate 50 */
  --md-on-surface-variant: #CBD5E1;   /* Slate 300 */
  --md-on-surface-muted:   #94A3B8;   /* Slate 400 */
  
  --md-outline:            #475569;
  --md-outline-variant:    #334155;
  
  --md-secondary-container:#334155;
  --md-on-secondary-container:#F1F5F9;

  --md-error-container:    #7F1D1D;
  --md-on-error-container: #FEE2E2;
  --md-success-container:  #064E3B;
  --md-on-success-container:#D1FAE5;
  --md-warning-container:  #78350F;
  --md-on-warning-container:#FEF3C7;

  --elev-1:  0px 1px 3px rgba(0,0,0,.5);
  --elev-2:  0px 2px 6px rgba(0,0,0,.6);
  --elev-3:  0px 4px 12px rgba(0,0,0,.7);
}

/* ── Reset & Base ── */
*, *::before, *::after {
  -webkit-tap-highlight-color: transparent;
  -ms-overflow-style: none;
  scrollbar-width: none;
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
::-webkit-scrollbar { display: none; }

body {
  font-family: -apple-system, "SF Pro Text", BlinkMacSystemFont, "Roboto", "Segoe UI", sans-serif;
  background: #E8EAF6;
  margin: 0;
  padding: 0;
}

/* ── State Layer ── */
.state-layer {
  position: relative;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}
.state-layer::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--md-primary);
  opacity: 0;
  transition: opacity 0.15s ease;
  border-radius: inherit;
  pointer-events: none;
}
.state-layer:hover::after  { opacity: 0.08; }
.state-layer:active::after { opacity: 0.12; }

/* ── Buttons ── */
.btn-filled {
  background: var(--md-primary);
  color: var(--md-on-primary);
  border: none;
  border-radius: var(--shape-full);
  height: 40px;
  min-width: 48px;
  padding: 0 24px;
  font-size: var(--type-label-large);
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: box-shadow 0.2s, opacity 0.15s;
  position: relative;
  overflow: hidden;
}
.btn-filled:hover  { box-shadow: var(--elev-1); }
.btn-filled:active { opacity: 0.88; transform: scale(0.97); }

.btn-tonal {
  background: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
  border: none;
  border-radius: var(--shape-full);
  height: 40px;
  min-width: 48px;
  padding: 0 24px;
  font-size: var(--type-label-large);
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: box-shadow 0.2s, opacity 0.15s;
  position: relative;
  overflow: hidden;
}
.btn-tonal:hover  { box-shadow: var(--elev-1); }
.btn-tonal:active { opacity: 0.84; }

.btn-text {
  background: none;
  color: var(--md-primary);
  border: none;
  border-radius: var(--shape-full);
  height: 40px;
  min-width: 48px;
  padding: 0 12px;
  font-size: var(--type-label-large);
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  position: relative;
  overflow: hidden;
}
.btn-text:hover  { background: rgba(79,70,229,0.08); }
.btn-text:active { background: rgba(79,70,229,0.12); }

.btn-outlined {
  background: transparent;
  color: var(--md-primary);
  border: 1.5px solid var(--md-outline);
  border-radius: var(--shape-full);
  height: 40px;
  min-width: 48px;
  padding: 0 24px;
  font-size: var(--type-label-large);
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  position: relative;
  overflow: hidden;
}
.btn-outlined:hover  { background: rgba(79,70,229,0.08); }
.btn-outlined:active { background: rgba(79,70,229,0.12); }

/* ── Filter chips ── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1.5px solid var(--md-outline-variant);
  border-radius: var(--shape-sm);
  height: 32px;
  padding: 0 12px;
  font-size: var(--type-label-medium);
  font-weight: 500;
  color: var(--md-on-surface-variant);
  background: var(--md-surface);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.chip.selected {
  background: var(--md-secondary-container);
  border-color: transparent;
  color: var(--md-on-secondary-container);
}

/* ── Checkbox ── */
.cb-wrap { display: flex; align-items: center; flex-shrink: 0; }
.cb-custom {
  appearance: none;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  border: 2px solid var(--md-on-surface-variant);
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  position: relative;
  transition: background 0.18s, border-color 0.18s;
  margin: 0;
}
.cb-custom:checked {
  background: var(--md-primary);
  border-color: var(--md-primary);
}
.cb-custom:checked::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 1px;
  width: 6px;
  height: 10px;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
}

/* ── Cards ── */
.card {
  background: var(--md-surface);
  border-radius: var(--shape-xl);
  box-shadow: var(--elev-1);
  overflow: hidden;
}
.card-filled {
  background: var(--md-surface-1);
  border-radius: var(--shape-xl);
}
.card-outlined {
  background: var(--md-surface);
  border-radius: var(--shape-xl);
  border: 1px solid var(--md-outline-variant);
}

/* ── Navigation tabs ── */
.nav-tab        { display: none; }
.nav-tab.active { display: flex; flex-direction: column; }

/* ── Bottom Nav ── */
.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 4px;
  cursor: pointer;
  border: none;
  background: none;
  padding: 12px 0 calc(8px + var(--safe-bottom));
  position: relative;
  color: var(--md-on-surface-variant);
  transition: color 0.2s;
  text-decoration: none;
  min-height: 64px;
}
.nav-btn.active { color: var(--md-on-secondary-container); }

.nav-btn .nav-indicator {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: 64px;
  height: 32px;
  background: var(--md-secondary-container);
  border-radius: var(--shape-full);
  opacity: 0;
  transition: opacity 0.2s;
}
.nav-btn.active .nav-indicator { opacity: 1; }
.nav-btn .nav-icon  { position: relative; z-index: 1; display: flex; align-items: center; justify-content: center;}
.nav-btn .nav-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  position: relative;
  z-index: 1;
}

/* ── Content Tab Bar ── */
.ctab-bar {
  display: flex;
  border-bottom: 1px solid var(--md-outline-variant);
  background: var(--md-surface);
  position: relative;
}
.ctab-btn {
  flex: 1;
  height: 48px;
  font-size: var(--type-label-medium);
  font-weight: 600;
  color: var(--md-on-surface-muted);
  background: none;
  border: none;
  cursor: pointer;
  position: relative;
  letter-spacing: 0.01em;
  transition: color 0.2s;
}
.ctab-btn.active { color: var(--md-primary); }
.ctab-btn.active::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  background: var(--md-primary);
  border-radius: 3px 3px 0 0;
}
.ctab-panel        { display: none; }
.ctab-panel.active { display: block; }

/* ── Course Pill ── */
.course-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  border: 1.5px solid var(--md-outline-variant);
  border-radius: var(--shape-sm);
  height: 32px;
  padding: 0 12px;
  font-size: var(--type-label-medium);
  font-weight: 500;
  background: var(--md-surface);
  color: var(--md-on-surface-variant);
  transition: all 0.15s;
  white-space: nowrap;
}
.course-pill.selected {
  background: var(--md-primary-container);
  color: var(--md-on-primary-container);
  border-color: var(--md-primary-container);
}

/* ── Overlay panels ── */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: var(--md-surface);
  padding-bottom: var(--nav-height);
}
.overlay.hidden { display: none; }

/* ── Slide transitions ── */
.slide-in  { animation: slideIn  0.28s cubic-bezier(0.2,0,0,1) forwards; }
.slide-out { animation: slideOut 0.25s cubic-bezier(0.4,0,1,1) forwards; }
@keyframes slideIn  { from { transform: translateX(100%); opacity: 0.6; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideOut { from { transform: translateX(0); opacity: 1; }      to { transform: translateX(100%); opacity: 0.6; } }

/* ── Modal Backdrop ── */
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  padding: 0;
}
.modal-backdrop.center { align-items: center; padding: 16px; }
.modal-backdrop.hidden { display: none; }

/* Modal Sheet */
.modal-sheet {
  background: var(--md-surface);
  border-radius: 28px 28px 0 0;
  width: 100%;
  overflow: hidden;
  box-shadow: var(--elev-3);
  animation: sheetUp 0.3s cubic-bezier(0.2,0,0,1) forwards;
  padding-bottom: var(--safe-bottom);
}
/* Modal Dialog */
.modal-dialog {
  background: var(--md-surface-1);
  border-radius: var(--shape-2xl);
  width: 100%;
  max-width: 400px;
  overflow: hidden;
  box-shadow: var(--elev-3);
  animation: dialogIn 0.22s cubic-bezier(0.2,0,0,1) forwards;
}

@keyframes sheetUp  { from { transform: translateY(60%); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }
@keyframes dialogIn { from { transform: scale(0.9);     opacity: 0; }    to { transform: scale(1);     opacity: 1; } }

.modal-handle {
  width: 32px;
  height: 4px;
  background: var(--md-outline-variant);
  border-radius: 2px;
  margin: 12px auto 8px;
}

/* ── Snackbar ── */
.snackbar {
  position: fixed;
  bottom: calc(var(--nav-height) + 8px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(24px);
  background: #313033;
  color: #E6E1E5;
  padding: 14px 20px;
  border-radius: var(--shape-xs);
  font-size: var(--type-body-medium);
  font-weight: 500;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.2,0,0,1);
  z-index: 9999;
  white-space: nowrap;
  box-shadow: var(--elev-3);
  min-width: 180px;
  max-width: calc(100% - 32px);
  text-align: center;
}
.snackbar.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── List Items ── */
.list-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  min-height: 56px;
  background: var(--md-surface);
  cursor: pointer;
  position: relative;
  transition: background 0.15s;
  text-decoration: none;
}
.list-item:hover  { background: rgba(79,70,229,0.04); }
.list-item:active { background: rgba(79,70,229,0.08); }
.list-item .leading-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--shape-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ── Progress Indicator ── */
.progress-track {
  width: 100%;
  height: 4px;
  background: var(--md-primary-container);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--md-primary);
  border-radius: 2px;
  transition: width 0.5s cubic-bezier(0.2,0,0,1);
}

/* ── Badge ── */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--md-error);
  color: #fff;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  padding: 0 4px;
}

/* ── Divider ── */
.divider {
  height: 1px;
  background: var(--md-outline-variant);
  margin: 0;
}

/* ── Status Badges ── */
.status-overdue  { background: var(--md-error-container);   color: var(--md-error); }
.status-today    { background: var(--md-warning-container);  color: var(--md-warning); }
.status-upcoming { background: var(--md-primary-container);  color: var(--md-on-primary-container); }
.status-done     { background: var(--md-surface-variant);    color: var(--md-on-surface-muted); }

/* ── Streak pulse ── */
.streak-pulse {
  animation: pulse 2.2s ease-in-out infinite;
  display: inline-block;
}
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.18); } }

/* ── FAB ── */
.fab {
  position: absolute;
  bottom: calc(var(--nav-height) + 16px);
  right: 16px;
  width: 56px;
  height: 56px;
  border-radius: var(--shape-lg);
  background: var(--md-primary-container);
  color: var(--md-on-primary-container);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--elev-3);
  cursor: pointer;
  border: none;
  transition: transform 0.15s, box-shadow 0.15s;
  z-index: 10;
}
.fab:hover  { box-shadow: var(--elev-3); transform: scale(1.02); }
.fab:active { transform: scale(0.94); box-shadow: var(--elev-1); }

/* ── Eyebrow label ── */
.section-eyebrow {
  font-size: var(--type-label-small);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--md-on-surface-muted);
}

/* ── Text fields ── */
.text-field {
  width: 100%;
  height: 56px;
  padding: 0 16px;
  border: 1.5px solid var(--md-outline);
  border-radius: var(--shape-xs);
  font-size: var(--type-body-large);
  font-family: inherit;
  background: var(--md-surface);
  color: var(--md-on-surface);
  outline: none;
  transition: border-color 0.18s, border-width 0.18s;
  appearance: none;
  -webkit-appearance: none;
}
.text-field:focus {
  border-color: var(--md-primary);
  border-width: 2px;
}
.text-field::placeholder { color: var(--md-on-surface-muted); }

/* ── Select fields ── */
.select-field {
  width: 100%;
  height: 56px;
  padding: 0 40px 0 16px;
  border: 1.5px solid var(--md-outline);
  border-radius: var(--shape-xs);
  font-size: var(--type-body-large);
  font-family: inherit;
  background: var(--md-surface);
  color: var(--md-on-surface);
  appearance: none;
  -webkit-appearance: none;
  outline: none;
  cursor: pointer;
  transition: border-color 0.18s;
}
.select-field:focus {
  border-color: var(--md-primary);
  border-width: 2px;
}

/* ── Toggle Switch ── */
.toggle-track {
  width: 52px;
  height: 32px;
  border-radius: 16px;
  background: var(--md-outline);
  cursor: pointer;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
  border: none;
  appearance: none;
  -webkit-appearance: none;
}
.toggle-track.on { background: var(--md-primary); }
.toggle-track::after {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  width: 24px;
  height: 24px;
  border-radius: 12px;
  background: #fff;
  transition: transform 0.2s cubic-bezier(0.2,0,0,1), width 0.1s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle-track.on::after { transform: translateX(20px); }
.toggle-track:active::after { width: 28px; }

/* ── Textarea ── */
.textarea-field {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid var(--md-outline);
  border-radius: var(--shape-xs);
  font-size: var(--type-body-medium);
  font-family: inherit;
  background: var(--md-surface);
  color: var(--md-on-surface);
  outline: none;
  transition: border-color 0.18s;
  resize: none;
}
.textarea-field:focus {
  border-color: var(--md-primary);
  border-width: 2px;
}

/* ── Shimmer skeleton ── */
/* ── Progress Rings (SVG) ── */
.progress-ring-circle {
  transition: stroke-dashoffset 0.35s;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
}

.shimmer {
  background: linear-gradient(90deg,
    var(--md-surface-variant) 25%,
    var(--md-surface) 50%,
    var(--md-surface-variant) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── Focus-visible ── */
:focus-visible {
  outline: 3px solid var(--md-primary);
  outline-offset: 2px;
}
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--md-primary);
  outline-offset: 2px;
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
