:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --radius: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

.ic { width: 16px; height: 16px; flex: none; display: inline-block; }
h3 .ic, .h3 .ic { vertical-align: -2px; margin-right: 6px; color: var(--primary); }
h2 .ic { vertical-align: -2px; margin-right: 6px; color: var(--primary); }
h1 .ic { vertical-align: -3px; margin-right: 8px; }
.btn .ic { vertical-align: -2px; margin-right: 4px; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at center, rgba(100,116,139,.12) 1.2px, transparent 1.3px), var(--bg);
  background-size: 24px 24px;
  color: var(--text);
  min-height: 100vh;
}

/* ===== AUTH PAGE ===== */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #9333ea 100%);
}

.auth-card {
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  padding: 40px;
  width: 100%;
  max-width: 420px;
}

.auth-card h1 {
  font-size: 24px;
  text-align: center;
  margin-bottom: 6px;
}

.auth-card .subtitle {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 24px;
}

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #f8fafc;
  transition: border .2s, box-shadow .2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.15);
  background: #fff;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: filter .2s, transform .1s;
  color: #fff;
  background: var(--primary);
}

.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(.98); }

.btn-block { width: 100%; }

.btn-green { background: var(--success); }
.btn-red { background: var(--danger); }
.btn-blue { background: var(--primary); }
.btn-ghost { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ===== TAB SWITCH ===== */
.tab-bar {
  display: flex;
  background: #f1f5f9;
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 24px;
}

.tab-bar button {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-radius: 8px;
  font-family: inherit;
  transition: all .2s;
}

.tab-bar button.active {
  background: var(--card);
  color: var(--primary);
  box-shadow: var(--shadow);
}

.hidden { display: none !important; }

.alert {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
}

.alert-error { background: #fee2e2; color: #991b1b; }
.alert-success { background: #dcfce7; color: #166534; }

/* ===== LAYOUT / DASHBOARD ===== */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.topbar .brand {
  font-weight: 700;
  font-size: 18px;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar .brand .dot {
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--primary);
}

.topbar .brand .dot .ic { width: 20px; height: 20px; }

.topbar .user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.badge {
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.badge-student { background: #dbeafe; color: #1d4ed8; }
.badge-teacher { background: #dcfce7; color: #166534; }
.badge-admin { background: #fef3c7; color: #92400e; }
.badge-attestation { background: #f3e8ff; color: #7c3aed; }

.container { max-width: 1100px; margin: 0 auto; padding: 24px; }

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

.page-head h2 { font-size: 22px; }

/* ===== CARDS / GRID ===== */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  transition: transform .15s, box-shadow .15s;
}

.card.hoverable:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 20px rgba(0,0,0,.12);
}

.card h3 { font-size: 16px; margin-bottom: 8px; }

.card .meta { font-size: 13px; color: var(--muted); margin-top: 10px; }
.card .card-actions { margin-top: 14px; display: flex; gap: 8px; flex-wrap: wrap; }

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.stat-card .num { font-size: 28px; font-weight: 800; color: var(--primary); }
.stat-card .lbl { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* ===== TABLES ===== */
.table-wrap {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

table { width: 100%; border-collapse: collapse; }

th, td {
  padding: 12px 16px;
  text-align: left;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th { background: #f8fafc; font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

/* ===== SCORE PILLS ===== */
.score-pill {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.score-good { background: #dcfce7; color: #166534; }
.score-mid { background: #fef3c7; color: #92400e; }
.score-low { background: #fee2e2; color: #991b1b; }

/* ===== TEST TAKING ===== */
.test-header {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.timer {
  font-size: 20px;
  font-weight: 800;
  color: var(--danger);
  font-variant-numeric: tabular-nums;
}

.timer.warning { animation: pulse 1s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .4; }
}

.question-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 16px;
}

.question-card .q-num {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 12px;
}

.question-card .q-text { font-size: 16px; font-weight: 600; margin-bottom: 16px; }

.options { display: flex; flex-direction: column; gap: 10px; }

.option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: all .2s;
  font-size: 14px;
}

.option:hover { border-color: var(--primary); background: #eef2ff; }

.option input { accent-color: var(--primary); }

.option.selected, .option:has(input:checked) {
  border-color: var(--primary);
  background: #eef2ff;
}

.option.correct {
  border-color: var(--success);
  background: #dcfce7;
}

.option.wrong {
  border-color: var(--danger);
  background: #fee2e2;
}

.option .mark { margin-left: auto; font-weight: 700; display: inline-flex; align-items: center; }
    .option .mark .ic { width: 15px; height: 15px; }

.test-actions {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
}

/* ===== RESULT VIEW ===== */
.result-hero {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px;
  text-align: center;
  margin-bottom: 24px;
}

.result-hero .big {
  font-size: 56px;
  font-weight: 800;
}

.result-hero .sub { font-size: 16px; color: var(--muted); margin-top: 8px; }

/* ===== QUESTION EDITOR (teacher) ===== */
.editor-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
  border-left: 4px solid var(--primary);
}

.editor-card .opt-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}

.editor-card .opt-row input[type="text"] { flex: 1; }

.editor-card .opt-row label { font-size: 13px; font-weight: 600; min-width: 90px; }

/* ===== QUESTIONS LIST ===== */
.q-list-item {
  background: var(--card);
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

/* ===== UTIL ===== */
.text-muted { color: var(--muted); }
.text-sm { font-size: 13px; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.flex { display: flex; gap: 8px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 40px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 2px dashed var(--border);
}

.section-title {
  font-size: 18px;
  font-weight: 700;
  margin: 24px 0 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.spinner {
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  animation: spin 1s linear infinite;
  margin: 20px auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== ADMIN TABS ===== */
.admin-tabs {
  display: flex;
  gap: 6px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px;
  margin-bottom: 24px;
  overflow-x: auto;
}

.admin-tabs button {
  flex: 1;
  min-width: 130px;
  padding: 10px 16px;
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-radius: 8px;
  font-family: inherit;
  transition: all .2s;
  white-space: nowrap;
}

.admin-tabs button:hover { background: #f1f5f9; color: var(--text); }

.admin-tabs button.active {
  background: var(--primary);
  color: #fff;
}

/* O'quvchilar bo'limi ichidagi kichik yorliqlar */
.admin-tabs.sub-tabs {
  padding: 4px;
  margin-bottom: 16px;
}
.admin-tabs.sub-tabs button {
  min-width: 110px;
  padding: 7px 14px;
  font-size: 13px;
}

/* Fanlar ro'yxati */
.subject-input {
  flex: 1;
  min-width: 170px;
  max-width: 320px;
}
.subject-list { list-style: none; padding: 0; margin: 0; }
.subject-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 14px;
  margin-bottom: 8px;
}
.subject-list-item .spacer { flex: 1; }
.subject-count { white-space: nowrap; }

/* ===== SUBJECT CHIP ===== */
.subject-chip {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #eef2ff;
  color: var(--primary);
}

.target-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.target-student { background: #dbeafe; color: #1d4ed8; }
.target-teacher { background: #dcfce7; color: #166534; }
.target-attestation { background: #f3e8ff; color: #7c3aed; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.modal-card {
  background: #fff;
  border-radius: 16px;
  padding: 28px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  position: relative;
}

.modal-card h2 { margin-bottom: 16px; font-size: 20px; }
.modal-card .close-x { position: absolute; top: 12px; right: 14px; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal-card .close-x:hover { color: var(--danger); }

/* ===== WORD IMPORT ===== */
.word-format {
  background: #f8fafc;
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.7;
  margin: 10px 0;
  color: var(--muted);
}

.word-textarea {
  width: 100%;
  min-height: 220px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
  resize: vertical;
  box-sizing: border-box;
}

.word-textarea:focus { outline: none; border-color: var(--primary); }

/* ===== BAR CHART (statistika) ===== */
.bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.bar-row .lbl { min-width: 130px; font-size: 13px; font-weight: 600; }

.bar-track {
  flex: 1;
  height: 18px;
  background: #f1f5f9;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), #7c3aed);
  transition: width .4s;
}

.bar-row .val { min-width: 48px; text-align: right; font-size: 13px; font-weight: 700; }

.panel-section-title {
  font-size: 16px;
  font-weight: 700;
  margin: 6px 0 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.float-right { margin-left: auto; }

.welcome-line { font-size: 14px; color: var(--muted); margin-bottom: 18px; }

/* ===== GRUP KARTALARI ===== */
.group-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}

.group-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  cursor: pointer;
  text-align: center;
  border-top: 4px solid var(--primary);
  transition: transform .15s, box-shadow .15s;
  position: relative;
}

.group-card:hover { transform: translateY(-3px); box-shadow: 0 10px 20px rgba(0,0,0,.12); }

.group-card .g-icon { font-size: 26px; color: var(--primary); display: inline-flex; }
    .group-card .g-icon .ic { width: 30px; height: 30px; }
.group-card .g-name { font-weight: 700; font-size: 16px; margin-top: 8px; }
.group-card .g-count { font-size: 13px; color: var(--muted); margin-top: 4px; }

.group-card .g-del {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  border-radius: 6px;
  padding: 2px 6px;
}

.group-card .g-del:hover { background: #fee2e2; color: var(--danger); }

/* ===== IMPORT PANELI ===== */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.import-hint {
  font-size: 12px;
  color: var(--muted);
  background: #f8fafc;
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  margin-top: 10px;
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}

.btn-outline:hover { background: #eef2ff; }

/* SPA sahifa ko'rsatish */
.view { display: none; }
.view.active { display: block; }

.topbar-nav-host a { text-decoration: none; }

/* Kirish oynasi: rol belgisi, orqaga, demo */
.role-label {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 12px;
}
.role-label.student { background: #dbeafe; color: #1d4ed8; }
.role-label.teacher { background: #dcfce7; color: #166534; }
.role-label.admin { background: #fef3c7; color: #92400e; }

.back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  margin-bottom: 16px;
}
.back:hover { color: var(--primary); }

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

/* Natijalar jadvali hujayralari tekislash */
.table-wrap table td { vertical-align: middle; }