/* ═══════════════════════════════════════════════════════
   PSDM Student Manager — Main Styles
   Professional Design System
═══════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* ─── Design Tokens ───────────────────────────────────── */
:root {
  /* Brand */
  --primary:      #2563eb;
  --primary-h:    #1d4ed8;
  --primary-l:    #eff6ff;
  --primary-ll:   #dbeafe;
  --primary-d:    #1e40af;

  /* Neutrals */
  --bg:           #f1f5f9;
  --bg2:          #ffffff;
  --bg3:          #f8fafc;
  --bg4:          #f1f5f9;
  --bg5:          #e2e8f0;

  /* Text */
  --text:         #0f172a;
  --text2:        #334155;
  --text3:        #64748b;
  --text4:        #94a3b8;

  /* Borders */
  --border:       #e2e8f0;
  --border2:      #cbd5e1;

  /* Semantic */
  --green:        #059669;
  --green-l:      #ecfdf5;
  --green-d:      #047857;
  --red:          #dc2626;
  --red-l:        #fef2f2;
  --yellow:       #d97706;
  --yellow-l:     #fffbeb;
  --orange:       #ea580c;
  --orange-l:     #fff7ed;
  --purple:       #7c3aed;
  --purple-l:     #f5f3ff;

  /* Layout */
  --sidebar-w:    240px;
  --header-h:     60px;

  /* Shape */
  --radius:       12px;
  --radius-sm:    8px;
  --radius-xs:    6px;

  /* Shadows */
  --shadow-xs:    0 1px 2px rgba(0,0,0,.05);
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:    0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.04);
  --shadow-lg:    0 10px 15px rgba(0,0,0,.08), 0 4px 6px rgba(0,0,0,.04);
  --shadow-xl:    0 20px 25px rgba(0,0,0,.1), 0 8px 10px rgba(0,0,0,.05);

  /* Animation */
  --ease:         cubic-bezier(.4,0,.2,1);
  --transition:   .15s var(--ease);
  --transition-md:.25s var(--ease);
}

/* Dark mode */
[data-theme="dark"] {
  --bg:           #0d1117;
  --bg2:          #161b22;
  --bg3:          #1c2128;
  --bg4:          #21262d;
  --bg5:          #30363d;
  --text:         #f0f6fc;
  --text2:        #c9d1d9;
  --text3:        #8b949e;
  --text4:        #6e7681;
  --border:       #30363d;
  --border2:      #484f58;
  --primary-l:    #0d2137;
  --primary-ll:   #1a3a5c;
  --green-l:      #0a2d1f;
  --red-l:        #2d0a0a;
  --yellow-l:     #2d1c00;
  --orange-l:     #2d1500;
  --purple-l:     #1a0d40;
  --shadow:       0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
  --shadow-md:    0 4px 6px rgba(0,0,0,.3), 0 2px 4px rgba(0,0,0,.2);
  --shadow-lg:    0 10px 15px rgba(0,0,0,.35), 0 4px 6px rgba(0,0,0,.2);
}

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

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ─── App Shell ────────────────────────────────────────── */
#app-shell { display: flex; min-height: 100vh; }

/* ─── Header ───────────────────────────────────────────── */
#app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 14px;
  z-index: 100;
  box-shadow: var(--shadow-xs);
}

#header-logo {
  height: 34px;
  width: auto;
  object-fit: contain;
  border-radius: 6px;
}

#header-inst-name {
  font-weight: 700;
  font-size: 15px;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: linear-gradient(135deg, var(--primary) 0%, var(--purple) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#header-save-status {
  font-size: 11.5px;
  color: var(--text3);
  white-space: nowrap;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--bg3);
}

#header-user {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 6px 12px 6px 6px;
  border-radius: 40px;
  border: 1px solid var(--border);
  position: relative;
  transition: all var(--transition);
}
#header-user:hover {
  background: var(--bg3);
  border-color: var(--border2);
}

.header-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

#header-user-name { font-size: 13px; font-weight: 600; }
#header-user-role { font-size: 11px; color: var(--text3); }

.header-user-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xl);
  min-width: 200px;
  z-index: 200;
  display: none;
  overflow: hidden;
}
.header-user-menu.open { display: block; }
.header-user-menu-item {
  padding: 11px 16px;
  font-size: 13.5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  transition: background var(--transition);
}
.header-user-menu-item:hover { background: var(--bg3); }
.header-user-menu-item.danger { color: var(--red); }
.header-user-menu-divider { height: 1px; background: var(--border); }

.hamburger {
  display: none;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text);
  padding: 6px;
  border-radius: var(--radius-xs);
  transition: background var(--transition);
}
.hamburger:hover { background: var(--bg3); }

/* ─── Sidebar ──────────────────────────────────────────── */
#app-sidebar {
  position: fixed;
  top: var(--header-h);
  left: 0;
  width: var(--sidebar-w);
  height: calc(100vh - var(--header-h));
  background: var(--bg2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 90;
  padding: 12px 8px;
  transition: transform var(--transition-md);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#app-sidebar::-webkit-scrollbar { width: 4px; }
#app-sidebar::-webkit-scrollbar-track { background: transparent; }
#app-sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text3);
  border-radius: var(--radius-sm);
  margin-bottom: 2px;
  transition: all var(--transition);
  position: relative;
}
.nav-item:hover {
  background: var(--bg3);
  color: var(--text2);
}
.nav-item.active {
  background: var(--primary-l);
  color: var(--primary);
  font-weight: 600;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 25%;
  bottom: 25%;
  width: 3px;
  background: var(--primary);
  border-radius: 0 3px 3px 0;
  margin-left: -8px;
}
.nav-item .nav-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
  opacity: .8;
}
.nav-item.active .nav-icon { opacity: 1; }
.nav-separator {
  height: 1px;
  background: var(--border);
  margin: 8px 4px;
}
.nav-group-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text4);
  padding: 10px 12px 4px;
}

/* ─── Main Content ─────────────────────────────────────── */
#main-content {
  margin-left: var(--sidebar-w);
  margin-top: var(--header-h);
  padding: 24px;
  min-height: calc(100vh - var(--header-h));
  flex: 1;
  max-width: calc(100vw - var(--sidebar-w));
}

/* ─── PIN Screen ───────────────────────────────────────── */
.fullscreen-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 50%, #7c3aed 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

#pin-screen .pin-card {
  background: var(--bg2);
  border-radius: 20px;
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 360px;
  padding: 36px 32px;
  text-align: center;
  border: 1px solid rgba(255,255,255,.1);
}

#pin-screen .pin-logo {
  margin-bottom: 20px;
  display: flex;
  justify-content: center;
}
#pin-screen .pin-logo img {
  max-height: 52px;
  max-width: 180px;
  object-fit: contain;
}

#pin-screen h2 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text);
}
#pin-screen .inst-name {
  font-size: 13px;
  color: var(--text3);
  margin-bottom: 24px;
  font-weight: 500;
}

.pin-dots {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin: 16px 0 20px;
}
.pin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border2);
  transition: all .2s var(--ease);
  background: transparent;
}
.pin-dot.filled {
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-ll);
  transform: scale(1.15);
}
.pin-dot.error {
  background: var(--red);
  border-color: var(--red);
  box-shadow: 0 0 0 4px var(--red-l);
  animation: shake .3s ease;
}

@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-width: 240px;
  margin: 0 auto 16px;
}
.key {
  padding: 16px 10px;
  text-align: center;
  background: var(--bg3);
  border-radius: var(--radius-sm);
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  border: 1px solid var(--border);
  transition: all .1s var(--ease);
  color: var(--text);
}
.key:hover {
  background: var(--primary-l);
  border-color: var(--primary);
  color: var(--primary);
}
.key:active {
  transform: scale(.93);
  background: var(--primary-ll);
}

.pin-attempt-msg {
  background: var(--red-l);
  color: var(--red);
  padding: 10px 14px;
  border-radius: var(--radius-xs);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 12px;
  display: none;
  border: 1px solid rgba(220,38,38,.15);
}

/* ─── Page Header ──────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -.3px;
}
.page-subtitle {
  font-size: 13.5px;
  color: var(--text3);
  margin-top: 2px;
}
.page-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* ─── Cards ────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ─── Stats Grid ───────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all var(--transition-md);
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--purple));
  opacity: 0;
  transition: opacity var(--transition-md);
}
.stat-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-3px);
  border-color: var(--primary-ll);
}
.stat-card:hover::before { opacity: 1; }

.stat-icon {
  font-size: 26px;
  margin-bottom: 10px;
  display: block;
}
.stat-val {
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
  letter-spacing: -.5px;
}
.stat-lbl {
  font-size: 12px;
  color: var(--text3);
  margin-top: 5px;
  font-weight: 500;
}
.stat-trend {
  font-size: 11px;
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 3px;
}

/* ─── Offline Banner ───────────────────────────────────── */
#offline-banner {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: linear-gradient(90deg, #d97706, #f59e0b);
  color: #fff;
  padding: 10px 20px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  z-index: 500;
  display: none;
  letter-spacing: .2px;
}
