/* =================== RESET =================== */
* { box-sizing: border-box; }
:root {
  --module: #2563eb;
  --module-soft: #dbeafe;
  --module-dark: #173b8f;
}
html, body {
  margin: 0; padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Sarabun", "Prompt", "Noto Sans Thai", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}
button { font-family: inherit; }
input, select, textarea, button { font-size: 1rem; }

a { color: var(--navy); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
em { color: var(--danger); font-style: normal; }
#viewApp {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* =================== LOADING / TOAST =================== */
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(11,31,58,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 9500;
}
.loading-box {
  background: var(--white);
  padding: var(--space-5) var(--space-6);
  border-radius: var(--radius);
  display: flex; align-items: center; gap: var(--space-3);
  box-shadow: var(--shadow);
  min-width: 220px;
  font-weight: 600;
}
.spinner {
  width: 22px; height: 22px;
  border: 3px solid var(--line);
  border-top-color: var(--module);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  left: 50%; bottom: 28px;
  transform: translateX(-50%);
  background: var(--module-dark);
  color: var(--white);
  padding: 12px 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 9600;
  max-width: 90vw;
  text-align: center;
  font-weight: 600;
  animation: slideUp 0.25s ease;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
.toast.warn    { background: var(--warn); }
@keyframes slideUp { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* =================== LOGIN =================== */
.login-wrap {
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(214,162,30,0.18), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(11,31,58,0.18), transparent 60%),
    var(--bg);
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  align-items: center;
  justify-items: center;
  gap: var(--space-4);
  padding: 32px var(--space-5) 12px;
}
.login-card {
  width: 100%; max-width: 680px;
  background: var(--white);
  padding: 40px 48px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transform: translateY(42px);
}
.portal-link {
  display: inline-flex;
  align-items: center;
  margin-bottom: var(--space-5);
  color: var(--muted);
  text-decoration: none;
  font-weight: 700;
}
.portal-link:hover { color: var(--navy); }
.brand { display: flex; gap: var(--space-4); align-items: center; justify-content: center; text-align: left; margin-bottom: var(--space-5); }
.brand h1 { font-size: 1.5rem; margin: 0; color: var(--navy); }
.brand p  { margin: 0; font-size: 1.05rem; }
.brand-mark {
  width: 72px; height: 72px;
  border-radius: 12px;
  background: var(--white);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.brand-mark.sm { width: 32px; height: 32px; border-radius: 8px; }
.topbar .brand-mark.sm {
  background: transparent;
  border-radius: 0;
  overflow: visible;
}
.topbar .brand-mark.sm img {
  border-radius: 0;
}

.hint { color: var(--muted); font-size: 0.85rem; text-align: center; margin-top: var(--space-4); }

/* Auth toggle (login / register) */
.auth-toggle {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: var(--space-4);
}
.auth-toggle .auth-tab {
  background: transparent;
  border: 0;
  padding: 10px 12px;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
  min-height: 40px;
  transition: background 0.15s, color 0.15s;
}
.auth-toggle .auth-tab.active {
  background: var(--white);
  color: var(--navy);
  box-shadow: 0 1px 3px rgba(11,31,58,0.08);
}

/* Role picker (radio cards) */
.role-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}
.role-picker label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--white);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.role-picker label:hover { border-color: var(--module); }
.role-picker input[type="radio"] {
  width: 18px; height: 18px; accent-color: var(--module);
}
.role-picker input[type="radio"]:checked + span { color: var(--navy); font-weight: 700; }
.role-picker label:has(input:checked) {
  border-color: var(--module);
  background: #eff6ff;
}

/* =================== FORMS =================== */
.field {
  display: flex; flex-direction: column;
  gap: 6px;
  margin-bottom: var(--space-4);
}
.field > span {
  font-weight: 600;
  color: var(--navy);
  font-size: 0.9rem;
}
.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--module);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.18);
}
.field textarea { resize: vertical; min-height: 96px; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}
.grid-span-2 {
  grid-column: 1 / -1;
}
@media (max-width: 600px) {
  .grid-2 { grid-template-columns: 1fr; }
  .grid-span-2 { grid-column: auto; }
}

@media (max-width: 600px) {
  .login-wrap {
    min-height: 100dvh;
    padding: var(--space-4) var(--space-4) 10px;
  }
  .login-card {
    padding: var(--space-6);
    max-width: 480px;
    transform: none;
  }
  .auth-toggle { grid-template-columns: 1fr; }
  .auth-toggle .auth-tab { padding: 10px 8px; font-size: 0.86rem; }
  .brand { justify-content: flex-start; }
  .brand h1 { font-size: 1.15rem; }
  .brand p { font-size: 0.85rem; }
  .brand-mark { width: 52px; height: 52px; font-size: 1.45rem; }
}

/* checklists */
.checklist {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  background: var(--white);
  max-height: 240px;
  overflow-y: auto;
}
.checklist.vertical {
  grid-template-columns: 1fr;
}
#topicsList,
.modal-card .checklist.vertical {
  max-height: none;
  overflow: visible;
}
.checklist label {
  display: flex; gap: 10px; align-items: center;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.checklist label:hover { background: var(--bg); }
.checklist input[type="checkbox"] {
  width: 18px; height: 18px; accent-color: var(--module);
}
.inline-check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--navy);
  font-weight: 700;
}
.inline-check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--module);
}
.locked-item {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  color: var(--navy);
  font-weight: 700;
}

.form-actions {
  display: flex; justify-content: flex-end; gap: var(--space-2);
  margin-top: var(--space-4);
}
@media (max-width: 480px) {
  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; }
}

/* =================== BUTTONS =================== */
.btn {
  appearance: none;
  border: 1px solid transparent;
  background: var(--navy);
  color: var(--white);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.01em;
  transition: transform 0.05s, background 0.15s, border-color 0.15s, color 0.15s;
  min-height: 44px;
}
.btn:hover:not(:disabled) { background: var(--navy-2); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn-block { width: 100%; }

.btn-primary { background: var(--module); color: var(--white); }
.btn-primary:hover:not(:disabled) { background: var(--module-dark); color: var(--white); }

.btn-ghost {
  background: transparent;
  color: var(--navy);
  border-color: var(--line);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg); }

.btn-success { background: var(--success); color: var(--white); }
.btn-success:hover:not(:disabled) { background: #166e3c; }

.btn-sm { padding: 8px 12px; min-height: 36px; font-size: 0.9rem; }
.btn[disabled] { opacity: 0.6; cursor: not-allowed; }
.icon-btn {
  width: 36px; height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--navy);
  cursor: pointer;
  font-size: 1.35rem;
  line-height: 1;
}

/* =================== APP CHROME =================== */
.topbar {
  background: var(--module-dark);
  color: var(--white);
  padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0;
  z-index: 50;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
.topbar strong { color: var(--white); }
.topbar-left, .topbar-right { display: flex; align-items: center; gap: var(--space-3); }
.user-name { font-size: 0.9rem; opacity: 0.9; max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .btn-ghost { color: var(--white); border-color: rgba(255,255,255,0.25); }
.topbar .btn-ghost:hover { background: rgba(255,255,255,0.08); }

.badge {
  display: inline-block;
  background: var(--module-soft);
  color: var(--module-dark);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  margin-left: 8px;
  vertical-align: middle;
}

.tabbar {
  display: flex;
  gap: 2px;
  background: var(--white);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  position: sticky; top: 56px; z-index: 40;
}
.tabbar button {
  background: transparent;
  border: 0;
  padding: 14px 18px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  min-height: 48px;
}
.tabbar button.active {
  color: var(--module-dark);
  border-bottom-color: var(--module);
}
.tabbar button:hover { color: var(--navy); }

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-5);
  flex: 1 0 auto;
}
@media (max-width: 600px) {
  .container { padding: var(--space-3); }
}

.footer {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  text-align: center;
  padding: var(--space-5) var(--space-4);
  font-size: 0.85rem;
  color: var(--muted);
  border-top: 1px solid var(--line);
  background: #fff;
  margin-top: auto;
}
.login-footer {
  width: min(720px, 100%);
  border-top: 1px solid rgba(15, 23, 42, 0.08);
  background: transparent;
  padding: 12px var(--space-4) 0;
  margin-top: 0;
  align-self: end;
}
@media (max-width: 600px) {
  .footer {
    gap: 4px;
  }
  .login-footer {
    width: 100%;
    font-size: 0.74rem;
  }
}

/* =================== CARD =================== */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
}
.card h2 {
  margin: 0 0 var(--space-4) 0;
  font-size: 1.1rem;
  color: var(--navy);
}
.form-card { max-width: 900px; margin-left: auto; margin-right: auto; }

/* =================== STATS =================== */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: var(--space-4);
  box-shadow: var(--shadow);
  border-left: 4px solid var(--module);
}
.stat-card .label { color: var(--muted); font-size: 0.8rem; }
.stat-card .value { color: var(--navy); font-size: 1.6rem; font-weight: 800; }

/* =================== TABLE =================== */
.table-wrap {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;          /* horizontal scroll on mobile */
  -webkit-overflow-scrolling: touch;
}
table.data {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}
table.data th, table.data td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  font-size: 0.92rem;
}
table.data th {
  background: #fafbfd;
  color: var(--navy);
  font-weight: 700;
  position: sticky; top: 0;
  z-index: 1;
}
table.data tr:hover td { background: #fafbfd; }
table.data tr.clickable-row { cursor: pointer; }
table.data .nowrap { white-space: nowrap; }
.row-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.advisor-cell {
  min-width: 220px;
}
.advisor-select {
  width: 100%;
  min-width: 210px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--text);
}
.advisor-select:focus {
  border-color: var(--module);
  outline: none;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.18);
}
.advisor-panels {
  display: grid;
  gap: var(--space-4);
}
.assignment-toggle {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  margin: 0 0 var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #f8fafc;
}
.assignment-toggle button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 9px 14px;
  font-weight: 800;
  cursor: pointer;
}
.assignment-toggle button.active {
  background: var(--module-dark);
  color: var(--white);
}
.year-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}
.year-tabs button {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--navy);
  padding: 8px 12px;
  font-weight: 800;
  cursor: pointer;
}
.year-tabs button.active {
  background: var(--module);
  border-color: var(--module);
  color: var(--white);
}
.student-filter-bar {
  display: grid;
  grid-template-columns: minmax(140px, 180px) minmax(180px, 240px) minmax(220px, 1fr);
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}
.student-filter-bar select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--text);
}
.advisor-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  padding: var(--space-4);
}
.advisor-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.advisor-panel-head h3 {
  margin: 0;
  color: var(--navy);
  font-size: 1.05rem;
}
.advisor-add-row {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(180px, 220px) auto;
  gap: var(--space-2);
  align-items: center;
  margin-bottom: var(--space-3);
}
.advisor-slot-select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--text);
}
.advisor-manage-cell {
  min-width: 420px;
}
.advisor-inline-add {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 140px auto;
  gap: 8px;
  align-items: center;
}
.compact-table table.data {
  min-width: 640px;
}
@media (max-width: 760px) {
  .assignment-toggle {
    display: grid;
    width: 100%;
    grid-template-columns: 1fr;
  }
  .student-filter-bar {
    grid-template-columns: 1fr;
  }
  .advisor-add-row {
    grid-template-columns: 1fr;
  }
  .advisor-inline-add {
    grid-template-columns: 1fr;
  }
  .advisor-add-row .btn {
    width: 100%;
  }
}
table.data td .topic-chip {
  display: inline-block;
  background: #eef2f8;
  color: var(--navy);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  margin: 0 4px 4px 0;
}

.add-student-context {
  margin: 0 0 var(--space-4);
  padding: var(--space-4);
  border-radius: var(--radius-sm);
  background: #fafbfd;
  border: 1px solid var(--line);
}
.add-student-context .subsection-head {
  margin: 0 0 var(--space-3);
}
.next-round {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--module);
  color: var(--white);
  font-weight: 900;
  white-space: nowrap;
}
.student-picker-field {
  grid-column: 1 / -1;
}
.student-multi-picker {
  display: grid;
  gap: var(--space-3);
  max-height: 420px;
  overflow: auto;
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #f8fafc;
}
.student-year-picker {
  display: grid;
  gap: var(--space-2);
}
.student-year-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  color: var(--module-dark);
}
.student-choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-2);
}
.student-choice {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  min-height: 58px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
}
.student-choice:has(input:checked) {
  border-color: var(--module);
  background: #eff6ff;
  box-shadow: inset 3px 0 0 var(--module);
}
.student-choice input {
  margin-top: 3px;
  accent-color: var(--module);
}
.student-choice span {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.student-choice strong,
.student-choice small {
  overflow-wrap: anywhere;
}
.student-choice small {
  color: var(--muted);
}
.previous-records-title {
  margin: var(--space-3) 0 var(--space-2);
  color: var(--navy);
  font-weight: 800;
}
.empty {
  padding: var(--space-6);
  text-align: center;
  color: var(--muted);
}

/* status pills */
.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}
.pill-pending   { background: #fff5d9; color: #8a6300; }
.pill-confirmed { background: #e3f6e9; color: #166e3c; }
.pill-follow    { background: #fff1d6; color: #9a3412; border: 1px solid #fed7aa; }

/* toolbar above tables */
.toolbar {
  display: flex; flex-wrap: wrap; gap: var(--space-2);
  align-items: center; justify-content: space-between;
  margin-bottom: var(--space-3);
}
.toolbar .search {
  flex: 1;
  min-width: 220px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--white);
}
.student-list-card {
  margin-bottom: var(--space-3);
}
.student-record-panel {
  margin-top: 0;
}
.student-contact {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 var(--space-4);
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #f8fafc;
}
.student-contact > div {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.student-contact span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}
.student-contact strong {
  color: var(--navy);
  font-weight: 800;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.student-contact.compact {
  display: block;
  margin: 4px 0 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}
.empty-contact {
  grid-template-columns: 1fr;
  color: var(--muted);
  font-weight: 700;
}
.subsection-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.subsection-head h3 {
  margin: 0;
  color: var(--navy);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9200;
  background: rgba(11,31,58,0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
}
.modal-card {
  width: min(760px, 100%);
  max-height: 90dvh;
  overflow: auto;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 18px 48px rgba(11,31,58,0.22);
  padding: var(--space-6);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.modal-head h2 {
  margin: 0;
  color: var(--navy);
}
.record-meta {
  display: grid;
  gap: 6px;
  margin: calc(var(--space-4) * -0.5) 0 var(--space-4);
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  color: var(--muted);
  font-size: 0.9rem;
}
.record-meta strong {
  color: var(--navy);
}

/* details dialog-ish */
.detail-block {
  background: #fafbfd;
  border: 1px solid var(--line);
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  margin-top: 6px;
  white-space: pre-wrap;
}

.assignment-explorer {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: var(--space-4);
  align-items: start;
}
.explorer-sidebar {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  overflow: hidden;
  position: sticky;
  top: 12px;
}
.explorer-tabs {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  margin: 0;
  padding: var(--space-2);
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: #eef3f8;
}
.explorer-tabs button {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
}
.explorer-list {
  display: grid;
  gap: 4px;
  max-height: 68vh;
  overflow: auto;
  padding: var(--space-2);
}
.explorer-item {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.explorer-item:hover {
  background: #fff;
  border-color: #dbe3ee;
}
.explorer-item.active {
  background: #fff;
  border-color: var(--module);
  box-shadow: inset 3px 0 0 var(--module);
}
.explorer-item.active .folder-icon {
  transform: rotate(90deg);
}
.folder-icon {
  color: var(--muted);
  font-size: 0.85rem;
  transition: transform 120ms ease;
}
.explorer-text {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.explorer-text strong,
.explorer-text small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.explorer-text small {
  color: var(--muted);
}
.mini-pill {
  border-radius: 999px;
  padding: 2px 8px;
  background: #fff4cf;
  color: #8a6300;
  font-size: 0.75rem;
  font-weight: 800;
}
.explorer-detail-pane {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  padding: var(--space-4);
}
.explorer-detail {
  min-width: 0;
}
.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.detail-head h3 {
  margin: 0 0 2px;
  color: var(--navy);
}
.detail-kicker {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}
.explorer-inline-add {
  margin-top: var(--space-3);
}
.explorer-sidebar .student-filter-bar {
  grid-template-columns: 1fr;
  padding: var(--space-2);
  margin: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
@media (max-width: 980px) {
  .assignment-explorer {
    grid-template-columns: 1fr;
  }
  .explorer-sidebar {
    position: static;
  }
  .explorer-list {
    max-height: 360px;
  }
}

@media (max-width: 760px) {
  html, body {
    font-size: 16px;
    background: linear-gradient(180deg, var(--module-dark) 0 158px, var(--bg) 158px 100%);
  }
  #viewApp {
    background: transparent;
  }
  .login-wrap {
    display: block;
    min-height: 100dvh;
    padding: calc(14px + env(safe-area-inset-top)) 12px calc(18px + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, var(--module-dark) 0 168px, var(--bg) 168px 100%);
  }
  .login-card {
    padding: 22px 16px;
    max-width: none;
    border-radius: 22px 22px 18px 18px;
    transform: none;
    border-top: 4px solid var(--module);
    box-shadow: 0 18px 42px rgba(4,13,27,0.2);
  }
  .portal-link {
    margin-bottom: 14px;
  }
  .brand {
    justify-content: flex-start;
    gap: 12px;
    margin-bottom: 18px;
  }
  .brand h1 {
    font-size: 1.12rem;
    line-height: 1.25;
  }
  .brand p {
    font-size: 0.84rem;
  }
  .auth-toggle {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  .auth-toggle .auth-tab {
    min-height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
  }
  .field input,
  .field select,
  .field textarea,
  .toolbar .search,
  .student-filter-bar select,
  .advisor-select,
  .advisor-slot-select {
    min-height: 48px;
    font-size: 16px;
  }
  .btn {
    min-height: 48px;
    padding: 12px 14px;
  }
  .btn-sm {
    min-height: 42px;
  }
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: calc(10px + env(safe-area-inset-top)) 12px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    box-shadow: 0 8px 24px rgba(4,13,27,0.18);
  }
  .topbar-left,
  .topbar-right {
    width: 100%;
    justify-content: space-between;
  }
  .topbar-left > div:last-child {
    min-width: 0;
  }
  #appTitle {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: calc(100vw - 94px);
  }
  .badge {
    margin: 4px 0 0;
    width: max-content;
  }
  .user-name {
    max-width: none;
    min-width: 0;
    flex: 1;
  }
  .topbar .btn-ghost {
    width: auto;
    min-width: 92px;
    min-height: 42px;
    padding: 9px 12px;
    border-radius: 999px;
  }
  .tabbar {
    top: calc(102px + env(safe-area-inset-top));
    scroll-snap-type: x proximity;
    background: rgba(247,249,252,0.94);
    backdrop-filter: blur(14px);
    -webkit-overflow-scrolling: touch;
  }
  .tabbar button {
    min-height: 48px;
    padding: 12px 16px;
    scroll-snap-align: start;
    border-radius: 999px;
  }
  .container {
    padding: 14px 10px calc(20px + env(safe-area-inset-bottom));
  }
  .card,
  .stat-card,
  .table-wrap,
  .modal-card,
  .advisor-panel,
  .explorer-sidebar,
  .explorer-detail-pane {
    border-radius: 10px;
    box-shadow: 0 4px 14px rgba(11,31,58,0.09);
  }
  .card,
  .advisor-panel,
  .explorer-detail-pane {
    padding: 14px;
    border: 1px solid rgba(227,232,239,0.86);
  }
  .card h2 {
    font-size: 1.04rem;
    line-height: 1.3;
  }
  .stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }
  .stat-card {
    min-width: 0;
    padding: 10px 8px;
  }
  .stat-card .label {
    font-size: 0.72rem;
    line-height: 1.25;
    overflow-wrap: anywhere;
  }
  .stat-card .value {
    font-size: 1.45rem;
    line-height: 1.15;
  }
  .toolbar,
  .subsection-head,
  .advisor-panel-head,
  .detail-head {
    align-items: stretch;
    flex-direction: column;
  }
  .toolbar .search {
    min-width: 0;
    width: 100%;
  }
  .table-wrap {
    margin-left: -4px;
    margin-right: -4px;
    border-radius: 8px;
    overflow-x: visible;
  }
  table.data {
    min-width: 0;
    width: 100%;
    display: block;
  }
  table.data thead {
    display: none;
  }
  table.data tbody,
  table.data tr,
  table.data td {
    display: block;
    width: 100%;
  }
  table.data tr {
    padding: 12px;
    border-bottom: 1px solid var(--line);
  }
  table.data tr:last-child {
    border-bottom: 0;
  }
  table.data th,
  table.data td {
    padding: 4px 0;
    border-bottom: 0;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  table.data .nowrap {
    white-space: normal;
  }
  .row-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .row-actions .btn {
    width: 100%;
  }
  .student-list-card {
    padding: 12px;
  }
  .student-list-card h2 {
    margin-bottom: 10px;
  }
  .student-list-card table.data tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 3px 10px;
    align-items: start;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    margin-bottom: 8px;
  }
  .student-list-card table.data tbody {
    display: grid;
    gap: 0;
  }
  .student-list-card table.data td {
    padding: 0;
  }
  .student-list-card table.data td:nth-child(1) {
    grid-column: 1;
    grid-row: 2;
    color: var(--muted);
    font-size: 0.76rem;
  }
  .student-list-card table.data td:nth-child(2) {
    grid-column: 1;
    grid-row: 1;
  }
  .student-list-card table.data td:nth-child(2) strong {
    display: block;
    font-size: 0.96rem;
    line-height: 1.25;
  }
  .student-list-card table.data td:nth-child(3) {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    padding: 2px 8px;
    border-radius: 999px;
    background: #eef4ff;
    color: var(--module-dark);
    font-size: 0.76rem;
    font-weight: 800;
  }
  .student-list-card table.data td:nth-child(4),
  .student-list-card table.data td:nth-child(5) {
    display: none;
  }
  .student-list-card table.data td:nth-child(6) {
    grid-column: 1 / -1;
    grid-row: 3;
    margin-top: 6px;
  }
  .student-list-card .student-contact.compact {
    display: none;
  }
  .student-list-card .row-actions {
    grid-template-columns: 1fr 1fr;
  }
  .student-list-card .row-actions .btn {
    min-height: 40px;
    padding: 8px 10px;
  }
  .student-record-panel {
    padding: 12px;
  }
  .student-record-panel .subsection-head {
    gap: 8px;
  }
  .student-record-panel .subsection-head h3 {
    margin: 0;
    font-size: 1.02rem;
    line-height: 1.28;
  }
  .student-record-panel .pill {
    align-self: flex-start;
  }
  .checklist {
    grid-template-columns: 1fr;
    max-height: 320px;
  }
  #topicsList,
  .modal-card .checklist.vertical {
    max-height: none;
    overflow: visible;
  }
  .student-multi-picker {
    max-height: 360px;
    padding: 10px;
  }
  .student-year-head {
    align-items: stretch;
    flex-direction: column;
  }
  .student-year-head .btn {
    width: 100%;
  }
  .student-choice-grid {
    grid-template-columns: 1fr;
  }
  .student-choice {
    min-height: 64px;
  }
  .checklist label {
    min-height: 44px;
  }
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }
  .modal-card {
    width: 100%;
    max-height: 92dvh;
    border-radius: 14px 14px 0 0;
    padding: 16px;
  }
  .modal-head {
    align-items: flex-start;
  }
  .modal-head h2 {
    font-size: 1.08rem;
    line-height: 1.3;
  }
  .detail-block {
    max-height: 240px;
    overflow: auto;
  }
  .student-contact {
    grid-template-columns: 1fr;
    margin-bottom: 12px;
    gap: 8px;
    padding: 10px;
  }
  .student-contact span {
    font-size: 0.72rem;
  }
  .student-contact strong {
    font-size: 0.9rem;
    line-height: 1.35;
  }
  .explorer-tabs button,
  .explorer-item {
    min-height: 46px;
  }
  .explorer-list {
    max-height: 320px;
  }
  .advisor-manage-cell {
    min-width: 0;
  }
  .toast {
    left: 12px;
    right: 12px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    transform: none;
    max-width: none;
  }
  .loading-box {
    width: min(320px, calc(100vw - 32px));
    justify-content: center;
    padding: 18px;
  }
  .footer {
    display: flex;
    padding: 12px 10px calc(14px + env(safe-area-inset-bottom));
    font-size: 0.72rem;
  }
}

@media (max-width: 420px) {
  table.data {
    min-width: 0;
  }
  .brand-mark {
    width: 48px;
    height: 48px;
  }
  #appTitle {
    max-width: calc(100vw - 82px);
  }
}
