:root {
  color-scheme: light;
  --bg: #f6f8fc;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --panel-strong: #eef2ff;
  --text: #111827;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --line: #e5e7eb;
  --line-soft: #eef2f7;
  --primary: #4f46e5;
  --primary-2: #4338ca;
  --primary-soft: #eef2ff;
  --green: #16a34a;
  --green-soft: #ecfdf3;
  --red: #dc2626;
  --red-soft: #fff1f2;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --orange: #ea580c;
  --purple: #7c3aed;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 12px 32px rgba(15, 23, 42, .08), 0 2px 6px rgba(15, 23, 42, .04);
  --shadow-lg: 0 24px 70px rgba(15, 23, 42, .17);
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 24px;
  --radius-xl: 32px;
  --sidebar: 264px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #050b18;
  --panel: #0d1627;
  --panel-soft: #111d30;
  --panel-strong: #172554;
  --text: #f8fafc;
  --muted: #a8b3c7;
  --muted-2: #718096;
  --line: #22304a;
  --line-soft: #18243a;
  --primary: #818cf8;
  --primary-2: #6366f1;
  --primary-soft: #1e1b4b;
  --green: #4ade80;
  --green-soft: #052e1b;
  --red: #fb7185;
  --red-soft: #3b0a16;
  --amber: #fbbf24;
  --amber-soft: #342108;
  --orange: #fb923c;
  --purple: #c4b5fd;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .24);
  --shadow: 0 16px 38px rgba(0, 0, 0, .28);
  --shadow-lg: 0 28px 80px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
a { color: inherit; }
img { max-width: 100%; }
[hidden] { display: none !important; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--muted-2) 60%, transparent); border-radius: 999px; }

.icon {
  display: inline-block;
  width: 1.15em;
  height: 1.15em;
  flex: 0 0 auto;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  vertical-align: -0.2em;
}

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

/* Shared controls */
.btn {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 14px;
  padding: 10px 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text);
  background: var(--panel-soft);
  font-weight: 750;
  font-size: 13px;
  line-height: 1;
  text-decoration: none;
  transition: transform .15s ease, background .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.98); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 10px 24px color-mix(in srgb, var(--primary) 25%, transparent); }
.btn-primary:hover { background: var(--primary-2); }
.btn-dark { background: #111827; color: #fff; }
html[data-theme="dark"] .btn-dark { background: #243047; }
.btn-danger { color: var(--red); background: var(--red-soft); border-color: color-mix(in srgb, var(--red) 18%, transparent); }
.btn-success { color: #fff; background: #059669; }
.btn-warning { color: #fff; background: #d97706; }
.btn-outline { background: transparent; border-color: var(--line); color: var(--muted); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-small { min-height: 34px; padding: 8px 11px; border-radius: 10px; font-size: 11px; }
.btn-icon { width: 40px; height: 40px; min-height: 40px; padding: 0; border-radius: 12px; }
.btn-block { width: 100%; }

.field { display: grid; gap: 7px; min-width: 0; }
.field label, .field-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.input, .select, .textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 11px 13px;
  background: var(--panel-soft);
  color: var(--text);
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.textarea { min-height: 105px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent);
  background: var(--panel);
}
.input::placeholder, .textarea::placeholder { color: var(--muted-2); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.form-span-2 { grid-column: span 2; }
.form-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; padding-top: 18px; border-top: 1px solid var(--line); }
.checkbox-row, .radio-row { display: flex; align-items: center; gap: 9px; color: var(--text); font-weight: 650; }
.checkbox-row input, .radio-row input { width: 17px; height: 17px; accent-color: var(--primary); }
.help { color: var(--muted); font-size: 12px; }
.password-cell { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.password-cell code { min-width: 72px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-soft); color: var(--text); font-size: 13px; letter-spacing: .08em; text-align: center; }
.password-cell .btn { width: 31px; height: 31px; min-height: 31px; border-radius: 9px; }
.error-text { color: var(--red); font-size: 12px; font-weight: 700; }

.card {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 24px; }
.card-header {
  padding: 19px 22px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.card-title { margin: 0; font-size: 18px; font-weight: 850; letter-spacing: -.02em; }
.card-subtitle { margin: 3px 0 0; color: var(--muted); font-size: 13px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 24px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: 10px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: .06em;
  white-space: nowrap;
}
.badge-primary { color: var(--primary); background: var(--primary-soft); border-color: color-mix(in srgb, var(--primary) 18%, transparent); }
.badge-live { color: var(--green); background: var(--green-soft); border-color: color-mix(in srgb, var(--green) 18%, transparent); }
.badge-danger { color: var(--red); background: var(--red-soft); border-color: color-mix(in srgb, var(--red) 18%, transparent); }
.badge-warning { color: var(--amber); background: var(--amber-soft); border-color: color-mix(in srgb, var(--amber) 18%, transparent); }

.empty-state { padding: 64px 24px; text-align: center; color: var(--muted); }
.empty-icon {
  width: 70px;
  height: 70px;
  margin: 0 auto 16px;
  display: grid;
  place-items: center;
  border-radius: 22px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 28px;
}
.empty-state h3 { margin: 0 0 5px; color: var(--text); font-size: 18px; }
.empty-state p { margin: 0 auto 18px; max-width: 480px; }

/* Login */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 12% 12%, color-mix(in srgb, var(--primary) 18%, transparent), transparent 36%),
    radial-gradient(circle at 88% 86%, rgba(124, 58, 237, .14), transparent 34%),
    var(--bg);
}
.login-card {
  width: min(100%, 455px);
  overflow: hidden;
  border-radius: 34px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  position: relative;
}
.login-hero {
  padding: 38px 34px 31px;
  text-align: center;
  color: #fff;
  background: linear-gradient(135deg, #4f46e5, #4338ca 55%, #6d28d9);
  position: relative;
  overflow: hidden;
}
.login-hero::before, .login-hero::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,.10);
  filter: blur(2px);
}
.login-hero::before { width: 150px; height: 150px; right: -70px; top: -55px; }
.login-hero::after { width: 120px; height: 120px; left: -45px; bottom: -65px; }
.login-logo {
  width: 76px;
  height: 76px;
  border-radius: 25px;
  margin: 0 auto 17px;
  display: grid;
  place-items: center;
  background: rgba(255,255,255,.16);
  border: 1px solid rgba(255,255,255,.28);
  box-shadow: inset 0 1px rgba(255,255,255,.12), 0 0 0 8px rgba(255,255,255,.06);
  overflow: hidden;
}
.login-logo img { width: 100%; height: 100%; object-fit: cover; }
.login-logo .icon { width: 38px; height: 38px; }
.login-hero h1 { margin: 0; font-size: 30px; line-height: 1.12; letter-spacing: -.04em; }
.login-hero p { margin: 6px 0 0; color: rgba(255,255,255,.75); font-size: 11px; font-weight: 850; letter-spacing: .18em; text-transform: uppercase; }
.login-body { padding: 26px 30px 30px; }
.role-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 6px; border-radius: 16px; background: var(--panel-soft); border: 1px solid var(--line); margin-bottom: 22px; }
.role-tab { min-width: 0; min-height: 42px; padding: 8px; border: 0; border-radius: 11px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 800; display: flex; align-items: center; justify-content: center; gap: 6px; }
.role-tab.active { background: var(--panel); color: var(--primary); box-shadow: var(--shadow-sm); }
.login-form { display: grid; gap: 16px; }
.login-error { border: 1px solid color-mix(in srgb, var(--red) 18%, transparent); background: var(--red-soft); color: var(--red); padding: 12px 14px; border-radius: 13px; font-size: 12px; font-weight: 700; display: flex; gap: 8px; }
.login-default { text-align: center; color: var(--muted); font-size: 11px; }
.login-default code { color: var(--primary); background: var(--primary-soft); padding: 2px 5px; border-radius: 5px; }
.login-footer { padding: 17px; text-align: center; color: var(--muted-2); background: var(--panel-soft); border-top: 1px solid var(--line); font-size: 10px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }

/* App shell */
.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  z-index: 40;
  inset: 0 auto 0 0;
  width: var(--sidebar);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; margin: 0 4px 32px; min-width: 0; }
.brand-logo { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; flex: 0 0 auto; overflow: hidden; background: var(--primary); color: #fff; font-weight: 900; font-size: 19px; box-shadow: 0 10px 22px color-mix(in srgb, var(--primary) 25%, transparent); }
.brand-logo img { width: 100%; height: 100%; object-fit: cover; }
.brand-name { min-width: 0; font-weight: 900; font-size: 19px; letter-spacing: -.035em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav { display: grid; gap: 5px; }
.nav-button {
  width: 100%;
  min-height: 45px;
  padding: 11px 13px;
  border: 0;
  border-radius: 13px;
  background: transparent;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 11px;
  font-size: 13px;
  font-weight: 800;
  text-align: left;
}
.nav-button:hover { background: var(--panel-soft); color: var(--text); }
.nav-button.active { color: var(--primary); background: var(--primary-soft); }
.sidebar-bottom { margin-top: auto; padding-top: 18px; border-top: 1px solid var(--line); display: grid; gap: 11px; }
.profile-card { padding: 13px; border: 1px solid var(--line); background: var(--panel-soft); border-radius: 17px; }
.profile-head { display: flex; align-items: center; gap: 10px; min-width: 0; margin-bottom: 10px; }
.avatar { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); font-weight: 900; flex: 0 0 auto; }
.profile-meta { min-width: 0; }
.profile-name { font-size: 13px; font-weight: 850; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-role { color: var(--muted); font-size: 9px; font-weight: 850; letter-spacing: .10em; text-transform: uppercase; }
.main { margin-left: var(--sidebar); min-height: 100vh; padding: 32px; }
.main-inner { width: min(100%, 1480px); margin: 0 auto; }
.mobile-bar { display: none; }
.mobile-drawer, .drawer-backdrop { display: none; }

.page { animation: pageIn .18s ease both; }
@keyframes pageIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 25px; }
.page-title { margin: 0; font-size: clamp(26px, 3vw, 36px); line-height: 1.12; letter-spacing: -.045em; font-weight: 900; }
.page-description { margin: 6px 0 0; color: var(--muted); font-weight: 550; }
.page-actions { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 9px; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 17px; margin-bottom: 24px; }
.stat-card { padding: 19px; display: flex; align-items: center; gap: 14px; min-width: 0; }
.stat-icon { width: 48px; height: 48px; border-radius: 15px; display: grid; place-items: center; flex: 0 0 auto; background: var(--primary-soft); color: var(--primary); }
.stat-icon.green { background: var(--green-soft); color: var(--green); }
.stat-icon.amber { background: var(--amber-soft); color: var(--amber); }
.stat-icon.purple { background: color-mix(in srgb, var(--purple) 12%, transparent); color: var(--purple); }
.stat-label { color: var(--muted); font-size: 9px; font-weight: 900; letter-spacing: .09em; text-transform: uppercase; }
.stat-value { margin-top: 3px; font-size: 23px; line-height: 1; font-weight: 900; letter-spacing: -.03em; }

.segmented { display: inline-flex; gap: 5px; padding: 5px; margin-bottom: 20px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); }
.segmented button { min-height: 38px; padding: 8px 15px; border: 0; border-radius: 10px; color: var(--muted); background: transparent; font-size: 12px; font-weight: 850; display: inline-flex; align-items: center; gap: 7px; }
.segmented button.active { color: var(--primary); background: var(--primary-soft); }

.card-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
.entity-card { padding: 21px; min-height: 238px; display: flex; flex-direction: column; transition: transform .17s ease, box-shadow .17s ease, border-color .17s ease; }
.entity-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--primary) 22%, var(--line)); }
.entity-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.entity-icon { width: 46px; height: 46px; border-radius: 15px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.entity-card h3 { margin: 17px 0 4px; font-size: 20px; line-height: 1.2; letter-spacing: -.025em; font-weight: 900; overflow-wrap: anywhere; }
.entity-sub { color: var(--muted); font-size: 11px; font-weight: 850; letter-spacing: .07em; text-transform: uppercase; }
.entity-description { margin: 12px 0 0; color: var(--muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.entity-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin: 18px 0; }
.mini-stat { padding: 11px 12px; border: 1px solid var(--line); background: var(--panel-soft); border-radius: 13px; }
.mini-stat span { display: block; color: var(--muted); font-size: 9px; font-weight: 850; letter-spacing: .07em; text-transform: uppercase; }
.mini-stat strong { display: block; margin-top: 2px; font-size: 18px; }
.entity-actions { margin-top: auto; display: grid; gap: 8px; }
.action-row { display: flex; gap: 7px; }
.action-row > .btn:not(.btn-icon) { flex: 1; }

/* Class details */
.detail-banner { padding: 25px; display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 23px; }
.detail-title-row { display: flex; align-items: center; gap: 13px; min-width: 0; }
.detail-title-row h1 { margin: 0; font-size: 29px; letter-spacing: -.04em; }
.detail-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(270px, 1fr); gap: 20px; align-items: start; }
.stack { display: grid; gap: 18px; }
.student-mini-list { display: grid; }
.student-mini { display: flex; align-items: center; gap: 11px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.student-mini:last-child { border-bottom: 0; }
.student-mini .avatar { width: 34px; height: 34px; }
.student-mini-name { min-width: 0; flex: 1; }
.student-mini-name strong, .student-mini-name span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.student-mini-name span { color: var(--muted); font-size: 10px; font-weight: 750; }

/* Tables */
.table-wrap { width: 100%; overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 13px 16px; background: var(--panel-soft); color: var(--muted); font-size: 9px; font-weight: 900; letter-spacing: .10em; text-transform: uppercase; text-align: left; white-space: nowrap; }
td { padding: 14px 16px; border-top: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover { background: color-mix(in srgb, var(--panel-soft) 75%, transparent); }
.table-name { font-weight: 800; }
.table-muted { color: var(--muted); font-size: 12px; }
.table-actions { display: flex; justify-content: flex-end; gap: 6px; white-space: nowrap; }
.text-center { text-align: center; }
.text-right { text-align: right; }

.search-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.search-box { position: relative; flex: 1 1 240px; }
.search-box .icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted-2); }
.search-box .input { padding-left: 40px; }
.toolbar { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.bulk-bar { padding: 10px 14px; margin: 0 0 14px; border: 1px solid color-mix(in srgb, var(--primary) 20%, transparent); background: var(--primary-soft); border-radius: 13px; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

/* Exam editor */
.editor-shell { display: grid; grid-template-columns: minmax(270px, 360px) minmax(0, 1fr); gap: 20px; align-items: start; }
.editor-side { position: sticky; top: 24px; }
.editor-section { padding: 21px; }
.editor-section + .editor-section { border-top: 1px solid var(--line); }
.section-title { display: flex; align-items: center; gap: 9px; margin: 0 0 15px; font-size: 16px; font-weight: 900; }
.answer-toolbar { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.answer-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 18px; max-height: calc(100vh - 240px); overflow: auto; }
.answer-row { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--line); background: var(--panel-soft); border-radius: 13px; }
.answer-number { width: 34px; color: var(--muted); font-weight: 850; text-align: right; }
.bubbles { display: flex; flex-wrap: wrap; gap: 6px; }
.bubble {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}
.bubble:hover { border-color: var(--primary); color: var(--primary); }
.bubble.selected { color: #fff; background: var(--primary); border-color: var(--primary); box-shadow: 0 4px 12px color-mix(in srgb, var(--primary) 24%, transparent); transform: scale(1.07); }
.import-box { margin-top: 12px; padding: 14px; border: 1px dashed color-mix(in srgb, var(--primary) 35%, var(--line)); border-radius: 14px; background: var(--primary-soft); }

/* Modals */
.modal-layer { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; padding: 18px; background: rgba(2, 6, 23, .67); backdrop-filter: blur(5px); animation: fadeIn .15s ease; }
@keyframes fadeIn { from { opacity: 0; } }
.modal {
  width: min(100%, 620px);
  max-height: min(92vh, 900px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-radius: 25px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  animation: modalIn .17s ease;
}
.modal-wide { width: min(100%, 860px); }
.modal-xl { width: min(100%, 1100px); }
@keyframes modalIn { from { opacity: 0; transform: scale(.97) translateY(8px); } }
.modal-head { padding: 20px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.modal-head h2 { margin: 0; font-size: 21px; letter-spacing: -.025em; }
.modal-body { padding: 21px 22px; overflow: auto; }
.modal-foot { padding: 15px 22px; border-top: 1px solid var(--line); background: var(--panel-soft); display: flex; justify-content: flex-end; gap: 9px; flex-wrap: wrap; }
.manual-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-top: 13px; }
.manual-question { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px; border: 1px solid var(--line); background: var(--panel-soft); border-radius: 12px; }

/* Results */
.result-page { position: fixed; z-index: 80; inset: 0; background: var(--bg); overflow: auto; }
.result-topbar { position: sticky; z-index: 4; top: 0; min-height: 68px; padding: 12px 20px; display: flex; align-items: center; justify-content: space-between; gap: 14px; background: color-mix(in srgb, var(--panel) 95%, transparent); border-bottom: 1px solid var(--line); backdrop-filter: blur(12px); }
.result-top-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.result-top-left h1 { margin: 0; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-top-left p { margin: 2px 0 0; color: var(--muted); font-size: 11px; }
.result-content { width: min(100% - 28px, 1050px); margin: 0 auto; padding: 25px 0 44px; display: grid; gap: 18px; }
.score-card { padding: 22px; display: grid; grid-template-columns: 190px 1fr; align-items: center; gap: 24px; }
.donut-wrap { display: grid; place-items: center; }
.donut {
  width: 136px;
  height: 136px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  position: relative;
}
.donut::after { content: ""; position: absolute; inset: 18px; border-radius: 50%; background: var(--panel); }
.donut-center { position: relative; z-index: 1; text-align: center; }
.donut-center small { display: block; color: var(--muted); font-size: 9px; font-weight: 850; letter-spacing: .08em; }
.donut-center strong { font-size: 25px; }
.accuracy { margin-top: 9px; color: var(--green); font-size: 20px; font-weight: 900; }
.result-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 11px; }
.result-stat { min-height: 92px; padding: 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel-soft); }
.result-stat.primary { background: var(--primary); color: #fff; border-color: transparent; }
.result-stat.green { background: var(--green-soft); color: var(--green); border-color: color-mix(in srgb, var(--green) 15%, transparent); }
.result-stat.red { background: var(--red-soft); color: var(--red); border-color: color-mix(in srgb, var(--red) 15%, transparent); }
.result-stat.orange { background: color-mix(in srgb, var(--orange) 10%, transparent); color: var(--orange); }
.result-stat span { display: block; opacity: .78; font-size: 9px; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.result-stat strong { display: block; margin-top: 4px; font-size: 22px; }
.image-panel { overflow: hidden; }
.image-toolbar { padding: 13px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.image-toolbar-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.image-stage { min-height: 280px; max-height: 650px; display: grid; place-items: center; background: #020617; overflow: auto; position: relative; }
.image-relative { position: relative; max-width: 100%; transform-origin: center; transition: transform .2s ease; }
.image-relative.rotate-180 { transform: rotate(180deg); }
.image-relative > img { display: block; max-height: 630px; width: auto; object-fit: contain; }
.detect-box { position: absolute; border: 2px solid var(--red); background: color-mix(in srgb, var(--red) 14%, transparent); pointer-events: none; }
.confidence-row { padding: 12px 15px; display: flex; align-items: center; gap: 10px; background: var(--primary-soft); border: 1px solid color-mix(in srgb, var(--primary) 15%, transparent); border-radius: 13px; }
.confidence-row span { color: var(--primary); font-size: 10px; font-weight: 900; text-transform: uppercase; letter-spacing: .08em; }
.progress { height: 7px; flex: 1; border-radius: 999px; background: color-mix(in srgb, var(--primary) 14%, transparent); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--primary); border-radius: inherit; }
.response-pill { min-width: 34px; min-height: 30px; padding: 5px 8px; display: inline-grid; place-items: center; border-radius: 9px; font-size: 12px; font-weight: 850; border: 1px solid var(--line); }
.response-pill.correct { color: var(--green); background: var(--green-soft); border-color: color-mix(in srgb, var(--green) 20%, transparent); }
.response-pill.wrong { color: var(--red); background: var(--red-soft); border-color: color-mix(in srgb, var(--red) 20%, transparent); }
.response-pill.multiple { color: var(--orange); background: color-mix(in srgb, var(--orange) 11%, transparent); }
.response-pill.blank { color: var(--muted); background: var(--panel-soft); }

/* Scanner */
.scanner-layer { position: fixed; z-index: 130; inset: 0; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, .83); backdrop-filter: blur(5px); }
.scanner-dialog { width: min(100%, 760px); max-height: 94vh; border-radius: 25px; overflow: hidden; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; }
.scanner-head { padding: 17px 20px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: var(--panel-soft); }
.scanner-head h2 { margin: 0; font-size: 20px; }
.scanner-head p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.scanner-body { padding: 20px; overflow: auto; }
.scan-choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.scan-choice { min-height: 190px; border: 2px dashed var(--line); border-radius: 19px; background: var(--panel-soft); color: var(--text); display: grid; place-items: center; align-content: center; gap: 10px; text-align: center; padding: 24px; }
.scan-choice:hover { border-color: var(--primary); background: var(--primary-soft); }
.scan-choice .choice-icon { width: 58px; height: 58px; display: grid; place-items: center; border-radius: 17px; background: var(--primary); color: #fff; }
.scan-choice strong { font-size: 16px; }
.scan-choice span { color: var(--muted); font-size: 12px; }
.scan-note { margin-top: 14px; padding: 12px 14px; border-radius: 13px; display: flex; gap: 9px; color: var(--amber); background: var(--amber-soft); border: 1px solid color-mix(in srgb, var(--amber) 17%, transparent); font-size: 12px; }
.preview-stage { position: relative; min-height: 340px; max-height: 62vh; border-radius: 17px; background: #020617; overflow: hidden; display: grid; place-items: center; }
.preview-stage img { width: 100%; height: 100%; max-height: 62vh; object-fit: contain; transform-origin: center; transition: transform .2s ease; }
.preview-stage img.rotate-180 { transform: rotate(180deg); }
.preview-tools { margin-top: 10px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-soft); display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 11px; }
.preview-tools strong { color: var(--primary); }
.processing-cover { position: absolute; inset: 0; display: grid; place-items: center; align-content: center; gap: 13px; padding: 20px; background: rgba(2, 6, 23, .58); color: #fff; }
.processing-bar { width: min(100%, 320px); height: 8px; border-radius: 999px; background: rgba(255,255,255,.18); overflow: hidden; }
.processing-bar i { display: block; height: 100%; background: #818cf8; transition: width .3s ease; }
.scan-actions { display: flex; gap: 10px; margin-top: 13px; }
.scan-actions .btn { flex: 1; }
.camera-stage { position: relative; height: min(70vh, 660px); min-height: 430px; background: #000; overflow: hidden; border-radius: 17px; isolation: isolate; }
.camera-stage video { position: absolute; z-index: 0; inset: 0; width: 100%; height: 100%; min-height: 0; object-fit: cover; display: block; }
.camera-frame { position: absolute; z-index: 2; width: 360px; height: 509px; left: 50%; top: 64px; transform: translateX(-50%); border: 1px solid rgba(255,255,255,.72); border-radius: 10px; box-shadow: 0 0 0 9999px rgba(2,6,23,.25), inset 0 0 0 1px rgba(15,23,42,.25); pointer-events: none; transition: width .16s ease, height .16s ease, top .16s ease; }
.frame-corner { position: absolute; width: 28px; height: 28px; border-color: #818cf8; border-style: solid; border-width: 0; filter: drop-shadow(0 1px 2px rgba(0,0,0,.55)); }
.corner-tl { left: -3px; top: -3px; border-left-width: 4px; border-top-width: 4px; border-radius: 9px 0 0 0; }
.corner-tr { right: -3px; top: -3px; border-right-width: 4px; border-top-width: 4px; border-radius: 0 9px 0 0; }
.corner-bl { left: -3px; bottom: -3px; border-left-width: 4px; border-bottom-width: 4px; border-radius: 0 0 0 9px; }
.corner-br { right: -3px; bottom: -3px; border-right-width: 4px; border-bottom-width: 4px; border-radius: 0 0 9px 0; }
.camera-hint { position: absolute; z-index: 4; top: 13px; left: 50%; max-width: calc(100% - 24px); transform: translateX(-50%); padding: 7px 11px; border-radius: 999px; background: rgba(0,0,0,.62); color: #fff; font-size: 11px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.camera-controls { position: absolute; z-index: 4; left: 12px; right: 12px; bottom: 12px; display: flex; align-items: center; justify-content: center; gap: 10px; }
.camera-control { min-width: 44px; min-height: 44px; border: 1px solid rgba(255,255,255,.25); border-radius: 14px; background: rgba(0,0,0,.58); color: #fff; display: grid; place-items: center; font-weight: 800; backdrop-filter: blur(5px); }
.capture-button { width: 66px; height: 66px; border-radius: 50%; border: 5px solid rgba(255,255,255,.65); background: #fff; box-shadow: 0 0 0 3px rgba(0,0,0,.35); }
.camera-debug { position: absolute; z-index: 6; left: 10px; right: 10px; top: 52px; padding: 10px; border-radius: 12px; background: rgba(0,0,0,.82); color: #d1d5db; font: 11px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.auto-status { position: absolute; z-index: 5; top: 54px; left: 50%; transform: translateX(-50%); padding: 8px 12px; border-radius: 12px; background: rgba(79,70,229,.9); color: #fff; font-weight: 850; font-size: 12px; }
.drop-active { border-color: var(--primary) !important; background: var(--primary-soft) !important; }

/* Settings and information blocks */
.settings-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, .8fr); gap: 20px; align-items: start; }
.logo-editor { display: flex; gap: 16px; align-items: center; }
.logo-preview { width: 86px; height: 86px; border-radius: 20px; border: 1px solid var(--line); background: var(--panel-soft); display: grid; place-items: center; overflow: hidden; flex: 0 0 auto; color: var(--muted); }
.logo-preview img { width: 100%; height: 100%; object-fit: cover; }
.info-box { padding: 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel-soft); color: var(--muted); font-size: 12px; }
.danger-zone { border-color: color-mix(in srgb, var(--red) 20%, var(--line)); }

/* Franchise cards */
.franchise-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 17px; }
.franchise-card { padding: 20px; }
.franchise-card h3 { margin: 14px 0 2px; font-size: 19px; }
.franchise-meta { color: var(--muted); font-size: 12px; display: grid; gap: 3px; }
.permission-list { display: grid; gap: 8px; margin: 16px 0; padding: 12px; border-radius: 13px; background: var(--panel-soft); }
.permission-row { display: flex; align-items: center; justify-content: space-between; gap: 9px; font-size: 12px; font-weight: 700; text-transform: capitalize; }
.switch { position: relative; width: 38px; height: 22px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: .15s; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: .15s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::before { transform: translateX(16px); }

/* Toasts */
#toast-root { position: fixed; z-index: 500; top: 18px; right: 18px; display: grid; gap: 9px; pointer-events: none; }
.toast { min-width: 240px; max-width: min(390px, calc(100vw - 36px)); padding: 12px 14px; border-radius: 13px; background: var(--panel); color: var(--text); border: 1px solid var(--line); box-shadow: var(--shadow); display: flex; align-items: flex-start; gap: 9px; font-size: 12px; font-weight: 700; animation: toastIn .2s ease; }
.toast.success { border-color: color-mix(in srgb, var(--green) 30%, var(--line)); }
.toast.error { border-color: color-mix(in srgb, var(--red) 30%, var(--line)); }
.toast.warning { border-color: color-mix(in srgb, var(--amber) 30%, var(--line)); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } }

/* Loading */
.loading-screen { min-height: 100vh; display: grid; place-items: center; color: var(--muted); }
.spinner { width: 36px; height: 36px; border: 4px solid color-mix(in srgb, var(--primary) 18%, transparent); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive */
@media (max-width: 1240px) {
  .card-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .franchise-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 980px) {
  :root { --sidebar: 236px; }
  .main { padding: 25px; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-layout, .settings-grid { grid-template-columns: 1fr; }
  .editor-shell { grid-template-columns: 1fr; }
  .editor-side { position: static; }
  .answer-grid { max-height: none; }
}

@media (max-width: 760px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 86px 14px 24px; }
  .mobile-bar {
    position: fixed;
    z-index: 45;
    left: 0;
    right: 0;
    top: 0;
    min-height: 64px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: color-mix(in srgb, var(--panel) 94%, transparent);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
  }
  .mobile-brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
  .mobile-brand .brand-logo { width: 38px; height: 38px; border-radius: 12px; }
  .mobile-brand strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .drawer-backdrop { position: fixed; z-index: 90; inset: 0; display: block; background: rgba(2,6,23,.65); }
  .mobile-drawer { position: fixed; z-index: 91; inset: 0 auto 0 0; width: min(86vw, 300px); padding: 22px 18px; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); box-shadow: var(--shadow-lg); animation: slideIn .18s ease; }
  @keyframes slideIn { from { transform: translateX(-100%); } }
  .page-head { align-items: stretch; flex-direction: column; }
  .page-actions { justify-content: flex-start; }
  .page-actions .btn { flex: 1 1 auto; }
  .detail-banner { align-items: stretch; flex-direction: column; }
  .detail-title-row { align-items: flex-start; }
  .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
  .form-span-2 { grid-column: auto; }
  .manual-grid, .answer-grid { grid-template-columns: 1fr; }
  .score-card { grid-template-columns: 1fr; }
  .result-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .image-toolbar { align-items: flex-start; flex-direction: column; }
  .image-toolbar-actions { width: 100%; justify-content: flex-start; }
  .scan-choice-grid { grid-template-columns: 1fr; }
  .scan-choice { min-height: 145px; }
}

@media (max-width: 560px) {
  .login-screen { padding: 12px; }
  .login-card { border-radius: 25px; }
  .login-hero { padding: 30px 20px 25px; }
  .login-body { padding: 21px 18px 24px; }
  .role-tab { font-size: 10px; gap: 4px; }
  .stats-grid, .card-grid, .franchise-grid { grid-template-columns: 1fr; }
  .stat-card { padding: 16px; }
  .entity-card { min-height: 220px; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; justify-content: center; }
  .modal-layer { padding: 8px; align-items: end; }
  .modal { max-height: 96vh; border-radius: 22px 22px 0 0; }
  .modal-head, .modal-body, .modal-foot { padding-left: 16px; padding-right: 16px; }
  .modal-foot .btn { flex: 1; }
  .result-topbar { padding: 10px; }
  .result-topbar .btn span { display: none; }
  .result-content { width: min(100% - 16px, 1050px); padding-top: 12px; }
  .result-stats { grid-template-columns: 1fr 1fr; }
  .score-card { padding: 16px; }
  th, td { padding-left: 11px; padding-right: 11px; }
  .scanner-layer { padding: 0; }
  .scanner-dialog { width: 100%; max-height: 100vh; height: 100vh; border-radius: 0; }
  .scanner-body { padding: 14px; }
  .preview-tools { align-items: stretch; flex-direction: column; }
  .preview-tools .btn { width: 100%; }
  .camera-stage { height: calc(100dvh - 142px); min-height: 360px; max-height: none; border-radius: 12px; }
  .camera-stage video { min-height: 0; border-radius: 12px; }
  .camera-controls { gap: 7px; }
  .camera-control { min-width: 40px; min-height: 40px; }
  .capture-button { width: 60px; height: 60px; }
  #toast-root { left: 10px; right: 10px; top: 10px; }
  .toast { min-width: 0; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
