/* Сакта — mini app. Brand: iConsult blue (#0066CC fill / #4D9FE6 on dark) on graphite-navy.
   Theme follows the Telegram app (data-theme on <html>). */
:root {
  --bg: #0d1218; --surface: #151c25; --surface-2: #1c2531; --surface-3: #243040;
  --line: rgba(255,255,255,.07); --line-strong: rgba(255,255,255,.12);
  --text: #e9eef4; --muted: #8d9bab; --faint: #6b7889;
  --accent: #4D9FE6; --accent-fill: #0066CC; --accent-deep: #004A99; --accent-soft: rgba(77,159,230,.14);
  --ok: #3fb970; --ok-soft: rgba(63,185,112,.14); --warn: #e0a43a; --bad: #e5534b;
  --video: #4D9FE6; --audio: #3fb970; --textc: #a78bfa; --textc-soft: rgba(167,139,250,.14);
  --r-lg: 20px; --r: 16px; --r-sm: 12px; --r-xs: 9px;
  --shadow: 0 1px 0 rgba(255,255,255,.04) inset, 0 8px 24px rgba(0,0,0,.25);
  --ease: cubic-bezier(.2,.7,.2,1); --t: .18s;
  --font: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --tabs-h: 64px;
}
html[data-theme="light"] {
  --bg: #f3f5f8; --surface: #ffffff; --surface-2: #f2f4f7; --surface-3: #e8ecf1;
  --line: rgba(15,23,42,.08); --line-strong: rgba(15,23,42,.14);
  --text: #171717; --muted: #5f6b7a; --faint: #737f8e;
  --accent: #0066CC; --accent-soft: rgba(0,102,204,.09);
  --ok-soft: rgba(63,185,112,.12); --textc: #7c5ce0; --textc-soft: rgba(124,92,224,.1);
  --shadow: 0 1px 2px rgba(15,23,42,.05), 0 6px 18px rgba(15,23,42,.06);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic.sm { width: 17px; height: 17px; }
.muted { color: var(--muted); font-size: 13px; }

#app { min-height: 100vh; padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 12px); }
main { padding: 0 16px; max-width: 640px; margin: 0 auto; }

/* ---------- header ---------- */
.top { position: sticky; top: 0; z-index: 5; padding: 14px 16px 12px; background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; max-width: 640px; margin: 0 auto; }
.mark { width: 40px; height: 40px; flex: none; }
.brand-name { font-weight: 800; font-size: 19px; letter-spacing: -.01em; }
.brand-sub { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.off { background: var(--bad); }

.banner { margin: 12px 16px 0; padding: 12px 14px; border-radius: var(--r-sm); background: rgba(229,83,75,.1);
  border: 1px solid rgba(229,83,75,.25); font-size: 14px; }
.btn-link { color: var(--accent); font-weight: 700; margin-left: 4px; }

/* ---------- cards & controls ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 18px; margin-top: 14px; box-shadow: var(--shadow); }
.card-head { display: flex; gap: 12px; align-items: center; margin-bottom: 6px; }
.card-head small, .opt-txt small { display: block; color: var(--muted); font-size: 13px; font-weight: 500; }
.field-label { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); margin: 18px 0 9px; }
.field-label.first { margin-top: 0; }

.url { display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 14px; border-radius: var(--r);
  background: var(--surface-2); border: 1px solid var(--line); transition: border-color var(--t); }
.url:focus-within { border-color: var(--accent); }
.url .ic { color: var(--muted); }
.url input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; font-size: 16px; padding: 10px 0; }
.url input::placeholder { color: var(--faint); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 10px 14px; border-radius: 12px;
  background: var(--accent-fill); color: #fff; font-weight: 700; font-size: 14px; white-space: nowrap; }
.pill:active { transform: scale(.97); }

.platforms { display: grid; grid-template-columns: repeat(4,1fr); gap: 8px; margin-top: 12px; }
.platforms span { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 10px 4px;
  border-radius: var(--r-sm); border: 1px solid var(--line); color: var(--faint); font-size: 12px; font-weight: 600;
  transition: all var(--t) var(--ease); }
.platforms span.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px;
  border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line); }
.seg button { padding: 10px 4px; border-radius: 10px; font-weight: 600; font-size: 14px; color: var(--muted);
  transition: all var(--t) var(--ease); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.18); }
html[data-theme="dark"] .seg button.on { background: var(--surface-3); }

.chips { display: flex; gap: 8px; }
.chips.scroll { overflow-x: auto; scrollbar-width: none; margin: 0 -18px; padding: 0 18px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; }
.chips button { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--line-strong); font-weight: 600; font-size: 14px; color: var(--muted); white-space: nowrap;
  transition: all var(--t) var(--ease); }
.chips button.on { background: var(--text); color: var(--bg); border-color: var(--text); }

.opt { display: flex; align-items: center; gap: 12px; padding: 14px; margin-top: 12px; border-radius: var(--r);
  background: var(--surface-2); border: 1px solid var(--line); }
.opt.flat { background: none; border: 0; padding: 14px 0 0; border-top: 1px solid var(--line); border-radius: 0; margin-top: 16px; }
.opt-ic { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; flex: none;
  background: var(--accent-soft); color: var(--accent); }
.opt-txt { flex: 1; min-width: 0; }
.inline-select { color: var(--accent); font-weight: 700; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 99px; background: var(--surface-3); transition: background var(--t); }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform var(--t) var(--ease); }
.switch input:checked + i { background: var(--accent-fill); }
.switch input:checked + i::after { transform: translateX(20px); }

.cta { width: 100%; margin-top: 18px; display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 17px; border-radius: var(--r); background: linear-gradient(180deg, #1a7ae0, var(--accent-fill));
  color: #fff; font-weight: 800; font-size: 17px; box-shadow: 0 8px 22px rgba(0,102,204,.35);
  transition: transform var(--t) var(--ease), opacity var(--t); }
.cta:active { transform: scale(.985); }
.cta:disabled { opacity: .45; box-shadow: none; }
.hint { text-align: center; color: var(--faint); font-size: 12.5px; margin: 12px 0 0; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin: 26px 2px 10px; }
.section-head h2 { margin: 0; font-size: 13px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.badge { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 99px; background: var(--ok-soft); color: var(--ok); }

/* ---------- queue ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.job { display: flex; gap: 12px; padding: 14px; border-radius: var(--r); background: var(--surface);
  border: 1px solid var(--line); }
.job.run { border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  background: linear-gradient(180deg, var(--accent-soft), transparent 70%), var(--surface); }
.job-ic { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex: none;
  background: var(--surface-2); color: var(--muted); }
.job-ic.youtube { color: #ff4e45; } .job-ic.instagram { color: #e1306c; } .job-ic.tiktok { color: var(--text); }
.job-ic.facebook { color: #1877f2; }
.job-main { flex: 1; min-width: 0; }
.job-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 6px; border-radius: 99px; background: var(--surface-3); margin: 9px 0 7px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width .6s var(--ease); }
.job.done .bar i { background: var(--ok); }
.job.fail .bar i { background: var(--bad); }
.job-meta { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); }
.job-meta b { font-weight: 600; color: var(--accent); white-space: nowrap; }
.job.done .job-meta b { color: var(--ok); } .job.fail .job-meta b { color: var(--bad); }
.empty { text-align: center; color: var(--muted); padding: 28px 16px; border: 1px dashed var(--line-strong);
  border-radius: var(--r); font-size: 14px; }

/* ---------- transcripts ---------- */
.search { display: flex; align-items: center; gap: 10px; margin-top: 14px; padding: 0 14px; border-radius: var(--r);
  background: var(--surface); border: 1px solid var(--line); }
.search .ic { color: var(--muted); }
.search input { flex: 1; border: 0; outline: 0; background: none; padding: 14px 0; font-size: 16px; }
.tcard { border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); overflow: hidden; }
.tcard.open { border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.tcard-head { display: flex; align-items: flex-start; gap: 12px; padding: 16px; cursor: pointer; }
.tcard-head .grow { flex: 1; min-width: 0; }
.tcard-title { font-weight: 700; font-size: 16px; line-height: 1.3; }
.meta-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.tag { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; padding: 4px 9px;
  border-radius: 8px; background: var(--surface-2); color: var(--muted); }
.tag.acc { background: var(--accent-soft); color: var(--accent); }
.tag.txt { background: var(--textc-soft); color: var(--textc); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.chev { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2);
  color: var(--muted); transition: transform var(--t) var(--ease); flex: none; }
.tcard.open .chev { transform: rotate(180deg); background: var(--accent-fill); color: #fff; }
.tcard-body { padding: 0 16px 16px; }

.reader { margin-top: 4px; }
.para { padding: 12px 0; border-top: 1px solid var(--line); }
.para:first-child { border-top: 0; }
.ts { font: 500 12.5px var(--mono); color: var(--accent); background: var(--accent-soft); padding: 2px 7px; border-radius: 6px;
  margin-right: 6px; }
.para p { margin: 6px 0 0; font-size: 16px; line-height: 1.6; }
.para p.tr { color: var(--text); }
.para p.orig-dim { color: var(--muted); font-size: 14.5px; }
.para p.failed { color: var(--warn); }

.tr-panel { margin-top: 14px; padding: 14px; border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--line); }
.tr-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tr-row .grow { flex: 1; }
.sel { padding: 9px 12px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line-strong); font-weight: 600; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 10px 14px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line-strong); font-weight: 700; font-size: 14px; }
.btn.primary { background: var(--accent-fill); border-color: var(--accent-fill); color: #fff; }
.btn.ghost-ok { color: var(--ok); }
.btn.danger { color: var(--bad); }
.btn:active { transform: scale(.97); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.summary { margin-top: 14px; padding: 14px; border-radius: var(--r); background: var(--ok-soft); border: 1px solid rgba(63,185,112,.25);
  white-space: pre-line; font-size: 15px; line-height: 1.55; }

/* ---------- library ---------- */
.storage .st-row { display: flex; align-items: center; gap: 12px; }
.storage .st-ic { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); }
.storage b { font-size: 16px; }
.st-bar { display: flex; gap: 3px; height: 8px; margin: 14px 0 10px; border-radius: 99px; overflow: hidden; background: var(--surface-3); }
.st-bar i { display: block; height: 100%; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--c); }
.lib-bar { display: flex; align-items: center; gap: 10px; margin: 16px 0 12px; }
.lib-bar .chips { flex: 1; margin: 0; padding: 0; }
.view-toggle { display: flex; padding: 3px; gap: 2px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); flex: none; }
.view-toggle button { width: 36px; height: 32px; border-radius: 9px; display: grid; place-items: center; color: var(--muted); }
.view-toggle button.on { background: var(--text); color: var(--bg); }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid.as-list { grid-template-columns: 1fr; }
.mcard { border-radius: var(--r); background: var(--surface); border: 1px solid var(--line); overflow: hidden; text-align: left;
  display: flex; flex-direction: column; transition: transform var(--t) var(--ease); }
.mcard:active { transform: scale(.98); }
.thumb { position: relative; aspect-ratio: 16/10; background: var(--surface-3) center/cover no-repeat; }
.thumb.audio { background: linear-gradient(135deg, #12382a, #0f2a3d); display: grid; place-items: center; }
html[data-theme="light"] .thumb.audio { background: linear-gradient(135deg, #d7f2e3, #dbe8f7); }
.wave { display: flex; align-items: center; gap: 3px; height: 40%; }
.wave i { width: 3px; border-radius: 3px; background: var(--audio); opacity: .85; }
.dur { position: absolute; left: 8px; bottom: 8px; font: 500 12px var(--mono); color: #fff; background: rgba(0,0,0,.62);
  padding: 3px 7px; border-radius: 7px; }
.kind { position: absolute; right: 8px; bottom: 8px; width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  background: rgba(0,0,0,.55); color: #fff; }
.kind .ic { width: 15px; height: 15px; }
.trb { position: absolute; left: 8px; top: 8px; font-size: 11px; font-weight: 800; color: #fff; padding: 3px 8px; border-radius: 7px;
  background: rgba(0,102,204,.92); }
.mcard-body { padding: 11px 12px 13px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.mcard-title { font-weight: 700; font-size: 14.5px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden; }
.mcard-meta { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); margin-top: auto; flex-wrap: wrap; }
.grid.as-list .mcard { flex-direction: row; }
.grid.as-list .thumb { width: 128px; aspect-ratio: 16/11; flex: none; }

.dcard .doc-top { display: flex; justify-content: space-between; align-items: flex-start; padding: 12px 12px 0; }
.doc-ic { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; background: var(--textc-soft); color: var(--textc); }
.doc-preview { margin: 10px 12px 0; padding: 10px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--line); }
.doc-preview div { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-left: 2px solid var(--textc); padding-left: 8px; margin: 4px 0; }
.doc-preview .ln { height: 6px; border-radius: 4px; background: var(--surface-3); margin: 8px 0 0; border: 0; }
.doc-preview .ln.short { width: 60%; }

/* ---------- settings ---------- */
.lang-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.lang-grid button { padding: 11px 6px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 3px; font-weight: 700; font-size: 13px; color: var(--muted);
  transition: all var(--t) var(--ease); }
.lang-grid button .fl { font-size: 20px; line-height: 1; }
.lang-grid button.on { background: var(--accent-fill); border-color: var(--accent-fill); color: #fff; }
.owner { display: flex; align-items: center; gap: 10px; margin-top: 12px; padding: 12px 14px; border-radius: var(--r-sm);
  background: var(--surface-2); font-weight: 600; }
.foot { text-align: center; color: var(--faint); font-size: 12.5px; margin: 26px 0 8px; line-height: 1.6; }

/* ---------- tab bar ---------- */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: repeat(4,1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 90%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line); }
.tabs button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-size: 11.5px; font-weight: 700; color: var(--faint); transition: color var(--t); }
.tabs button .ic { width: 24px; height: 24px; padding: 0; transition: all var(--t) var(--ease); }
.tabs button.on { color: var(--accent); }
.tabs button.on .ic { background: var(--accent-fill); color: #fff; border-radius: 50%; width: 34px; height: 34px; padding: 6px;
  margin: -5px 0; box-shadow: 0 4px 14px rgba(0,102,204,.4); }

/* ---------- sheet (item view) ---------- */
.sheet { position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow-y: auto; animation: up .26s var(--ease); }
@keyframes up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-body { max-width: 640px; margin: 0 auto; padding: 12px 16px 40px; }
.sheet-top { display: flex; justify-content: flex-end; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); }
.player { margin: 10px -16px 0; background: #000; }
.player video { display: block; width: 100%; max-height: 62vh; background: #000; }
.player audio { width: calc(100% - 32px); margin: 16px; }
.sheet h1 { font-size: 20px; line-height: 1.3; margin: 16px 0 0; letter-spacing: -.01em; }
.sheets-img img { width: 100%; border-radius: var(--r-sm); margin-top: 10px; display: block; }

.picker { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.picker-card { width: 100%; max-width: 640px; margin: 0 auto; background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 18px 16px calc(22px + env(safe-area-inset-bottom)); }
.picker-title { font-weight: 800; font-size: 16px; margin-bottom: 14px; text-align: center; }

.toast { position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px); transform: translateX(-50%);
  z-index: 40; background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.3); max-width: calc(100% - 32px); animation: fade .2s; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
