/* ===== Design tokens ===== */
:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #f1f4f8;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --primary: #1e3a5f;
  --primary-hover: #16304f;
  --on-primary: #ffffff;
  --secondary: #2563eb;
  --secondary-soft: #e8f0fe;
  --accent: #059669;
  --accent-soft: #e6f6f0;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --ring: rgba(37, 99, 235, 0.35);
  --paper: #fffdf8;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 16px -4px rgba(15, 23, 42, 0.08), 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 12px 32px -8px rgba(15, 23, 42, 0.18);

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-full: 999px;
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 24px; --s-6: 32px; --s-7: 48px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --dur: 180ms;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220; --surface: #111a2b; --surface-2: #17223a; --text: #e6edf7; --text-2: #b4c0d3; --text-3: #8b9ab1;
    --border: #22304a; --border-strong: #31415f; --primary: #3b82f6; --primary-hover: #2f6fde; --on-primary: #ffffff;
    --secondary: #60a5fa; --secondary-soft: #172a4a; --accent: #34d399; --accent-soft: #0f2e27; --danger: #f87171;
    --danger-soft: #3a1a1d; --ring: rgba(96, 165, 250, 0.4); --paper: #0f1828;
    --shadow-md: 0 4px 16px -4px rgba(0, 0, 0, 0.5); --shadow-lg: 0 12px 32px -8px rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1220; --surface: #111a2b; --surface-2: #17223a; --text: #e6edf7; --text-2: #b4c0d3; --text-3: #8b9ab1;
  --border: #22304a; --border-strong: #31415f; --primary: #3b82f6; --primary-hover: #2f6fde; --on-primary: #ffffff;
  --secondary: #60a5fa; --secondary-soft: #172a4a; --accent: #34d399; --accent-soft: #0f2e27; --danger: #f87171;
  --danger-soft: #3a1a1d; --ring: rgba(96, 165, 250, 0.4); --paper: #0f1828;
  --shadow-md: 0 4px 16px -4px rgba(0, 0, 0, 0.5); --shadow-lg: 0 12px 32px -8px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

/* ===== Base ===== */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Vazirmatn", Tahoma, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}
h2 { font-size: 1rem; font-weight: 700; margin: 0; }
p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--secondary); outline-offset: 2px; border-radius: var(--r-sm); }
.muted { color: var(--text-3); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-lg { width: 28px; height: 28px; }

/* ===== Top bar ===== */
.topbar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1120px; margin: 0 auto; padding: var(--s-3) var(--s-4); display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: var(--s-3); }
.brand strong { display: block; font-size: 1.05rem; line-height: 1.3; }
.brand-sub { font-size: 0.8rem; color: var(--text-3); }
.brand-mark { width: 40px; height: 40px; border-radius: var(--r-md); display: grid; place-items: center; background: linear-gradient(135deg, var(--primary), var(--secondary)); color: #fff; box-shadow: var(--shadow-md); }

.icon-btn { width: 44px; height: 44px; border-radius: var(--r-md); display: grid; place-items: center; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); transition: background var(--dur) var(--ease), color var(--dur) var(--ease); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.theme-light { display: none; }
:root[data-theme="dark"] .theme-light { display: block; }
:root[data-theme="dark"] .theme-dark { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-light { display: block; }
  :root:not([data-theme="light"]) .theme-dark { display: none; }
}

/* ===== Layout ===== */
.container { max-width: 1120px; margin: 0 auto; padding: var(--s-5) var(--s-4) var(--s-7); }
.layout { display: grid; grid-template-columns: 1.1fr 1fr; gap: var(--s-4); align-items: start; }
.col { display: flex; flex-direction: column; gap: var(--s-4); min-width: 0; }
@media (max-width: 880px) { .layout { grid-template-columns: 1fr; } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s-5); box-shadow: var(--shadow-sm); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-4); flex-wrap: wrap; }
@media (max-width: 480px) { .card { padding: var(--s-4); } }

/* ===== Stepper ===== */
.stepper { list-style: none; margin: 0 0 var(--s-5); padding: 0; display: flex; align-items: center; gap: var(--s-3); }
.step { display: flex; align-items: center; gap: var(--s-2); color: var(--text-3); font-size: 0.9rem; font-weight: 500; white-space: nowrap; transition: color var(--dur) var(--ease); }
.step-dot { width: 28px; height: 28px; border-radius: var(--r-full); display: grid; place-items: center; font-size: 0.85rem; font-weight: 700; background: var(--surface); border: 1.5px solid var(--border-strong); transition: all var(--dur) var(--ease); }
.step-line { flex: 1; height: 2px; background: var(--border); border-radius: 2px; min-width: 16px; }
.step.active { color: var(--text); }
.step.active .step-dot { border-color: var(--secondary); color: var(--secondary); background: var(--secondary-soft); }
.step.done { color: var(--accent); }
.step.done .step-dot { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (max-width: 480px) { .step span:last-child { font-size: 0.8rem; } }

/* ===== Badge ===== */
.badge { font-size: 0.78rem; font-weight: 600; padding: 2px 10px; border-radius: var(--r-full); background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.badge.live { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.busy { background: var(--secondary-soft); color: var(--secondary); border-color: transparent; }
.badge.ok { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* ===== Recorder ===== */
.recorder.dragover { border-color: var(--secondary); box-shadow: 0 0 0 4px var(--ring); }
.rec-stage { display: flex; flex-direction: column; align-items: center; gap: var(--s-3); padding: var(--s-3) 0 var(--s-2); }
.rec-btn { position: relative; width: 88px; height: 88px; border-radius: var(--r-full); border: none; display: grid; place-items: center; background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow-lg); transition: background var(--dur) var(--ease), transform var(--dur) var(--ease); }
.rec-btn:hover:not(:disabled) { background: var(--primary-hover); }
.rec-btn:active:not(:disabled) { transform: scale(0.96); }
.rec-btn:disabled { opacity: 0.55; }
.rec-btn .rec-icon-stop { display: none; }
.rec-btn.recording { background: var(--danger); }
.rec-btn.recording .rec-icon-mic { display: none; }
.rec-btn.recording .rec-icon-stop { display: block; fill: currentColor; }
.rec-ring { position: absolute; inset: -6px; border-radius: inherit; border: 2px solid var(--danger); opacity: 0; pointer-events: none; }
.rec-btn.recording .rec-ring { animation: pulse 1.6s var(--ease) infinite; }
@keyframes pulse { 0% { transform: scale(0.95); opacity: 0.7; } 100% { transform: scale(1.35); opacity: 0; } }

.wave { width: 100%; max-width: 360px; height: 56px; display: block; }
.rec-meta { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.timer { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; direction: ltr; letter-spacing: 0.02em; }
.hint { font-size: 0.85rem; color: var(--text-3); }
audio { width: 100%; height: 40px; margin-top: var(--s-3); }

.divider { display: flex; align-items: center; gap: var(--s-3); color: var(--text-3); font-size: 0.8rem; margin: var(--s-4) 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.upload { display: flex; align-items: center; justify-content: center; gap: var(--s-2); min-height: 48px; padding: var(--s-3); border: 1.5px dashed var(--border-strong); border-radius: var(--r-md); color: var(--text-2); font-size: 0.9rem; cursor: pointer; text-align: center; transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), color var(--dur) var(--ease); }
.upload:hover { border-color: var(--secondary); color: var(--secondary); background: var(--secondary-soft); }
.upload:focus-within { outline: 2px solid var(--secondary); outline-offset: 2px; }

/* ===== Fields ===== */
.field-wrap { position: relative; }
textarea, input[type="text"] {
  font: inherit; width: 100%; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s-3) var(--s-4);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
}
input[type="text"] { min-height: 44px; padding-block: var(--s-2); }
textarea { resize: vertical; display: block; line-height: 1.9; }
textarea::placeholder, input::placeholder { color: var(--text-3); }
textarea:hover, input[type="text"]:hover { border-color: var(--border-strong); }
textarea:focus, input[type="text"]:focus { outline: none; background: var(--surface); border-color: var(--secondary); box-shadow: 0 0 0 4px var(--ring); }
.field-foot { display: flex; justify-content: flex-end; margin-top: var(--s-2); font-size: 0.8rem; color: var(--text-3); }

.overlay { position: absolute; inset: 0; border-radius: var(--r-md); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s-2); background: color-mix(in srgb, var(--surface) 88%, transparent); color: var(--text-2); font-size: 0.9rem; backdrop-filter: blur(2px); }
.overlay[hidden] { display: none; }
.dots { display: inline-flex; gap: 5px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--secondary); animation: dot 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-4px); } }

.field { display: flex; flex-direction: column; gap: var(--s-1); font-size: 0.85rem; font-weight: 500; color: var(--text-2); margin-top: var(--s-3); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--s-3); }
@media (max-width: 480px) { .grid-2 { grid-template-columns: 1fr; } }

/* ===== Chips ===== */
.group { border: 0; padding: 0; margin: 0 0 var(--s-5); }
.group legend { font-size: 0.85rem; font-weight: 600; color: var(--text-2); margin-bottom: var(--s-2); padding: 0; }
.chips { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.chip { position: relative; cursor: pointer; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 var(--s-4);
  border-radius: var(--r-full); border: 1px solid var(--border); background: var(--surface);
  font-size: 0.9rem; font-weight: 500; color: var(--text-2); user-select: none;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.chip:hover span { border-color: var(--border-strong); color: var(--text); }
.chip input:checked + span { background: var(--secondary-soft); border-color: var(--secondary); color: var(--secondary); font-weight: 600; }
.chip input:focus-visible + span { outline: 2px solid var(--secondary); outline-offset: 2px; }

/* ===== Details ===== */
.more { border-top: 1px solid var(--border); padding-top: var(--s-3); margin-bottom: var(--s-5); }
.more summary { cursor: pointer; font-size: 0.9rem; font-weight: 600; color: var(--text-2); list-style: none; display: flex; align-items: center; gap: var(--s-2); min-height: 32px; }
.more summary::-webkit-details-marker { display: none; }
.more summary::before { content: ""; width: 7px; height: 7px; border-inline-start: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); transition: transform var(--dur) var(--ease); margin-inline-end: 2px; }
.more[open] summary::before { transform: rotate(-45deg); }
.more summary .muted { font-weight: 400; }

/* ===== Buttons ===== */
.primary-btn {
  width: 100%; min-height: 52px; display: flex; align-items: center; justify-content: center; gap: var(--s-2);
  border: none; border-radius: var(--r-md); background: var(--primary); color: var(--on-primary);
  font-size: 1rem; font-weight: 700; box-shadow: var(--shadow-md);
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.primary-btn:hover:not(:disabled) { background: var(--primary-hover); }
.primary-btn:active:not(:disabled) { transform: translateY(1px); }
.primary-btn:disabled { opacity: 0.7; }
.spinner { display: none; width: 18px; height: 18px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.35); border-top-color: #fff; animation: spin 0.8s linear infinite; }
.primary-btn.loading .spinner { display: block; }
.primary-btn.loading .btn-icon { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.kbd-hint { text-align: center; font-size: 0.78rem; color: var(--text-3); margin-top: var(--s-2); }
@media (hover: none) { .kbd-hint { display: none; } }
kbd { font-family: inherit; font-size: 0.72rem; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--border-strong); background: var(--surface-2); direction: ltr; display: inline-block; }

.ghost-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 var(--s-3);
  border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface);
  font-size: 0.85rem; font-weight: 500; color: var(--text-2);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.ghost-btn .icon { width: 16px; height: 16px; }
.ghost-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.ghost-btn:disabled { opacity: 0.45; }
.ghost-btn.accent:not(:disabled) { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); background: var(--accent-soft); }
.ghost-btn.accent:hover:not(:disabled) { filter: brightness(0.97); }
.actions { display: flex; gap: var(--s-2); flex-wrap: wrap; }

/* ===== Output ===== */
.output { margin-top: var(--s-4); }
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--s-1); padding: var(--s-7) var(--s-4); border: 1.5px dashed var(--border); border-radius: var(--r-md); }
.empty-icon { width: 56px; height: 56px; border-radius: var(--r-full); display: grid; place-items: center; background: var(--surface-2); color: var(--text-3); margin-bottom: var(--s-2); }
.empty-title { font-weight: 600; }
.empty .muted { font-size: 0.9rem; max-width: 380px; }

.skeleton { display: flex; flex-direction: column; gap: var(--s-3); padding: var(--s-5); border-radius: var(--r-md); background: var(--paper); border: 1px solid var(--border); }
.skeleton[hidden] { display: none; }
.skeleton i { display: block; height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite linear; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.stages { list-style: none; margin: 0 0 var(--s-2); padding: 0; display: flex; flex-direction: column; gap: var(--s-2); }
.stages li { display: flex; align-items: center; gap: var(--s-2); font-size: 0.9rem; color: var(--text-3); }
.stage-mark { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border-strong); flex: none; display: grid; place-items: center; }
.stages li.active { color: var(--text); font-weight: 600; }
.stages li.active .stage-mark { border-color: var(--secondary); border-top-color: transparent; animation: spin 0.8s linear infinite; }
.stages li.done { color: var(--accent); }
.stages li.done .stage-mark { border-color: var(--accent); background: var(--accent); }
.stages li.done .stage-mark::after { content: ""; width: 5px; height: 8px; border: solid #fff; border-width: 0 2px 2px 0; transform: translate(0, -1px) rotate(45deg); }

.cleaned { margin: var(--s-4) 0 0; }
.cleaned-text { margin-top: var(--s-2); padding: var(--s-3) var(--s-4); background: var(--surface-2); border-radius: var(--r-md); font-size: 0.9rem; color: var(--text-2); white-space: pre-wrap; }

.paper { background: var(--paper); padding: var(--s-6); font-size: 1rem; line-height: 2.1; min-height: 360px; animation: fadein 260ms var(--ease); }
@media (max-width: 480px) { .paper { padding: var(--s-4); } }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ===== Toasts ===== */
.toasts { position: fixed; bottom: var(--s-5); inset-inline: 0; display: flex; flex-direction: column; align-items: center; gap: var(--s-2); pointer-events: none; z-index: 50; padding: 0 var(--s-4); }
.toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: var(--s-3); max-width: 520px; width: 100%;
  padding: var(--s-3) var(--s-4); border-radius: var(--r-md); background: var(--surface); color: var(--text);
  border: 1px solid var(--border); box-shadow: var(--shadow-lg); font-size: 0.9rem;
  animation: toastin 220ms var(--ease);
}
.toast .icon { margin-top: 3px; }
.toast.error { border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.toast.error > .icon { color: var(--danger); }
.toast.success > .icon { color: var(--accent); }
.toast p { flex: 1; }
.toast button { border: 0; background: none; color: var(--text-3); width: 28px; height: 28px; display: grid; place-items: center; border-radius: 6px; margin: -2px; }
.toast button:hover { background: var(--surface-2); color: var(--text); }
.toast.out { animation: toastout 160ms var(--ease) forwards; }
@keyframes toastin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toastout { to { opacity: 0; transform: translateY(6px); } }

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