/* The logo cell and the document header share this height, so their
   bottom edges line up when a file is open. */
.shell.is-v2 {
  --viewer-bar-h: 76px;
}

/* AlphaEdge IDP Studio v2 — simplified shell (no top bar), Drive-style grids,
   scan / classification dialogs, live progress, rich-text tables, chat. Built
   on the tokens of tokens.css so both themes follow. */

/* ==========================================================================
   Shell without top bar
   ========================================================================== */
.shell.is-v2 {
  grid-template-rows: var(--viewer-bar-h) 1fr;
  grid-template-areas:
    "brand main"
    "sidebar main";
}

.shell.is-v2 .main {
  background: var(--surface-1, var(--surface));
}

.shell.is-v2 .view {
  overflow-y: auto;
}

.shell.is-v2 .view:has(> .page) {
  overflow: hidden;
}

.shell.is-v2 .status-line {
  flex-wrap: nowrap;
}

.shell.is-v2 .theme-toggle {
  margin-left: auto;
  flex: none;
}

.shell.is-v2 .theme-toggle + .sidebar-version {
  margin-left: 0;
}

.shell.is-collapsed .status-line {
  flex-direction: column;
  gap: 6px;
  padding: 0;
}

.shell.is-collapsed .theme-toggle {
  margin: 0;
}

/* Navigation: three groups (overview, the processing chain, configuration)
   separated by hairlines; the chain is drawn as numbered, linked steps. */
.shell.is-v2 .sidebar {
  background: linear-gradient(180deg, var(--surface) 0%, color-mix(in srgb, var(--surface-2) 70%, var(--surface)) 100%);
}

.shell.is-v2 .brand {
  gap: 10px;
  padding: 0 14px 0 22px;
}

.shell.is-v2 .brand-logo {
  height: 36px;
  max-width: 214px;
}

.shell.is-collapsed.is-v2 .brand {
  padding: 0;
}

.shell.is-v2 .nav {
  padding: 26px 0 18px;
}

.shell.is-v2 .nav-group {
  margin: 0;
  padding: 0 12px;
}

/* Hairline between groups, inset from the sidebar edges. */
.shell.is-v2 .nav-group + .nav-group::before {
  content: "";
  display: block;
  height: 1px;
  margin: 16px 10px 20px;
  background: var(--border);
}

.shell.is-v2 .nav-group-label {
  padding: 0 10px 10px;
  font-size: 10.5px;
  letter-spacing: 0.12em;
}

.shell.is-v2 .nav-item {
  gap: 11px;
  min-height: 40px;
  padding: 7px 10px;
  margin-bottom: 2px;
  border-radius: 10px;
  font-size: 13.5px;
}

.shell.is-v2 .nav-item.is-active {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent-border);
}

.shell.is-v2 .nav-item.is-active::before {
  display: none;
}

.nav-icon {
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  color: var(--ink-muted);
  transition: background var(--transition), color var(--transition);
}

/* Even sizes (28px box, 16px glyph): whole-pixel margins on every side, so
   the stroke stays sharp and looks centred, with or without the 1px border. */
.shell.is-v2 .nav-item svg {
  display: block;
  width: 16px;
  height: 16px;
  opacity: 1;
}

.nav-item:hover .nav-icon {
  color: var(--ink);
}

.nav-item.is-active .nav-icon {
  background: var(--accent);
  color: var(--accent-contrast);
}

.nav-group.is-pipeline .nav-icon {
  border: 1px solid var(--border-strong);
  background: var(--surface);
}

.nav-group.is-pipeline .nav-item.is-active .nav-icon {
  border-color: var(--accent);
  background: var(--accent);
}

/* Link between two consecutive steps of the chain. */
.nav-group.is-pipeline .nav-item:not(:last-child) .nav-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  top: calc(100% + 1px);
  width: 0;
  height: 14px;
  border-left: 1.5px dashed var(--border-strong);
  transform: translateX(-50%);
}

/* The rail's 1px right border would leave the icons half a pixel off centre. */
.shell.is-collapsed .nav-group {
  padding-inline: 8px 7px;
}

.shell.is-collapsed.is-v2 .nav-group + .nav-group::before {
  margin-inline: 6px;
}

.shell.is-collapsed .nav-group-label {
  display: none;
}

.shell.is-collapsed .nav-item {
  justify-content: center;
  padding-inline: 0;
}

.nav-tip {
  position: fixed;
  z-index: 1200;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 14px;
  border-radius: 10px;
  background: #0b1a3a;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 10px 24px -8px rgba(11, 26, 58, 0.45), 0 2px 6px rgba(15, 23, 42, 0.18);
  pointer-events: none;
  opacity: 0;
  transform: translate(-4px, -50%);
  transition: opacity 120ms ease, transform 160ms cubic-bezier(0.16, 1, 0.3, 1);
}

.nav-tip::before {
  content: "";
  position: absolute;
  left: -4px;
  top: 50%;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: inherit;
  transform: translateY(-50%) rotate(45deg);
}

.nav-tip.is-visible {
  opacity: 1;
  transform: translate(0, -50%);
}

.nav-tip-count {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.nav-tip-count.is-alert {
  background: var(--orange-700, #d9480f);
}

html[data-theme="dark"] .nav-tip {
  background: var(--surface-3);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--border-strong), 0 12px 28px -8px rgba(0, 0, 0, 0.8);
}

html[data-theme="dark"] .nav-tip::before {
  box-shadow: -1px 1px 0 var(--border-strong);
}

html[data-theme="dark"] .nav-tip-count {
  background: var(--surface-1);
}

html[data-theme="dark"] .nav-tip-count.is-alert {
  background: var(--orange-700);
  color: #1a0d07;
}

/* ==========================================================================
   Page frame
   ========================================================================== */
.page {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.page-head {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 28px var(--view-pad-x) 12px;
  flex: none;
}

.page-head h1 {
  font-size: 22px;
  font-weight: 680;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.page-sub {
  margin-top: 2px;
  font-size: var(--fs-md);
  color: var(--ink-muted);
}

.page-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.page.is-viewing .page-head,
.page.is-viewing .run-panel,
.page.is-chatting .page-head {
  display: none;
}

/* ==========================================================================
   Drive grid
   ========================================================================== */
.drive {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.drive-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px var(--view-pad-x) 10px;
  flex-wrap: wrap;
}

.drive-toolbar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex: 0 0 auto;
  margin-left: auto;
}

.drive-crumbs:empty {
  display: none;
}

.drive-crumbs {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  flex-wrap: wrap;
}

.drive-crumb {
  padding: 5px 9px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: none;
  font-size: var(--fs-lg);
  font-weight: 600;
  color: var(--ink-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.drive-crumb:hover {
  background: var(--surface-3);
  color: var(--ink);
}

.drive-crumb.is-current {
  color: var(--ink);
}

span.drive-crumb.is-current {
  cursor: default;
}

.drive-crumb.is-drop-target {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.drive-crumb-sep {
  display: inline-flex;
  color: var(--ink-faint);
}

.drive-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.drive-search-wrap svg {
  position: absolute;
  left: 11px;
  color: var(--ink-faint);
  pointer-events: none;
}

.drive-search {
  width: 220px;
  padding-left: 32px;
  border-radius: 999px;
}

.drive-folder-filter {
  max-width: 200px;
  border-radius: 999px;
}

.drive-selection {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  padding: 6px var(--view-pad-x);
  border-top: 1px solid var(--border-faint);
  border-bottom: 1px solid var(--border-faint);
  background: var(--surface);
}

.drive-selection .btn {
  border-radius: 999px;
}

.drive-select-all {
  margin: 0;
}

.drive-scroll {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px var(--view-pad-x) 48px;
}

.drive:focus {
  outline: none;
}

.drive.has-fab .drive-scroll {
  padding-bottom: 116px;
}

.drive.is-lassoing,
.drive.is-lassoing * {
  user-select: none;
}

.drive.is-lassoing .drive-card {
  pointer-events: none;
}

.drive-lasso {
  position: absolute;
  z-index: 5;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  pointer-events: none;
}

/* Main action of the page, bottom-right like a floating action button. */
.drive-fab {
  position: absolute;
  right: calc(var(--view-pad-x) + 4px);
  bottom: 26px;
  z-index: 6;
  display: flex;
  gap: 10px;
  pointer-events: none;
}

.drive-fab:empty {
  display: none;
}

.drive-fab > * {
  pointer-events: auto;
}

.btn-fab {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 56px;
  padding: 0 26px 0 22px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-contrast, #fff);
  font-size: 15.5px;
  font-weight: 650;
  letter-spacing: 0.005em;
  box-shadow: 0 10px 28px -8px color-mix(in srgb, var(--accent) 65%, transparent), 0 2px 6px rgba(15, 23, 42, 0.18);
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease, opacity 140ms ease;
}

.btn-fab svg {
  width: 20px;
  height: 20px;
}

.btn-fab:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 14px 34px -8px color-mix(in srgb, var(--accent) 70%, transparent), 0 3px 8px rgba(15, 23, 42, 0.2);
}

.btn-fab:active:not(:disabled) {
  transform: translateY(0);
}

.btn-fab:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-fab .btn-fab-count {
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  font-size: 12.5px;
  line-height: 24px;
  text-align: center;
}

.btn-fab.is-ai,
.btn-ai {
  background: linear-gradient(125deg, #0b1a3a 0%, #1d3a8a 55%, #4a6fe0 100%);
  color: #fff;
}

.btn-fab.is-ai {
  box-shadow: 0 10px 28px -8px rgba(29, 58, 138, 0.65), 0 2px 6px rgba(15, 23, 42, 0.18);
}

.btn-fab.is-ai:hover:not(:disabled) {
  box-shadow: 0 14px 34px -8px rgba(74, 111, 224, 0.7), 0 3px 8px rgba(15, 23, 42, 0.2);
}

.btn-fab.is-ai svg,
.btn-ai svg {
  color: #ffd66b;
}

.btn-ai {
  border: none;
}

.viewer-toolbar .btn-ai[hidden] {
  display: none !important;
}

.btn-ai:hover:not(:disabled),
.btn.btn-ai.btn-pill:hover:not(:disabled) {
  background: linear-gradient(125deg, #0b1a3a 0%, #1d3a8a 55%, #4a6fe0 100%);
  color: #fff;
  border-color: transparent;
  filter: brightness(1.12);
}

.btn-ai.is-on {
  box-shadow: 0 0 0 3px color-mix(in srgb, #4a6fe0 35%, transparent);
}

.drive-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(188px, 1fr));
  gap: 16px;
  align-content: start;
  transition: opacity var(--transition);
}

.drive-grid.is-loading {
  opacity: 0.55;
}

.drive-empty {
  grid-column: 1 / -1;
  padding: 48px 0;
}

.drive-card {
  position: relative;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition), opacity 380ms ease;
  user-select: none;
}

.drive-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.drive-card:focus-visible {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}

.drive-card.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent);
}

.drive-card.is-dragging {
  opacity: 0.4;
}

.drive-card.is-drop-target {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
  background: var(--accent-soft);
}

.drive-card.is-reorder-target {
  box-shadow: -4px 0 0 0 var(--accent);
}

.drive-card.is-leaving {
  opacity: 0;
  transform: scale(0.92);
  pointer-events: none;
}

.drive-card.is-folder {
  flex-direction: row;
  align-items: center;
  align-self: start;
  gap: 12px;
  padding: 14px 40px 14px 14px;
  min-height: 64px;
}

.drive-folder-icon {
  display: flex;
  color: var(--accent);
  flex: none;
}

.drive-folder-icon svg {
  fill: color-mix(in srgb, var(--accent) 14%, transparent);
}

.drive-thumb {
  position: relative;
  aspect-ratio: 4 / 4.6;
  margin: 8px 8px 0;
  border-radius: 9px;
  background: var(--surface-3);
  overflow: hidden;
}

.drive-thumb-img {
  width: 100%;
  height: 100%;
}

.drive-thumb-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  display: block;
}

.drive-thumb-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  height: 100%;
  color: var(--ink-faint);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
}

.drive-badge-slot {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  gap: 4px;
}

.drive-card-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px 12px;
  min-width: 0;
}

.drive-card.is-folder .drive-card-body {
  padding: 0;
  flex: 1;
}

.drive-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.drive-kind {
  display: flex;
  color: var(--ink-faint);
  flex: none;
}

.drive-name {
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drive-meta {
  font-size: var(--fs-xs);
  color: var(--ink-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drive-rename {
  width: 100%;
}

.drive-check {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: var(--accent);
  opacity: 0;
  cursor: pointer;
  transition: opacity var(--transition);
}

.drive-card.is-folder .drive-check {
  top: 50%;
  transform: translateY(-50%);
}

.drive-card:hover .drive-check,
.drive-card.is-selected .drive-check,
.drive:has(.drive-card.is-selected) .drive-check {
  opacity: 1;
}

.drive-progress-slot:empty {
  display: none;
}

.drive-progress-slot {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 12px 12px;
}

.drive-progress-label {
  font-size: var(--fs-xs);
  color: var(--accent-ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.progress-thin {
  height: 4px;
}

.progress-bar.is-idle {
  background: var(--ink-faint);
}

.progress-bar.is-animated {
  background-image: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.35), transparent);
  background-size: 200% 100%;
  animation: bar-shine 1.4s linear infinite;
}

@keyframes bar-shine {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

.drive-card.is-running {
  border-color: var(--accent);
}

.drive-card.is-running .drive-thumb::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 0%, color-mix(in srgb, var(--accent) 22%, transparent) 50%, transparent 100%);
  background-size: 100% 60%;
  background-repeat: no-repeat;
  animation: scan-sweep 1.6s ease-in-out infinite;
}

@keyframes scan-sweep {
  from {
    background-position: 0 -120%;
  }
  to {
    background-position: 0 240%;
  }
}

/* External file drop */
.drive-drop {
  position: absolute;
  inset: 8px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--drop-tint);
  border-radius: 18px;
  background: color-mix(in srgb, var(--drop-tint) 10%, transparent);
  pointer-events: none;
}

.drive-drop.hidden {
  display: none;
}

.drive-drop-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 22px 30px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  color: var(--drop-tint);
}

.drive-drop-card strong {
  color: var(--ink);
}

/* Upload toast: a flat list of files, each with a hairline progress bar. */
.toast.is-upload {
  padding: 14px 16px;
  border-left-width: 1px;
  border-radius: 14px;
}

.toast.is-upload > div > p {
  margin-top: 1px;
}

.upload-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 10px 0 0 -4px;
  max-height: 220px;
  overflow-y: auto;
}

.upload-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  border: 0;
  border-radius: 8px;
  background: none;
}

.upload-icon {
  display: inline-flex;
  color: var(--ink-faint);
}

.upload-main {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.upload-name {
  overflow: hidden;
  font-size: 13px;
  font-weight: 550;
  color: var(--ink);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.upload-bar {
  height: 3px;
  border-radius: 3px;
  background: var(--surface-3);
  overflow: hidden;
}

.upload-bar > i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 200ms ease;
}

.upload-state {
  max-width: 120px;
  overflow: hidden;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.upload-row.is-done .upload-bar > i {
  background: var(--success);
}

.upload-row.is-done .upload-state {
  color: var(--success);
}

.upload-row.is-error .upload-bar > i {
  width: 100% !important;
  background: var(--danger);
}

.upload-row.is-error .upload-state {
  color: var(--danger);
}

/* Scores and types on cards */
.score-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.score-badge.is-green {
  background: var(--success);
}

.score-badge.is-orange {
  background: #d98a00;
}

.score-badge.is-red {
  background: var(--danger);
}

.drive-card.is-tier-red {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
}

.drive-card.is-tier-orange {
  border-color: color-mix(in srgb, #d98a00 45%, var(--border));
}

.drive-card.is-tier-green {
  border-color: color-mix(in srgb, var(--success) 35%, var(--border));
}

.drive-card.is-tier-red .drive-thumb {
  box-shadow: inset 0 -3px 0 var(--danger);
}

.drive-card.is-tier-orange .drive-thumb {
  box-shadow: inset 0 -3px 0 #d98a00;
}

.drive-card.is-tier-green .drive-thumb {
  box-shadow: inset 0 -3px 0 var(--success);
}

.type-chip {
  align-self: flex-start;
  margin-top: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: var(--fs-xs);
  font-weight: 600;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.type-chip.is-lg {
  font-size: var(--fs-sm);
  padding: 4px 11px;
}

.type-chip.is-new {
  animation: chip-pop 420ms cubic-bezier(0.2, 0.9, 0.3, 1.4);
}

@keyframes chip-pop {
  from {
    transform: scale(0.6);
    opacity: 0;
  }
}

/* Quality tier filter */
.tier-filter {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: var(--surface-3);
}

.tier-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 13px;
  border: 0;
  border-radius: 999px;
  background: none;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.tier-chip:hover {
  color: var(--ink);
}

.tier-chip.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.tier-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.tier-dot.is-red {
  background: var(--danger);
}

.tier-dot.is-orange {
  background: #d98a00;
}

.tier-dot.is-green {
  background: var(--success);
}

.tier-count {
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-3);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.tier-chip.is-active .tier-count {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

/* ==========================================================================
   Context menu
   ========================================================================== */
.ctx-menu {
  position: fixed;
  z-index: 120;
  min-width: 210px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: pop-in 110ms cubic-bezier(0.2, 0.9, 0.3, 1);
}

.ctx-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  font-size: var(--fs-md);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.ctx-item svg {
  color: var(--ink-muted);
  flex: none;
}

.ctx-item:hover:not(:disabled),
.ctx-item:focus-visible {
  background: var(--surface-3);
  outline: none;
}

.ctx-item:disabled {
  opacity: 0.45;
  cursor: default;
}

.ctx-item.is-danger,
.ctx-item.is-danger svg {
  color: var(--danger);
}

.ctx-item.is-danger:hover {
  background: var(--danger-soft);
}

.ctx-hint {
  margin-left: auto;
  font-size: var(--fs-xs);
  color: var(--ink-faint);
}

.ctx-icon-gap {
  width: 16px;
  flex: none;
}

.ctx-sep {
  height: 1px;
  margin: 5px 6px;
  background: var(--border-faint);
}

.ctx-label {
  min-width: 0;
}

.ctx-heading {
  padding: 8px 10px 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.ctx-item.is-checked {
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 650;
}

.ctx-item.is-checked svg {
  color: var(--accent-ink);
}

.ctx-item:active:not(:disabled) {
  background: var(--surface-3);
}

.ctx-check {
  display: inline-flex;
  margin-left: auto;
}

.ctx-menu.is-select {
  max-height: min(320px, 60vh);
  overflow-y: auto;
}

/* Native selects stay in the DOM for their value, and a button draws the
   list. The open state is the same accent ring as a focused field. */
select.select.is-enhanced {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  border: 0 !important;
  white-space: nowrap !important;
}

.select-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 36px;
  padding: 6px 12px 6px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  font: inherit;
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

.select-button-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.select-button-chevron {
  display: inline-flex;
  color: var(--ink-faint);
  transition: transform 160ms ease, color var(--transition);
}

.select-button:hover:not(:disabled) {
  border-color: var(--ink-faint);
}

.select-button:focus-visible,
.select-button.is-open {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent);
}

.select-button.is-open {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.select-button.is-open .select-button-chevron {
  transform: rotate(180deg);
  color: var(--accent-ink);
}

.select-button.is-placeholder .select-button-label {
  color: var(--ink-muted);
  font-weight: 550;
}

.select-button:disabled {
  color: var(--ink-faint);
  background: var(--surface-2);
  cursor: not-allowed;
}

.drive-bar .select-button {
  width: auto;
  max-width: 240px;
}

.drive-bar-btn.is-open {
  border-color: var(--accent) !important;
  background: var(--accent-soft) !important;
  color: var(--accent-ink);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent);
}

.drive-bar-btn svg:last-child {
  transition: transform 160ms ease;
}

.drive-bar-btn.is-open svg:last-child {
  transform: rotate(180deg);
}

/* ==========================================================================
   Live run panel (scan / classification)
   ========================================================================== */
.run-panel {
  margin: 0 var(--view-pad-x) 12px;
  padding: 14px 18px;
  border: 1px solid var(--accent-border);
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent-soft), var(--surface) 70%);
  box-shadow: var(--shadow-sm);
  flex: none;
}

.run-panel.hidden {
  display: none;
}

.run-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.run-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.run-title .small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.run-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--success);
  flex: none;
}

.run-dot.is-live {
  background: var(--accent);
  animation: pulse 1.3s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent);
  }
  50% {
    box-shadow: 0 0 0 7px transparent;
  }
}

.run-bar {
  height: 8px;
  margin: 12px 0;
  border-radius: 999px;
}

.run-bar .progress-bar {
  border-radius: 999px;
}

.run-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}

.run-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.run-stat span {
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.run-stat strong {
  font-size: 18px;
  font-weight: 680;
  color: var(--ink);
}

.run-stat.is-success strong {
  color: var(--success);
}

.run-stat.is-warning strong {
  color: var(--warning);
}

.run-stat.is-danger strong {
  color: var(--danger);
}

.run-types {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

/* ==========================================================================
   Modern dialogs (scan, classification, templates)
   ========================================================================== */
.modal.is-scan-modal {
  width: min(760px, 100%);
  border-radius: 22px;
  overflow: hidden;
}

.modal.is-scan-modal .modal-head {
  padding: 20px 24px 14px;
  border-bottom: 0;
}

.modal.is-scan-modal .modal-head h3 {
  font-size: 19px;
  font-weight: 700;
}

.modal.is-scan-modal .modal-body {
  padding: 4px 24px 20px;
}

.modal.is-scan-modal .modal-foot {
  padding: 14px 24px;
  border-radius: 0;
}

.modal.is-scan-modal .modal-foot .btn-lg {
  border-radius: 999px;
  padding-inline: 22px;
}

/* The footer continues the dialog surface: no grey band, no rule. Cancel is a
   quiet text pill beside the main action. */
.modal-foot,
.modal.is-scan-modal .modal-foot {
  gap: 8px;
  padding: 6px 24px 22px;
  border-top: 0;
  background: var(--surface);
}

.modal-foot .btn-primary.btn-lg,
.modal-foot .btn-cancel {
  height: 44px;
  border-radius: 999px;
  font-size: 14.5px;
}

.btn-cancel {
  padding: 0 20px;
  border: 1px solid transparent;
  background: none;
  color: var(--ink-muted);
  font-weight: 600;
  box-shadow: none;
}

.btn-cancel svg {
  display: none;
}

.btn-cancel:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: transparent;
  color: var(--ink);
}

.btn-cancel:focus-visible {
  border-color: var(--accent-border);
}

.sm {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sm-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border-faint);
  border-radius: 16px;
  background: var(--surface-1, var(--surface));
}

.sm-section-title {
  font-size: var(--fs-md);
  font-weight: 680;
  color: var(--ink);
}

.sm-toggle {
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
}

.sm-toggle-text {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.sm-toggle-text strong {
  font-size: var(--fs-md);
  font-weight: 600;
}

.sm-toggle-text span {
  font-size: var(--fs-sm);
  color: var(--ink-muted);
}

.sm-advanced summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink-muted);
  cursor: pointer;
  list-style: none;
}

.sm-advanced summary::-webkit-details-marker {
  display: none;
}

.sm-advanced summary svg {
  transition: transform var(--transition);
}

.sm-advanced[open] summary svg {
  transform: rotate(90deg);
}

.sm-advanced-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 12px;
  padding-left: 20px;
}

.sm-goals {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.sm-goal {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

.sm-goal:hover {
  border-color: var(--border-strong);
}

.sm-goal.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

.sm-goal-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--surface-3);
  color: var(--accent);
  flex: none;
}

.sm-goal.is-active .sm-goal-icon {
  background: var(--accent);
  color: var(--accent-contrast);
}

.sm-goal-text {
  display: flex;
  flex-direction: column;
}

.sm-goal-text strong {
  font-size: var(--fs-md);
}

.sm-goal-text span {
  font-size: var(--fs-sm);
  color: var(--ink-muted);
}

.sm-goal-body:empty {
  display: none;
}

.sm-goal-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sm-source {
  align-self: flex-start;
}

.sm-save-template {
  align-self: flex-start;
}

.sm-templates {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
}

.sm-template {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}

.sm-template.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.sm-template-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.sm-type-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sm-note {
  padding: 4px 0;
}

/* Field blocks */
.fb {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  gap: 14px;
}

.fb-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.fb-label {
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.fb-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-content: flex-start;
  max-height: 260px;
  overflow-y: auto;
}

.fb-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border: 1px dashed var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  font-size: var(--fs-sm);
  color: var(--ink-soft);
  cursor: grab;
  transition: border-color var(--transition), background var(--transition), color var(--transition);
}

.fb-chip:hover {
  border-color: var(--accent);
  border-style: solid;
  color: var(--accent-ink);
  background: var(--accent-soft);
}

.fb-chip.is-static {
  border-style: solid;
  border-color: var(--border);
  background: var(--surface-3);
  font-size: var(--fs-xs);
  padding: 2px 8px;
  cursor: default;
}

.fb-board {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 120px;
  padding: 10px;
  border: 1.5px dashed var(--border-strong);
  border-radius: 14px;
  background: var(--surface-inset);
  transition: border-color var(--transition), background var(--transition);
}

.fb-board.is-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.fb-board.is-insert-end::after {
  content: "";
  height: 3px;
  border-radius: 3px;
  background: var(--accent);
}

.fb-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1;
  min-height: 96px;
  font-size: var(--fs-sm);
  color: var(--ink-faint);
}

.fb-block {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  cursor: grab;
  animation: pop-in 140ms ease;
}

.fb-block.is-dragging {
  opacity: 0.4;
}

.fb-block.is-insert-before::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -5px;
  height: 3px;
  border-radius: 3px;
  background: var(--accent);
}

.fb-grip {
  display: flex;
  color: var(--ink-faint);
  transform: rotate(90deg);
}

.fb-name {
  flex: 1;
  min-width: 0;
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: none;
  font: inherit;
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--ink);
}

.fb-name:hover,
.fb-name:focus {
  border-color: var(--border);
  background: var(--surface-inset);
  outline: none;
}

.fb-type {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-3);
  font: inherit;
  font-size: var(--fs-xs);
  color: var(--ink-soft);
}

.fb-remove {
  display: flex;
  padding: 4px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--ink-faint);
  cursor: pointer;
}

.fb-remove:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.fb-add {
  position: relative;
  display: flex;
  align-items: center;
}

.fb-add svg {
  position: absolute;
  left: 10px;
  color: var(--ink-faint);
}

.fb-add-input {
  width: 100%;
  padding-left: 30px;
  border-radius: 10px;
}

.fb-json-wrap {
  grid-column: 1 / -1;
}

.fb-json-wrap summary {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink-muted);
  cursor: pointer;
}

.fb-json {
  margin-top: 8px;
  padding: 12px;
  border-radius: 10px;
  background: var(--surface-inset);
  border: 1px solid var(--border-faint);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--ink-soft);
  max-height: 200px;
  overflow: auto;
}

/* ==========================================================================
   Document preview & viewer
   ========================================================================== */
.docpreview {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  outline: none;
}

/* Under the header: the page list on the left, the page itself on the right. */
.viewer-body {
  flex: 1;
  min-height: 0;
  display: flex;
}

.viewer-body > .viewer-canvas,
.viewer-body > .viewer-stage {
  flex: 1;
  min-width: 0;
}

.docpreview > .viewer-body > .page-rail,
.viewer-body > .viewer-rail {
  flex: none;
  width: 120px;
}

.row.gap-4 {
  gap: 4px;
}

.page-slider {
  width: 120px;
  accent-color: var(--accent);
}

/* Document header: one white bar with full-size controls. Secondary actions
   live behind « ⋯ »; below a given width the zoom folds away (the wheel still
   zooms) rather than shrinking every control. */
.docpreview .viewer-toolbar,
.viewer.is-v2 .viewer-toolbar {
  flex: none;
  flex-wrap: nowrap;
  align-items: center;
  gap: 10px;
  height: var(--viewer-bar-h, 76px);
  min-height: var(--viewer-bar-h, 76px);
  padding: 0 20px;
  container-type: inline-size;
}

.docpreview .viewer-toolbar > *,
.viewer.is-v2 .viewer-toolbar > * {
  flex: none;
}

.docpreview .viewer-toolbar > .viewer-title,
.viewer.is-v2 .viewer-toolbar > .viewer-title {
  flex: 1 1 auto;
  align-items: flex-start;
  min-width: 120px;
  max-width: none;
  margin-right: 6px;
}

.docpreview .viewer-toolbar > .spacer,
.viewer.is-v2 .viewer-toolbar > .spacer {
  display: none;
}

@container (max-width: 880px) {
  .tb-zoom {
    display: none !important;
  }
}

@container (max-width: 640px) {
  .tb-pager {
    display: none !important;
  }
}

.tb-btn.btn {
  position: relative;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink-soft);
}

.tb-btn.btn svg {
  width: 18px;
  height: 18px;
}

.tb-btn.btn:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--surface-2);
  color: var(--ink);
}

.tb-btn.viewer-back {
  border-radius: 999px;
}

.tb-btn.is-on {
  border-color: var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.tb-btn.is-on:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent-soft) 70%, var(--accent) 12%);
  color: var(--accent-ink);
}

.tb-dot {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--surface);
}

.tb-dot.is-green { background: var(--success); }
.tb-dot.is-orange { background: #d98a00; }
.tb-dot.is-red { background: var(--danger); }

.tb-btn.btn-ghost-danger:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
  background: color-mix(in srgb, var(--danger) 8%, var(--surface));
  color: var(--danger);
}

.tb-zoom-value {
  min-width: 56px;
}

.docpreview .viewer-toolbar .btn-sm,
.viewer.is-v2 .viewer-toolbar .btn-sm {
  height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  font-size: 13.5px;
}

.docpreview .viewer-toolbar .btn-icon.btn-sm,
.viewer.is-v2 .viewer-toolbar .btn-icon.btn-sm {
  width: 38px;
  padding: 0;
}

.docpreview .viewer-toolbar .btn-sm svg,
.viewer.is-v2 .viewer-toolbar .btn-sm svg {
  width: 17px;
  height: 17px;
}

.docpreview .viewer-toolbar .badge,
.viewer.is-v2 .viewer-toolbar .badge {
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 12.5px;
  display: inline-flex;
  align-items: center;
}

.tb-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 42px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}

.tb-group .btn-sm {
  height: 32px !important;
  border-radius: 9px !important;
}

.tb-group .btn-icon.btn-sm {
  width: 32px !important;
}

.tb-group .page-counter,
.tb-group .tnum {
  padding: 0 6px;
  font-weight: 600;
}

.tb-group .page-slider {
  margin: 0 4px;
}

.btn.btn-pill {
  height: 42px !important;
  padding: 0 22px 0 18px !important;
  border-radius: 999px !important;
  font-size: 14.5px !important;
  font-weight: 650;
  box-shadow: 0 6px 18px -8px color-mix(in srgb, var(--accent) 70%, transparent);
}

.btn.btn-pill svg {
  width: 18px !important;
  height: 18px !important;
}

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

.btn-ghost-danger:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--red-700, #c92a2a) 35%, transparent);
  background: color-mix(in srgb, var(--red-700, #c92a2a) 9%, transparent);
  color: var(--red-700, #c92a2a);
}

.viewer-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  max-width: 44ch;
}

.viewer-name {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  margin-left: -8px;
  padding: 3px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 15.5px;
  font-weight: 650;
  text-align: left;
  cursor: text;
  transition: background var(--transition), border-color var(--transition);
}

.viewer-name svg {
  flex: none;
  color: var(--ink-faint);
  opacity: 0;
  transition: opacity var(--transition);
}

.viewer-name:hover {
  border-color: var(--border);
  background: var(--surface-2);
}

.viewer-name:hover svg {
  opacity: 1;
}

.viewer-name-input {
  height: 34px;
  min-width: 260px;
  font-size: 15px;
  font-weight: 600;
}

.viewer-meta {
  overflow: hidden;
  font-size: 12px;
  color: var(--ink-muted);
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* Side panel tabs: roomier. */
.viewer.is-v2 .viewer-side-tabs {
  flex: none;
  gap: 2px;
  padding: 16px 14px 0;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--surface);
}

.viewer.is-v2 .viewer-side-tabs button {
  flex: none;
  padding: 10px 11px 13px;
  font-size: 13.5px;
  white-space: nowrap;
}

.viewer.is-v2 .viewer-side-body {
  padding: 18px 18px 24px;
}

.page-rail {
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100%;
  padding: 16px 18px 24px;
  overflow-y: auto;
  border-right: 1px solid var(--border-faint);
  background: var(--surface-2);
  scrollbar-width: thin;
}

.page-rail-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.page-rail-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1.38;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}

.page-rail-item:hover .page-rail-thumb {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px -8px rgba(15, 23, 42, 0.35);
}

.page-rail-item .page-rail-num {
  position: absolute;
  left: 50%;
  bottom: -8px;
  min-width: 22px;
  height: 18px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  line-height: 16px;
  text-align: center;
  transform: translateX(-50%);
}

.page-rail-item.is-active .page-rail-num {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-contrast, #fff);
}

.page-rail-item:last-child {
  margin-bottom: 8px;
}

.page-rail-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
  display: block;
}

.page-rail-blank {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--ink-faint);
}

.page-rail-item:hover .page-rail-thumb {
  border-color: var(--border-strong);
}

.page-rail-item.is-active .page-rail-thumb {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.page-rail-num {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.page-rail-mark {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 0 2px #fff;
}

.viewer.is-v2 {
  --side-w: 500px;
  grid-template-columns: minmax(0, 1fr) 6px var(--side-w);
}

.viewer.is-v2.has-rail {
  grid-template-columns: minmax(0, 1fr) 6px var(--side-w);
}

.viewer-rail {
  min-height: 0;
  overflow: hidden;
}

.viewer-resizer {
  position: relative;
  cursor: col-resize;
  background: var(--border);
  transition: background var(--transition);
  touch-action: none;
}

.viewer-resizer::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2px;
  height: 36px;
  border-radius: 2px;
  background: var(--ink-faint);
  transform: translate(-50%, -50%);
}

.viewer-resizer:hover,
.viewer.is-resizing .viewer-resizer {
  background: var(--accent);
}

.viewer.is-resizing {
  user-select: none;
  cursor: col-resize;
}

.viewer.is-resizing .viewer-stage {
  pointer-events: none;
}

.viewer.is-v2 .viewer-side {
  border-left: 0;
}

/* Main action of the side panel (e.g. « Valider et suivant »), bottom-right. */
.viewer-side-foot {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  padding: 14px 18px;
  border-top: 1px solid var(--border-faint);
  background: var(--surface);
}

.viewer-side-foot-hint {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--ink-faint);
}

.viewer-side-foot .btn-pill {
  height: 48px !important;
  padding: 0 26px 0 22px !important;
  font-size: 15px !important;
}

/* ==========================================================================
   Rich text (formatted tables)
   ========================================================================== */
.rt-editor {
  display: flex;
  flex-direction: column;
}

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

.rt-editor.is-compact .rt-body {
  gap: 6px;
}

.rt-text-input {
  width: 100%;
  min-height: 24px;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: none;
  font: inherit;
  font-size: var(--fs-md);
  line-height: 1.55;
  color: var(--ink);
  resize: none;
  overflow: hidden;
  white-space: pre-wrap;
}

.rt-text-input:hover {
  border-color: var(--border-faint);
  background: var(--surface-inset);
}

.rt-text-input:focus {
  border-color: var(--accent);
  background: var(--surface);
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent);
}

.rt-raw {
  min-height: 160px;
}

/* Rendered passage (Markdown, formulas, inline HTML). */
.rt-md {
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: var(--fs-md);
  line-height: 1.6;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.rt-md.is-editable {
  cursor: text;
  transition: background var(--transition), border-color var(--transition);
}

.rt-md.is-editable:hover,
.rt-md.is-editable:focus-visible {
  border-color: var(--border-faint);
  background: var(--surface-inset, var(--surface-2));
  outline: none;
}

.rt-md.is-empty {
  color: var(--ink-faint);
  font-style: italic;
}

.rt-md > :first-child {
  margin-top: 0;
}

.rt-md > :last-child {
  margin-bottom: 0;
}

.rt-md p {
  margin: 0 0 0.55em;
}

.rt-md h1,
.rt-md h2,
.rt-md h3,
.rt-md h4,
.rt-md h5,
.rt-md h6 {
  margin: 0.5em 0 0.35em;
  font-weight: 700;
  line-height: 1.3;
  color: var(--ink);
}

.rt-md h1 { font-size: 1.35em; }
.rt-md h2 { font-size: 1.22em; }
.rt-md h3 { font-size: 1.1em; }
.rt-md h4,
.rt-md h5,
.rt-md h6 { font-size: 1em; }

.rt-md strong,
.rt-md b {
  font-weight: 700;
}

.rt-md ul,
.rt-md ol {
  margin: 0.2em 0 0.55em;
  padding-left: 1.4em;
}

.rt-md li + li {
  margin-top: 0.15em;
}

.rt-md blockquote {
  margin: 0.4em 0;
  padding: 2px 0 2px 12px;
  border-left: 3px solid var(--border-strong);
  color: var(--ink-muted);
}

.rt-md code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-3);
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.92em;
}

.rt-md mark {
  padding: 0 2px;
  border-radius: 3px;
  background: color-mix(in srgb, #ffd43b 45%, transparent);
  color: inherit;
}

.rt-md hr {
  margin: 0.6em 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.rt-md .katex-display {
  margin: 0.5em 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.rt-md .md-table-wrap {
  overflow-x: auto;
}

.rt-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.rt-table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
}

.rt-table-wrap th,
.rt-table-wrap td {
  padding: 6px 9px;
  border-bottom: 1px solid var(--border-faint);
  border-right: 1px solid var(--border-faint);
  text-align: left;
  vertical-align: top;
  color: var(--ink);
}

.rt-table-wrap th:last-child,
.rt-table-wrap td:last-child {
  border-right: 0;
}

.rt-table-wrap tr:last-child td {
  border-bottom: 0;
}

.rt-table-wrap th,
.rt-table-wrap thead td {
  background: var(--surface-3);
  font-weight: 650;
}

.rt-table-wrap thead:not(:has(th:not(:empty))):not(:focus-within) th {
  height: 6px;
  padding-top: 0;
  padding-bottom: 0;
}

.rt-table-wrap tbody tr:nth-child(even) td {
  background: color-mix(in srgb, var(--surface-3) 40%, transparent);
}

.rt-table-wrap.is-editable td[contenteditable],
.rt-table-wrap.is-editable th[contenteditable] {
  cursor: text;
  outline: none;
  transition: box-shadow var(--transition);
}

.rt-table-wrap.is-editable td[contenteditable]:hover,
.rt-table-wrap.is-editable th[contenteditable]:hover {
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

.rt-table-wrap.is-editable td[contenteditable]:focus,
.rt-table-wrap.is-editable th[contenteditable]:focus {
  box-shadow: inset 0 0 0 2px var(--accent);
  background: var(--accent-soft);
}

.rt-view {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rt-text {
  white-space: pre-wrap;
  font-size: var(--fs-md);
  line-height: 1.55;
}

.rt-toggle {
  margin: 0;
  flex: none;
}

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

.text-panel-head,
.text-panel-foot {
  gap: 8px;
}

.rt-status {
  font-variant-numeric: tabular-nums;
}

.correction-body .rt-toggle {
  align-self: flex-end;
}

/* ==========================================================================
   Chat (Résultats)
   ========================================================================== */
/* Grid / document / sources on the left, the agent docked on the right. */
.results-split {
  --agent-w: 540px;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  overflow: hidden;
}

.results-split.has-dock {
  grid-template-columns: minmax(0, 1fr) 6px var(--agent-w);
}

.results-split.is-resizing {
  user-select: none;
  cursor: col-resize;
}

.results-split.is-resizing .results-main {
  pointer-events: none;
}

.results-main {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.results-main > .viewer,
.results-main > .src-pane {
  flex: 1;
  min-height: 0;
}

/* Next to the agent, an opened document keeps the page and its rail: the OCR
   tabs come back when the agent is closed. */
.results-split.has-dock .viewer.is-v2,
.agent-context .viewer.is-v2 {
  grid-template-columns: minmax(0, 1fr);
}

.results-split.has-dock .viewer.is-v2 .viewer-side,
.results-split.has-dock .viewer.is-v2 .viewer-resizer,
.agent-context .viewer.is-v2 .viewer-side,
.agent-context .viewer.is-v2 .viewer-resizer {
  display: none;
}

.agent-resizer {
  position: relative;
  cursor: col-resize;
  background: var(--border);
  touch-action: none;
  transition: background var(--transition);
}

.agent-resizer::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2px;
  height: 40px;
  border-radius: 2px;
  background: var(--ink-faint);
  transform: translate(-50%, -50%);
}

.agent-resizer:hover,
.results-split.is-resizing .agent-resizer {
  background: var(--accent);
}

.agent-dock {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  background: var(--surface);
  animation: agent-in 260ms cubic-bezier(0.2, 0.9, 0.3, 1);
}

@keyframes agent-in {
  from {
    opacity: 0;
    transform: translateX(24px);
  }
}

.agent-context {
  display: none;
  min-width: 0;
  min-height: 0;
}

.agent-dock.is-full {
  position: fixed;
  inset: 0;
  z-index: 70;
  grid-template-columns: minmax(360px, 44%) minmax(0, 1fr);
  animation: agent-full 220ms ease-out;
}

@keyframes agent-full {
  from {
    opacity: 0;
    transform: scale(0.985);
  }
}

.agent-dock.is-full .agent-context {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}

.agent-dock.is-full .agent-context > .src-pane {
  flex: 1;
  min-height: 0;
}

.agent-dock.is-full .agent-chat .chat-messages,
.agent-dock.is-full .agent-chat .chat-compose,
.agent-dock.is-full .agent-history {
  width: 100%;
  max-width: 900px;
  margin-inline: auto;
}

.agent-dock.is-full .agent-chat .chat-compose {
  max-width: 872px;
}

body.has-agent-full {
  overflow: hidden;
}

.agent-chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
}

.agent-head {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
  box-sizing: border-box;
  height: var(--viewer-bar-h, 76px);
  padding: 0 14px 0 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent-soft) 55%, var(--surface)) 0%, var(--surface) 100%);
}

.agent-badge {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin-right: 4px;
  border-radius: 11px;
  background: linear-gradient(125deg, #0b1a3a 0%, #1d3a8a 55%, #4a6fe0 100%);
  color: #ffd66b;
  box-shadow: 0 6px 16px -8px rgba(29, 58, 138, 0.8);
}

.agent-title {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 0;
}

.agent-title strong {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}

.agent-scope {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  padding: 2px 8px 2px 6px;
  margin-left: -6px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: none;
  font-size: 12px;
  color: var(--ink-muted);
  cursor: pointer;
}

.agent-scope svg {
  flex: none;
  color: var(--accent);
}

.agent-scope:hover {
  border-color: var(--border);
  background: var(--surface);
  color: var(--ink);
}

.agent-tool {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: none;
  color: var(--ink-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.agent-tool svg {
  width: 18px;
  height: 18px;
}

.agent-tool:hover,
.agent-tool.is-on {
  border-color: var(--border);
  background: var(--surface);
  color: var(--ink);
}

.agent-tool.is-strong {
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--ink);
}

.agent-tool.is-strong svg {
  stroke-width: 2.6;
}

.agent-tool.is-strong:hover {
  border-color: var(--accent);
  color: var(--accent-ink);
}

.chat-divider {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-muted);
}

.chat-divider::before,
.chat-divider::after {
  content: "";
  flex: 1;
  border-top: 1px dashed var(--border-strong);
}

.chat-divider svg {
  color: var(--accent);
}

.agent-history {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 12px 14px 20px;
}

.agent-history.hidden,
.chat-messages.hidden,
.chat-compose.hidden {
  display: none;
}

.agent-history-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 12px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border-faint);
}

.agent-history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.agent-history-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 10px 10px 12px;
  border: 1px solid var(--border-faint);
  border-radius: 12px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}

.agent-history-row:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.agent-history-row.is-current {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.agent-history-icon {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--surface-3);
  color: var(--ink-muted);
}

.agent-history-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.agent-history-text strong {
  font-size: 13.5px;
  color: var(--ink);
}

.agent-history-text span {
  font-size: 11.5px;
  color: var(--ink-muted);
}

.agent-history-remove {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--ink-faint);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition), background var(--transition), color var(--transition);
}

.agent-history-row:hover .agent-history-remove,
.agent-history-remove:focus-visible {
  opacity: 1;
}

.agent-history-remove:hover {
  background: color-mix(in srgb, var(--red-700, #c92a2a) 10%, transparent);
  color: var(--red-700, #c92a2a);
}

.agent-history-empty,
.agent-history-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin: auto 0;
  padding: 40px 0;
  color: var(--ink-muted);
  font-size: var(--fs-sm);
  text-align: center;
}

.agent-history-empty strong {
  color: var(--ink);
}

/* Scope browser */
.src-scope {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.src-scope .src-section {
  margin-bottom: 0;
}

.src-scope-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--accent-border);
  border-radius: 12px;
  background: var(--accent-soft);
  font-size: var(--fs-sm);
  line-height: 1.45;
  color: var(--ink-soft);
}

.src-scope-note svg {
  flex: none;
  margin-top: 2px;
  color: var(--accent);
}

.src-scope-note strong {
  color: var(--ink);
}

.src-crumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
}

.src-crumb,
.src-pin {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-muted);
  cursor: pointer;
}

.src-crumb:hover,
.src-pin:hover {
  background: var(--surface-3);
  color: var(--ink);
}

.src-crumb.is-scope,
.src-pin.is-scope {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

/* Borderless, so its text lines up with the title instead of its box. */
.src-crumbs > .src-crumb:first-child:not(.is-scope) {
  margin-left: -10px;
}

.src-pin {
  align-self: flex-start;
  border-color: var(--border);
}

.src-crumb-sep {
  display: inline-flex;
  color: var(--ink-faint);
}

.src-folder {
  grid-column: span 2;
  align-self: start;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.src-folder.is-in {
  opacity: 1;
}

.src-folder:hover {
  opacity: 1;
  border-color: var(--border-strong);
}

.src-folder.is-scope {
  opacity: 1;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent);
}

.src-folder-icon {
  flex: none;
  display: flex;
  color: var(--accent);
}

.src-folder-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.src-folder-text strong {
  font-size: 13px;
  color: var(--ink);
}

.src-folder-text span {
  font-size: 11.5px;
  color: var(--ink-muted);
}

.src-doc-thumb {
  position: relative;
}

.src-doc-open {
  position: absolute;
  top: 5px;
  right: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.72);
  color: #fff;
  opacity: 0;
  transition: opacity var(--transition);
}

.src-doc:hover .src-doc-open {
  opacity: 1;
}

.src-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--surface-1, var(--surface));
}

.src-pane > .viewer {
  flex: 1;
  min-height: 0;
}

.src-head:empty {
  display: none;
}

.src-hero {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-width: 0;
  margin-bottom: 4px;
}

.src-hero-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.src-kicker {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.src-hero strong {
  font-size: 22px;
  font-weight: 720;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--ink);
}

.src-hero-desc {
  max-width: 62ch;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink-muted);
}

.src-back {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
}

.src-back:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.src-back:active {
  transform: translateX(-2px);
}

.src-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.src-section {
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 8px;
}

.src-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 28px 16px;
  border: 1.5px dashed var(--border-strong);
  border-radius: 16px;
  text-align: center;
  color: var(--ink-muted);
  font-size: var(--fs-sm);
}

.src-empty svg {
  color: var(--accent);
}

.src-empty strong {
  color: var(--ink);
}

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

.src-card {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.src-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
}

.src-card.is-new {
  border-color: var(--accent);
  animation: src-in 520ms cubic-bezier(0.2, 0.9, 0.3, 1);
}

@keyframes src-in {
  from {
    opacity: 0;
    transform: translateX(-14px);
  }
}

.src-card-thumb,
.src-doc-thumb {
  aspect-ratio: 1 / 1.3;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--border-faint);
  overflow: hidden;
}

.src-card-thumb img,
.src-doc-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
  display: block;
}

.src-thumb-blank {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--ink-faint);
  background: var(--surface-3);
}

.src-card-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.src-excerpt {
  margin-top: 4px;
  font-size: var(--fs-sm);
  line-height: 1.45;
  color: var(--ink-soft);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.src-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 10px;
}

.src-doc {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.src-doc.is-in {
  opacity: 1;
}

.src-doc:hover {
  opacity: 1;
  border-color: var(--border-strong);
}

.src-doc.is-cited {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
}

.src-doc.is-scope {
  opacity: 1;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent);
}

.src-doc-name {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.chat-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-title .small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chat-intro {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin: auto 0;
  text-align: center;
}

.chat-intro-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  margin-bottom: 4px;
  border-radius: 16px;
  background: var(--accent-soft);
  color: var(--accent);
}

.chat-suggestions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 380px;
  margin-top: 12px;
}

.chat-suggestion {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-size: var(--fs-md);
  color: var(--ink-soft);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}

.chat-suggestion:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.chat-msg {
  display: flex;
}

.chat-msg.is-user {
  justify-content: flex-end;
}

.chat-bubble {
  max-width: 92%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: var(--fs-md);
  line-height: 1.55;
}

.chat-msg.is-user .chat-bubble {
  background: var(--accent);
  color: var(--accent-contrast);
  border-bottom-right-radius: 5px;
}

.chat-msg.is-assistant .chat-bubble {
  background: var(--surface-3);
  color: var(--ink);
  border-bottom-left-radius: 5px;
}

.chat-msg.is-error .chat-bubble {
  background: var(--danger-soft);
  color: var(--danger);
}

.chat-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.chat-source {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--accent-ink);
  cursor: pointer;
}

.chat-source span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-source:hover {
  border-color: var(--accent);
}

.chat-meta {
  margin-top: 6px;
  font-size: var(--fs-xs);
  color: var(--ink-faint);
}

.typing-dots {
  display: inline-flex;
  gap: 4px;
  margin-right: 8px;
}

.typing-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-muted);
  animation: typing 1s ease-in-out infinite;
}

.typing-dots i:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dots i:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typing {
  0%,
  100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  50% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.chat-compose {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0 14px 14px;
  padding: 8px 8px 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.chat-compose:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent);
}

.chat-input {
  flex: 1;
  min-height: 24px;
  max-height: 160px;
  padding: 6px 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: var(--fs-base);
  color: var(--ink);
  resize: none;
  outline: none;
}

.chat-send {
  border-radius: 12px;
  flex: none;
}

/* ==========================================================================
   Paramètres
   ========================================================================== */
/* The whole page scrolls, so there is a single scrollbar against the right
   edge of the window; the tab list stays in view. */
.page.page-settings {
  display: block;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
}

.page-settings .set-layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  align-items: start;
  gap: 24px;
  padding: 8px var(--view-pad-x) 0;
}

.set-tabs {
  position: sticky;
  top: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.set-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 0;
  border-radius: 12px;
  background: none;
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--ink-muted);
  text-align: left;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.set-tab:hover {
  background: var(--surface-3);
  color: var(--ink);
}

.set-tab.is-active {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.set-content {
  min-width: 0;
  padding-bottom: 48px;
}

.set-content .view,
.set-content .view-pad,
.set-content .page {
  height: auto;
  overflow: visible;
}

.set-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 860px;
}

.set-card {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.set-card-head {
  padding: 16px 20px 0;
}

.set-card-head h3 {
  font-size: var(--fs-lg);
  font-weight: 680;
}

.set-card-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px 20px 20px;
}

.set-embedded .view-pad {
  padding: 0;
  max-width: 1100px;
  margin: 0;
}

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

.tpl-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border-faint);
  border-radius: 12px;
  background: var(--surface-1, var(--surface));
}

.tpl-row.is-off {
  opacity: 0.55;
}

.tpl-main {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

/* ==========================================================================
   Small screens
   ========================================================================== */
@media (max-width: 1080px) {
  .shell.is-v2 .brand {
    justify-content: center;
    padding: 0;
  }

  .shell.is-v2 .brand-logo,
  .shell.is-v2 .brand-toggle,
  .shell.is-v2 .status-label,
  .shell.is-v2 .sidebar-version,
  .shell.is-v2 .account-meta {
    display: none;
  }

  .shell.is-v2 .brand-mark {
    display: block;
  }

  .shell.is-v2 .nav-group {
    padding-inline: 8px;
  }

  .shell.is-v2 .nav-group-label {
    display: none;
  }

  .shell.is-v2 .nav-group + .nav-group::before {
    margin-inline: 6px;
  }

  .shell.is-v2 .nav-item {
    justify-content: center;
    padding-inline: 0;
  }

  .shell.is-v2 .status-line {
    flex-direction: column;
    gap: 6px;
    padding: 0;
  }

  .shell.is-v2 .theme-toggle {
    margin: 0;
  }
}

@media (max-width: 900px) {
  .fb {
    grid-template-columns: 1fr;
  }

  .sm-goals {
    grid-template-columns: 1fr;
  }

  .results-split.has-dock {
    grid-template-columns: minmax(0, 1fr);
  }

  .results-split.has-dock .results-main,
  .results-split.has-dock .agent-resizer {
    display: none;
  }

  .agent-dock.is-full {
    grid-template-columns: minmax(0, 1fr);
  }

  .agent-dock.is-full .agent-context {
    display: none;
  }

  .page-settings .set-layout {
    grid-template-columns: 1fr;
  }

  .set-tabs {
    flex-direction: row;
    overflow-x: auto;
  }

  .viewer.is-v2,
  .viewer.is-v2.has-rail {
    grid-template-columns: minmax(0, 1fr);
  }

  .viewer.is-v2 .viewer-resizer {
    display: none;
  }
}

/* ==========================================================================
   Polish pass
   ========================================================================== */

/* Folders first, then files on their own rows. The break is a zero-height
   full row; the negative margin cancels the extra row gap it creates. */
.drive-break {
  grid-column: 1 / -1;
  height: 0;
  margin-top: -16px;
}

/* Compact stand-in while dragging tiles. Rendered off-screen for the
   browser to snapshot. */
.drive-ghost {
  position: fixed;
  top: -1000px;
  left: -1000px;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 220px;
  padding: 6px 12px 6px 6px;
  border: 1px solid var(--accent-border, var(--border));
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 8px 20px -8px rgba(15, 23, 42, 0.35);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  pointer-events: none;
}

.drive-ghost-thumb {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--surface-3);
  color: var(--ink-muted);
  overflow: hidden;
}

.drive-ghost-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
}

.drive-ghost-name {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.drive-ghost-count {
  flex: none;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-contrast, #fff);
  font-size: 12px;
  line-height: 22px;
  text-align: center;
}

/* Grid bar: the white pill is the search field, with the selection controls
   on its right; the page's buttons sit outside it, on the same line. It takes
   the accent tint while something is selected. */
.drive-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px var(--view-pad-x) 0;
}

.drive-bar + .drive-scroll {
  padding-top: 20px;
}

.drive-toolbar:has(.drive-crumbs:empty) {
  display: none;
}

.drive-selection {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 48px;
  margin: 0;
  padding: 0 6px 0 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  cursor: text;
  transition: background 220ms ease, border-color 220ms ease, box-shadow 220ms ease;
}

.drive-selection:hover {
  border-color: var(--border-strong);
}

.drive-selection:focus-within {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 10%, transparent);
}

.drive-selection.has-selection {
  border-color: var(--accent-border);
  background: var(--accent-soft);
}

.drive-search-icon {
  flex: none;
  display: inline-flex;
  color: var(--ink-faint);
  pointer-events: none;
}

.drive-selection:focus-within .drive-search-icon {
  color: var(--accent-ink);
}

.drive-selection .drive-search {
  flex: 1;
  min-width: 80px;
  width: auto;
  height: 100%;
  padding: 0;
  border: 0;
  outline: none;
  background: none;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
}

.drive-selection .drive-search::placeholder {
  color: var(--ink-faint);
}

.drive-selection .drive-search::-webkit-search-cancel-button {
  cursor: pointer;
}

.drive-selection-main {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: default;
}

.drive-selection-count {
  padding: 0 6px;
  font-size: 12.5px;
  color: var(--ink-faint);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.drive-selection.has-selection .drive-selection-count {
  color: var(--accent-ink);
  font-weight: 650;
  animation: drive-count-in 220ms ease;
}

@keyframes drive-count-in {
  from { opacity: 0; transform: translateY(3px); }
}

.drive-selection-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--ink-muted);
  cursor: pointer;
  animation: drive-count-in 220ms ease;
  transition: background var(--transition), color var(--transition);
}

.drive-selection-icon:hover {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent-ink);
}

.drive-selection-icon.is-danger:hover {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
}

.drive-selection-sep {
  width: 1px;
  height: 22px;
  margin: 0 6px;
  background: var(--border);
}

.drive-selection .drive-select-all {
  display: inline-flex;
  align-items: center;
  position: relative;
  gap: 8px;
  height: 36px;
  margin: 0 0 0 12px;
  padding: 0 14px 0 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  color: var(--ink-soft);
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.drive-selection .drive-select-all input {
  margin: 0;
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

.drive-selection .drive-select-all:hover {
  background: var(--surface-2);
}

.drive-selection .drive-select-all::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 8px;
  bottom: 8px;
  width: 1px;
  background: var(--border);
}

.drive-selection.has-selection .drive-select-all::before {
  display: none;
}

.drive-selection .drive-select-all:has(input:checked),
.drive-selection .drive-select-all:has(input:indeterminate) {
  background: color-mix(in srgb, var(--accent) 16%, var(--surface));
  color: var(--accent-ink);
}

.drive-selection.has-selection .drive-select-all:hover {
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
}

.drive-bar .drive-toolbar-right {
  flex: none;
  margin-left: 0;
  gap: 10px;
}

.drive-bar .drive-toolbar-right:empty {
  display: none;
}

.drive-toolbar-extra {
  display: contents;
}

.drive-bar .drive-toolbar-right .btn,
.drive-bar .drive-toolbar-right .select,
.drive-bar .drive-toolbar-right .select-button {
  height: 48px;
  border-radius: 999px;
}

.drive-bar-btn.btn {
  padding: 0 20px 0 17px;
  font-size: 14px;
  font-weight: 600;
}

.drive-bar-btn.btn:not(.btn-primary) {
  border-color: var(--border);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.drive-bar-btn.btn:not(.btn-primary):hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--surface);
}

.drive-bar .drive-folder-filter {
  max-width: 220px;
}

@media (max-width: 860px) {
  .drive-bar {
    flex-wrap: wrap;
  }

  .drive-selection {
    flex-basis: 100%;
  }

  .drive-select-all span {
    display: none;
  }
}

/* Reorder markers: a bar on the side where the tile will land. */
.drive-card.is-reorder-before {
  box-shadow: -5px 0 0 -1px var(--accent);
}

.drive-card.is-reorder-after {
  box-shadow: 5px 0 0 -1px var(--accent);
}

/* Contrôle qualité: hovering a tile lifts it with a soft halo in its score
   colour and thickens the colour line under the preview. */
.drive-card.is-tier-green { --tier: var(--success); }
.drive-card.is-tier-orange { --tier: #d98a00; }
.drive-card.is-tier-red { --tier: var(--danger); }

.drive-card[class*="is-tier-"] .drive-thumb {
  transition: box-shadow 220ms ease;
}

.drive-card[class*="is-tier-"]:hover {
  border-color: color-mix(in srgb, var(--tier) 60%, var(--border));
  box-shadow: 0 10px 26px -14px color-mix(in srgb, var(--tier) 75%, transparent), 0 0 0 3px color-mix(in srgb, var(--tier) 10%, transparent);
  transform: translateY(-2px);
}

.drive-card[class*="is-tier-"]:hover .drive-thumb {
  box-shadow: inset 0 -5px 0 var(--tier);
}

.drive-card[class*="is-tier-"] .score-badge {
  transition: transform 220ms ease;
}

.drive-card[class*="is-tier-"]:hover .score-badge {
  transform: scale(1.06);
}

.drive-card[class*="is-tier-"].is-selected {
  border-color: var(--accent);
}

/* Main buttons share the Agent IA look (navy gradient), with white icons. */
.btn-fab:not(.is-ai),
.btn.btn-primary.btn-pill,
.drive-bar-btn.btn-primary,
.modal-foot .btn-primary.btn-lg {
  border: none;
  background: linear-gradient(125deg, #0b1a3a 0%, #1d3a8a 55%, #4a6fe0 100%);
  color: #fff;
  box-shadow: 0 10px 24px -10px rgba(29, 58, 138, 0.65), 0 2px 5px rgba(15, 23, 42, 0.16);
}

.btn-fab:not(.is-ai):hover:not(:disabled),
.btn.btn-primary.btn-pill:hover:not(:disabled),
.drive-bar-btn.btn-primary:hover:not(:disabled),
.modal-foot .btn-primary.btn-lg:hover:not(:disabled) {
  background: linear-gradient(125deg, #0b1a3a 0%, #1d3a8a 55%, #4a6fe0 100%);
  filter: brightness(1.12);
  box-shadow: 0 14px 30px -10px rgba(74, 111, 224, 0.7), 0 3px 8px rgba(15, 23, 42, 0.2);
}

.btn-fab:not(.is-ai) svg,
.btn.btn-primary.btn-pill svg,
.drive-bar-btn.btn-primary svg {
  color: #fff;
}

.btn.btn-ai.btn-pill {
  box-shadow: 0 10px 24px -10px rgba(29, 58, 138, 0.65), 0 2px 5px rgba(15, 23, 42, 0.16);
}

/* Dark theme: the navy gradient sinks into dark surfaces. A brighter blue,
   a light top edge and a thin halo keep the main buttons readable. */
html[data-theme="dark"] .btn-fab,
html[data-theme="dark"] .btn-ai,
html[data-theme="dark"] .btn.btn-primary.btn-pill,
html[data-theme="dark"] .drive-bar-btn.btn-primary,
html[data-theme="dark"] .modal-foot .btn-primary.btn-lg {
  background: linear-gradient(125deg, #2447a8 0%, #3a64d8 55%, #6b8ff0 100%);
  color: #fff;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    0 0 0 1px rgba(122, 156, 245, 0.45),
    0 12px 28px -10px rgba(0, 0, 0, 0.8),
    0 6px 22px -8px rgba(74, 111, 224, 0.55);
}

html[data-theme="dark"] .btn-fab:hover:not(:disabled),
html[data-theme="dark"] .btn-ai:hover:not(:disabled),
html[data-theme="dark"] .btn.btn-ai.btn-pill:hover:not(:disabled),
html[data-theme="dark"] .btn.btn-primary.btn-pill:hover:not(:disabled),
html[data-theme="dark"] .drive-bar-btn.btn-primary:hover:not(:disabled),
html[data-theme="dark"] .modal-foot .btn-primary.btn-lg:hover:not(:disabled) {
  background: linear-gradient(125deg, #2447a8 0%, #3a64d8 55%, #6b8ff0 100%);
  color: #fff;
  filter: brightness(1.1);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.26),
    0 0 0 1px rgba(150, 178, 250, 0.6),
    0 14px 32px -10px rgba(0, 0, 0, 0.85),
    0 8px 26px -8px rgba(92, 130, 240, 0.7);
}

html[data-theme="dark"] .btn-fab:not(.is-ai) svg,
html[data-theme="dark"] .btn.btn-primary.btn-pill svg,
html[data-theme="dark"] .drive-bar-btn.btn-primary svg,
html[data-theme="dark"] .modal-foot .btn-primary.btn-lg svg {
  color: #fff;
}

html[data-theme="dark"] .btn-fab .btn-fab-count {
  background: rgba(255, 255, 255, 0.24);
  color: #fff;
}

/* Dialogs: soft rise on open, quick fade on close. */
.overlay {
  animation: overlay-in 200ms ease-out;
}

.overlay > .modal {
  animation: modal-in 260ms cubic-bezier(0.16, 1, 0.3, 1);
}

.overlay.is-leaving {
  pointer-events: none;
  animation: overlay-out 180ms ease-in forwards;
}

.overlay.is-leaving > .modal {
  animation: modal-out 180ms ease-in forwards;
}

@keyframes overlay-in {
  from { opacity: 0; }
}

@keyframes overlay-out {
  to { opacity: 0; }
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.97);
  }
}

@keyframes modal-out {
  to {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

/* Confirmation dialogs: icon, title and message in one block, no separate
   header strip. */
.modal.is-confirm {
  position: relative;
  width: min(460px, 100%);
  border-radius: 20px;
  overflow: hidden;
}

.modal.is-confirm .modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
}

.modal.is-confirm .modal-body {
  padding: 26px 26px 8px;
}

.confirm-body {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.confirm-icon {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.modal.is-danger .confirm-icon {
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
  color: var(--danger);
}

.confirm-text {
  flex: 1;
  min-width: 0;
  padding-right: 22px;
}

.confirm-text h3 {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--ink);
}

.confirm-text p {
  margin-top: 6px;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink-muted);
  overflow-wrap: anywhere;
}

.confirm-option {
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}

.modal.is-confirm .modal-foot {
  padding: 18px 26px 22px;
  border-top: 0;
  background: none;
}

.modal.is-confirm:has(.confirm-remember) {
  width: min(520px, 100%);
}

.modal.is-confirm:has(.confirm-remember) .modal-foot {
  flex-wrap: wrap;
  row-gap: 12px;
}

.confirm-remember {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 36px;
  margin-left: -8px;
  padding: 0 12px 0 8px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 550;
  color: var(--ink-muted);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition), color var(--transition);
}

.confirm-remember:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.confirm-remember input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.confirm-remember-box {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: transparent;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, transform 140ms ease;
}

.confirm-remember-box svg {
  width: 12px;
  height: 12px;
  stroke-width: 3;
  transform: scale(0.6);
  transition: transform 160ms cubic-bezier(0.16, 1, 0.3, 1);
}

.confirm-remember:hover .confirm-remember-box {
  border-color: var(--ink-faint);
}

.confirm-remember input:checked + .confirm-remember-box {
  border-color: transparent;
  background: linear-gradient(125deg, #0b1a3a 0%, #1d3a8a 55%, #4a6fe0 100%);
  color: #fff;
}

.confirm-remember input:checked + .confirm-remember-box svg {
  transform: scale(1);
}

.confirm-remember:has(input:checked) {
  color: var(--ink);
}

.confirm-remember input:focus-visible + .confirm-remember-box {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}

html[data-theme="dark"] .confirm-remember input:checked + .confirm-remember-box {
  background: linear-gradient(125deg, #2447a8 0%, #3a64d8 55%, #6b8ff0 100%);
}

.modal.is-confirm .modal-foot .btn-lg {
  height: 44px;
  padding: 0 22px;
  border-radius: 999px;
  font-size: 14.5px;
  font-weight: 650;
}

.modal.is-danger .confirm-ok.btn-danger {
  border: none;
  background: var(--danger);
  color: #fff;
  box-shadow: 0 8px 20px -10px color-mix(in srgb, var(--danger) 80%, transparent);
}

.modal.is-danger .confirm-ok.btn-danger:hover:not(:disabled) {
  filter: brightness(1.08);
}

/* ==========================================================================
   Tableau de bord
   ========================================================================== */
.page.page-dashboard {
  display: block;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
}

.dash {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 8px var(--view-pad-x) 48px;
}

.dash-flow {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.dash-step {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 20px 20px 18px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  font: inherit;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}

.dash-step:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.dash-step:not(:last-child)::after {
  content: "";
  position: absolute;
  top: 50%;
  right: -14px;
  width: 10px;
  border-top: 1.5px dashed var(--border-strong);
}

.dash-step-icon {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--ink-soft);
}

.dash-step-num {
  position: absolute;
  right: -6px;
  bottom: -5px;
  min-width: 17px;
  height: 17px;
  border: 2px solid var(--surface);
  border-radius: 999px;
  background: var(--ink-muted);
  color: var(--surface);
  font-size: 9.5px;
  font-weight: 750;
  line-height: 13px;
  text-align: center;
}

.dash-step-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.dash-step-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-muted);
}

.dash-step-value {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.dash-step-value.is-word {
  font-size: 22px;
  letter-spacing: -0.01em;
}

.dash-step-unit {
  font-size: 13px;
  font-weight: 650;
  color: var(--ink-soft);
}

.dash-step-accent {
  font-style: normal;
  color: #b76e00;
}

.dash-step-cta {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 10px 7px 13px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 12.5px;
  font-weight: 650;
  color: var(--ink-soft);
  transition: background var(--transition), color var(--transition);
}

.dash-step:hover .dash-step-cta {
  background: linear-gradient(125deg, #0b1a3a 0%, #1d3a8a 55%, #4a6fe0 100%);
  color: #fff;
}

html[data-theme="dark"] .dash-step-cta {
  background: color-mix(in srgb, var(--accent) 16%, var(--surface));
  box-shadow: inset 0 0 0 1px var(--accent-border);
  color: var(--accent-ink);
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
}

html[data-theme="dark"] .dash-step:hover .dash-step-cta {
  background: linear-gradient(125deg, #2447a8 0%, #3a64d8 55%, #6b8ff0 100%);
  color: #fff;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    0 0 0 1px rgba(122, 156, 245, 0.45),
    0 6px 18px -8px rgba(74, 111, 224, 0.6);
}

.dash-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.dash-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  min-width: 0;
}

.dash-card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px 0;
}

.dash-card-head > div:first-child {
  flex: 1;
  min-width: 0;
}

.dash-card-head h3 {
  font-size: 15px;
  font-weight: 680;
}

.dash-card-head p {
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--ink-muted);
}

.dash-card-head .btn {
  border-radius: 999px;
}

.dash-card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 16px 20px 20px;
}

.dash-legend {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--ink-muted);
}

.dash-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.dash-legend i {
  width: 9px;
  height: 9px;
  border-radius: 3px;
}

.dash-quality {
  display: flex;
  align-items: center;
  gap: 26px;
}

.dash-quality-score {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dash-quality-score strong {
  font-size: 38px;
  font-weight: 720;
  letter-spacing: -0.02em;
  line-height: 1;
}

.dash-quality-score strong.is-green { color: var(--success); }
.dash-quality-score strong.is-orange { color: #d98a00; }
.dash-quality-score strong.is-red { color: var(--danger); }

.dash-quality-score span {
  font-size: 12.5px;
  color: var(--ink-muted);
}

.dash-quality-split {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dash-bar {
  display: flex;
  gap: 3px;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-3);
}

.dash-bar i {
  flex: 1 1 0;
  min-width: 6px;
}

.dash-bar i.is-green { background: var(--success); }
.dash-bar i.is-orange { background: #d98a00; }
.dash-bar i.is-red { background: var(--danger); }
.dash-bar i.is-empty { background: none; }

.dash-tiers {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
}

.dash-tier {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--ink-muted);
}

.dash-tier strong {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.dash-facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: auto;
}

.dash-fact {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface-2);
}

.dash-fact strong {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.dash-fact span {
  font-size: 12px;
  color: var(--ink-muted);
}

.dash-list {
  display: flex;
  flex-direction: column;
}

.dash-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
}

.dash-row + .dash-row {
  border-top: 1px solid var(--border-faint);
}

.dash-row-icon {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink-muted);
}

.dash-row-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dash-row-text strong {
  overflow: hidden;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.dash-row-text span {
  font-size: 12px;
  color: var(--ink-faint);
}

.dash-insights {
  display: flex;
  flex-direction: column;
  gap: 18px;
  flex: 1;
}

.dash-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.dash-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px 7px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 550;
}

.dash-chip i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.dash-chip strong {
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 12px;
  text-align: center;
}

.dash-types {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dash-type {
  display: grid;
  grid-template-columns: minmax(70px, 130px) minmax(0, 1fr) 32px 40px;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}

.dash-type-name {
  overflow: hidden;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-transform: capitalize;
}

.dash-type-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.dash-type-bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.dash-type strong {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.dash-type-share {
  text-align: right;
  font-size: 12px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.dash-empty {
  font-size: 13px;
  color: var(--ink-muted);
}

@media (max-width: 1180px) {
  .dash-flow,
  .dash-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .dash-step:not(:last-child)::after {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .overlay,
  .overlay > .modal,
  .overlay.is-leaving,
  .overlay.is-leaving > .modal {
    animation-duration: 1ms;
  }
}
