/* ===== Tokens ===== */
:root {
  --bg: #0f1419;
  --bg-elevated: #171d25;
  --bg-panel: #1c2430;
  --bg-soft: #232d3b;
  --border: #2d3a4d;
  --border-soft: #243041;
  --text: #e8eef6;
  --text-muted: #8b9bb0;
  --text-dim: #6b7c91;
  --primary: #3d9cf0;
  --primary-hover: #5aadf5;
  --primary-soft: rgba(61, 156, 240, 0.14);
  --success: #34c759;
  --success-soft: rgba(52, 199, 89, 0.14);
  --warning: #f5a524;
  --warning-soft: rgba(245, 165, 36, 0.14);
  --danger: #ff5c5c;
  --danger-soft: rgba(255, 92, 92, 0.12);
  --info: #64d2ff;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --max: 1280px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(61, 156, 240, 0.12), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(52, 199, 89, 0.06), transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

a {
  color: var(--primary);
}

#app {
  min-height: 100vh;
  padding: 24px 20px 48px;
}

.view {
  display: none;
  max-width: var(--max);
  margin: 0 auto;
}

.view.active {
  display: block;
  animation: fadeIn 0.28s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.hidden {
  display: none !important;
}

/* ===== Landing ===== */
#view-landing {
  display: none;
  min-height: calc(100vh - 48px);
  align-items: center;
  justify-content: center;
}

#view-landing.active {
  display: flex;
}

.landing-card {
  width: min(720px, 100%);
  background: linear-gradient(180deg, rgba(28, 36, 48, 0.95), rgba(23, 29, 37, 0.98));
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 40px 36px;
  box-shadow: var(--shadow);
}

.brand {
  text-align: center;
  margin-bottom: 32px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: linear-gradient(135deg, #3d9cf0, #1f6fbf);
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-bottom: 16px;
  box-shadow: 0 8px 24px rgba(61, 156, 240, 0.35);
}

.brand h1 {
  margin: 0 0 8px;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0;
  color: var(--text-muted);
  max-width: 420px;
  margin-inline: auto;
}

.host-url {
  margin: 10px 0 0;
  letter-spacing: 0.02em;
}

.sync-badge {
  display: inline-flex;
  align-items: center;
  margin: 12px 0 0;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 650;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text-muted);
}

.sync-badge:not(.hidden) {
  display: inline-flex;
}

.sync-badge.shared {
  color: var(--success);
  border-color: rgba(52, 199, 89, 0.35);
  background: var(--success-soft);
}

.sync-badge.local {
  color: var(--warning);
  border-color: rgba(245, 165, 36, 0.35);
  background: var(--warning-soft);
}

.sync-badge.syncing {
  color: var(--primary);
  border-color: rgba(61, 156, 240, 0.35);
  background: var(--primary-soft);
}

.sync-badge.error {
  color: var(--danger);
  border-color: rgba(255, 92, 92, 0.35);
  background: var(--danger-soft);
}

.role-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.role-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  text-align: left;
  padding: 22px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-soft);
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
}

.role-icon {
  font-size: 1.75rem;
}

.role-title {
  font-size: 1.15rem;
  font-weight: 700;
}

.role-desc {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.role-cta {
  margin-top: 6px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary);
}

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.sticky-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  padding: 10px 0 12px;
  margin-top: -4px;
  background: linear-gradient(180deg, var(--bg) 70%, transparent);
  backdrop-filter: blur(8px);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar-title h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.topbar-right {
  color: var(--text-muted);
  font-size: 0.92rem;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  text-align: right;
}

.topbar-right strong {
  color: var(--text);
}

.identity-class {
  display: inline-block;
  margin-left: 0;
  font-size: 0.8rem;
  color: var(--primary);
  font-weight: 600;
  background: var(--primary-soft);
  padding: 2px 8px;
  border-radius: 999px;
}

/* ===== Entry / steps ===== */
.entry-panel {
  max-width: 720px;
}

.steps {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.step {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
}

.step.active {
  color: var(--primary);
  border-color: rgba(61, 156, 240, 0.35);
  background: var(--primary-soft);
}

.step.done {
  color: var(--success);
  border-color: rgba(52, 199, 89, 0.3);
  background: var(--success-soft);
}

.step-line {
  flex: 1;
  min-width: 24px;
  height: 2px;
  background: var(--border);
}

.chip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin: 12px 0 18px;
  max-height: min(42vh, 360px);
  overflow-y: auto;
  padding: 2px;
  -webkit-overflow-scrolling: touch;
}

.class-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  min-height: 72px;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.class-chip:hover,
.class-chip:focus-visible {
  border-color: var(--primary);
  outline: none;
}

.class-chip.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 2px rgba(61, 156, 240, 0.2);
}

.class-chip-label {
  font-weight: 700;
  font-size: 0.95rem;
}

.class-chip-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.class-chip-teachers {
  font-size: 0.72rem;
  color: var(--text-dim);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.chip-empty {
  grid-column: 1 / -1;
  padding: 16px;
}

.teacher-pick-block {
  margin-bottom: 14px;
}

.hint {
  margin: 6px 0 0;
  font-size: 0.82rem;
  color: var(--text-dim);
}

.btn-block {
  width: 100%;
}

/* ===== Identity banner ===== */
.identity-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 16px;
  margin-bottom: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(61, 156, 240, 0.12), rgba(28, 36, 48, 0.9));
}

.banner-title {
  font-weight: 700;
  font-size: 1.05rem;
}

.banner-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===== Workspace tabs ===== */
.workspace-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  padding: 4px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.wtab,
.wtab-admin.tab {
  flex: 1 1 auto;
  min-width: max-content;
  padding: 10px 14px;
  border-radius: 9px;
  font-weight: 650;
  font-size: 0.9rem;
  color: var(--text-muted);
  min-height: 44px;
  border-bottom: none !important;
  margin-bottom: 0 !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.wtab.active,
.wtab-admin.tab.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.wtab-panel {
  display: none;
}

.wtab-panel.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

.tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.4em;
  height: 1.4em;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.72rem;
  font-weight: 700;
}

.tab-count.warn {
  background: var(--warning-soft);
  color: var(--warning);
}

/* ===== Filters ===== */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
  align-items: stretch;
}

.filter-bar.compact {
  margin-bottom: 8px;
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
}

.search-wrap.grow {
  flex: 1 1 220px;
}

.search-wrap .search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-dim);
  pointer-events: none;
  font-size: 1rem;
}

.search-wrap input {
  padding-left: 34px;
  padding-right: 36px;
  width: 100%;
}

.search-wrap .clear-btn {
  position: absolute;
  right: 6px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 1.2rem;
  line-height: 1;
}

.search-wrap .clear-btn:hover {
  background: var(--bg-soft);
  color: var(--text);
}

.filter-select {
  flex: 0 1 160px;
  min-width: 130px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.filter-chip {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.82rem;
  min-height: 36px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.filter-chip:hover {
  border-color: var(--text-dim);
  color: var(--text);
}

.filter-chip.active {
  background: var(--primary-soft);
  border-color: rgba(61, 156, 240, 0.4);
  color: var(--primary);
}

.result-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.link-btn {
  color: var(--primary);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 4px 6px;
  border-radius: 6px;
}

.link-btn:hover {
  background: var(--primary-soft);
}

.list-select {
  width: 100%;
  min-height: 140px;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
}

.list-select option {
  padding: 8px;
  border-radius: 6px;
}

.panel-intro {
  margin: -8px 0 14px;
}

/* Clickable stats */
.stat-card.stat-btn {
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}

.stat-card.stat-btn:hover,
.stat-card.stat-btn:focus-visible {
  border-color: var(--primary);
  outline: none;
}

/* Collapsible add student */
.add-details {
  margin-top: 16px;
  border-top: 1px dashed var(--border);
  padding-top: 4px;
}

.add-details summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 4px;
  min-height: 48px;
  user-select: none;
}

.add-details summary::-webkit-details-marker {
  display: none;
}

.summary-title {
  font-weight: 700;
  color: var(--primary);
}

.summary-sub {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.add-body {
  padding: 0 2px 8px;
}

/* Screen reader only */
.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ===== Admin export + directory ===== */
.admin-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.export-menu {
  position: relative;
}

.export-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 220px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.export-item {
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text);
  font-weight: 550;
  font-size: 0.9rem;
}

.export-item:hover {
  background: var(--primary-soft);
  color: var(--primary);
}

.section-title {
  margin: 22px 0 10px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.directory-summary {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  margin: 8px 0 18px;
}

.dir-class-card {
  text-align: left;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  min-height: 88px;
  transition: border-color 0.15s, background 0.15s;
}

.dir-class-card:hover,
.dir-class-card.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.dir-class-name {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 4px;
}

.dir-class-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.dir-class-teachers {
  font-size: 0.72rem;
  color: var(--text-dim);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.warn-text {
  color: var(--warning);
  font-weight: 650;
}

.row-pending {
  background: rgba(245, 165, 36, 0.06) !important;
}

/* ===== Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.badge.role {
  background: var(--primary-soft);
  color: var(--primary);
  margin-bottom: 4px;
}

.badge.role.admin {
  background: var(--warning-soft);
  color: var(--warning);
}

.badge.status-approved,
.badge.status-done {
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid rgba(52, 199, 89, 0.35);
}

.badge.status-pending,
.badge.status-open {
  background: var(--warning-soft);
  color: var(--warning);
  border: 1px solid rgba(245, 165, 36, 0.35);
}

.badge.status-in_progress {
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid rgba(61, 156, 240, 0.35);
}

.badge.status-add {
  background: rgba(100, 210, 255, 0.14);
  color: var(--info);
}

.badge.status-edit {
  background: var(--primary-soft);
  color: var(--primary);
}

.badge.status-delete {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(255, 92, 92, 0.35);
}

.row-delete-pending {
  background: rgba(255, 92, 92, 0.06) !important;
}

.row-delete-pending .name-cell {
  text-decoration: line-through;
  color: var(--text-muted);
}

.row-delete-pending .email-cell {
  text-decoration: line-through;
}

/* ===== Panels ===== */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 18px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.panel-head h2,
.panel h2,
.panel h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
}

.panel h3 {
  margin-bottom: 4px;
}

.panel-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.select-panel {
  max-width: 520px;
  margin: 40px auto;
}

.select-panel h2 {
  margin-bottom: 6px;
}

.teacher-entry-form {
  margin-top: 14px;
}

.teacher-entry-form .btn.primary {
  margin-top: 4px;
}

/* ===== Layout ===== */
.layout-2col {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 18px;
  align-items: start;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}

.stat-card .label {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-bottom: 4px;
}

.stat-card .value {
  font-size: 1.45rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.stat-card .value.success {
  color: var(--success);
}

.stat-card .value.warning {
  color: var(--warning);
}

/* ===== Forms ===== */
.form-row,
.form-stack,
.form-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label,
.form-row label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

input[type="text"],
input[type="email"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

textarea {
  resize: vertical;
  min-height: 96px;
}

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

.muted.small,
.small {
  font-size: 0.85rem;
}

.form-error {
  margin: 0;
  color: var(--danger);
  font-size: 0.88rem;
  font-weight: 560;
}

.teacher-class-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 600;
  margin-right: 6px;
  margin-bottom: 4px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.92rem;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

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

.btn.primary {
  background: var(--primary);
  color: #061018;
}

.btn.primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}

.btn.ghost:hover:not(:disabled) {
  border-color: var(--text-dim);
  color: var(--text);
}

.btn.success {
  background: var(--success-soft);
  color: var(--success);
  border-color: transparent;
}

.btn.success:hover:not(:disabled) {
  background: rgba(52, 199, 89, 0.22);
}

.btn.warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.btn.danger {
  color: var(--danger);
}

.btn.danger:hover:not(:disabled) {
  background: var(--danger-soft);
}

.btn.sm {
  padding: 6px 10px;
  font-size: 0.8rem;
  border-radius: 8px;
}

.btn.icon {
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 1.35rem;
  color: var(--text-muted);
  border-radius: 8px;
}

.btn.icon:hover {
  background: var(--bg-soft);
  color: var(--text);
}

/* ===== Tables ===== */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}

.data-table th {
  background: var(--bg-soft);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table .email-cell {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.data-table .name-cell {
  font-weight: 560;
}

.add-block {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px dashed var(--border);
}

.empty-hint {
  color: var(--text-dim);
  text-align: center;
  padding: 28px 12px;
  margin: 0;
}

/* ===== Queries ===== */
.query-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.query-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-left: 4px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  transition: border-color 0.15s, background 0.15s;
}

/* Open — needs admin action (amber) */
.query-card.open,
.query-card.status-open {
  border-left-color: var(--warning);
  background: linear-gradient(90deg, rgba(245, 165, 36, 0.08), var(--bg-elevated) 40%);
}

/* In progress — admin working (blue) */
.query-card.in_progress,
.query-card.status-in_progress {
  border-left-color: var(--primary);
  background: linear-gradient(90deg, rgba(61, 156, 240, 0.1), var(--bg-elevated) 40%);
}

/* Done / approved — resolved (green) */
.query-card.done,
.query-card.status-done {
  border-left-color: var(--success);
  border-color: rgba(52, 199, 89, 0.35);
  background: linear-gradient(90deg, rgba(52, 199, 89, 0.12), var(--bg-elevated) 45%);
}

.query-card.done h3,
.query-card.status-done h3 {
  color: #b8f0c6;
}

.query-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.query-card-head h3 {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-done {
  color: var(--success);
  font-size: 1.1rem;
}

.query-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.query-body {
  color: var(--text-muted);
  font-size: 0.9rem;
  white-space: pre-wrap;
  margin: 0 0 10px;
}

.query-admin-note {
  background: var(--primary-soft);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.85rem;
  margin-bottom: 10px;
  color: var(--text);
}

.query-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.query-actions input[type="text"] {
  flex: 1;
  min-width: 160px;
  padding: 7px 10px;
  font-size: 0.85rem;
}

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}

.tab {
  padding: 10px 16px;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  border-radius: 8px 8px 0 0;
}

.tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 10, 16, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal {
  width: min(440px, 100%);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
  animation: fadeIn 0.2s ease;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #243041;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 200;
  font-weight: 550;
  font-size: 0.9rem;
  max-width: min(90vw, 420px);
  text-align: center;
  animation: toastIn 0.25s ease;
}

.toast.success {
  border-color: rgba(52, 199, 89, 0.4);
}

.toast.error {
  border-color: rgba(255, 92, 92, 0.4);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* ===== Base mobile / touch helpers ===== */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  overflow-x: hidden;
  -webkit-tap-highlight-color: rgba(61, 156, 240, 0.15);
}

/* Prevent iOS zoom on focus: inputs need ≥16px */
input[type="text"],
input[type="email"],
input[type="search"],
input[type="password"],
select,
textarea {
  font-size: 16px;
  max-width: 100%;
  min-height: 44px;
}

textarea {
  min-height: 110px;
}

.btn {
  min-height: 44px;
  touch-action: manipulation;
}

.btn.sm {
  min-height: 40px;
  min-width: 40px;
  padding: 8px 12px;
}

.btn.icon {
  width: 44px;
  height: 44px;
  min-height: 44px;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

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

/* Only apply hover lift when device supports hover */
@media (hover: hover) and (pointer: fine) {
  .role-card:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
    transform: translateY(-2px);
  }
}

@media (hover: none) {
  .role-card:hover {
    transform: none;
  }

  .role-card:active {
    border-color: var(--primary);
    background: var(--primary-soft);
  }
}

/* ===== Responsive: tablet ===== */
@media (max-width: 900px) {
  #app {
    padding: 18px 16px 40px;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    padding-bottom: max(40px, env(safe-area-inset-bottom));
  }

  .layout-2col {
    grid-template-columns: 1fr;
  }

  .role-grid {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .landing-card {
    padding: 28px 20px;
    border-radius: 18px;
  }

  .stats-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar-left {
    flex-wrap: wrap;
    width: 100%;
  }

  .topbar-right {
    width: 100%;
    align-items: flex-start;
    text-align: left;
    word-break: break-word;
  }

  .select-panel {
    margin: 16px auto;
    max-width: 100%;
  }

  .panel-actions {
    width: 100%;
  }

  .panel-actions input,
  .panel-actions select {
    flex: 1 1 100%;
    min-width: 0;
  }

  .query-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .query-actions input[type="text"] {
    min-width: 0;
    width: 100%;
  }

  .query-actions .btn {
    width: 100%;
  }

  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .tabs::-webkit-scrollbar {
    display: none;
  }

  .tab {
    flex: 0 0 auto;
    white-space: nowrap;
    min-height: 44px;
  }

  .filter-bar {
    flex-direction: column;
  }

  .filter-select {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
  }

  .chip-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    max-height: min(48vh, 400px);
  }

  .identity-banner {
    align-items: flex-start;
  }

  .identity-banner .btn {
    width: 100%;
  }
}

/* ===== Responsive: phone ===== */
@media (max-width: 640px) {
  #app {
    padding: 12px 12px 36px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-bottom: max(36px, calc(16px + env(safe-area-inset-bottom)));
  }

  #view-landing.active {
    min-height: calc(100dvh - 24px);
    align-items: flex-start;
    padding-top: 12px;
  }

  .landing-card {
    padding: 22px 16px;
    border-radius: 16px;
  }

  .brand {
    margin-bottom: 22px;
  }

  .brand-mark {
    width: 48px;
    height: 48px;
    border-radius: 14px;
  }

  .brand h1 {
    font-size: 1.35rem;
    line-height: 1.25;
  }

  .subtitle {
    font-size: 0.92rem;
  }

  .role-card {
    padding: 18px 16px;
    min-height: 88px;
  }

  .topbar {
    gap: 10px;
    margin-bottom: 14px;
  }

  .topbar-title h1 {
    font-size: 1.1rem;
  }

  .btn-back {
    flex-shrink: 0;
    padding-inline: 12px;
  }

  .panel {
    padding: 14px;
    border-radius: 12px;
    margin-bottom: 14px;
  }

  .panel-head {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .panel-head h2 {
    font-size: 1rem;
  }

  .stats-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 14px;
  }

  .stat-card {
    padding: 12px;
  }

  .stat-card .label {
    font-size: 0.72rem;
    line-height: 1.3;
  }

  .stat-card .value {
    font-size: 1.2rem;
    word-break: break-word;
  }

  .form-grid {
    gap: 10px;
  }

  .select-panel {
    margin: 8px 0;
    width: 100%;
  }

  .btn.primary,
  .form-stack > .btn,
  .form-row + .btn,
  #btn-enter-teacher,
  #form-admin-login .btn,
  #form-add-student .btn,
  #form-query .btn {
    width: 100%;
  }

  .modal-actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .modal-actions .btn {
    width: 100%;
  }

  .modal-backdrop {
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    align-items: flex-end;
  }

  .modal {
    width: 100%;
    max-height: min(90dvh, 100%);
    overflow-y: auto;
    border-radius: 16px 16px 12px 12px;
    padding: 16px;
    -webkit-overflow-scrolling: touch;
  }

  .toast {
    bottom: max(16px, env(safe-area-inset-bottom));
    left: 12px;
    right: 12px;
    transform: none;
    width: auto;
    max-width: none;
    border-radius: 14px;
    padding: 12px 14px;
  }

  @keyframes toastIn {
    from {
      opacity: 0;
      transform: translateY(10px);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }

  .query-card {
    padding: 12px;
  }

  .query-card-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .query-card-head h3 {
    font-size: 0.95rem;
    line-height: 1.35;
    word-break: break-word;
  }

  /* Card-style tables on small screens */
  .table-wrap {
    border: none;
    overflow: visible;
    border-radius: 0;
  }

  .data-table,
  .data-table tbody,
  .data-table tr,
  .data-table td {
    display: block;
    width: 100%;
  }

  .data-table thead {
    display: none;
  }

  .data-table tbody {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .data-table tr {
    background: var(--bg-elevated);
    border: 1px solid var(--border-soft);
    border-radius: 12px;
    padding: 10px 12px;
  }

  .data-table tbody tr:hover {
    background: var(--bg-elevated);
  }

  .data-table th,
  .data-table td {
    padding: 6px 0;
    border-bottom: none;
  }

  .data-table td {
    display: grid;
    grid-template-columns: 96px 1fr;
    gap: 8px;
    align-items: start;
    font-size: 0.9rem;
  }

  .data-table td::before {
    content: attr(data-label);
    color: var(--text-dim);
    font-size: 0.72rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding-top: 3px;
  }

  .data-table td.actions-cell {
    grid-template-columns: 1fr;
    margin-top: 6px;
    padding-top: 10px;
    border-top: 1px dashed var(--border-soft);
  }

  .data-table td.actions-cell::before {
    display: none;
  }

  .data-table td.actions-cell .btn,
  .data-table td.actions-cell .row-actions {
    width: 100%;
  }

  .data-table td.actions-cell .row-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .data-table td.actions-cell .row-actions .btn {
    width: 100%;
  }

  .data-table .email-cell {
    word-break: break-all;
    overflow-wrap: anywhere;
  }

  .data-table .name-cell {
    word-break: break-word;
  }

  .add-block {
    margin-top: 16px;
    padding-top: 14px;
  }

  .empty-hint {
    padding: 20px 8px;
    font-size: 0.9rem;
  }
}

/* Very small phones */
@media (max-width: 380px) {
  .stats-row {
    grid-template-columns: 1fr;
  }

  .data-table td {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .data-table td.actions-cell .row-actions {
    grid-template-columns: 1fr;
  }

  .brand h1 {
    font-size: 1.2rem;
  }
}

/* Landscape phones: keep usable height */
@media (max-height: 500px) and (orientation: landscape) {
  #view-landing.active {
    align-items: flex-start;
    min-height: auto;
    padding-block: 12px;
  }

  .modal-backdrop {
    align-items: center;
  }

  .modal {
    max-height: 92dvh;
  }
}
