:root {
  --app-bg: #f5f7fa;
  --app-panel: #ffffff;
  --app-text: #17202a;
  --app-muted: #5f6f80;
  --app-line: #d9e0e7;
  --app-primary: #2563eb;
  --app-success: #16875a;
  --app-warning: #b7791f;
  --app-danger: #c2412f;
}

* {
  box-sizing: border-box;
}

body {
  background: var(--app-bg);
  color: var(--app-text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

.app-body {
  min-height: 100vh;
}

.auth-body {
  min-height: 100vh;
  background:
    linear-gradient(rgba(23, 32, 42, 0.58), rgba(23, 32, 42, 0.72)),
    url("https://images.unsplash.com/photo-1499750310107-5fef28a66643?auto=format&fit=crop&w=1800&q=80") center / cover fixed;
}

.app-main {
  padding-top: 24px;
  padding-bottom: 40px;
}

.app-nav {
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--app-line);
  box-shadow: 0 8px 22px rgba(23, 32, 42, 0.05);
}

.navbar-brand {
  color: var(--app-primary);
  font-weight: 800;
  letter-spacing: 0;
}

.nav-link {
  color: #36495d;
  font-weight: 600;
}

.nav-link:hover,
.nav-link:focus {
  color: var(--app-primary);
}

.app-panel,
.metric,
.question-shell,
.auth-panel {
  background: var(--app-panel);
  border: 1px solid var(--app-line);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(23, 32, 42, 0.06);
}

.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(430px, 100%);
  padding: 28px;
}

.auth-brand {
  color: #ffffff;
  text-align: center;
  margin-bottom: 18px;
}

.auth-brand h1 {
  font-size: 2.4rem;
  font-weight: 800;
  margin: 0;
}

.auth-brand p {
  margin: 6px 0 0;
  color: rgba(255, 255, 255, 0.82);
}

.page-title {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: end;
  gap: 14px;
  margin-bottom: 18px;
}

.page-title h1 {
  font-size: clamp(1.55rem, 2vw, 2rem);
  margin: 0;
  font-weight: 800;
}

.page-title p {
  color: var(--app-muted);
  margin: 4px 0 0;
}

.metric {
  padding: 18px;
  min-height: 112px;
}

.metric span {
  color: var(--app-muted);
  display: block;
  font-size: 0.88rem;
}

.metric strong {
  display: block;
  font-size: 1.5rem;
  margin-top: 8px;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.admin-action {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px;
  color: var(--app-text);
  text-decoration: none;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.admin-action:hover {
  border-color: var(--app-primary);
  transform: translateY(-1px);
}

.admin-action i {
  color: var(--app-primary);
  font-size: 1.4rem;
}

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

.toolbar .btn,
.icon-btn {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  padding: 0;
}

.question-list {
  max-height: calc(100vh - 180px);
  overflow-y: auto;
  border-right: 1px solid var(--app-line);
  padding: 10px;
}

.question-number {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--app-line);
  background: #ffffff;
  display: grid;
  place-items: center;
  margin: 0 auto 8px;
  cursor: pointer;
  font-weight: 700;
}

.question-number.active {
  background: var(--app-primary);
  border-color: var(--app-primary);
  color: #ffffff;
}

.rich-editor,
.question-text {
  min-height: 150px;
  border: 1px solid var(--app-line);
  border-radius: 8px;
  padding: 12px;
  background: #ffffff;
  overflow-y: auto;
}

.question-text {
  max-height: 420px;
}

.question-text img,
.rich-editor img {
  max-width: 100%;
  height: auto;
}

.question-text table,
.rich-editor table {
  border-collapse: collapse;
  max-width: 100%;
}

.question-text td,
.question-text th,
.rich-editor td,
.rich-editor th {
  border: 1px solid #6b7280;
  padding: 6px;
}

.exam-layout {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 18px;
}

.exam-sidebar {
  max-height: calc(100vh - 125px);
  overflow-y: auto;
  padding: 8px;
}

.exam-question-nav {
  display: grid;
  gap: 8px;
}

.exam-dot {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--app-line);
  background: #ffffff;
  display: grid;
  place-items: center;
  font-weight: 800;
  position: relative;
}

.exam-dot.active {
  background: #36495d;
  color: #ffffff;
}

.exam-dot.answered {
  background: var(--app-primary);
  border-color: var(--app-primary);
  color: #ffffff;
}

.exam-dot.seen {
  outline: 3px solid #8b96a4;
  outline-offset: 3px;
}

.exam-dot.correct {
  background: var(--app-success);
  border-color: var(--app-success);
  color: #ffffff;
}

.exam-dot.wrong {
  background: var(--app-danger);
  border-color: var(--app-danger);
  color: #ffffff;
}

.flag-mark {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--app-warning);
  color: #ffffff;
  display: grid;
  place-items: center;
  font-size: 0.62rem;
}

.option-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.option-row input {
  position: absolute;
  opacity: 0;
}

.option-label {
  border: 1px solid var(--app-line);
  background: #ffffff;
  border-radius: 8px;
  padding: 12px 14px;
  cursor: pointer;
  width: 100%;
}

.option-row input:checked + .option-label {
  background: var(--app-primary);
  border-color: var(--app-primary);
  color: #ffffff;
}

.option-label.canceled {
  color: var(--app-muted);
  text-decoration: line-through;
}

.option-label.correct-option {
  background: var(--app-success) !important;
  color: #ffffff !important;
}

.option-label.wrong-option {
  background: var(--app-danger) !important;
  color: #ffffff !important;
}

.plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(245px, 1fr));
  gap: 16px;
}

.plan-card {
  min-height: 430px;
  display: flex;
  flex-direction: column;
}

.plan-card .card-body {
  flex: 1;
}

.table-responsive {
  border-radius: 8px;
}

@media (max-width: 768px) {
  .exam-layout {
    grid-template-columns: 1fr;
  }

  .exam-sidebar {
    max-height: none;
    overflow-x: auto;
  }

  .exam-question-nav {
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  }

  .question-list {
    max-height: 170px;
    border-right: 0;
    border-bottom: 1px solid var(--app-line);
  }
}
