/* ComQua UI — порт из ComQuaAgent-main/src/index.css */

:root {
  color-scheme: light;
  --bg: #FAFBFC;
  --surface: #F3F4F6;
  --surface-hover: #E5E7EB;
  --accent: #2563EA;
  --accent-secondary: #3B81EF;
  --text-primary: #111828;
  --text-secondary: #6B7380;
  --success: #10B982;
  --warning: #F39E0B;
  --error: #EE4444;
  --border: #D1D5DB;
  --chart-1: #3B82F6;
  --chart-2: #10B981;
  --chart-3: #F59E0B;
  --chart-4: #EF4444;
  --chart-5: #8B5CF6;
  --chart-6: #EC4899;
  --chart-bg-hover: rgba(59, 130, 246, 0.1);
  --chart-grid: #D1D5DB;
  --card-shadow: 0 1px 3px rgba(15, 23, 42, 0.1), 0 1px 2px -1px rgba(15, 23, 42, 0.08);
  --background: var(--bg);
  --foreground: var(--text-primary);
  --card: var(--surface);
  --accent-foreground: #FFFFFF;
  --font-size-h1: 40px;
  --font-size-h2: 32px;
  --font-size-h3: 24px;
  --font-size-body: 14px;
  --font-size-small: 12px;
  --font-size-caption: 11px;
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 0.75rem;
  --spacing-lg: 1rem;
  --spacing-xl: 1.5rem;
  --spacing-2xl: 2rem;
  --spacing-3xl: 3rem;
  --spacing-4xl: 4rem;
  --transition-fast: 0.15s ease-in-out;
  --transition-base: 0.2s ease-in-out;
  --transition-slow: 0.3s ease-in-out;
  --ease-smooth: cubic-bezier(0.22, 1, 0.36, 1);
  --sidebar-width: 320px;
  --sidebar-collapsed: 64px;
  --header-height: 64px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14161C;
  --surface: #1C1E26;
  --surface-hover: rgba(255, 255, 255, 0.06);
  --accent: #4C8AF5;
  --accent-hover: #7BA4FF;
  --accent-secondary: #3B81EF;
  --text-primary: #FEFAF9;
  --text-secondary: #79818C;
  --success: #3BA982;
  --warning: #A6AA3B;
  --error: #873C3A;
  --border: #79818C;
  --card-shadow: none;
  --chart-1: #60A5FA;
  --chart-2: #34D399;
  --chart-3: #FBBF24;
  --chart-4: #F87171;
  --chart-5: #A78BFA;
  --chart-6: #F472B6;
  --chart-bg-hover: rgba(255, 255, 255, 0.05);
  --chart-grid: #27272A;
}

[data-theme="light"] {
  color-scheme: light;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  background: var(--bg);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", "Helvetica Neue", Arial, sans-serif;
  font-size: var(--font-size-body);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.45s var(--ease-smooth), color 0.45s var(--ease-smooth);
}

h1 { font-size: var(--font-size-h1); font-weight: 600; line-height: 1.2; color: var(--text-primary); }
h2 { font-size: var(--font-size-h2); font-weight: 600; line-height: 1.3; color: var(--text-primary); }
h3 { font-size: var(--font-size-h3); font-weight: 600; line-height: 1.4; color: var(--text-primary); }

button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button, a, input, select, textarea { transition: all var(--transition-base); }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-secondary); border-radius: 3px; opacity: 0.5; }
::-webkit-scrollbar-thumb:hover { opacity: 0.8; }

/* Typography utilities */
.text-h1 { font-size: var(--font-size-h1); font-weight: 600; line-height: 1.2; }
.text-h2 { font-size: var(--font-size-h2); font-weight: 600; line-height: 1.3; }
.text-h3 { font-size: var(--font-size-h3); font-weight: 600; line-height: 1.4; }
.text-body { font-size: var(--font-size-body); }
.text-small { font-size: var(--font-size-small); }
.text-caption { font-size: var(--font-size-caption); text-transform: uppercase; letter-spacing: 0.05em; }
.text-secondary { color: var(--text-secondary); }
.text-primary { color: var(--text-primary); }
.text-accent { color: var(--accent); }
.text-error { color: var(--error); }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.uppercase { text-transform: uppercase; }
.tracking-wider { letter-spacing: 0.05em; }

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--card-shadow);
  transition: box-shadow 0.45s var(--ease-smooth), border-color 0.35s var(--ease-smooth), transform 0.45s var(--ease-smooth);
}

@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .card:hover {
    box-shadow: var(--card-shadow), 0 12px 40px -16px rgba(15, 23, 42, 0.14);
    border-color: color-mix(in srgb, var(--accent) 28%, var(--border));
  }
  [data-theme="dark"] .card:hover {
    box-shadow: 0 14px 48px -12px rgba(0, 0, 0, 0.55);
    border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-weight: 500;
  border-radius: 4px;
  padding: 0.5rem 1rem;
  font-size: var(--font-size-body);
  cursor: pointer;
  border: none;
  transition: all var(--transition-base);
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary, .btn-primary.btn {
  background: var(--accent);
  color: var(--accent-foreground);
  padding: 12px 24px;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-secondary); }
[data-theme="dark"] .btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-hover); }

.btn-outline {
  background: transparent;
  color: var(--accent);
  border: 2px solid var(--accent);
}
.btn-outline:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 10%, transparent); }

.btn-ghost {
  background: transparent;
  color: var(--text-primary);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-hover); }

.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover:not(:disabled) { opacity: 0.9; }

.btn-icon {
  padding: 0.5rem;
  border-radius: 9999px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
}
.btn-icon:hover { background: var(--surface-hover); color: var(--text-primary); }
.btn-icon.danger:hover { background: color-mix(in srgb, var(--error) 10%, transparent); color: var(--error); }

.btn-full { width: 100%; }

/* Form */
.input-group { margin-bottom: 1.5rem; }
.input-label {
  display: block;
  font-size: var(--font-size-caption);
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}
.input-wrap { position: relative; }
.input-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.25rem;
  height: 1.25rem;
  color: var(--text-secondary);
  pointer-events: none;
}
.input, .textarea, .select {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: var(--font-size-body);
  font-family: inherit;
}
.input.with-icon { padding-left: 2.5rem; }
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent);
  border-color: transparent;
}
.input::placeholder, .textarea::placeholder { color: var(--text-secondary); }
.textarea { resize: vertical; min-height: 120px; }

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.6rem;
  border-radius: 9999px;
  font-size: var(--font-size-small);
  font-weight: 500;
}
.badge-grade-5 { background: color-mix(in srgb, var(--success) 20%, transparent); color: var(--success); }
.badge-grade-4 { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); }
.badge-grade-3 { background: color-mix(in srgb, var(--warning) 20%, transparent); color: var(--warning); }
.badge-grade-2 { background: color-mix(in srgb, var(--error) 20%, transparent); color: var(--error); }

/* Alerts / Toast */
.alert {
  padding: 0.75rem 1rem;
  border-radius: 4px;
  font-size: var(--font-size-small);
  border: 1px solid var(--border);
}
.alert-error { background: color-mix(in srgb, var(--error) 10%, var(--surface)); color: var(--error); border-color: var(--error); }
.alert-success { background: color-mix(in srgb, var(--success) 10%, var(--surface)); color: var(--success); border-color: var(--success); }

.toast {
  position: fixed;
  top: calc(var(--header-height) + 1rem);
  right: 1.5rem;
  z-index: 200;
  max-width: min(360px, calc(100vw - 2rem));
  padding: 0.75rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: 0 10px 40px rgba(0,0,0,0.15);
  backdrop-filter: blur(8px);
  animation: slideDown 0.3s ease-out;
  font-size: var(--font-size-small);
  line-height: 1.4;
  pointer-events: none;
}

/* Loading */
.spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.spinner-accent {
  border-color: color-mix(in srgb, var(--accent) 20%, transparent);
  border-top-color: var(--accent);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Background effects */
.app-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.app-bg canvas { width: 100%; height: 100%; display: block; }

.nebula-blob {
  position: absolute;
  border-radius: 9999px;
  filter: blur(64px);
  opacity: 0.18;
  will-change: transform;
}
[data-theme="dark"] .nebula-blob { filter: blur(70px); opacity: 0.22; }
.nebula-blob-1 {
  width: 44vw; height: 44vw; left: -8vw; top: -8vh;
  background: radial-gradient(circle at 30% 30%, var(--accent), transparent 70%);
  animation: nebula-float-1 28s ease-in-out infinite;
}
.nebula-blob-2 {
  width: 38vw; height: 38vw; right: -6vw; top: 10vh;
  background: radial-gradient(circle at 50% 50%, var(--accent-secondary), transparent 70%);
  animation: nebula-float-2 34s ease-in-out infinite;
}
.nebula-blob-3 {
  width: 40vw; height: 40vw; left: 25vw; bottom: -14vh;
  background: radial-gradient(circle at 40% 60%, var(--accent), transparent 72%);
  animation: nebula-float-3 31s ease-in-out infinite;
}
@keyframes nebula-float-1 { 50% { transform: translate(7vw, 6vh) scale(1.08); } }
@keyframes nebula-float-2 { 50% { transform: translate(-6vw, 8vh) scale(1.1); } }
@keyframes nebula-float-3 { 50% { transform: translate(5vw, -7vh) scale(1.06); } }

/* Animations */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

.animate-slide-up { animation: slideUp 0.3s ease-out; }
.animate-scale { animation: scaleIn 0.2s ease-out; }

.stagger-children > * { animation: fadeUpStagger 0.5s var(--ease-smooth) both; }
.stagger-children > *:nth-child(1) { animation-delay: 0.03s; }
.stagger-children > *:nth-child(2) { animation-delay: 0.06s; }
.stagger-children > *:nth-child(3) { animation-delay: 0.09s; }
.stagger-children > *:nth-child(4) { animation-delay: 0.12s; }
@keyframes fadeUpStagger { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

@media (prefers-reduced-motion: reduce) {
  .nebula-blob, .stagger-children > *, .animate-slide-up { animation: none !important; }
}

/* ========== LOGIN PAGE ========== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  position: relative;
  z-index: 1;
}
.login-card { width: 100%; max-width: 28rem; padding: 2rem; }
.login-logo { text-align: center; margin-bottom: 3rem; }
.login-footer {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  text-align: center;
}

/* ========== APP LAYOUT (ComQua) ========== */
.app-shell { min-height: 100vh; position: relative; }

.app-header {
  position: fixed;
  top: 0;
  right: 0;
  height: var(--header-height);
  z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
  transition: left 0.3s var(--ease-smooth), background-color 0.45s var(--ease-smooth), border-color 0.45s var(--ease-smooth);
  left: var(--sidebar-width);
}
[data-theme="dark"] .app-header {
  box-shadow: 0 1px 0 var(--border);
}
.app-shell.sidebar-collapsed .app-header { left: var(--sidebar-collapsed); }

.app-header-logo {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: var(--font-size-h3);
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  max-width: calc(100% - 18rem);
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
  position: relative;
  z-index: 2;
  flex-shrink: 0;
}

.user-avatar {
  width: 2rem;
  height: 2rem;
  border-radius: 9999px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.app-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  z-index: 30;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width 0.3s var(--ease-smooth), background-color 0.45s var(--ease-smooth), border-color 0.45s var(--ease-smooth);
}
.app-shell.sidebar-collapsed .app-sidebar { width: var(--sidebar-collapsed); }

.sidebar-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.app-shell.sidebar-collapsed .sidebar-header { padding: 0 0.75rem; justify-content: center; }
.app-shell.sidebar-collapsed .sidebar-title { display: none; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 0;
}

.sidebar-section-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 1.5rem;
  font-size: var(--font-size-caption);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: none;
  border: none;
  cursor: default;
  text-align: left;
}
.app-shell.sidebar-collapsed .sidebar-section-title { justify-content: center; padding: 0.5rem; }
.app-shell.sidebar-collapsed .sidebar-section-title span { display: none; }

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  padding: 0.625rem 1.5rem;
  font-size: var(--font-size-body);
  color: var(--text-primary);
  background: none;
  border: none;
  border-radius: 0 8px 8px 0;
  cursor: pointer;
  transition: all 0.2s var(--ease-smooth);
}
.sidebar-link:hover {
  background: color-mix(in srgb, var(--surface) 90%, var(--accent));
  transform: translateX(2px);
}
.sidebar-link.active {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  color: var(--accent);
  font-weight: 500;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 25%, transparent);
}
.app-shell.sidebar-collapsed .sidebar-link { justify-content: center; padding: 0.75rem; }
.app-shell.sidebar-collapsed .sidebar-link span { display: none; }

.sidebar-link svg { width: 1rem; height: 1rem; flex-shrink: 0; }

.sidebar-link-admin {
  margin-bottom: 0.25rem;
  color: color-mix(in srgb, var(--accent) 85%, #fff);
}
.sidebar-link-admin.active {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}
.sidebar-divider {
  height: 1px;
  margin: 0.5rem 1.25rem 0.75rem;
  background: var(--border);
}

.app-main {
  position: relative;
  z-index: 10;
  margin-left: var(--sidebar-width);
  padding-top: var(--header-height);
  min-height: 100vh;
  transition: margin-left 0.3s var(--ease-smooth);
}
.app-shell.sidebar-collapsed .app-main { margin-left: var(--sidebar-collapsed); }

.page-content {
  width: 100%;
  max-width: none;
  padding: 1.5rem 2.5rem 2.5rem;
  animation: slideUp 0.3s ease-out;
}

.page-title { font-size: 1.75rem; font-weight: 600; margin-bottom: 0.25rem; }
.page-subtitle { color: var(--text-secondary); margin-bottom: 1.5rem; }

/* Theme dropdown */
.theme-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 0.5rem);
  width: 15rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.12);
  padding: 0.5rem;
  z-index: 50;
  animation: scaleIn 0.2s ease-out;
  transform-origin: top right;
}
[data-theme="dark"] .theme-dropdown {
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
.theme-dropdown-section {
  font-size: var(--font-size-caption);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  padding: 0.25rem 0.5rem 0.5rem;
}
.theme-option {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  padding: 0.5rem;
  border: none;
  background: none;
  border-radius: 6px;
  font-size: var(--font-size-body);
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
}
.theme-option:hover { background: var(--bg); }
.theme-option.active { background: color-mix(in srgb, var(--accent) 10%, transparent); color: var(--accent); }
.theme-option svg { width: 1rem; height: 1rem; flex-shrink: 0; }
.theme-divider { border-top: 1px solid var(--border); margin: 0.5rem 0; }
.bg-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.375rem; padding: 0 0.25rem 0.25rem; }
.bg-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem 0.25rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: none;
  font-size: 10px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
}
.bg-option:hover { color: var(--text-primary); background: var(--bg); }
.bg-option.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); color: var(--accent); }
.bg-option svg { width: 0.875rem; height: 0.875rem; }

.theme-toggle-wrap { position: relative; }

.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 9999px;
  background: var(--bg);
  color: var(--text-primary);
  cursor: pointer;
  flex-shrink: 0;
}
.theme-toggle-btn:hover {
  background: var(--surface-hover);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  color: var(--accent);
}
.theme-toggle-btn svg {
  width: 1.15rem;
  height: 1.15rem;
  flex-shrink: 0;
}

.auth-theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 50;
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}
.stat-card { padding: 1.5rem; }
.stat-card .label {
  font-size: var(--font-size-caption);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}
.stat-card .value { font-size: var(--font-size-h1); font-weight: 600; line-height: 1.1; }

/* Panels */
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: slideUp 0.25s ease-out; }

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.5rem;
}

/* Панель проверки */
.check-workflow {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}
.check-workflow .card { height: 100%; }
.check-panel-full { width: 100%; }

.result-section {
  width: 100%;
  margin-top: 1.5rem;
}
.result-header {
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

/* Table */
.data-table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead { background: var(--surface); border-bottom: 1px solid var(--border); }
.data-table th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-size: var(--font-size-caption);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  font-weight: 500;
}
.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}
.data-table tbody tr:hover td { background: var(--surface-hover); }

/* Upload */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition-base), background var(--transition-base);
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 5%, transparent);
}
.upload-zone input { display: none; }

/* Result */
.result-box {
  margin-top: 1.5rem;
  padding: 1.5rem;
  border-left: 4px solid var(--accent);
}
.result-grade {
  font-size: 3rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  background: none;
}
.result-grade.grade-5 { color: var(--success); }
.result-grade.grade-4 { color: var(--accent); }
.result-grade.grade-3 { color: var(--warning); }
.result-grade.grade-2 { color: var(--error); }
.result-meta { display: flex; gap: 1.5rem; flex-wrap: wrap; margin-top: 0.75rem; }

.assignment-preview {
  max-height: min(60vh, 520px);
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: var(--font-size-small);
  line-height: 1.6;
  padding: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.hidden { display: none !important; }

.desktop-only { display: block; }
.mobile-only { display: none; }

@media (min-width: 769px) {
  .hidden-mobile { display: inline; }
  .mobile-only { display: none !important; }
}

@media (max-width: 768px) {
  .hidden-mobile { display: none; }
  .desktop-only { display: none !important; }
  .mobile-only { display: block; }
  .mobile-only.btn-icon,
  .mobile-only.mobile-nav-item {
    display: inline-flex;
  }
  .mobile-only.mobile-bottom-nav {
    display: flex;
  }

  .app-sidebar {
    display: flex;
    width: min(88vw, 300px);
    z-index: 70;
    transform: translateX(-105%);
    transition: transform 0.3s var(--ease-smooth);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.18);
  }
  [data-theme="dark"] .app-sidebar {
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.5);
  }
  .app-shell.mobile-nav-open .app-sidebar {
    transform: translateX(0);
  }
  .app-shell.sidebar-collapsed .app-sidebar {
    width: min(88vw, 300px);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 65;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s var(--ease-smooth);
  }
  [data-theme="dark"] .sidebar-backdrop {
    background: rgba(0, 0, 0, 0.6);
  }
  .app-shell.mobile-nav-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .app-header {
    display: flex;
    left: 0 !important;
    gap: 0.35rem;
    padding: 0 0.75rem;
    padding-top: env(safe-area-inset-top, 0);
    overflow: visible;
  }
  .app-header-actions {
    gap: 0.25rem;
    overflow: visible;
  }
  .app-header-actions .theme-toggle-wrap {
    overflow: visible;
  }
  .app-header-logo {
    position: static;
    transform: none;
    flex: 1;
    text-align: center;
    font-size: 0.95rem;
    max-width: none;
    margin: 0 0.25rem;
  }
  .app-header-actions .theme-toggle-btn {
    width: 2.5rem;
    height: 2.5rem;
  }

  .app-main {
    margin-left: 0 !important;
    padding-top: calc(var(--header-height) + env(safe-area-inset-top, 0));
    padding-bottom: calc(4.75rem + env(safe-area-inset-bottom, 0));
  }

  .page-content {
    padding: 1rem 1rem 1.25rem;
  }
  .page-title {
    font-size: 1.35rem;
  }
  .page-subtitle {
    font-size: var(--font-size-small);
    margin-bottom: 1rem;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
  }
  .stat-card {
    padding: 1rem;
  }
  .stat-card .value {
    font-size: 1.5rem;
  }

  .grid-2,
  .check-workflow {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  .result-blocks {
    grid-template-columns: 1fr;
  }

  .data-table-wrap {
    -webkit-overflow-scrolling: touch;
    margin: 0 -0.25rem;
    padding: 0 0.25rem;
  }
  .data-table th,
  .data-table td {
    padding: 0.625rem 0.5rem;
    font-size: var(--font-size-caption);
  }

  .students-filters {
    padding: 0 1rem 0.5rem;
  }
  .students-filter-field {
    min-width: 100%;
  }
  .students-filter-hint,
  .table-pagination {
    padding-left: 1rem;
    padding-right: 1rem;
  }
  .table-pagination {
    flex-direction: column;
    align-items: stretch;
  }
  .table-pagination-controls {
    justify-content: space-between;
  }

  .check-mode-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .check-mode-tab {
    text-align: center;
    justify-content: center;
  }

  .admin-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.75rem;
  }
  .admin-tab {
    flex-shrink: 0;
    min-height: 2.75rem;
  }

  .site-gauges-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
  }

  .mobile-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 45;
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    gap: 0.25rem;
    padding: 0.35rem 0.5rem calc(0.35rem + env(safe-area-inset-bottom, 0));
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.08);
  }
  [data-theme="dark"] .mobile-bottom-nav {
    box-shadow: 0 -1px 0 var(--border);
  }
  .mobile-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    min-height: 3.25rem;
    padding: 0.35rem 0.25rem;
    border: none;
    border-radius: 8px;
    background: none;
    color: var(--text-secondary);
    font-size: 0.65rem;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.2s var(--ease-smooth), background 0.2s var(--ease-smooth);
  }
  .mobile-nav-item svg {
    width: 1.25rem;
    height: 1.25rem;
    flex-shrink: 0;
  }
  .mobile-nav-item.active {
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 10%, transparent);
  }

  .btn,
  .btn-primary,
  .btn-secondary {
    min-height: 2.75rem;
  }
  .btn-icon {
    min-width: 2.5rem;
    min-height: 2.5rem;
  }

  .login-page {
    padding: 1rem 0.75rem calc(1rem + env(safe-area-inset-bottom, 0));
    align-items: flex-start;
    padding-top: calc(3.5rem + env(safe-area-inset-top, 0));
  }
  .login-card {
    padding: 1.5rem;
    max-width: none;
  }
  .login-logo {
    margin-bottom: 1.75rem;
  }
  .auth-theme-toggle {
    top: calc(0.75rem + env(safe-area-inset-top, 0));
    right: 0.75rem;
  }

  .theme-dropdown .bg-grid {
    gap: 0.3rem;
  }
  .theme-dropdown .bg-option {
    font-size: 9px;
    line-height: 1.25;
    padding: 0.45rem 0.15rem;
    min-width: 0;
  }

  html,
  body {
    overflow-x: hidden;
    max-width: 100%;
  }
  .app-shell,
  .app-main,
  .page-content,
  .tab-panel,
  .card {
    max-width: 100%;
    min-width: 0;
  }
  .app-main {
    overflow-x: clip;
  }
  .stat-card .value {
    overflow-wrap: anywhere;
    word-break: break-word;
    font-size: clamp(1.25rem, 6vw, 1.75rem);
  }
  .result-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
  }
  .check-result-item > div:first-child {
    flex-direction: column;
    align-items: flex-start !important;
  }
  .input,
  .select,
  .textarea {
    max-width: 100%;
  }
  pre,
  code {
    max-width: 100%;
    overflow-x: auto;
  }

  .toast {
    top: auto;
    right: auto;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(5rem + env(safe-area-inset-bottom, 0));
    width: max-content;
    max-width: calc(100vw - 2rem);
    text-align: center;
    animation: toastSlideUp 0.3s ease-out;
  }

  @keyframes toastSlideUp {
    from { opacity: 0; transform: translateX(-50%) translateY(0.75rem); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
  }

  .student-search-results {
    max-height: min(50vh, 280px);
  }

  .result-header {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 0.75rem;
  }
  .result-header .result-grade {
    font-size: 2rem;
  }
}

.checkbox-cell input { width: 1rem; height: 1rem; accent-color: var(--accent); cursor: pointer; }
.file-link { color: var(--accent); text-decoration: none; font-size: var(--font-size-small); word-break: break-all; }
.file-link:hover { text-decoration: underline; }
.works-list { display: flex; flex-direction: column; gap: 0.5rem; }
.work-option {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition-base);
  background: var(--bg);
  min-width: 0;
  overflow: hidden;
}
.work-option:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.work-option.selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--bg));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 25%, transparent);
}
.work-option input { margin-top: 0.2rem; accent-color: var(--accent); flex-shrink: 0; }
.work-option-body { flex: 1; min-width: 0; overflow: hidden; }
.work-option-title {
  font-weight: 500;
  font-size: var(--font-size-small);
  line-height: 1.4;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.work-option-meta {
  font-size: var(--font-size-caption);
  color: var(--text-secondary);
  margin-top: 0.25rem;
  word-break: break-all;
  overflow-wrap: anywhere;
}
.check-result-item { padding: 1rem 0; border-bottom: 1px solid var(--border); }
.check-result-item:last-child { border-bottom: none; }

.result-work-meta {
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  line-height: 1.5;
}
.result-work-text {
  word-break: break-word;
  font-size: var(--font-size-small);
  line-height: 1.7;
}
.result-work-text.doc-content {
  white-space: normal;
}
.doc-content .doc-lead {
  margin: 0 0 1rem;
  color: var(--text-secondary);
  font-size: var(--font-size-caption);
}
.doc-content .doc-h {
  margin: 1.1rem 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.4;
}
.doc-content .doc-h-main {
  font-size: 1rem;
}
.doc-content .doc-h:first-child,
.doc-content .doc-lead + .doc-h {
  margin-top: 0;
}
.doc-content .doc-p {
  margin: 0 0 0.75rem;
  color: var(--text-primary);
}
.doc-content .doc-p:last-child {
  margin-bottom: 0;
}
.doc-content .doc-ul,
.doc-content .doc-ol {
  margin: 0.35rem 0 0.85rem 1.1rem;
  padding: 0;
}
.doc-content .doc-ul li,
.doc-content .doc-ol li {
  margin-bottom: 0.4rem;
  padding-left: 0.15rem;
}
.doc-content .doc-ul li::marker {
  color: var(--accent);
}
.doc-content .doc-ol li::marker {
  font-weight: 600;
  color: var(--accent);
}
.doc-content strong {
  font-weight: 600;
  color: var(--text-primary);
}

.result-blocks {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.25rem;
  align-items: stretch;
  width: 100%;
}
.result-block { padding: 0; overflow: hidden; display: flex; flex-direction: column; height: 100%; }
.result-block-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--accent) 5%, var(--surface));
}
.result-block-header h4 { font-size: var(--font-size-body); font-weight: 600; margin: 0; }
.result-block-num {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 9999px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-small);
  font-weight: 600;
  flex-shrink: 0;
}
.result-block-body {
  padding: 1.25rem;
  font-size: var(--font-size-small);
  line-height: 1.7;
  white-space: pre-wrap;
  flex: 1;
  overflow-y: auto;
  min-height: 200px;
  max-height: 520px;
}
.result-block-body--rich {
  white-space: normal;
}
.result-markdown strong { font-weight: 600; color: var(--text-primary); }
.result-meta-row { margin-bottom: 0.5rem; }
.result-meta-row strong { color: var(--text-primary); }
.result-header .result-grade {
  font-size: 2.5rem;
  margin-top: 0.25rem;
  background: none;
}

.students-filters {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: flex-end;
  padding: 0 1.5rem 0.5rem;
}
.students-filter-field {
  flex: 1;
  min-width: 160px;
  margin: 0;
}
.students-filter-hint {
  padding: 0 1.5rem 0.75rem;
  margin: 0;
}

.table-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.75rem 1.5rem 1.25rem;
  border-top: 1px solid var(--border);
}
.table-pagination-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.select-compact {
  width: auto;
  min-width: 4.5rem;
  padding: 0.35rem 0.5rem;
  font-size: var(--font-size-small);
}
.btn-compact {
  padding: 0.35rem 0.75rem;
  font-size: var(--font-size-small);
}

.student-search-wrap {
  position: relative;
}
.student-combobox-control {
  position: relative;
  display: flex;
  align-items: stretch;
}
.student-combobox-input {
  padding-right: 2.75rem;
}
.student-combobox-toggle {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 2.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 0 6px 6px 0;
}
.student-combobox-toggle:hover {
  color: var(--accent);
  background: var(--surface-hover);
}
.student-combobox-toggle.open svg {
  transform: rotate(180deg);
}
.student-combobox-toggle svg {
  transition: transform 0.2s var(--ease-smooth);
}
.student-search-results {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 0.25rem);
  z-index: 20;
  max-height: 280px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow-md);
}
.student-search-results-header {
  padding: 0.5rem 0.875rem;
  font-size: var(--font-size-caption);
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, var(--bg));
  position: sticky;
  top: 0;
  z-index: 1;
}
.student-search-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.625rem 0.875rem;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-primary);
  font-size: var(--font-size-small);
}
.student-search-item:hover,
.student-search-item:focus,
.student-search-item.active {
  background: var(--surface-hover);
}
.student-search-item.active {
  color: var(--accent);
}
.student-search-item strong {
  display: block;
  font-weight: 500;
}
.student-search-empty {
  padding: 0.75rem 0.875rem;
  font-size: var(--font-size-small);
  color: var(--text-secondary);
}
.student-search-loading {
  padding: 0.75rem 0.875rem;
  font-size: var(--font-size-small);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.check-mode-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.check-mode-tab {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: var(--font-size-small);
  transition: all var(--transition-base);
}
.check-mode-tab:hover { color: var(--text-primary); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.check-mode-tab.active {
  border-color: var(--accent);
  color: var(--text-primary);
  background: color-mix(in srgb, var(--accent) 10%, var(--bg));
}

.admin-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
  flex-wrap: wrap;
}
.admin-tab {
  padding: 0.5rem 1rem;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: var(--font-size-small);
  transition: all var(--transition-base);
}
.admin-tab:hover { color: var(--text-primary); background: color-mix(in srgb, var(--accent) 6%, transparent); }
.admin-tab.active {
  color: var(--text-primary);
  border-color: var(--border);
  background: var(--surface);
}
.admin-section { display: none; }
.admin-section.active { display: block; }

.site-gauges-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}
.gauge-card {
  padding: 1.25rem 1rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  text-align: center;
}
.gauge-card-label {
  font-size: var(--font-size-caption);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.25rem;
}
.gauge-card-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  margin-top: -0.35rem;
}
.gauge-card-sub {
  font-size: var(--font-size-caption);
  color: var(--text-secondary);
  margin-top: 0.15rem;
}
.gauge-svg {
  width: 100%;
  max-width: 220px;
  height: auto;
  display: block;
  margin: 0 auto;
}
.gauge-track {
  fill: none;
  stroke: color-mix(in srgb, var(--border) 80%, transparent);
  stroke-width: 14;
  stroke-linecap: round;
}
.gauge-fill {
  fill: none;
  stroke-width: 14;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.6s ease;
}
.site-daily-gauges {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 0.75rem 0.5rem;
}
.daily-gauge {
  text-align: center;
}
.daily-gauge .gauge-svg {
  max-width: 72px;
}
.daily-gauge .gauge-track,
.daily-gauge .gauge-fill {
  stroke-width: 8;
}
.daily-gauge-value {
  font-size: 0.75rem;
  font-weight: 600;
  margin-top: -0.2rem;
}
.daily-gauge-date {
  font-size: 0.65rem;
  color: var(--text-secondary);
  margin-top: 0.1rem;
}

.login-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}
.login-tab {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: var(--font-size-small);
}
.login-tab.active {
  border-color: var(--accent);
  color: var(--text-primary);
  background: color-mix(in srgb, var(--accent) 8%, var(--bg));
}

.btn-sm { padding: 0.35rem 0.65rem; font-size: var(--font-size-caption); }
.badge-success { background: color-mix(in srgb, #22c55e 20%, transparent); color: #4ade80; }
.badge-neutral { background: color-mix(in srgb, var(--text-secondary) 15%, transparent); color: var(--text-secondary); }
.badge-error { background: color-mix(in srgb, var(--error) 20%, transparent); color: var(--error); }

@media (max-width: 1200px) {
  .check-workflow { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .result-blocks { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 768px) {
  .text-h1, .stat-card .value { font-size: 28px; }
  .site-gauges-grid {
    grid-template-columns: 1fr;
  }
}
