/* ═══════════════════════════════════════════════════════════════════
   CELESTIAL INTELLIGENCE — Design System
   DTU SE-A2 Attendance Tracker
═══════════════════════════════════════════════════════════════════ */

/* ─── Custom Properties ─────────────────────────────────────────── */
:root {
  /* Palette */
  --bg:            #090d16;
  --surface:       #0f131c;
  --surface-low:   #181b25;
  --surface-mid:   #1c1f29;
  --surface-high:  #262a34;
  --surface-top:   #31353f;

  --primary:       #6366f1;
  --primary-end:   #a855f7;
  --primary-light: #c0c1ff;
  --teal:          #3cddc7;
  --rose:          #f43f5e;
  --amber:         #f59e0b;

  --text:          #dfe2ef;
  --text-sub:      #c7c4d7;
  --text-muted:    #908fa0;
  --outline:       #464554;

  /* Glassmorphism */
  --glass-bg:      rgba(255,255,255,0.035);
  --glass-border:  rgba(255,255,255,0.08);
  --glass-blur:    12px;

  /* Gradient */
  --grad:          linear-gradient(135deg, #6366f1, #a855f7);
  --grad-teal:     linear-gradient(135deg, #2dd4bf, #06b6d4);

  /* Spacing (8px base) */
  --sp-xs:  4px;
  --sp-sm:  8px;
  --sp-md: 16px;
  --sp-lg: 24px;
  --sp-xl: 40px;

  /* Radius */
  --r-sm:  6px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;

  /* Transitions */
  --ease: cubic-bezier(0.4,0,0.2,1);
}

/* ─── Reset & Base ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* Subtle noise-texture background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 50% at 50% 0%, rgba(99,102,241,0.12) 0%, transparent 60%),
    radial-gradient(ellipse 40% 30% at 80% 10%, rgba(168,85,247,0.08) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

.app-root {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ─── Glass Card ─────────────────────────────────────────────────── */
.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--r-lg);
}

/* ─── AUTH SCREEN ────────────────────────────────────────────────── */
.auth-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-md);
  position: relative;
}

.auth-glow {
  position: fixed;
  top: -120px;
  left: 50%;
  transform: translateX(-50%);
  width: 600px;
  height: 400px;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(99,102,241,0.18) 0%, transparent 70%);
  pointer-events: none;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: var(--sp-xl) var(--sp-lg);
  animation: fadeSlideUp 0.5s var(--ease) both;
  /* Top gradient line */
  position: relative;
  overflow: hidden;
}

.auth-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--grad);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
}

/* Brand header */
.auth-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  margin-bottom: var(--sp-xl);
}

.brand-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 20px rgba(99,102,241,0.35);
}

.brand-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
  font-family: 'Geist Mono', monospace;
}

/* Auth steps */
.auth-step { display: flex; flex-direction: column; gap: var(--sp-md); }

.auth-hint {
  font-size: 0.85rem;
  color: var(--text-sub);
  line-height: 1.5;
}

.auth-link-row {
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
}

.auth-link {
  color: var(--primary-light);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: transparent;
  transition: text-decoration-color 0.2s;
  margin-left: 4px;
}
.auth-link:hover { text-decoration-color: var(--primary-light); }

.setup-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(99,102,241,0.15);
  border: 1px solid rgba(99,102,241,0.3);
  border-radius: 99px;
  padding: 4px 12px;
  font-size: 0.78rem;
  color: var(--primary-light);
  font-weight: 600;
  width: fit-content;
}

.auth-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: var(--sp-xl);
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: 'Geist Mono', monospace;
  letter-spacing: 0.04em;
}
.auth-footer .dot { color: var(--outline); }

/* ─── FORM ELEMENTS ──────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-sub);
  letter-spacing: 0.03em;
  font-family: 'Geist Mono', monospace;
}

.form-input {
  background: rgba(15,19,28,0.7);
  border: 1px solid var(--outline);
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  padding: 10px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
  width: 100%;
}

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}

.form-input::placeholder { color: var(--text-muted); }

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23908fa0' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
  cursor: pointer;
}

.otp-input {
  text-align: center;
  font-size: 1.5rem;
  letter-spacing: 0.5rem;
  font-family: 'Geist Mono', monospace;
  font-weight: 700;
}

.date-input { width: auto; cursor: pointer; }
.date-input::-webkit-calendar-picker-indicator {
  filter: invert(0.7);
  cursor: pointer;
}

/* ─── BUTTONS ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 18px;
  border-radius: var(--r-sm);
  font-size: 0.88rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: all 0.2s var(--ease);
  white-space: nowrap;
  text-decoration: none;
}

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

.btn-primary {
  background: var(--grad);
  color: #fff;
  box-shadow: 0 2px 12px rgba(99,102,241,0.3);
}
.btn-primary:hover:not(:disabled) {
  box-shadow: 0 4px 20px rgba(99,102,241,0.5);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }

.btn-ghost {
  background: rgba(255,255,255,0.06);
  color: var(--text-sub);
  border: 1px solid var(--glass-border);
}
.btn-ghost:hover:not(:disabled) {
  background: rgba(255,255,255,0.1);
  color: var(--text);
}

.btn-danger {
  background: rgba(244,63,94,0.15);
  color: #f87171;
  border: 1px solid rgba(244,63,94,0.25);
}
.btn-danger:hover:not(:disabled) { background: rgba(244,63,94,0.25); }

.btn-success {
  background: rgba(61,221,199,0.12);
  color: var(--teal);
  border: 1px solid rgba(61,221,199,0.25);
  padding: 7px 12px;
  font-size: 0.8rem;
}
.btn-success:hover:not(:disabled) { background: rgba(61,221,199,0.22); }

.btn-warn {
  background: rgba(245,158,11,0.12);
  color: var(--amber);
  border: 1px solid rgba(245,158,11,0.25);
  padding: 7px 12px;
  font-size: 0.8rem;
}
.btn-warn:hover:not(:disabled) { background: rgba(245,158,11,0.22); }

.btn-sm { padding: 7px 12px; font-size: 0.8rem; }
.btn-icon { padding: 7px 10px; }
.btn-full { width: 100%; }

/* ─── APP HEADER ─────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-md);
  padding: 12px var(--sp-lg);
  border-radius: 0;
  border-top: none;
  border-left: none;
  border-right: none;
  border-bottom: 1px solid var(--glass-border);
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(9,13,22,0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.brand-icon-sm {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
}

.header-title-main {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}
.header-title-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: 'Geist Mono', monospace;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-mid);
  border: 1px solid var(--glass-border);
  border-radius: 99px;
  padding: 4px 12px 4px 4px;
}

.user-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--grad);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.user-name {
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
}

.user-roll {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: 'Geist Mono', monospace;
  white-space: nowrap;
}

/* ─── CHIP BADGES ────────────────────────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.chip-admin {
  background: rgba(99,102,241,0.18);
  border: 1px solid rgba(99,102,241,0.35);
  color: var(--primary-light);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-family: 'Geist Mono', monospace;
}

.badge-theory  { background:rgba(99,102,241,0.15); color:#a5b4fc; border:1px solid rgba(99,102,241,0.3); }
.badge-lab     { background:rgba(61,221,199,0.12); color:var(--teal); border:1px solid rgba(61,221,199,0.25); }
.badge-g1      { background:rgba(168,85,247,0.15); color:#d8b4fe; border:1px solid rgba(168,85,247,0.3); }
.badge-g2      { background:rgba(245,158,11,0.12); color:#fcd34d; border:1px solid rgba(245,158,11,0.25); }
.badge-g3      { background:rgba(34,211,238,0.12); color:#67e8f9; border:1px solid rgba(34,211,238,0.25); }
.badge-cancelled { background:rgba(244,63,94,0.1); color:#fca5a5; border:1px solid rgba(244,63,94,0.25); }
.badge-future  { background:rgba(148,163,184,0.1); color:#94a3b8; border:1px solid rgba(148,163,184,0.2); display:inline-flex;align-items:center;gap:5px;padding:3px 10px;border-radius:99px;font-size:0.75rem;font-weight:600; }

/* ─── MAIN CONTENT LAYOUT ────────────────────────────────────────── */
#studentDashboard, #adminDashboard {
  max-width: 880px;
  margin: 0 auto;
  width: 100%;
  padding: var(--sp-lg);
  display: flex;
  flex-direction: column;
  gap: var(--sp-lg);
}

/* ─── STATS GRID ─────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-md);
}

.stat-card {
  padding: var(--sp-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-sm);
  text-align: center;
  transition: transform 0.2s var(--ease), box-shadow 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(0,0,0,0.3);
}

.stat-card-status {
  justify-content: center;
}

/* SVG Progress Rings */
.ring-wrap {
  position: relative;
  width: 72px; height: 72px;
  flex-shrink: 0;
}

.ring-svg {
  width: 72px; height: 72px;
  transform: rotate(-90deg);
}

.ring-bg {
  fill: none;
  stroke: rgba(255,255,255,0.06);
  stroke-width: 7;
}

.ring-fg {
  fill: none;
  stroke-width: 7;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.8s var(--ease);
}

.ring-indigo { stroke: url(#ringIndigo); }
.ring-teal   { stroke: #3cddc7; }
.ring-purple { stroke: url(#ringPurple); }

.ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text);
}
.ring-label-sm { font-size: 0.85rem; }

/* Hidden SVG defs for gradients */
body::after {
  content: '';
  position: absolute;
}

.stat-meta { text-align: center; }
.stat-num  { font-size: 1.1rem; font-weight: 800; color: var(--text); }
.stat-desc { font-size: 0.72rem; color: var(--text-muted); font-family:'Geist Mono',monospace; margin-top:2px; }

.stat-status-icon {
  font-size: 2rem;
  margin-bottom: var(--sp-sm);
}

.stat-status-text {
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.4;
}

/* ─── SECTION CARDS ──────────────────────────────────────────────── */
.section-card { padding: var(--sp-lg); }

.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-md);
  margin-bottom: var(--sp-lg);
  flex-wrap: wrap;
}

.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.section-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 3px;
}

.date-notice-badge {
  font-size: 0.75rem;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.date-controls {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  flex-wrap: nowrap;
}

/* ─── SUBJECT GRID ───────────────────────────────────────────────── */
.subject-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--sp-md);
}

.subject-card {
  background: var(--surface-mid);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-md);
  padding: var(--sp-md);
  transition: border-color 0.2s, transform 0.2s;
}
.subject-card:hover { transform: translateY(-1px); border-color: var(--outline); }

.subj-code { font-size: 0.82rem; font-weight: 700; color: var(--text); }
.subj-pct  { font-size: 1.5rem; font-weight: 800; line-height: 1.2; margin: 4px 0; }
.subj-status { font-size: 0.72rem; font-weight: 600; display:flex;align-items:center;gap:4px; }

/* ─── SESSIONS LIST ──────────────────────────────────────────────── */
.sessions-list { display: flex; flex-direction: column; gap: var(--sp-sm); }

.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-md);
  padding: 12px 16px;
  background: var(--surface-mid);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-md);
  transition: border-color 0.2s;
  flex-wrap: wrap;
}
.session-item:hover { border-color: var(--outline); }

.session-info { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }

.session-name-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.session-subj {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.session-slot {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: 'Geist Mono', monospace;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Attendance toggle */
.att-toggle {
  display: flex;
  border-radius: var(--r-sm);
  overflow: hidden;
  border: 1px solid var(--outline);
  flex-shrink: 0;
}

.att-btn {
  padding: 6px 14px;
  font-size: 0.75rem;
  font-weight: 700;
  font-family: 'Geist Mono', monospace;
  letter-spacing: 0.04em;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  border-radius: 0;
}

.att-btn.active-p {
  background: rgba(61,221,199,0.2);
  color: var(--teal);
}

.att-btn.active-a {
  background: rgba(244,63,94,0.18);
  color: #f87171;
}

/* ─── ADMIN TABS ─────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  gap: var(--sp-sm);
  padding: var(--sp-sm);
  border-radius: var(--r-md);
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--r-sm);
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text-muted);
  transition: all 0.2s;
}

.tab-btn:hover { background: rgba(255,255,255,0.07); color: var(--text); }
.tab-btn.tab-active { background: var(--grad); color: #fff; box-shadow: 0 2px 12px rgba(99,102,241,0.3); }

/* ─── ROSTER TABLE ───────────────────────────────────────────────── */
.roster-filters {
  display: flex;
  gap: var(--sp-sm);
  flex-wrap: wrap;
}

.table-wrap {
  overflow-x: auto;
  border-radius: var(--r-md);
  border: 1px solid var(--glass-border);
  margin-top: var(--sp-md);
}

.roster-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
}

.roster-table th {
  padding: 10px 16px;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--surface-mid);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-family: 'Geist Mono', monospace;
  border-bottom: 1px solid var(--glass-border);
  white-space: nowrap;
}

.roster-table td {
  padding: 10px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  color: var(--text-sub);
  vertical-align: middle;
}

.roster-table tr:last-child td { border-bottom: none; }
.roster-table tr:hover td { background: rgba(255,255,255,0.025); }

/* ─── CUSTOM SESSION FORM ────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--glass-border);
  margin: var(--sp-lg) 0;
}

.custom-sess-fields {
  display: flex;
  gap: var(--sp-sm);
  flex-wrap: wrap;
  align-items: center;
}

/* ─── EMPTY STATES ───────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: var(--sp-xl) var(--sp-md);
  color: var(--text-muted);
}
.empty-state i { font-size: 2.2rem; margin-bottom: var(--sp-md); display: block; opacity: 0.5; }
.empty-state p { font-size: 0.85rem; }

/* ─── TOAST NOTIFICATIONS ────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: var(--sp-lg);
  right: var(--sp-lg);
  display: flex;
  flex-direction: column;
  gap: var(--sp-sm);
  z-index: 9999;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: var(--r-md);
  font-size: 0.85rem;
  font-weight: 500;
  max-width: 340px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
  animation: toastIn 0.3s var(--ease) both;
  backdrop-filter: blur(16px);
  pointer-events: all;
}

.toast.success {
  background: rgba(61,221,199,0.12);
  border: 1px solid rgba(61,221,199,0.25);
  color: #5eead4;
}

.toast.error {
  background: rgba(244,63,94,0.12);
  border: 1px solid rgba(244,63,94,0.25);
  color: #fca5a5;
}

/* ─── ANIMATIONS ─────────────────────────────────────────────────── */
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(24px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ─── RESPONSIVE ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .header-right { gap: 6px; }
  .user-meta { display: none; }
  .btn-label { display: none; }
  .user-pill { padding: 4px; }

  #studentDashboard, #adminDashboard {
    padding: var(--sp-md);
    gap: var(--sp-md);
  }

  .section-header { flex-direction: column; align-items: flex-start; }
  .date-controls  { flex-wrap: wrap; }
  .roster-filters { flex-direction: column; }
  .custom-sess-fields { flex-direction: column; align-items: stretch; }
  .custom-sess-fields .btn { width: 100%; }

  .session-item { flex-direction: column; align-items: flex-start; }
  .att-toggle { align-self: flex-end; }

  .auth-card { padding: var(--sp-lg) var(--sp-md); }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: var(--sp-sm); }
  .stat-card  { padding: var(--sp-md) var(--sp-sm); }
  .ring-wrap, .ring-svg { width: 58px; height: 58px; }
  .subject-grid { grid-template-columns: 1fr 1fr; }

  .date-input { width: 130px; }
}

/* SVG gradient defs rendered in page */
svg.defs-only { position: absolute; width: 0; height: 0; overflow: hidden; }
