:root {
  --bg: #edf0f6;
  --card: #ffffff;
  --ink: #161a22;
  --muted: #656e7e;
  --line: #e2e7f0;
  --sig1: #6b4cf6;
  --sig2: #10b8c7;
  --danger: #e5484d;
  --ok: #12a150;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 26, 40, .04), 0 12px 32px rgba(20, 26, 40, .06);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { max-width: 100%; overflow-x: hidden; }
html { scrollbar-gutter: stable; }  /* резерв под скроллбар → нет сдвига при открытии попапа */
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(107, 76, 246, .06), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(16, 184, 199, .05), transparent 55%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2 { margin: 0; letter-spacing: -.02em; }
::selection { background: rgba(107, 76, 246, .18); }

/* ---------- Waveform signature ---------- */
.wave { display: inline-flex; align-items: center; gap: 3px; height: 20px; }
.wave i {
  width: 3px; height: 40%; border-radius: 3px;
  background: linear-gradient(var(--sig1), var(--sig2));
  animation: wv 1.3s ease-in-out infinite;
}
.wave i:nth-child(1) { height: 35%; animation-delay: 0s; }
.wave i:nth-child(2) { height: 70%; animation-delay: .12s; }
.wave i:nth-child(3) { height: 100%; animation-delay: .24s; }
.wave i:nth-child(4) { height: 55%; animation-delay: .36s; }
.wave i:nth-child(5) { height: 80%; animation-delay: .48s; }
.wave i:nth-child(6) { height: 45%; animation-delay: .6s; }
.wave i:nth-child(7) { height: 65%; animation-delay: .72s; }
.wave.lg { height: 46px; gap: 5px; }
.wave.lg i { width: 5px; }
@keyframes wv { 0%, 100% { transform: scaleY(.5); opacity: .8; } 50% { transform: scaleY(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .wave i { animation: none; } }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 900px; margin: 0 auto; padding: 20px 24px;
}
.brand {
  display: inline-flex; align-items: center; gap: 12px;
  font-weight: 800; font-size: 19px; letter-spacing: -.03em;
}

/* ---------- Layout ---------- */
.container {
  max-width: 900px; margin: 0 auto; padding: 4px 24px 64px;
  display: grid; gap: 22px;
}
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px;
}

/* ---------- Dropzone ---------- */
.dropzone {
  display: grid; justify-items: center; gap: 6px; text-align: center;
  padding: 40px 20px; cursor: pointer;
  border: 1.5px dashed var(--line); border-radius: 12px;
  background: linear-gradient(180deg, rgba(107, 76, 246, .015), transparent);
  transition: border-color .15s, background .15s, transform .05s;
}
.dropzone:hover { border-color: var(--sig1); background: rgba(107, 76, 246, .03); }
.dropzone.drag { border-color: var(--sig1); background: rgba(107, 76, 246, .06); transform: scale(.995); }
.dropzone .wave.lg { margin-bottom: 8px; }
.dz-title { font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.dz-sub { color: var(--muted); }
.dz-formats { font-family: var(--mono); font-size: 11.5px; color: var(--muted); letter-spacing: .02em; margin-top: 6px; }

/* ---------- Controls ---------- */
.controls { display: flex; gap: 10px; margin-top: 16px; }
.field {
  font: inherit; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 13px; background: #fbfcfe; outline: none; min-width: 0;
  transition: border-color .15s, box-shadow .15s;
}
.field:focus { border-color: var(--sig1); box-shadow: 0 0 0 3px rgba(107, 76, 246, .12); }
.controls .field { flex: 1; }

/* кастомная стрелка дропдаунов — с нормальным отступом от края, консистентно */
select.field {
  appearance: none; -webkit-appearance: none; cursor: pointer; padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23656e7e' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 13px center;
}

.btn-primary {
  font: inherit; font-weight: 700; color: #fff; cursor: pointer;
  border: 0; border-radius: 10px; padding: 11px 20px;
  background: linear-gradient(135deg, var(--sig1), var(--sig2));
  box-shadow: 0 6px 16px rgba(107, 76, 246, .28);
  transition: filter .15s, transform .05s, opacity .15s;
  white-space: nowrap;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }

.btn-ghost {
  font: inherit; color: var(--muted); cursor: pointer; text-decoration: none;
  border: 1px solid var(--line); border-radius: 9px; padding: 8px 14px;
  background: #fff; transition: color .15s, border-color .15s, background .15s;
}
.btn-ghost:hover { color: var(--ink); border-color: #cfd6e2; }
.btn-ghost.icon { padding: 8px 11px; }

/* ---------- Toggle (не грузить в Obsidian) ---------- */
.toggle {
  display: flex; align-items: center; gap: 11px; margin-top: 12px;
  cursor: pointer; user-select: none;
}
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.tg-track {
  flex-shrink: 0; position: relative; width: 42px; height: 24px; border-radius: 999px;
  background: #d7dded; transition: background .2s;
}
.tg-thumb {
  position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(20, 26, 40, .25); transition: transform .2s;
}
.toggle input:checked + .tg-track { background: linear-gradient(135deg, var(--sig1), var(--sig2)); }
.toggle input:checked + .tg-track .tg-thumb { transform: translateX(18px); }
.toggle input:focus-visible + .tg-track { box-shadow: 0 0 0 3px rgba(107, 76, 246, .2); }
.tg-text { display: flex; flex-direction: column; line-height: 1.3; font-weight: 600; }
.tg-sub { font-weight: 400; font-size: 12px; color: var(--muted); }
.toggle.on .tg-text { color: var(--sig1); }
select:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Status ---------- */
.status {
  display: flex; align-items: center; gap: 12px; margin-top: 16px;
  padding: 14px 16px; border-radius: 11px; border: 1px solid var(--line);
  background: #fbfcfe; font-weight: 500;
}
.status.working { border-color: rgba(107, 76, 246, .3); background: rgba(107, 76, 246, .05); }
.status.working .wave i { animation-duration: .7s; }
.status.ok { border-color: rgba(18, 161, 80, .3); background: rgba(18, 161, 80, .06); }
.status.err { border-color: rgba(229, 72, 77, .35); background: rgba(229, 72, 77, .06); color: var(--danger); }
.status .msg { flex: 1; min-width: 0; }
.status .sub { color: var(--muted); font-weight: 400; font-size: 13px; }

/* ---------- Progress (upload + stepper) ---------- */
.status.prog-mode {
  flex-direction: column; align-items: stretch; gap: 16px;
  animation: progIn .3s ease;
}
@keyframes progIn { from { opacity: 0; transform: translateY(6px); } }
.prog { display: grid; gap: 16px; }

/* upload bar */
.prog-file {
  display: grid; grid-template-columns: 1fr auto; gap: 6px 12px;
  grid-template-areas: "name pct" "track track";
  transition: opacity .4s ease;
}
.prog-file.uploaded { opacity: .55; }
.prog-name {
  grid-area: name; font-weight: 600; letter-spacing: -.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.prog-pct { grid-area: pct; font-family: var(--mono); font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.prog-track {
  grid-area: track; position: relative; height: 8px; border-radius: 999px;
  background: #e9edf6; overflow: hidden;
}
.prog-fill {
  position: absolute; inset: 0 auto 0 0; width: 0;
  border-radius: 999px; background: linear-gradient(90deg, var(--sig1), var(--sig2));
  transition: width .25s cubic-bezier(.4, 0, .2, 1);
}
.prog-fill::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .55), transparent);
  transform: translateX(-100%); animation: shimmer 1.2s ease-in-out infinite;
}
.prog-file.uploaded .prog-fill::after { animation: none; opacity: 0; }
@keyframes shimmer { to { transform: translateX(100%); } }

/* stepper */
.steps { list-style: none; margin: 0; padding: 0; display: grid; }
.step {
  position: relative; display: grid; grid-template-columns: 26px 1fr auto;
  align-items: center; gap: 12px; padding: 8px 0; min-height: 40px;
}
.step:not(:last-child)::after {
  content: ""; position: absolute; left: 12px; top: 50%; width: 2px; height: 100%;
  background: var(--line); border-radius: 2px; z-index: 0;
  transition: background .4s ease;
}
.step.done:not(:last-child)::after { background: linear-gradient(var(--sig1), var(--sig2)); }

.s-dot {
  position: relative; z-index: 1; width: 24px; height: 24px; border-radius: 50%;
  flex-shrink: 0; display: grid; place-items: center; background: var(--card);
  border: 2px solid var(--line);
  transition: border-color .3s, background .3s, box-shadow .3s;
}
.s-wave { display: none; }              /* волну заменили чистой точкой-пульсом */
.s-check {
  display: none; width: 13px; height: 13px; fill: none;
  stroke: #fff; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 16; stroke-dashoffset: 16;
}
.s-label { color: var(--muted); font-weight: 500; transition: color .3s; }
.s-note { font-family: var(--mono); font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* active step — залит градиентом, мягкий пульс-ореол + белая «дышащая» точка */
.step.active .s-dot {
  border-color: transparent;
  background: linear-gradient(135deg, var(--sig1), var(--sig2));
  box-shadow: 0 0 0 0 rgba(107, 76, 246, .3); animation: dotPulse 1.8s ease-out infinite;
}
.step.active .s-dot::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%; background: #fff;
  animation: corePulse 1.4s ease-in-out infinite;
}
.step.active .s-label { color: var(--ink); font-weight: 600; }
@keyframes dotPulse {
  0% { box-shadow: 0 0 0 0 rgba(107, 76, 246, .28); }
  70% { box-shadow: 0 0 0 6px rgba(107, 76, 246, 0); }
  100% { box-shadow: 0 0 0 0 rgba(107, 76, 246, 0); }
}
@keyframes corePulse {
  0%, 100% { transform: scale(.6); opacity: .65; }
  50% { transform: scale(1); opacity: 1; }
}

/* done step */
.step.done .s-dot {
  border-color: transparent; background: linear-gradient(135deg, var(--sig1), var(--sig2));
  animation: dotPop .3s ease;
}
.step.done .s-wave { display: none; }
.step.done .s-check { display: block; animation: checkDraw .4s ease forwards; }
.step.done .s-label { color: var(--ink); }
@keyframes dotPop { 0% { transform: scale(.6); } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes checkDraw { to { stroke-dashoffset: 0; } }

@media (prefers-reduced-motion: reduce) {
  .status.prog-mode, .step.done .s-dot, .step.done .s-check { animation: none; }
  .prog-fill::after, .step.active .s-dot, .step.active .s-dot::before { animation: none; }
  .step.done .s-check { stroke-dashoffset: 0; }
}

/* ---------- Archive ---------- */
.section-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; margin-bottom: 16px;
}
.section-head h2 { font-size: 18px; }
.count {
  font-family: var(--mono); font-size: 12px; color: var(--muted);
  background: #f1f3f9; border-radius: 999px; padding: 2px 9px; margin-left: 4px;
}
.arch-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.search-wrap { position: relative; flex: 1 1 260px; min-width: 200px; }
.search-ic { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.arch-bar .search { width: 100%; padding-left: 38px; }
.field.mini { padding: 10px 36px 10px 12px; font-size: 14px; }
.arch-bar .field.mini { flex: 0 0 auto; min-width: 150px; }
.btn-reset {
  font: inherit; font-size: 13.5px; font-weight: 600; color: var(--muted); cursor: pointer;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; background: #fff;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  transition: color .15s, border-color .15s, background .15s;
}
.btn-reset:hover { color: var(--sig1); border-color: var(--sig1); background: rgba(107, 76, 246, .05); }

.btn-more {
  font: inherit; font-weight: 600; color: var(--sig1); cursor: pointer;
  border: 1px solid var(--line); border-radius: 10px; padding: 11px; margin-top: 12px;
  background: #fff; width: 100%; transition: border-color .15s, background .15s;
}
.btn-more:hover { border-color: var(--sig1); background: rgba(107, 76, 246, .04); }

.list { display: grid; gap: 10px; }
.item {
  position: relative;
  border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
  cursor: pointer; background: #fff;
  transition: border-color .12s, box-shadow .12s, transform .05s;
}
.item-del {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  display: grid; place-items: center; width: 30px; height: 30px;
  border: 1px solid transparent; border-radius: 8px; background: transparent;
  color: #b7c0d0; cursor: pointer; opacity: 0;
  transition: opacity .12s, color .12s, border-color .12s, background .12s;
}
.item:hover .item-del { opacity: 1; }
.item-del:hover { color: var(--danger); border-color: rgba(229, 72, 77, .35); background: rgba(229, 72, 77, .07); }
@media (hover: none) { .item-del { opacity: 1; } }   /* тач — всегда видна */
.item:hover { border-color: #cdd4e2; box-shadow: 0 6px 18px rgba(20, 26, 40, .06); }
.item:active { transform: translateY(1px); }
.item-title { font-weight: 700; letter-spacing: -.01em; margin-bottom: 5px; padding-right: 28px; }
.item-meta {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-family: var(--mono); font-size: 12px; color: var(--muted); margin-bottom: 7px;
}
.item-preview {
  color: var(--muted); font-size: 13.5px; line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.item-snippet {
  color: var(--muted); font-size: 13.5px; line-height: 1.55;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.item-snippet mark {
  background: rgba(107, 76, 246, .16); color: var(--sig1); font-weight: 600;
  border-radius: 3px; padding: 0 2px;
}
.item-in {
  display: inline-block; font-family: var(--sans); font-size: 11px; font-weight: 600;
  color: var(--muted); background: #f1f3f9; border-radius: 999px; padding: 1px 8px; margin-left: 4px;
}
.dot { opacity: .4; }
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--sans); font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px;
}
.badge.site { background: rgba(107, 76, 246, .1); color: #5a3ee0; }
.badge.tg { background: rgba(16, 184, 199, .12); color: #0a8f9c; }
.badge.local { background: #eef0f5; color: var(--muted); }

.empty { color: var(--muted); text-align: center; padding: 32px 0; }

/* ---------- Modal ---------- */
html.modal-open { overflow: hidden; }
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 20px;
  background: rgba(16, 20, 30, .5); backdrop-filter: blur(3px);
}
.modal-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  width: min(720px, 100%); height: min(85vh, 800px); display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: 18px 20px; border-bottom: 1px solid var(--line);
}
.m-title { font-weight: 800; font-size: 17px; letter-spacing: -.02em; }
.m-meta { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-top: 4px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.modal-actions { display: flex; gap: 8px; flex-shrink: 0; }
.m-del { color: #b7c0d0; margin-right: 2px; }
.m-del:hover { color: var(--danger); border-color: rgba(229, 72, 77, .4); background: rgba(229, 72, 77, .07); }
.m-tabbar {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 12px 20px 0; border-bottom: 1px solid var(--line);
}
.m-tabs {
  display: flex; gap: 6px; flex-wrap: nowrap; flex: 1;
  overflow-x: auto; scrollbar-width: thin;
}
.m-tabs::-webkit-scrollbar { height: 0; }
.m-copybtn {
  flex-shrink: 0; margin-left: auto; margin-bottom: 6px; display: grid; place-items: center;
  width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--muted); cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.m-copybtn:hover { color: var(--sig1); border-color: var(--sig1); background: rgba(107, 76, 246, .05); }
.m-copybtn:active { transform: translateY(1px); }
.m-tab {
  font: inherit; font-size: 13px; font-weight: 600; color: var(--muted);
  cursor: pointer; border: 0; background: transparent;
  padding: 8px 12px; border-radius: 9px 9px 0 0; position: relative;
  transition: color .15s, background .15s;
}
.m-tab:hover { color: var(--ink); background: rgba(107, 76, 246, .05); }
.m-tab.on { color: var(--sig1); }
.m-tab.on::after {
  content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px;
  background: linear-gradient(90deg, var(--sig1), var(--sig2)); border-radius: 2px;
}

.m-body {
  flex: 1; min-height: 0;
  padding: 20px; overflow-y: auto; overscroll-behavior: contain;
  white-space: pre-wrap; word-break: break-word;
  line-height: 1.7; font-size: 15px;
}

/* process chips */
.proc-panel {
  padding: 14px 20px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(107, 76, 246, .04), transparent);
  display: grid; gap: 10px; animation: progIn .25s ease;
}
.proc-chips { display: flex; flex-wrap: nowrap; gap: 8px; overflow-x: auto; scrollbar-width: thin; }
.proc-chips::-webkit-scrollbar { height: 0; }
.proc-chips.busy { opacity: .55; pointer-events: none; }
.pchip {
  flex-shrink: 0; font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); border-radius: 999px; padding: 7px 13px;
  background: #fff; color: var(--muted); white-space: nowrap;
  transition: border-color .15s, background .15s, color .15s;
}
.pchip:hover { border-color: #cfd6e2; color: var(--ink); }
.pchip.sel { border-color: var(--sig1); background: rgba(107, 76, 246, .08); color: var(--sig1); }
.pchip.done {
  cursor: default; border-color: rgba(18, 161, 80, .4);
  background: rgba(18, 161, 80, .07); color: var(--ok);
}
.proc-run { display: flex; align-items: center; gap: 12px; }
.btn-primary.sm { padding: 8px 16px; font-size: 14px; }
.proc-status { font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 8px; min-height: 16px; }
.wave.sm { height: 12px; gap: 2px; }
.wave.sm i { width: 2px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 10px;
  font-weight: 500; font-size: 14px; z-index: 60; box-shadow: var(--shadow);
  animation: pop .2s ease;
}
@keyframes pop { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- Login ---------- */
.center { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login {
  width: min(380px, 92vw); display: grid; gap: 12px; text-align: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 30px;
}
.login .wave { justify-self: center; margin-bottom: 4px; }
.login h1 { font-size: 22px; font-weight: 800; }
.login p { margin: 0 0 6px; color: var(--muted); }
.login .field { text-align: center; }
.login .btn-primary { padding: 12px; }
.login .error {
  color: var(--danger); font-size: 13px; background: rgba(229, 72, 77, .07);
  border-radius: 9px; padding: 8px;
}

/* ---------- Responsive ---------- */
@media (max-width: 560px) {
  .topbar, .container { padding-left: 16px; padding-right: 16px; }
  .controls { flex-direction: column; }
  .btn-primary { width: 100%; }
  .search { max-width: none; }
}
