/* ====================================================================
   SCHOOL GRADING SYSTEM — iOS MOBILE DESIGN
   Inspired by Apple Settings, Reminders, and Education apps
   Mobile-first, touch-optimized, SF Pro design language
   ==================================================================== */

/* ---------- iOS DESIGN TOKENS ---------- */
:root {
  /* iOS System Colors */
  --ios-blue:       #007AFF;
  --ios-blue-dark:  #0A5BC4;
  --ios-green:      #34C759;
  --ios-indigo:     #5856D6;
  --ios-orange:      #FF9500;
  --ios-pink:        #FF2D55;
  --ios-purple:      #AF52DE;
  --ios-red:         #FF3B30;
  --ios-teal:        #5AC8FA;
  --ios-yellow:      #FFCC00;
  --ios-gray:        #8E8E93;
  --ios-gray2:       #AEAEB2;
  --ios-gray3:       #C7C7CC;
  --ios-gray4:       #D1D1D6;
  --ios-gray5:       #E5E5EA;
  --ios-gray6:       #F2F2F7;

  /* Semantic Surfaces */
  --bg:             var(--ios-gray6);
  --bg-grouped:     #EFEFF4;
  --surface:        #FFFFFF;
  --surface-2:      var(--ios-gray6);
  --surface-3:      #F9F9F9;

  /* Text */
  --text:           #000000;
  --text-secondary: rgba(60, 60, 67, 0.60);
  --text-tertiary:  rgba(60, 60, 67, 0.30);
  --text-quaternary:rgba(60, 60, 67, 0.18);
  --text-on-blue:   #FFFFFF;
  --text-on-gray:   #FFFFFF;

  /* Separators */
  --separator:        rgba(60, 60, 67, 0.12);
  --separator-opaque: #C6C6C8;

  /* Brand mapping */
  --brand:          var(--ios-blue);
  --brand-hover:    var(--ios-blue-dark);

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.12);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.18);

  /* Radius */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-pill: 9999px;

  /* Spacing */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;

  /* Typography */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
          "Helvetica Neue", "Inter", Arial, sans-serif;
  --font-mono: "SF Mono", ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, monospace;

  /* Sizes */
  --nav-h: 44px;
  --tabbar-h: 49px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  /* Transitions */
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --t-fast: 120ms var(--ease);
  --t-base: 200ms var(--ease);
  --t-slow: 350ms var(--ease);
}

/* ---------- RESET & BASE ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { font-size: 17px; -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  overflow-x: hidden;
  padding-top: var(--safe-top);
}
a { color: var(--ios-blue); text-decoration: none; }
a:active { opacity: 0.5; }
button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}
input, select, textarea {
  -webkit-appearance: none;
  appearance: none;
  border: none;
  background: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238E8E93' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}
img { max-width: 100%; height: auto; display: block; }
table { border-collapse: collapse; }
:focus-visible { outline: none; }
:focus { outline: none; }

/* ---------- UTILITY ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ====================================================================
   LOGIN SCREEN
   ==================================================================== */
#login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--sp-6);
  background: linear-gradient(180deg, #F2F2F7 0%, #E3E3E8 100%);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  padding: var(--sp-8) var(--sp-6);
  padding-top: var(--sp-10);
}
.login-header { text-align: center; margin-bottom: var(--sp-8); }
.login-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto var(--sp-4);
  background: linear-gradient(135deg, var(--ios-blue), var(--ios-indigo));
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 4px 14px rgba(0,122,255,0.3);
}
.login-title { font-size: 24px; font-weight: 700; letter-spacing: -0.5px; }
.login-subtitle { font-size: 15px; color: var(--text-secondary); margin-top: var(--sp-1); }

.login-form .form-field { margin-bottom: var(--sp-4); }
.login-form .form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--sp-1);
  padding-left: var(--sp-1);
  text-transform: none;
  letter-spacing: 0;
}
.login-form .input-wrapper {
  background: var(--ios-gray6);
  border-radius: var(--r-sm);
  border: 1px solid var(--separator);
  overflow: hidden;
}
.login-form .input-wrapper:focus-within {
  border-color: var(--ios-blue);
  box-shadow: 0 0 0 3px rgba(0,122,255,0.12);
}
.login-form .form-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 17px;
  border: none;
  background: transparent;
  padding-left: 44px;
}
.login-form .input-icon { position: absolute; left: 14px; color: var(--ios-gray); }
.login-form .form-hint { display: none; }

.login-form .btn-block {
  width: 100%;
  min-height: 50px;
  font-size: 17px;
  font-weight: 600;
  border-radius: var(--r-md);
  margin-top: var(--sp-4);
}

.login-footer {
  text-align: center;
  margin-top: var(--sp-6);
  font-size: 13px;
  color: var(--text-tertiary);
}

/* Login message */
.login-form .msg { text-align: center; font-size: 14px; }
.msg.err { color: var(--ios-red); }

/* ====================================================================
   APP SHELL
   ==================================================================== */
#app { display: none; min-height: 100vh; min-height: 100dvh; }

/* ---------- NAVIGATION BAR ---------- */
.topbar {
  position: fixed;
  top: var(--safe-top);
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--nav-h);
  background: rgba(249, 249, 249, 0.72);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
  display: flex;
  align-items: center;
  padding: 0 var(--sp-4);
  padding-left: max(var(--sp-4), var(--safe-left));
  padding-right: max(var(--sp-4), var(--safe-right));
}
.topbar-left { display: flex; align-items: center; gap: var(--sp-2); flex: 1; }
.topbar-right { display: flex; align-items: center; gap: var(--sp-2); }
.topbar-spacer { flex: 1; }

.nav-toggle { display: none; }

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.3px;
}
.brand-icon {
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, var(--ios-blue), var(--ios-indigo));
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

/* User menu */
.user-menu { position: relative; }
.user-avatar-btn {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 4px 10px 4px 4px;
  border-radius: var(--r-pill);
  background: var(--ios-gray6);
  border: none;
  cursor: pointer;
  transition: opacity var(--t-fast);
}
.user-avatar-btn:active { opacity: 0.6; }
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ios-blue), var(--ios-indigo));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 500; }
.user-role {
  font-size: 11px;
  color: #fff;
  background: var(--ios-blue);
  padding: 2px 8px;
  border-radius: var(--r-pill);
  font-weight: 600;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  background: var(--surface);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: none;
  z-index: 200;
}
.dropdown-menu.show { display: block; animation: dropdownIn var(--t-base); }
@keyframes dropdownIn { from { opacity: 0; transform: translateY(-8px) scale(0.96); } to { opacity: 1; transform: none; } }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 12px 16px;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-size: 15px;
  cursor: pointer;
  transition: background var(--t-fast);
}
.dropdown-item:active { background: var(--ios-gray6); }
.dropdown-item.danger { color: var(--ios-red); }
.dropdown-divider { height: 0.5px; background: var(--separator); }

/* ---------- LAYOUT ---------- */
.layout {
  display: flex;
  flex-direction: column;
  padding-top: var(--nav-h);
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom));
}

/* Hide old sidebar */
.sidebar, .nav-backdrop, .nav-toggle, #nav-toggle, #nav-close, #nav-backdrop { display: none !important; }
.layout.nav-open { overflow: hidden; }

/* ---------- MAIN CONTENT ---------- */
.main {
  flex: 1;
  min-height: 0;
}

/* ---------- PAGES ---------- */
.page {
  display: none;
  animation: pageIn var(--t-base);
}
.page.active { display: block; }
@keyframes pageIn { from { opacity: 0; transform: translateX(8px); } to { opacity: 1; transform: none; } }

/* Page header — iOS large title */
.page-header,
.page-header-flex {
  padding: var(--sp-4) var(--sp-4) var(--sp-3);
  padding-left: max(var(--sp-4), var(--safe-left));
  padding-right: max(var(--sp-4), var(--safe-right));
}
.page-header-flex {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
}
.page-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
  line-height: 1.1;
}
.page-desc {
  font-size: 15px;
  color: var(--text-secondary);
  margin-top: var(--sp-1);
}
.page-header-flex .page-desc { margin-top: 2px; }

/* ====================================================================
   STAT CARDS (Dashboard)
   ==================================================================== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-3);
  padding: 0 var(--sp-4);
  padding-left: max(var(--sp-4), var(--safe-left));
  padding-right: max(var(--sp-4), var(--safe-right));
  margin-bottom: var(--sp-4);
}
.stat-card {
  background: var(--surface);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.stat-card .n {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -1px;
  color: var(--text);
}
.stat-card .l {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-top: 2px;
}
.stat-card .icon { display: none; }
.stat-card:hover { transform: none; box-shadow: var(--shadow-sm); }

/* Activity list */
.section { margin-bottom: var(--sp-6); padding: 0 var(--sp-4); padding-left: max(var(--sp-4), var(--safe-left)); padding-right: max(var(--sp-4), var(--safe-right)); }
.section-header { margin-bottom: var(--sp-2); }
.section-title { font-size: 13px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }

.activity-list { padding: 0; }
.activity-list .activity-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 0.5px solid var(--separator);
}
.activity-list .activity-item:last-child { border-bottom: none; }
.activity-list .activity-icon { font-size: 22px; flex-shrink: 0; }
.activity-list .activity-content { flex: 1; min-width: 0; }
.activity-list .activity-text { font-size: 15px; font-weight: 500; color: var(--text); }
.activity-list .activity-meta { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.activity-list .activity-empty { padding: var(--sp-6); text-align: center; color: var(--text-tertiary); font-size: 14px; }

/* Dashboard empty */
.empty { padding: var(--sp-6); text-align: center; color: var(--text-tertiary); }

/* ====================================================================
   CARDS
   ==================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: var(--r-md);
  box-shadow: none;
  overflow: hidden;
}
.card-header { padding: var(--sp-4) var(--sp-4); border-bottom: 0.5px solid var(--separator); }
.card-title { font-size: 17px; font-weight: 600; }
.card-subtitle { font-size: 13px; color: var(--text-secondary); }
.card-body { padding: var(--sp-4); }
.card-footer { padding: var(--sp-3) var(--sp-4); border-top: 0.5px solid var(--separator); display: flex; justify-content: flex-end; gap: var(--sp-2); }

/* ====================================================================
   BUTTONS — iOS Style
   ==================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 10px 20px;
  font-size: 17px;
  font-weight: 500;
  line-height: 1.2;
  border-radius: var(--r-md);
  border: none;
  cursor: pointer;
  transition: opacity var(--t-fast), transform var(--t-fast);
  white-space: nowrap;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}
.btn:active:not(:disabled) { opacity: 0.6; transform: scale(0.97); }
.btn:disabled { opacity: 0.4; }

.btn-sm { padding: 6px 14px; font-size: 13px; min-height: 32px; border-radius: var(--r-sm); }
.btn-lg { padding: 14px 24px; font-size: 17px; min-height: 50px; }
.btn-block { width: 100%; }

.btn-primary {
  background: var(--ios-blue);
  color: #fff;
}
.btn-secondary {
  background: var(--ios-gray6);
  color: var(--ios-blue);
}
.btn-ghost {
  background: transparent;
  color: var(--ios-blue);
}
.btn-danger {
  background: var(--ios-red);
  color: #fff;
}
.btn-success {
  background: var(--ios-green);
  color: #fff;
}
.btn-outline {
  background: transparent;
  color: var(--ios-blue);
  border: 1px solid var(--ios-blue);
}

/* SVG icons in buttons should size to font */
.btn svg { width: 1em; height: 1em; }

/* ====================================================================
   FORM CONTROLS — iOS Style
   ==================================================================== */
.form-field { margin-bottom: var(--sp-3); }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--sp-1);
  padding-left: var(--sp-4);
  text-transform: none;
  letter-spacing: 0;
}
.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 12px 14px;
  font-size: 17px;
  line-height: 1.3;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: var(--r-sm);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--ios-blue);
  box-shadow: 0 0 0 3px rgba(0,122,255,0.12);
}
.form-input::placeholder { color: var(--text-tertiary); }
.form-input:disabled, .form-select:disabled { background: var(--ios-gray6); color: var(--text-tertiary); }
.form-input.error, .form-select.error { border-color: var(--ios-red); }
.form-textarea { min-height: 100px; resize: vertical; border-radius: var(--r-md); }
.form-hint { font-size: 12px; color: var(--text-tertiary); margin-top: var(--sp-1); padding-left: var(--sp-4); }
.form-error { font-size: 12px; color: var(--ios-red); margin-top: var(--sp-1); padding-left: var(--sp-4); }

/* Input with icon */
.input-wrapper { position: relative; display: flex; align-items: center; background: var(--surface); border: 1px solid var(--separator); border-radius: var(--r-sm); overflow: hidden; }
.input-wrapper:focus-within { border-color: var(--ios-blue); box-shadow: 0 0 0 3px rgba(0,122,255,0.12); }
.input-wrapper .form-input { border: none; background: transparent; padding-left: 40px; }
.input-wrapper:focus-within .form-input { box-shadow: none; }
.input-icon { position: absolute; left: 12px; color: var(--ios-gray); pointer-events: none; z-index: 1; }

/* Select styling */
.form-select {
  cursor: pointer;
  padding-right: 30px;
  background-color: var(--surface);
}

/* ====================================================================
   TOOLBAR — iOS grouped filters
   ==================================================================== */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  margin: 0 var(--sp-4) var(--sp-3);
  margin-left: max(var(--sp-4), var(--safe-left));
  margin-right: max(var(--sp-4), var(--safe-right));
  padding: var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: var(--r-md);
  box-shadow: none;
}
.toolbar-group { display: flex; align-items: center; gap: var(--sp-2); flex: 1; min-width: 140px; }
.toolbar-group.single { flex: 0 0 auto; }
.toolbar-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  min-width: 50px;
}
.toolbar .form-select { min-width: 100px; }
.toolbar-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }

/* ====================================================================
   TABLES — iOS List Style
   ==================================================================== */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--r-md);
  border: 1px solid var(--separator);
  background: var(--surface);
  margin: 0 var(--sp-4);
  margin-left: max(var(--sp-4), var(--safe-left));
  margin-right: max(var(--sp-4), var(--safe-right));
  -webkit-overflow-scrolling: touch;
}
.table { width: 100%; font-size: 15px; }
.table thead { background: var(--ios-gray6); }
.table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  border-bottom: 0.5px solid var(--separator);
  white-space: nowrap;
}
.table td {
  padding: 12px 14px;
  border-bottom: 0.5px solid var(--separator);
  color: var(--text);
  vertical-align: middle;
}
.table tbody tr { transition: background var(--t-fast); }
.table tbody tr:active { background: var(--ios-gray6); }
.table tbody tr:last-child td { border-bottom: none; }
.table td.actions { white-space: nowrap; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--r-pill);
}
.badge-primary { background: rgba(0,122,255,0.12); color: var(--ios-blue); }
.badge-success { background: rgba(52,199,89,0.12); color: var(--ios-green); }
.badge-warning { background: rgba(255,149,0,0.12); color: var(--ios-orange); }
.badge-error { background: rgba(255,59,48,0.12); color: var(--ios-red); }
.badge-neutral { background: var(--ios-gray6); color: var(--ios-gray); }

/* Empty state */
.table-empty {
  padding: var(--sp-10) var(--sp-4);
  text-align: center;
  color: var(--text-tertiary);
}
.table-empty svg { width: 48px; height: 48px; margin: 0 auto var(--sp-3); opacity: 0.4; }

/* ====================================================================
   MODALS — iOS Bottom Sheet / Sheet
   ==================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 300;
  padding: 0;
}
.modal-backdrop.show {
  display: flex;
  animation: fadeIn var(--t-base);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: sheetUp var(--t-slow);
  padding-bottom: var(--safe-bottom);
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }

.modal-header {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 0.5px solid var(--separator);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
}
.modal-header::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: var(--ios-gray4);
}
.modal-header { padding-top: var(--sp-6); }
.modal-title { font-size: 17px; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  padding: 8px;
  color: var(--ios-blue);
  font-size: 17px;
  font-weight: 400;
  cursor: pointer;
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:active { background: var(--ios-gray6); }
.modal-body { padding: var(--sp-4); overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.modal-footer {
  padding: var(--sp-3) var(--sp-4);
  border-top: 0.5px solid var(--separator);
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
}

/* ====================================================================
   TOASTS — iOS Notification Style
   ==================================================================== */
.toast-container {
  position: fixed;
  top: calc(var(--safe-top) + 50px);
  left: var(--sp-4);
  right: var(--sp-4);
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: 14px 16px;
  background: rgba(28, 28, 30, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  min-width: 0;
  max-width: 100%;
  color: #fff;
  animation: toastIn var(--t-spring);
}
@keyframes toastIn { from { opacity: 0; transform: translateY(-20px) scale(0.9); } to { opacity: 1; transform: none; } }
.toast.success { border-left: none; }
.toast.error { border-left: none; }
.toast.warning { border-left: none; }
.toast.info { border-left: none; }
.toast-icon { flex-shrink: 0; width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; border-radius: 50%; }
.toast.success .toast-icon { color: var(--ios-green); }
.toast.error .toast-icon { color: var(--ios-red); }
.toast.warning .toast-icon { color: var(--ios-orange); }
.toast.info .toast-icon { color: var(--ios-blue); }
.toast-content { flex: 1; min-width: 0; }
.toast-title { font-weight: 600; font-size: 15px; color: #fff; }
.toast-message { font-size: 14px; color: rgba(255,255,255,0.7); margin-top: 2px; }
.toast-close { flex-shrink: 0; background: none; border: none; padding: 4px; color: rgba(255,255,255,0.4); cursor: pointer; font-size: 18px; }

/* ====================================================================
   BOTTOM TAB BAR — iOS Style
   ==================================================================== */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(249, 249, 249, 0.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
  display: flex;
  z-index: 100;
}
.tabbar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: none;
  cursor: pointer;
  padding-top: 6px;
  color: var(--ios-gray);
  font-size: 10px;
  font-weight: 500;
  transition: color var(--t-fast);
  -webkit-tap-highlight-color: transparent;
  min-height: 49px;
}
.tabbar-item.active { color: var(--ios-blue); }
.tabbar-item:active { opacity: 0.6; }
.tabbar-item svg { width: 24px; height: 24px; }
.tabbar-item span { font-size: 10px; line-height: 1; }

/* ====================================================================
   MORE SHEET — Bottom sheet for secondary nav items
   ==================================================================== */
.more-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-lg);
  z-index: 350;
  max-height: 70vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform: translateY(100%);
  transition: transform var(--t-slow);
  padding-bottom: var(--safe-bottom);
}
.more-sheet.show { transform: none; }
.more-sheet-handle {
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: var(--ios-gray4);
  margin: 8px auto 0;
}
.more-sheet-title {
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: var(--sp-2) var(--sp-4);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.more-sheet-group { margin: 0 var(--sp-4) var(--sp-3); }
.more-sheet-group-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0 var(--sp-4) var(--sp-1);
}
.more-sheet-list {
  background: var(--surface);
  border-radius: var(--r-md);
  overflow: hidden;
  border: 1px solid var(--separator);
}
.more-sheet-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 13px 16px;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-size: 17px;
  color: var(--text);
  cursor: pointer;
  border-bottom: 0.5px solid var(--separator);
  transition: background var(--t-fast);
  min-height: 44px;
}
.more-sheet-item:last-child { border-bottom: none; }
.more-sheet-item:active { background: var(--ios-gray6); }
.more-sheet-item .icon-wrap {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.more-sheet-item svg { width: 16px; height: 16px; }
.more-sheet-item .chevron {
  margin-left: auto;
  color: var(--ios-gray3);
  width: 7px !important;
  height: 12px !important;
}

/* More sheet backdrop */
.more-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 340;
  display: none;
}
.more-backdrop.show { display: block; animation: fadeIn var(--t-base); }

/* ====================================================================
   SETTINGS GRID (iOS grouped settings)
   ==================================================================== */
.settings-grid {
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
  padding: 0 var(--sp-4);
  padding-left: max(var(--sp-4), var(--safe-left));
  padding-right: max(var(--sp-4), var(--safe-right));
}
.settings-section {
  background: var(--surface);
  border-radius: var(--r-md);
  border: 1px solid var(--separator);
  padding: var(--sp-4);
}
.settings-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--sp-3);
  padding: 0 var(--sp-1);
}

/* ====================================================================
   CARDS (teacher assignments)
   ==================================================================== */
.cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-3);
  padding: 0 var(--sp-4);
  padding-left: max(var(--sp-4), var(--safe-left));
  padding-right: max(var(--sp-4), var(--safe-right));
}

/* ====================================================================
   ANALYTICS GRID
   ==================================================================== */
.analytics-grid {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: 0 var(--sp-4);
  padding-left: max(var(--sp-4), var(--safe-left));
  padding-right: max(var(--sp-4), var(--safe-right));
}

/* ====================================================================
   IFRAME / REPORT VIEWER
   ==================================================================== */
.iframe-wrap {
  width: 100%;
  min-height: 500px;
  border: none;
  border-radius: var(--r-md);
}

/* ====================================================================
   GRADE SCALE EDITOR
   ==================================================================== */
.grade-scale-editor {
  background: var(--surface);
  border-radius: var(--r-md);
  border: 1px solid var(--separator);
  overflow: hidden;
}
.grade-scale-header {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0;
  padding: 10px 12px;
  background: var(--ios-gray6);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
}

/* ====================================================================
   IMPORT TABS
   ==================================================================== */
.import-tabs {
  display: flex;
  background: var(--ios-gray6);
  border-radius: var(--r-sm);
  padding: 2px;
  margin-bottom: var(--sp-4);
}
.import-tab {
  flex: 1;
  padding: 8px 16px;
  border: none;
  background: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--t-fast);
}
.import-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}
.import-pane { display: none; }
.import-pane.active { display: block; }

/* ====================================================================
   MISC
   ==================================================================== */
.msg { font-size: 14px; padding: var(--sp-2) var(--sp-4); }
.msg.err { color: var(--ios-red); }
.msg.ok, .msg.success { color: var(--ios-green); }
iframe { border: none; }

/* Hide old nav elements */
.nav-group, .nav-group-label, .nav-btn, .sidebar-header, .sidebar-title, .sidebar-close { display: none !important; }

/* ====================================================================
   DESKTOP ADAPTATION (still mobile-first)
   ==================================================================== */
@media (min-width: 768px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .stat-card .n { font-size: 36px; }
  .toolbar-group { min-width: 200px; }
  .settings-grid { flex-direction: row; flex-wrap: wrap; }
  .settings-section { flex: 1; min-width: 320px; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .page-title { font-size: 34px; }
  .modal { max-width: 600px; align-self: center; border-radius: var(--r-xl); margin-bottom: env(safe-area-inset-bottom, 0); }
  .modal-backdrop { align-items: center; }
}

/* ====================================================================
   LEGACY CLASS COMPATIBILITY
   Map old v4 classes to iOS equivalents where they're used in JS
   ==================================================================== */
.stat-card .stat-value { font-size: 32px; font-weight: 700; letter-spacing: -1px; color: var(--text); }
.stat-card .stat-label { font-size: 13px; color: var(--text-secondary); font-weight: 500; margin-top: 2px; }

/* Old table data cells */
.table.data, table.data { width: 100%; font-size: 15px; border-collapse: collapse; }
.table.data th, table.data th { padding: 10px 14px; text-align: left; font-size: 12px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; border-bottom: 0.5px solid var(--separator); white-space: nowrap; background: var(--ios-gray6); }
.table.data td, table.data td { padding: 12px 14px; border-bottom: 0.5px solid var(--separator); color: var(--text); vertical-align: middle; }

/* Tag/badge compatibility */
.tag { display: inline-flex; align-items: center; padding: 2px 10px; font-size: 12px; font-weight: 600; border-radius: var(--r-pill); }

/* Field compat */
.field { margin-bottom: var(--sp-3); }

/* Card variants compat */
.card-t, .card-s, .card-m { background: var(--surface); border-radius: var(--r-md); border: 1px solid var(--separator); }

/* Ensure inline styles from JS still look OK */
table { font-size: 15px; }
th, td { padding: 10px 14px; }
input[type="number"] { -webkit-appearance: none; }
input[type="search"] { -webkit-appearance: none; border-radius: var(--r-sm); }
input[type="file"] { font-size: 15px; }
code { font-family: var(--font-mono); font-size: 0.85em; background: var(--ios-gray6); padding: 2px 6px; border-radius: 4px; }
