/* ==========================================================================
   سامانه هوشمند استخراج اطلاعات اسناد — design system
   Logical properties everywhere so the RTL mirroring is structural, not patched.
   ========================================================================== */

@font-face {
  font-family: 'Vazirmatn';
  src: url('../fonts/Vazirmatn-Regular.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('../fonts/Vazirmatn-Medium.woff2') format('woff2');
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('../fonts/Vazirmatn-Bold.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #f4f6f8;
  --bg-tint: #e9eef1;
  --surface: #ffffff;
  --surface-sunken: #f8fafb;
  --ink: #0e1a21;
  --ink-soft: #40525e;
  --muted: #6b7f8c;
  --line: #e2e8ed;
  --line-strong: #cfd9e0;

  --accent: #0e7c74;
  --accent-strong: #0a5f59;
  --accent-ink: #ffffff;
  --accent-soft: #e4f2f0;
  --accent-ring: rgba(14, 124, 116, 0.25);

  --danger: #b4443a;
  --danger-soft: #fbeceb;
  --success: #17795e;

  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;

  --shadow-sm: 0 1px 2px rgba(14, 26, 33, 0.05);
  --shadow: 0 4px 16px -4px rgba(14, 26, 33, 0.09), 0 1px 3px rgba(14, 26, 33, 0.05);
  --shadow-lg: 0 24px 48px -20px rgba(14, 26, 33, 0.22);

  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a1013;
    --bg-tint: #0e161a;
    --surface: #141d22;
    --surface-sunken: #101a1f;
    --ink: #e6eef2;
    --ink-soft: #b3c3cc;
    --muted: #8296a2;
    --line: #222f37;
    --line-strong: #2f3f49;

    --accent: #2fb3a6;
    --accent-strong: #45c9bb;
    --accent-ink: #06201d;
    --accent-soft: #102b29;
    --accent-ring: rgba(47, 179, 166, 0.3);

    --danger: #e08078;
    --danger-soft: #2a1614;
    --success: #4cc79f;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 4px 16px -4px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 24px 48px -20px rgba(0, 0, 0, 0.65);
    color-scheme: dark;
  }
}

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

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Vazirmatn', Tahoma, 'Iranian Sans', 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, p, figure {
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

[hidden] {
  display: none !important;
}

/* --------------------------------------------------------------------------
   Brand
   -------------------------------------------------------------------------- */

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand__mark {
  flex: none;
  inline-size: 40px;
  block-size: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--accent), var(--accent-strong));
  color: var(--accent-ink);
  box-shadow: 0 4px 12px -3px var(--accent-ring);
}

.brand__mark svg {
  inline-size: 21px;
  block-size: 21px;
}

.brand__text {
  min-width: 0;
}

.brand__name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.35;
  white-space: nowrap;
}

.brand__product {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  background: var(--surface);
  transition: background 0.18s var(--ease), border-color 0.18s var(--ease),
    transform 0.18s var(--ease), box-shadow 0.18s var(--ease), opacity 0.18s;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

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

.btn svg {
  inline-size: 16px;
  block-size: 16px;
  flex: none;
}

.btn--primary {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 6px 16px -6px var(--accent-ring);
}

.btn--primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

.btn--ghost {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--ink-soft);
}

.btn--ghost:hover:not(:disabled) {
  background: var(--surface-sunken);
  border-color: var(--muted);
}

.btn--quiet {
  background: transparent;
  color: var(--muted);
  padding: 8px 14px;
}

.btn--quiet:hover:not(:disabled) {
  background: var(--surface-sunken);
  color: var(--ink);
}

.btn--block {
  inline-size: 100%;
}

.btn--lg {
  padding: 13px 28px;
  font-size: 15px;
}

/* --------------------------------------------------------------------------
   Login
   -------------------------------------------------------------------------- */

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1100px 620px at 88% -8%, var(--accent-soft), transparent 62%),
    radial-gradient(900px 520px at 6% 106%, var(--bg-tint), transparent 60%),
    var(--bg);
}

.auth__card {
  inline-size: 100%;
  max-inline-size: 410px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 38px 34px 30px;
  animation: rise 0.5s var(--ease) both;
}

.auth__head {
  text-align: center;
  margin-block-end: 28px;
}

.auth__head .brand {
  justify-content: center;
  margin-block-end: 20px;
}

.auth__title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.auth__subtitle {
  font-size: 13.5px;
  color: var(--muted);
  margin-block-start: 4px;
}

.field {
  margin-block-end: 16px;
}

.field__label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  margin-block-end: 7px;
}

.field__input {
  inline-size: 100%;
  padding: 12px 15px;
  font: inherit;
  font-size: 14.5px;
  color: var(--ink);
  background: var(--surface-sunken);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease),
    background 0.18s var(--ease);
}

.field__input::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

.field__input:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-ring);
}

.field__wrap {
  position: relative;
}

.field__toggle {
  position: absolute;
  inset-inline-end: 6px;
  inset-block-start: 50%;
  transform: translateY(-50%);
  background: none;
  border: 0;
  padding: 8px;
  color: var(--muted);
  border-radius: 8px;
  display: grid;
  place-items: center;
}

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

.field__toggle svg {
  inline-size: 18px;
  block-size: 18px;
}

.alert {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  line-height: 1.6;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 26%, transparent);
  margin-block-end: 16px;
  animation: rise 0.3s var(--ease) both;
}

.alert svg {
  inline-size: 17px;
  block-size: 17px;
  flex: none;
  margin-block-start: 3px;
}

.auth__foot {
  margin-block-start: 24px;
  text-align: center;
  font-size: 11.5px;
  color: var(--muted);
  border-block-start: 1px solid var(--line);
  padding-block-start: 16px;
}

/* --------------------------------------------------------------------------
   App shell
   -------------------------------------------------------------------------- */

.topbar {
  position: sticky;
  inset-block-start: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px clamp(16px, 4vw, 34px);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(14px);
  border-block-end: 1px solid var(--line);
}

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

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px 6px 6px;
  border-radius: 999px;
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--ink-soft);
}

.user-chip__avatar {
  inline-size: 26px;
  block-size: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.layout {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  gap: clamp(16px, 2.4vw, 28px);
  max-inline-size: 1280px;
  margin: 0 auto;
  padding: clamp(18px, 3vw, 32px) clamp(16px, 4vw, 34px) 64px;
  align-items: start;
}

/* --------------------------------------------------------------------------
   Sidebar / history
   -------------------------------------------------------------------------- */

.sidebar {
  position: sticky;
  inset-block-start: 84px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.sidebar__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 18px;
  border-block-end: 1px solid var(--line);
}

.sidebar__title {
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar__title svg {
  inline-size: 16px;
  block-size: 16px;
  color: var(--muted);
}

.counter {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 9px;
  border-radius: 999px;
}

.history {
  list-style: none;
  margin: 0;
  padding: 8px;
  max-block-size: min(58vh, 520px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history__item {
  inline-size: 100%;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 11px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  text-align: start;
  transition: background 0.16s var(--ease), border-color 0.16s var(--ease);
  animation: rise 0.34s var(--ease) both;
}

.history__item:hover {
  background: var(--surface-sunken);
}

.history__item[aria-current='true'] {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}

.history__thumb {
  inline-size: 38px;
  block-size: 38px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  flex: none;
}

.history__meta {
  display: block;
  min-width: 0;
  flex: 1;
}

.history__label,
.history__time {
  display: block;
}

.history__label {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history__time {
  font-size: 11.5px;
  color: var(--muted);
}

.empty {
  padding: 30px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.empty svg {
  inline-size: 30px;
  block-size: 30px;
  opacity: 0.4;
  margin-block-end: 8px;
}

/* --------------------------------------------------------------------------
   Mode select (custom listbox — a native <select> cannot show a per-option
   description, which is the whole point of this control)
   -------------------------------------------------------------------------- */

.select {
  position: relative;
  max-inline-size: 420px;
}

.select__trigger {
  inline-size: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface-sunken);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  text-align: start;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease),
    background 0.18s var(--ease);
}

.select__trigger:hover {
  border-color: var(--accent);
  background: var(--surface);
}

.select__trigger[aria-expanded='true'] {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 4px var(--accent-ring);
}

.select__value {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.select__label {
  font-size: 15px;
  font-weight: 700;
}

.select__eta {
  font-size: 12px;
  color: var(--muted);
}

.select__chevron {
  inline-size: 18px;
  block-size: 18px;
  flex: none;
  color: var(--muted);
  transition: transform 0.22s var(--ease);
}

.select__trigger[aria-expanded='true'] .select__chevron {
  transform: rotate(180deg);
}

.select__list {
  position: absolute;
  inset-inline: 0;
  inset-block-start: calc(100% + 6px);
  z-index: 30;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  max-block-size: 340px;
  overflow-y: auto;
  animation: rise 0.18s var(--ease) both;
}

.select__option {
  padding: 11px 13px;
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.14s var(--ease);
}

.select__option:hover,
.select__option:focus-visible {
  background: var(--surface-sunken);
  outline: none;
}

.select__option[aria-selected='true'] {
  background: var(--accent-soft);
}

.select__option-head {
  display: flex;
  align-items: baseline;
  gap: 9px;
  margin-block-end: 3px;
}

.select__option-label {
  font-size: 14px;
  font-weight: 700;
}

.select__option[aria-selected='true'] .select__option-label {
  color: var(--accent);
}

.select__option-eta {
  font-size: 11.5px;
  color: var(--muted);
  margin-inline-start: auto;
  white-space: nowrap;
}

.select__option-desc {
  font-size: 12.5px;
  color: var(--ink-soft);
  line-height: 1.65;
}

.select__desc {
  margin-block-start: 12px;
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.7;
}

.select__footnote {
  margin-block-start: 6px;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.6;
}

/* --------------------------------------------------------------------------
   Stages
   -------------------------------------------------------------------------- */

.main {
  display: flex;
  flex-direction: column;
  gap: clamp(16px, 2.2vw, 22px);
  min-width: 0;
}

.stage {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: clamp(18px, 2.6vw, 26px);
  animation: rise 0.42s var(--ease) both;
}

/* Every stage runs the `rise` animation, and an animated transform makes the
   element its own stacking context. A dropdown inside one therefore cannot
   paint above the *next* stage however high its own z-index is — the z-index is
   trapped in the parent context. Lifting the stage itself is what escapes.
   Kept below the sticky topbar (z-index 20) so the menu still slides under it. */
.stage--menu-open {
  z-index: 5;
}

.stage__head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-block-end: 18px;
}

.stage__head--flush {
  margin-block-end: 0;
}

.stage__num {
  inline-size: 28px;
  block-size: 28px;
  flex: none;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.stage__title {
  font-size: 15.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.stage__hint {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
}

/* Document type cards */

.doctypes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(178px, 1fr));
  gap: 11px;
}

.doctype {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 16px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  text-align: start;
  transition: border-color 0.18s var(--ease), background 0.18s var(--ease),
    transform 0.18s var(--ease), box-shadow 0.18s var(--ease);
}

.doctype:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.doctype[aria-pressed='true'] {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.doctype__icon {
  inline-size: 38px;
  block-size: 38px;
  flex: none;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--surface-sunken);
  color: var(--muted);
  transition: background 0.18s var(--ease), color 0.18s var(--ease);
}

.doctype[aria-pressed='true'] .doctype__icon {
  background: var(--accent);
  color: var(--accent-ink);
}

.doctype__icon svg {
  inline-size: 19px;
  block-size: 19px;
}

.doctype__name {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
}

.doctype__check {
  inline-size: 18px;
  block-size: 18px;
  color: var(--accent);
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.18s var(--ease), transform 0.18s var(--ease);
}

.doctype[aria-pressed='true'] .doctype__check {
  opacity: 1;
  transform: scale(1);
}

/* Dropzone */

.dropzone {
  position: relative;
  display: grid;
  place-items: center;
  gap: 4px;
  padding: clamp(28px, 6vw, 52px) 24px;
  border: 2px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-sunken);
  text-align: center;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease),
    transform 0.2s var(--ease);
}

.dropzone:hover,
.dropzone.is-dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone.is-dragging {
  transform: scale(1.01);
}

.dropzone__icon {
  inline-size: 54px;
  block-size: 54px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--accent);
  margin-block-end: 10px;
  box-shadow: var(--shadow-sm);
}

.dropzone__icon svg {
  inline-size: 24px;
  block-size: 24px;
}

.dropzone__title {
  font-size: 15px;
  font-weight: 500;
}

.dropzone__hint {
  font-size: 12.5px;
  color: var(--muted);
}

.dropzone__actions {
  display: flex;
  gap: 9px;
  margin-block-start: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

/* Editor (preview + crop) */

.editor {
  display: grid;
  gap: 14px;
}

.canvas-wrap {
  position: relative;
  inline-size: 100%;
  min-block-size: 220px;
  max-block-size: 460px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background:
    repeating-conic-gradient(var(--surface-sunken) 0% 25%, var(--surface) 0% 50%)
    50% / 18px 18px;
  border: 1px solid var(--line);
  touch-action: none;
}

.canvas-wrap canvas {
  display: block;
  max-inline-size: 100%;
  max-block-size: 460px;
}

.crop-layer {
  position: absolute;
  inset: 0;
  cursor: crosshair;
}

.crop-box {
  position: absolute;
  border: 1.5px solid #fff;
  box-shadow: 0 0 0 9999px rgba(8, 16, 20, 0.52);
  cursor: move;
}

.crop-box::before,
.crop-box::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.crop-box::before {
  border-inline: 1px dashed rgba(255, 255, 255, 0.45);
  inline-size: 33.33%;
  margin-inline-start: 33.33%;
}

.crop-box::after {
  border-block: 1px dashed rgba(255, 255, 255, 0.45);
  block-size: 33.33%;
  margin-block-start: 33.33%;
}

.crop-handle {
  position: absolute;
  inline-size: 15px;
  block-size: 15px;
  background: #fff;
  border-radius: 3px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
}

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

.toolbar__spacer {
  flex: 1;
}

/* Progress */

.progress {
  display: grid;
  gap: 14px;
  padding-block: 10px;
}

.progress__bar {
  block-size: 7px;
  border-radius: 999px;
  background: var(--surface-sunken);
  overflow: hidden;
  border: 1px solid var(--line);
}

.progress__fill {
  block-size: 100%;
  inline-size: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  transition: inline-size 0.45s var(--ease);
  position: relative;
  overflow: hidden;
}

.progress__fill::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.4),
    transparent
  );
  animation: sweep 1.5s linear infinite;
}

.progress__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13.5px;
}

.progress__label {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink-soft);
}

.progress__pct {
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  font-weight: 700;
}

.spinner {
  inline-size: 16px;
  block-size: 16px;
  border: 2px solid var(--accent-ring);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.72s linear infinite;
  flex: none;
}

.steps {
  display: grid;
  gap: 7px;
  font-size: 12.5px;
  color: var(--muted);
}

.steps li {
  display: flex;
  align-items: center;
  gap: 9px;
  transition: color 0.3s var(--ease);
}

.steps li[data-state='done'] {
  color: var(--success);
}

.steps li[data-state='active'] {
  color: var(--ink);
  font-weight: 500;
}

.steps__dot {
  inline-size: 7px;
  block-size: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.45;
  flex: none;
}

.steps li[data-state='active'] .steps__dot,
.steps li[data-state='done'] .steps__dot {
  opacity: 1;
}

/* --------------------------------------------------------------------------
   Result
   -------------------------------------------------------------------------- */

.result__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-block-end: 18px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 13px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 500;
  background: color-mix(in srgb, var(--success) 12%, transparent);
  color: var(--success);
}

.badge svg {
  inline-size: 14px;
  block-size: 14px;
}

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

.result__section {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-block-start: 10px;
  padding-block-end: 7px;
  border-block-end: 1px solid var(--line);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--accent);
  animation: rise 0.4s var(--ease) both;
}

.result__section:first-child {
  margin-block-start: 0;
}

.fieldcard {
  position: relative;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
  animation: rise 0.45s var(--ease) both;
  /* Capped: a 27-field passport would otherwise take 1.4s to finish
     revealing itself, leaving the last cards blank on arrival. */
  animation-delay: calc(min(var(--i, 0), 10) * 45ms);
}

.fieldcard:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
}

.fieldcard__label {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--muted);
  margin-block-end: 3px;
}

.fieldcard__value {
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
  word-break: break-word;
  padding-inline-end: 26px;
}

.fieldcard--mono .fieldcard__value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  letter-spacing: 0.04em;
}

.fieldcard--empty .fieldcard__value {
  color: var(--muted);
  font-weight: 400;
  font-style: italic;
}

.fieldcard__copy {
  position: absolute;
  inset-block-start: 10px;
  inset-inline-end: 10px;
  padding: 5px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.18s var(--ease), background 0.18s var(--ease),
    color 0.18s var(--ease);
}

.fieldcard:hover .fieldcard__copy,
.fieldcard__copy:focus-visible {
  opacity: 1;
}

.fieldcard__copy:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.fieldcard__copy svg {
  inline-size: 14px;
  block-size: 14px;
  display: block;
}

.result__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-block-start: 18px;
  padding-block-start: 16px;
  border-block-start: 1px solid var(--line);
}

.result__stats {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

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

/* --------------------------------------------------------------------------
   Toast
   -------------------------------------------------------------------------- */

.toasts {
  position: fixed;
  inset-block-end: 22px;
  inset-inline-start: 22px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 9px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 17px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.34s var(--ease) both;
}

.toast svg {
  inline-size: 16px;
  block-size: 16px;
  flex: none;
}

.toast--error {
  background: var(--danger);
  color: #fff;
}

.toast--ok svg {
  color: var(--success);
}

/* --------------------------------------------------------------------------
   Motion
   -------------------------------------------------------------------------- */

@keyframes rise {
  from { opacity: 0; transform: translateY(9px); }
  to   { opacity: 1; transform: none; }
}

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

@keyframes sweep {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

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

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 940px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar {
    position: static;
    order: 2;
  }
  .main {
    order: 1;
  }
  .history {
    max-block-size: 300px;
  }
}

@media (max-width: 560px) {
  body { font-size: 14.5px; }
  .brand__product { display: none; }
  .user-chip__name { display: none; }
  .user-chip { padding: 6px; }
  .doctypes { grid-template-columns: minmax(0, 1fr); }
  .result__grid { grid-template-columns: minmax(0, 1fr); }
  .auth__card { padding: 30px 22px 24px; }
  .fieldcard__copy { opacity: 1; }
}

/* --------------------------------------------------------------------------
   Print
   -------------------------------------------------------------------------- */

@media print {
  .topbar,
  .sidebar,
  .result__actions,
  .toasts,
  #stage-source,
  #stage-doctype,
  #stage-mode,
  #stage-progress {
    display: none !important;
  }
  body { background: #fff; }
  .layout { display: block; padding: 0; max-inline-size: none; }
  .stage {
    border: 0;
    box-shadow: none;
    padding: 0;
    animation: none;
  }
  .result__section {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-block-start: 10px;
  padding-block-end: 7px;
  border-block-end: 1px solid var(--line);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--accent);
  animation: rise 0.4s var(--ease) both;
}

.result__section:first-child {
  margin-block-start: 0;
}

.fieldcard {
    break-inside: avoid;
    animation: none;
    border: 1px solid #ccc;
    background: #fff;
  }
}
