/* =========================================================================
   AprovIA - mobile-first stylesheet
   Breakpoints: base = smartphone, 768px = tablet, 1024px = desktop
   ========================================================================= */

:root {
  --bg: #f9fafb;
  --surface: #ffffff;
  --surface-muted: #f3f4f6;
  /* Contrast raised above the plain spec values: --text-muted is 7.0:1 on
     white and --border is clearly perceivable on light backgrounds. */
  --border: #d5d9e0;
  --border-strong: #b8bfc9;
  --text: #111827;
  --text-muted: #4b5563;
  /* Used only for the discreet footer signature; still AA (4.6:1) on white. */
  --text-quiet: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --success: #047857;
  --success-soft: #ecfdf5;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --warning: #b45309;
  --warning-soft: #fffbeb;
  --radius: 10px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.08);
  --shadow-md: 0 8px 24px rgba(17, 24, 39, 0.14);
  --sidebar-width: 236px;
  --topbar-height: 56px;
  --bottom-nav-height: 60px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

/* Component rules set `display`, so `hidden` needs to win explicitly. */
[hidden] {
  display: none !important;
}

/* ------------------------------------------------ icons and accessibility */

.icon {
  display: inline-block;
  vertical-align: middle;
  flex: none;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  z-index: 100;
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  color: var(--text);
  font-weight: 500;
}

.skip-link:focus {
  left: 8px;
}

/* ---------------------------------------------------------- loading state */

.spinner {
  display: inline-block;
  flex: none;
  width: 20px;
  height: 20px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spinner-sm {
  width: 16px;
  height: 16px;
}

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

.loading-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(249, 250, 251, 0.86);
}

.loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: min(100%, 340px);
  padding: 22px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  text-align: center;
}

.loading-card .spinner {
  width: 30px;
  height: 30px;
  border-width: 3px;
  color: var(--primary);
  margin-bottom: 4px;
}

.loading-title {
  margin: 0;
  font-weight: 600;
}

.loading-hint {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.86rem;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  overflow-x: hidden;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  line-height: 1.3;
  font-weight: 600;
}

p {
  margin: 0 0 0.75rem;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

ul,
ol {
  margin: 0;
  padding: 0;
}

img {
  max-width: 100%;
  height: auto;
}

code {
  background: var(--surface-muted);
  border-radius: 4px;
  padding: 0.1em 0.35em;
  font-size: 0.9em;
}

/* ------------------------------------------------------------------ layout */

.app-shell {
  min-height: 100dvh;
}

.app-main {
  min-width: 0;
}

.content {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--bottom-nav-height) + 32px);
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 40;
  width: min(78vw, var(--sidebar-width));
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform 0.2s ease;
  overflow-y: auto;
}

body.sidebar-open .sidebar {
  transform: translateX(0);
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(17, 24, 39, 0.45);
}

.sidebar-brand {
  padding: 18px 20px;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand a {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.sidebar-brand .icon {
  color: var(--primary);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.95rem;
}

.nav-link:hover {
  background: var(--surface-muted);
  text-decoration: none;
}

.nav-link.is-active {
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 600;
}

.nav-link-secondary {
  margin-top: 8px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

.nav-badge {
  margin-left: auto;
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--warning-soft);
  border: 1px solid #fde68a;
  color: var(--warning);
  font-size: 0.74rem;
  font-weight: 700;
  text-align: center;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--topbar-height);
  padding: 0 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  flex: 1;
  text-align: center;
  font-weight: 600;
  font-size: 0.98rem;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.icon-button:hover {
  background: var(--surface-muted);
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 25;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--bottom-nav-height);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.bottom-nav-link.is-active {
  color: var(--primary);
  font-weight: 600;
}

.bottom-nav-link:hover {
  text-decoration: none;
}

/* -------------------------------------------------------------- typography */

.page-heading {
  font-size: 1.35rem;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
  overflow-wrap: anywhere;
}

.section {
  margin-bottom: 28px;
}

.section-title {
  font-size: 1.02rem;
  margin-bottom: 10px;
}

.section-hint {
  margin: 0;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.subsection-title {
  font-size: 0.92rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 18px 0 8px;
}

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

.small {
  font-size: 0.85rem;
}

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

.section-head .section-title {
  margin: 0;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.divider-text {
  margin: 18px 0 12px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ------------------------------------------------------------------ buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
}

.btn:hover {
  text-decoration: none;
}

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

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

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

.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--surface-muted);
}

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

.btn-ghost:hover {
  background: var(--surface-muted);
  color: var(--text);
}

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

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

.btn-block {
  display: flex;
  width: 100%;
}

.btn-sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 0.86rem;
}

/* ------------------------------------------------------------------- forms */

.field {
  margin-bottom: 14px;
}

.field-label,
.field > label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
  font-weight: 500;
}

.input,
.textarea {
  width: 100%;
  min-height: 46px;
  padding: 11px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
}

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

.input:focus,
.textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
  border-color: var(--primary);
}

.search-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.search-form .input {
  flex: 1;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-size: 0.94rem;
}

.checkbox input {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
}

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

.choice {
  flex: 1 1 64px;
  position: relative;
}

.choice input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.choice span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 0.92rem;
  cursor: pointer;
}

.choice input:checked + span {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 600;
}

.choice-column {
  display: flex;
  flex-direction: column;
}

.advanced {
  margin-bottom: 14px;
}

.advanced summary {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 6px 0;
}

/* ---------------------------------------------------------------- surfaces */

.card,
.list,
.item-list,
.topic-list,
.result-list {
  list-style: none;
}

.list {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.list-item:last-child {
  border-bottom: 0;
}

.list-item-main {
  flex: 1;
  min-width: 0;
  display: block;
  color: var(--text);
}

.list-item-main:hover {
  text-decoration: none;
}

.list-item-title {
  display: block;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.list-item-meta {
  display: block;
  margin-top: 2px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.list-item-side {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
}

.delete-form {
  display: flex;
}

/* Compact destructive action: 44px touch target, icon only. */
.list-item-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.list-item-action:hover,
.list-item-action:focus-visible {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-completed,
.badge-correct,
.badge-score {
  background: var(--success-soft);
  border-color: #a7f3d0;
  color: var(--success);
}

.badge-processing {
  background: var(--warning-soft);
  border-color: #fde68a;
  color: var(--warning);
}

.badge-failed,
.badge-wrong {
  background: var(--danger-soft);
  border-color: #fecaca;
  color: var(--danger);
}

.badge-pending {
  background: var(--surface-muted);
}

/* ------------------------------------------------------------ OP: usuários */

.badge-op {
  background: var(--primary-soft);
  border-color: #bfdbfe;
  color: var(--primary-dark);
  vertical-align: middle;
}

.badge-user-pending {
  background: var(--warning-soft);
  border-color: #fde68a;
  color: var(--warning);
}

.badge-user-approved {
  background: var(--success-soft);
  border-color: #a7f3d0;
  color: var(--success);
}

.badge-user-blocked {
  background: var(--danger-soft);
  border-color: #fecaca;
  color: var(--danger);
}

.user-item {
  flex-wrap: wrap;
  align-items: flex-start;
}

.user-status {
  display: block;
  margin-top: 6px;
}

.user-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.action-form {
  display: flex;
}

.badge-priority-alta {
  background: var(--danger-soft);
  border-color: #fecaca;
  color: var(--danger);
}

.badge-priority-media {
  background: var(--warning-soft);
  border-color: #fde68a;
  color: var(--warning);
}

.badge-priority-baixa {
  background: var(--surface-muted);
}

.item-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.item-body {
  min-width: 0;
}

.item-main {
  margin: 0;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.item-detail {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.topic-tree {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.topic-tree-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 12px 14px;
}

.topic-tree-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.topic-tree-title {
  font-weight: 600;
}

.topic-tree-sub {
  list-style: none;
  margin-top: 8px;
  padding-left: 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.topic-tree-sub li {
  position: relative;
  padding-left: 14px;
}

.topic-tree-sub li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.62em;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--border);
}

.example-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 14px;
  margin-bottom: 10px;
}

.example-title {
  font-size: 0.98rem;
  margin-bottom: 6px;
}

.accordion {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 12px 14px;
  margin-bottom: 10px;
}

.accordion summary {
  cursor: pointer;
  font-weight: 500;
}

.accordion > *:not(summary) {
  margin-top: 10px;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 26px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
}

.empty-icon {
  color: var(--text-muted);
  margin-bottom: 2px;
}

.error-icon {
  color: var(--danger);
}

.empty-title {
  margin: 0;
  font-weight: 500;
}

.empty-text {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.callout {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-size: 0.9rem;
  margin-bottom: 16px;
}

.callout-warning {
  background: var(--warning-soft);
  border-color: #fde68a;
  color: #7c2d12;
}

.preview-text {
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.85rem;
  line-height: 1.5;
  background: var(--surface-muted);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin: 0;
}

.stat-strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 12px;
  margin-bottom: 16px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.stat-value {
  font-size: 1.3rem;
  font-weight: 700;
}

.stat-label {
  font-size: 0.76rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.progress {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-muted);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.3s ease;
}

.topic-item {
  margin-bottom: 12px;
}

.topic-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.9rem;
  margin-bottom: 6px;
}

.topic-name {
  overflow-wrap: anywhere;
}

.topic-percent {
  color: var(--text-muted);
  white-space: nowrap;
}

/* ------------------------------------------------------------------- prose */

.prose {
  font-size: 1rem;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.prose h2,
.prose h3,
.prose h4 {
  margin: 1.3em 0 0.5em;
  font-size: 1.05rem;
}

.prose h3 {
  font-size: 1rem;
}

.prose p {
  margin: 0 0 0.9em;
}

.prose ul,
.prose ol {
  margin: 0 0 0.9em;
  padding-left: 1.25em;
}

.prose li {
  margin-bottom: 0.35em;
}

.prose blockquote {
  margin: 0 0 0.9em;
  padding: 6px 14px;
  border-left: 3px solid var(--border);
  color: var(--text-muted);
}

.prose pre {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow-x: auto;
  font-size: 0.86rem;
  line-height: 1.5;
}

.prose pre code {
  background: none;
  padding: 0;
}

.prose table {
  display: block;
  width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  margin-bottom: 0.9em;
  font-size: 0.9rem;
}

.prose th,
.prose td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
  white-space: nowrap;
}

.prose th {
  background: var(--surface-muted);
}

.prose img {
  border-radius: var(--radius-sm);
}

.prose > *:last-child {
  margin-bottom: 0;
}

/* -------------------------------------------------------------- study view */

.study-header {
  margin-bottom: 16px;
}

.study-meta {
  color: var(--text-muted);
  font-size: 0.86rem;
}

.study-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.section-nav {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
  scrollbar-width: none;
}

.section-nav::-webkit-scrollbar {
  display: none;
}

.section-nav-link {
  flex: none;
  padding: 6px 10px;
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.section-nav-link.is-active {
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 600;
}

.study-section {
  margin-bottom: 30px;
  scroll-margin-top: 72px;
}

/* ------------------------------------------------------------------- tabs */

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  scrollbar-width: none;
}

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

.tab {
  flex: none;
  padding: 9px 12px;
  color: var(--text-muted);
  font-size: 0.9rem;
  border-bottom: 2px solid transparent;
}

.tab.is-active {
  color: var(--primary-dark);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

/* ------------------------------------------------------------------ upload */

.upload-form {
  margin-bottom: 8px;
}

.upload-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 22px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  text-align: center;
}

.upload-drop:hover {
  border-color: var(--primary);
}

.upload-drop input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.upload-icon {
  color: var(--primary);
}

.upload-title {
  font-weight: 500;
}

.upload-hint,
.upload-filename {
  font-size: 0.82rem;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.upload-filename {
  margin: 8px 0 0;
  text-align: center;
}

/* --------------------------------------------------------------- dashboard */

.hero-title {
  font-size: 1.4rem;
  margin-bottom: 14px;
}

.study-form {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 14px;
}

/* ------------------------------------------------------------------- quiz */

.quiz-header {
  position: sticky;
  top: var(--topbar-height);
  z-index: 15;
  background: var(--bg);
  padding: 8px 0 12px;
  margin-bottom: 8px;
}

.quiz-name {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0;
  overflow-wrap: anywhere;
}

.quiz-position {
  font-weight: 600;
  margin: 2px 0 8px;
}

.quiz-question {
  min-height: 45vh;
  margin-bottom: 16px;
}

.quiz-question-meta {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.quiz-question-text {
  font-size: 1.08rem;
  font-weight: 600;
  margin-bottom: 16px;
  overflow-wrap: anywhere;
}

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

.answer-option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-height: 56px;
  padding: 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}

.answer-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

/* Fallback for browsers without :has() support. */
.answer-option input:checked ~ .answer-option-key {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.answer-option-key {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.answer-option-text {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.answer-option:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.answer-option:has(input:checked) .answer-option-key {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

/* Kept above the fixed bottom navigation so the buttons stay tappable. */
.quiz-footer {
  position: sticky;
  bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.quiz-footer .btn-primary {
  grid-column: 1 / -1;
}

.quiz-hint {
  margin-top: 4px;
  text-align: center;
}

/* ---------------------------------------------------------------- results */

.score-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 18px 16px;
  text-align: center;
  margin-bottom: 20px;
}

.score-value {
  margin: 0;
  font-size: 2.1rem;
  font-weight: 700;
}

.score-total {
  font-size: 1.1rem;
  color: var(--text-muted);
  font-weight: 500;
}

.score-percent {
  margin: 0 0 14px;
  color: var(--text-muted);
  font-weight: 600;
}

.result-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.result-item {
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--radius);
  background: var(--surface);
  padding: 14px;
}

.result-item-correct {
  border-left-color: #34d399;
}

.result-item-wrong {
  border-left-color: #f87171;
}

.result-item-pending {
  border-left-color: #cbd5e1;
}

.result-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.result-item-index {
  font-size: 0.82rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.result-item-topic {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin: 0 0 6px;
}

.result-item-question {
  font-weight: 500;
  overflow-wrap: anywhere;
}

.result-options {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.result-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.94rem;
}

.result-option-icon {
  margin-top: 3px;
}

.result-option.is-correct .result-option-icon {
  color: var(--success);
}

.result-option.is-chosen .result-option-icon {
  color: var(--danger);
}

.result-option.is-correct {
  border-color: #a7f3d0;
  background: var(--success-soft);
}

.result-option.is-chosen {
  border-color: #fecaca;
  background: var(--danger-soft);
}

.result-answers {
  margin: 0 0 12px;
  font-size: 0.94rem;
}

.result-answers dt {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.result-answers dd {
  margin: 2px 0 10px;
  overflow-wrap: anywhere;
}

.result-feedback {
  font-size: 0.92rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.error-text {
  color: var(--danger);
  font-weight: 500;
}

.error-code {
  margin: 0;
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--text-muted);
}

/* --------------------------------------------------------- processing view */

.steps {
  list-style: none;
  margin: 18px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.step {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 0.94rem;
}

.step.is-active {
  color: var(--text);
  font-weight: 600;
}

.step-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex: none;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-muted);
}

.step.is-active .step-icon {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.step.is-done .step-icon {
  border-color: var(--success);
  background: var(--success-soft);
  color: var(--success);
}

.processing-message {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  color: var(--text);
}

.processing-message .spinner {
  color: var(--primary);
}

/* ------------------------------------------------------------------ dialog */

.dialog {
  width: min(94vw, 520px);
  max-height: 88dvh;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.dialog::backdrop {
  background: rgba(17, 24, 39, 0.5);
}

.dialog-form {
  display: flex;
  flex-direction: column;
  max-height: 88dvh;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.dialog-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
}

.dialog-title .icon {
  color: var(--primary);
}

.dialog-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.dialog-close:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.dialog-body {
  padding: 16px;
  overflow-y: auto;
}

.dialog-footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

/* ------------------------------------------------------------------ alerts */

.alerts {
  position: fixed;
  z-index: 60;
  left: 12px;
  right: 12px;
  bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom) + 12px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.alert {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-size: 0.92rem;
  pointer-events: auto;
}

.alert-success {
  background: var(--success-soft);
  border-color: #a7f3d0;
  color: #065f46;
}

.alert-error {
  background: var(--danger-soft);
  border-color: #fecaca;
  color: #7f1d1d;
}

.alert-warning {
  background: var(--warning-soft);
  border-color: #fde68a;
  color: #78350f;
}

.alert-info {
  background: var(--primary-soft);
  border-color: #bfdbfe;
  color: #1e3a8a;
}

.alert.is-leaving {
  opacity: 0;
  transition: opacity 0.15s ease;
}

.alert-close {
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

/* ------------------------------------------------------------------ footer */

.site-footer {
  margin-top: 8px;
  text-align: center;
  /* Leaves room for the fixed bottom navigation on phones. */
  padding: 12px 16px calc(var(--bottom-nav-height) + env(safe-area-inset-bottom) + 8px);
}

.footer-text {
  margin: 0;
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  /* Lighter than --text-muted on purpose: the signature is decoration, but the
     color still keeps 4.6:1 of contrast on white (WCAG AA for small text). */
  color: var(--text-quiet);
}

/* -------------------------------------------------------------------- auth */

.page-auth {
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.auth-wrapper {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.page-auth .site-footer {
  margin-top: 0;
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
}

.auth-card {
  width: 100%;
  max-width: 360px;
}

.auth-title {
  font-size: 1.4rem;
  margin-bottom: 4px;
}

.auth-subtitle {
  color: var(--text-muted);
  margin-bottom: 20px;
}

.auth-form {
  margin-top: 8px;
}

.auth-alt {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.field-hint {
  margin: 6px 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ------------------------------------------------------------- responsive */

@media (min-width: 480px) {
  .search-form .btn {
    flex: none;
  }
}

@media (min-width: 768px) {
  body {
    font-size: 16px;
  }

  .content {
    padding: 24px 24px 48px;
  }

  .bottom-nav {
    display: none;
  }

  .page-heading {
    font-size: 1.5rem;
  }

  .alerts {
    left: auto;
    right: 20px;
    bottom: 20px;
    width: 340px;
  }

  .site-footer {
    margin-top: 20px;
    padding-bottom: 18px;
  }

  .choice {
    flex: none;
    min-width: 88px;
  }

  .quiz-footer {
    bottom: 0;
    grid-template-columns: 140px 140px 1fr;
  }

  .quiz-footer .btn-primary {
    grid-column: auto;
  }
}

@media (min-width: 1024px) {
  .app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  }

  .sidebar {
    position: sticky;
    top: 0;
    transform: none;
    width: var(--sidebar-width);
    height: 100dvh;
  }

  .sidebar-backdrop {
    display: none !important;
  }

  .topbar {
    display: none;
  }

  .content {
    padding: 32px 32px 64px;
  }

  .study-section {
    scroll-margin-top: 24px;
  }

  .quiz-header {
    top: 0;
  }
}

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