:root {
  --bg: #f6f4ef;
  --surface: #fffdf9;
  --sidebar: #efece5;
  --ink: #1f1d1a;
  --muted: #78726a;
  --line: #e4dfd5;
  --accent: #1d7560;
  --accent-ink: #ffffff;
  --accent-soft: #e3efe9;
  --user: #e9e5dc;
  --warn: #a86512;
  --warn-soft: #fbf1e1;
  --danger: #b4372e;
  --danger-soft: #f9e6e3;
  --code: #f0ede6;
  --shadow: 0 1px 2px rgb(30 25 15 / .06), 0 8px 24px rgb(30 25 15 / .06);
  --radius: 14px;
  --font: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16161a;
    --surface: #1d1d22;
    --sidebar: #121215;
    --ink: #ecebe7;
    --muted: #9b978f;
    --line: #2c2c33;
    --accent: #4cc1a0;
    --accent-ink: #0c1f19;
    --accent-soft: #1b2f29;
    --user: #26262d;
    --warn: #e2a24c;
    --warn-soft: #2c2418;
    --danger: #ec7a70;
    --danger-soft: #2f1d1b;
    --code: #24242a;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15.5px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.error-text { color: var(--danger); margin: 0; font-size: 14px; }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent;
  background: none; font-weight: 550; transition: background .15s, border-color .15s, opacity .15s;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { opacity: .92; }
.btn.ghost { border-color: var(--line); background: var(--surface); }
.btn.ghost:hover { border-color: var(--muted); }
.btn.danger { color: var(--danger); }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px;
  border: 0; border-radius: 10px; background: none; color: var(--muted);
}
.icon-btn:hover { background: var(--user); color: var(--ink); }

/* ---------- вход ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(380px, 100%); display: grid; gap: 14px; text-align: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
  padding: 36px 28px 30px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 0; font-size: 26px; letter-spacing: -.02em; }
.login-card p { margin: -6px 0 6px; }
.login-logo { width: 56px; height: 56px; justify-self: center; }
.login-card input {
  height: 46px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); outline: none; font-size: 16px;
}
.login-card input:focus { border-color: var(--accent); }
.login-card .btn { height: 46px; }

/* ---------- каркас ---------- */
.app { display: grid; grid-template-columns: 280px 1fr; height: 100dvh; }
.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--sidebar); border-right: 1px solid var(--line);
}
.sidebar-head { padding: 14px 12px 8px; display: grid; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px; font-weight: 650; font-size: 17px; letter-spacing: -.01em; }
.brand img { width: 28px; height: 28px; }
.new-chat { justify-content: flex-start; width: 100%; }
.conv-list { flex: 1; overflow-y: auto; padding: 6px 8px 12px; display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: 2px; }
.conv-group { font-size: 12px; font-weight: 600; color: var(--muted); padding: 14px 10px 4px; text-transform: uppercase; letter-spacing: .04em; }
.conv {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  padding: 9px 10px; border: 0; border-radius: 9px; background: none; color: var(--ink);
}
.conv:hover { background: color-mix(in srgb, var(--user) 70%, transparent); }
.conv.active { background: var(--user); font-weight: 550; }
.conv-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .badge { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; animation: pulse 1.4s infinite; }
.conv .badge.wait { background: var(--warn); }
.sidebar-foot {
  display: flex; align-items: center; gap: 10px; margin: 8px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); text-align: left;
}
.sidebar-foot:hover { border-color: var(--muted); }
.foot-text { display: grid; line-height: 1.3; font-size: 13.5px; min-width: 0; }
.foot-text span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scrim { display: none; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  display: flex; align-items: center; gap: 8px; height: 56px; padding: 0 12px 0 20px;
  border-bottom: 1px solid var(--line); background: var(--bg); flex: none;
}
.conv-title { flex: 0 1 auto; min-width: 0; margin: 0; font-size: 15.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { margin-left: auto; display: flex; gap: 2px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  font-size: 12.5px; font-weight: 550; padding: 3px 10px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent);
}
.pill.wait { background: var(--warn-soft); color: var(--warn); }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- сообщения ---------- */
.scroller { flex: 1; overflow-y: auto; overscroll-behavior: contain; position: relative; }
.messages { max-width: 780px; margin: 0 auto; padding: 24px 20px 12px; display: grid; gap: 14px; }
.msg-user { justify-self: end; max-width: 85%; display: grid; gap: 6px; justify-items: end; }
.bubble {
  background: var(--user); padding: 10px 15px; border-radius: 18px 18px 6px 18px;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg-text { overflow-wrap: anywhere; }
.msg-text > :first-child { margin-top: 0; }
.msg-text > :last-child { margin-bottom: 0; }
.msg-text p, .msg-text ul, .msg-text ol, .msg-text pre, .msg-text table, .msg-text blockquote { margin: 0 0 .75em; }
.msg-text h1, .msg-text h2, .msg-text h3 { font-size: 1.08em; margin: 1.1em 0 .45em; letter-spacing: -.01em; }
.msg-text ul, .msg-text ol { padding-left: 1.4em; }
.msg-text li + li { margin-top: .2em; }
.msg-text a { color: var(--accent); }
.msg-text code { font: .88em var(--mono); background: var(--code); padding: .12em .38em; border-radius: 5px; }
.msg-text pre { background: var(--code); padding: 12px 14px; border-radius: 10px; overflow-x: auto; }
.msg-text pre code { background: none; padding: 0; font-size: 13px; line-height: 1.5; }
.msg-text table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 14px; }
.msg-text th, .msg-text td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.msg-text blockquote { border-left: 3px solid var(--line); padding-left: 12px; color: var(--muted); }
.msg-text img { max-width: 100%; border-radius: 8px; }
.cursor::after { content: ""; display: inline-block; width: 8px; height: 1.05em; margin-left: 2px; vertical-align: -.15em; background: var(--accent); border-radius: 2px; animation: pulse 1s infinite; }

.tool {
  display: flex; align-items: baseline; gap: 8px; min-width: 0;
  font-size: 13px; color: var(--muted); padding: 1px 2px;
}
.tool svg { width: 14px; height: 14px; align-self: center; }
.tool b { font-weight: 600; color: var(--ink); opacity: .75; flex: none; }
.tool code { font-family: var(--mono); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.tool-group { display: grid; gap: 3px; padding: 8px 12px; border-left: 2px solid var(--line); margin-left: 2px; }

.card {
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius);
  padding: 14px 16px; display: grid; gap: 10px; box-shadow: var(--shadow);
}
.approval { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); background: var(--warn-soft); box-shadow: none; }
.approval-head { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--warn); font-size: 14px; }
.approval pre {
  margin: 0; font: 12.5px/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; max-height: 260px; overflow: auto;
}
.approval-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.approval-actions .btn { height: 36px; }
.approval-status { font-size: 13.5px; font-weight: 550; }
.approval-status.ok { color: var(--accent); }
.approval-status.no { color: var(--danger); }
.approval.resolved { background: none; border-color: var(--line); padding: 10px 14px; gap: 6px; }
.approval.resolved .approval-head { color: var(--muted); font-weight: 550; }
.approval.resolved pre { max-height: 80px; }

.file-card { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; padding: 12px 14px; }
.file-card:hover { border-color: var(--muted); }
.file-icon { width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.file-meta { min-width: 0; display: grid; }
.file-meta b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta span { font-size: 13px; color: var(--muted); }
.file-card .dl { margin-left: auto; color: var(--muted); }
.file-image { display: grid; gap: 8px; }
.file-image img { max-width: min(100%, 520px); max-height: 420px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }
.caption { font-size: 14px; color: var(--muted); }

.att-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 240px;
  font-size: 13px; padding: 5px 10px; border-radius: 99px; background: var(--surface); border: 1px solid var(--line);
}
.att-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-chip svg { width: 14px; height: 14px; }
.att-chip button { border: 0; background: none; padding: 0; display: grid; color: var(--muted); }
.att-chip.loading { opacity: .6; }
.msg-files { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.msg-files a { text-decoration: none; color: inherit; }

.error { color: var(--danger); background: var(--danger-soft); padding: 10px 14px; border-radius: 10px; font-size: 14px; overflow-wrap: anywhere; }
.meta { font-size: 12px; color: var(--muted); padding-left: 2px; margin-top: -6px; }
.thinking { display: flex; gap: 5px; padding: 8px 2px; }
.thinking i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: bounce 1.2s infinite; }
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-4px); opacity: 1; } }

/* ---------- пустой экран ---------- */
.empty { max-width: 640px; margin: 0 auto; padding: 12vh 20px 24px; text-align: center; display: grid; gap: 10px; justify-items: center; }
.empty h1 { margin: 6px 0 0; font-size: 28px; letter-spacing: -.02em; }
.empty p { margin: 0 0 14px; max-width: 460px; }
.empty-logo { width: 52px; height: 52px; }
.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; }
.chip {
  text-align: left; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-size: 14px; line-height: 1.4; color: var(--ink);
}
.chip:hover { border-color: var(--accent); }

/* ---------- поле ввода ---------- */
.composer { position: relative; max-width: 780px; width: 100%; margin: 0 auto; padding: 8px 20px max(16px, env(safe-area-inset-bottom)); flex: none; }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.attachments:empty { display: none; }
.composer-row {
  display: flex; align-items: flex-end; gap: 6px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow);
  transition: border-color .15s;
}
.composer-row:focus-within { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.composer textarea {
  flex: 1; min-height: 38px; max-height: 40vh; resize: none; border: 0; outline: none; background: none;
  padding: 8px 4px; line-height: 1.45; font-size: 16px;
}
.attach { cursor: pointer; }
.send {
  width: 38px; height: 38px; border-radius: 12px; border: 0; flex: none;
  display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); transition: opacity .15s;
}
.send:disabled { opacity: .35; cursor: default; }
.send.stop { background: var(--ink); color: var(--bg); }
.send.stop svg { fill: currentColor; stroke: none; }
.drop-hint {
  position: absolute; inset: -8px 12px 8px; display: grid; place-items: center; z-index: 2;
  border: 2px dashed var(--accent); border-radius: 18px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  color: var(--accent); font-weight: 600;
}

/* ---------- настройки ---------- */
.dialog {
  width: min(440px, calc(100% - 32px)); padding: 0; border: 1px solid var(--line); border-radius: 18px;
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgb(0 0 0 / .25);
}
.dialog::backdrop { background: rgb(10 10 10 / .35); }
.dialog-body { display: grid; gap: 18px; padding: 18px 20px 20px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin: -4px -8px -4px 0; }
.dialog-head h3 { margin: 0; font-size: 17px; }
.field { display: grid; gap: 6px; font-size: 14px; }
.field > span { font-weight: 600; }
.field input[type="number"] { height: 42px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 16px; }
.field select { height: 42px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
.field.toggle { grid-template-columns: 1fr auto; align-items: center; gap: 14px; }
.field.toggle span { display: grid; gap: 2px; font-weight: 400; }
.field.toggle small { font-size: 13px; line-height: 1.35; }
.field.row { grid-template-columns: 1fr auto; }
.field.row span { font-weight: 400; color: var(--muted); }
input[role="switch"] {
  appearance: none; width: 44px; height: 26px; border-radius: 99px; background: var(--line);
  position: relative; cursor: pointer; transition: background .15s; margin: 0;
}
input[role="switch"]::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .25); transition: transform .15s;
}
input[role="switch"]:checked { background: var(--accent); }
input[role="switch"]:checked::after { transform: translateX(18px); }
.server-box { margin: 0; font: 12.5px/1.6 var(--mono); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; white-space: pre-wrap; }
.dialog-actions { display: flex; gap: 8px; justify-content: space-between; flex-wrap: wrap; }

/* ---------- телефон ---------- */
.only-mobile { display: none; }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .only-mobile { display: inline-grid; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(300px, 84vw); z-index: 20;
    transform: translateX(-100%); transition: transform .22s ease; padding-top: env(safe-area-inset-top);
  }
  .app.nav-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 10; background: rgb(0 0 0 / .3); }
  .topbar { padding: env(safe-area-inset-top) 8px 0 6px; height: calc(52px + env(safe-area-inset-top)); }
  .messages { padding: 16px 16px 8px; }
  .composer { padding: 6px 12px max(12px, env(safe-area-inset-bottom)); }
  .suggestions { grid-template-columns: 1fr; }
  .empty { padding-top: 6vh; }
  .msg-user { max-width: 92%; }
}

.helpers { display: grid; gap: 6px; }
.helper { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.helper b { font-weight: 600; }
.helper small { margin-left: auto; color: var(--muted); font-size: 12.5px; text-align: right; }
.helper .state { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: none; }
.helper.on .state { background: var(--accent); }
.tool.helper-call b, .tool.ds-call b { color: var(--accent); opacity: 1; }
.route-note { color: var(--muted); }
.route-en { font-size: 13px; color: var(--muted); font-style: italic; padding-left: 22px; overflow-wrap: anywhere; }
.by-badge { display: inline-block; font-size: 11.5px; font-weight: 600; letter-spacing: .02em; color: var(--accent); background: var(--accent-soft); padding: 1px 8px; border-radius: 99px; margin-bottom: 6px; }
.helper .who { display: grid; line-height: 1.3; }
.helper .who span { font-size: 12.5px; color: var(--muted); }
.file-image video { max-width: min(100%, 560px); max-height: 420px; border-radius: 12px; border: 1px solid var(--line); background: #000; }

.audio-card { gap: 10px; padding: 12px 14px; max-width: 560px; }
.audio-top { display: flex; align-items: center; gap: 10px; }
.audio-top .dl { margin-left: auto; color: var(--muted); display: grid; }
.audio-card audio { width: 100%; height: 40px; }

.notice { color: var(--warn); background: var(--warn-soft); padding: 10px 14px; border-radius: 10px; font-size: 14px; }

/* ---------- предупреждения о балансе ---------- */
.alerts { display: grid; gap: 6px; padding: 0 16px; max-width: 812px; width: 100%; margin: 8px auto 0; flex: none; }
.alerts:empty { display: none; }
.alert {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 12px; font-size: 14px;
  background: var(--warn-soft); color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
}
.alert.critical { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.alert.info { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }
.alert span { flex: 1; min-width: 0; color: var(--ink); }
.alert svg { width: 18px; height: 18px; }
.alert a { font-weight: 600; color: inherit; white-space: nowrap; }
.alert button { border: 0; background: none; color: var(--muted); padding: 2px; display: grid; }
.bal-grid { display: grid; gap: 8px; }
.bal { display: grid; gap: 6px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-weight: 400; }
.bal b { font-weight: 600; }
.bal small { font-size: 12.5px; }
.bal label { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13.5px; color: var(--muted); }
.bal input[type="number"] { width: 130px; height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); font-size: 15px; }
.bal label.check { justify-content: flex-start; }

/* ---------- папки ---------- */
.folders-head { display: flex; align-items: center; justify-content: space-between; padding-right: 4px; }
.mini-btn { border: 0; background: none; color: var(--muted); width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center; flex: none; }
.mini-btn svg { width: 16px; height: 16px; }
.mini-btn:hover { background: var(--user); color: var(--ink); }
.folders-empty { font-size: 12.5px; color: var(--muted); padding: 2px 10px 6px; line-height: 1.4; }
.folders-empty.nested { padding-left: 38px; }
.folder-row { display: flex; align-items: center; gap: 0; border-radius: 9px; }
.folder-row:hover, .folder-row.active { background: color-mix(in srgb, var(--user) 70%, transparent); }
.folder-row .mini-btn { opacity: 0; transition: opacity .12s; }
.folder-row:hover .mini-btn, .folder-row.active .mini-btn { opacity: 1; }
.folder { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; padding: 8px 6px 8px 4px; border: 0; background: none; color: var(--ink); text-align: left; }
.folder svg { width: 17px; height: 17px; color: var(--muted); }
.folder .caret svg { width: 14px; height: 14px; transition: transform .15s; }
.folder-row.open .caret svg { transform: rotate(90deg); }
.folder .count { font-size: 12px; color: var(--muted); }
.conv.nested { padding-left: 38px; }
.crumb { display: inline-flex; align-items: center; gap: 5px; border: 0; background: var(--user); color: var(--muted); border-radius: 8px; padding: 3px 9px; font-size: 13px; max-width: 30%; flex: none; }
.crumb span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumb svg { width: 15px; height: 15px; }
.crumb:hover { color: var(--ink); }
.empty-folder { display: grid; gap: 10px; justify-items: center; }
.empty-folder h1 { display: flex; align-items: center; gap: 10px; }
.empty-folder h1 svg { width: 30px; height: 30px; color: var(--accent); }
.empty-default { display: grid; gap: 10px; justify-items: center; }
.folder-quote { margin: 0; text-align: left; max-width: 520px; font-size: 14px; color: var(--muted); border-left: 3px solid var(--line); padding: 4px 12px; white-space: pre-wrap; }
.small { font-size: 12.5px; }
.dialog.wide { width: min(600px, calc(100% - 32px)); }
.text-input { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 15px; line-height: 1.45; resize: vertical; outline: none; }
.text-input:focus { border-color: var(--accent); }
input.text-input { height: 42px; }
.field.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.f-files { display: grid; gap: 4px; }
.f-file { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 4px 6px; border-radius: 8px; background: var(--bg); }
.f-file svg { width: 15px; height: 15px; color: var(--muted); }
.f-file a { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); text-decoration: none; }
.upload-btn { justify-self: start; cursor: pointer; height: 36px; font-size: 14px; }
.move-list { display: grid; gap: 4px; }
.move-opt { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); text-align: left; }
.move-opt svg { color: var(--muted); }
.move-opt.current { border-color: var(--accent); }
.move-opt:hover { border-color: var(--muted); }
@media (max-width: 820px) {
  .folder-row .mini-btn { opacity: 1; }
  .field.two { grid-template-columns: 1fr; }
  .crumb { max-width: 35%; }
}

/* ---------- планы ---------- */
.thinking { align-items: center; }
.thinking-label { font-size: 13px; color: var(--muted); margin-left: 6px; }
.plan { gap: 12px; }
.plan-head { display: flex; align-items: center; gap: 10px; }
.plan-head svg { color: var(--accent); }
.plan-head b { flex: 1; min-width: 0; font-size: 15.5px; }
.plan-pill { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--user); color: var(--muted); flex: none; }
.plan-pill.wait { background: var(--warn-soft); color: var(--warn); }
.plan-pill.run { background: var(--accent-soft); color: var(--accent); }
.plan-pill.ok { background: var(--accent-soft); color: var(--accent); }
.plan-pill.bad { background: var(--danger-soft); color: var(--danger); }
.plan-summary { margin: 0; color: var(--muted); font-size: 14px; }
.plan-questions { background: var(--warn-soft); border-radius: 10px; padding: 10px 12px; font-size: 14px; display: grid; gap: 4px; }
.plan-questions ul { margin: 0; padding-left: 1.2em; }
.plan-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.step { display: flex; gap: 10px; padding: 7px 8px; border-radius: 9px; }
.step.running { background: var(--accent-soft); }
.st-icon { width: 20px; flex: none; text-align: center; color: var(--muted); font-weight: 700; }
.step.done .st-icon { color: var(--accent); }
.step.failed .st-icon { color: var(--danger); }
.step.running .st-icon { color: var(--accent); animation: pulse 1.2s infinite; }
.step.skipped { opacity: .55; }
.st-body { flex: 1; min-width: 0; display: grid; gap: 3px; }
.st-title { display: flex; align-items: baseline; gap: 8px; cursor: pointer; font-size: 14.5px; }
.st-title span:first-child { flex: 1; min-width: 0; }
.exec { font-size: 11.5px; font-weight: 600; padding: 1px 7px; border-radius: 99px; background: var(--user); color: var(--muted); flex: none; }
.exec.opus, .exec.fable { background: var(--warn-soft); color: var(--warn); }
.exec.gemini { background: var(--accent-soft); color: var(--accent); }
.st-details { font-size: 13.5px; color: var(--muted); white-space: pre-wrap; display: grid; gap: 3px; }
.st-result { font-size: 13.5px; color: var(--ink); opacity: .85; }
.plan-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.plan-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.plan-actions .btn { height: 36px; }
.plan-step-divider { display: flex; align-items: baseline; gap: 8px; font-size: 13px; color: var(--muted); padding-top: 6px; border-top: 1px dashed var(--line); }
.plan-step-divider b { color: var(--ink); font-weight: 600; }
.plan-toggle {
  display: inline-flex; align-items: center; gap: 5px; height: 38px; padding: 0 10px; flex: none;
  border: 1px solid transparent; border-radius: 12px; background: none; color: var(--muted); font-size: 13.5px; font-weight: 550;
}
.plan-toggle svg { width: 17px; height: 17px; }
.plan-toggle:hover { background: var(--user); color: var(--ink); }
.plan-toggle.on { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
@media (max-width: 820px) { .plan-toggle span { display: none; } .plan-toggle { padding: 0 8px; } }

/* ---------- браузер ---------- */
.browser-dlg { width: min(1180px, calc(100% - 24px)); max-height: calc(100dvh - 24px); }
.browser-dlg.agent .bw-screen-wrap { outline: 2px solid var(--accent); }
.bw { display: grid; gap: 8px; padding: 10px; }
.bw-bar { display: flex; align-items: center; gap: 4px; }
.bw-url { flex: 1; min-width: 0; }
.bw-url input { width: 100%; height: 36px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 14.5px; outline: none; }
.bw-url input:focus { border-color: var(--accent); }
#bw-tabs { max-width: 200px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); padding: 0 8px; font-size: 13px; }
.bw-status { display: flex; align-items: center; gap: 10px; min-height: 22px; }
.bw-screen-wrap { position: relative; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; aspect-ratio: 1280 / 800; }
#bw-screen { width: 100%; height: 100%; display: block; object-fit: contain; cursor: default; outline: none; user-select: none; }
#bw-screen:focus { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 40%, transparent); }
.bw-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); background: var(--bg); }
.bw-typer { display: flex; gap: 6px; flex-wrap: wrap; }
.bw-typer input { flex: 1; min-width: 180px; height: 38px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 15px; }
.bw-typer .btn { height: 38px; padding: 0 12px; font-size: 14px; }
@media (max-width: 820px) {
  .browser-dlg { width: 100%; max-width: 100%; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  #bw-tabs { display: none; }
  .bw-bar .icon-btn[data-act="forward"] { display: none; }
}

/* ---------- роли, пользователи, общие папки ---------- */
.role-bar { display: flex; align-items: center; gap: 4px; }
.role-pick { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 0 10px; height: 38px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); cursor: pointer; }
.role-pick:focus-within { border-color: var(--accent); }
.role-pick svg { width: 16px; height: 16px; color: var(--accent); }
.role-pick select { flex: 1; min-width: 0; border: 0; background: none; font-weight: 600; font-size: 14.5px; outline: none;
  text-overflow: ellipsis; cursor: pointer; padding: 0; }
.inbox-btn { position: relative; }
.count-badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px; background: var(--warn); color: #fff;
  font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; }
.inbox-btn .count-badge { position: absolute; top: -4px; right: -5px; }
.role-hidden { display: none !important; }
.account-row { display: flex; align-items: center; gap: 12px; justify-content: space-between; flex-wrap: wrap; }
.account-row .who { display: grid; line-height: 1.35; }
.account-row .who b { font-weight: 600; }
.manage-links { display: flex; gap: 6px; flex-wrap: wrap; }
.manage-links .btn { height: 34px; font-size: 14px; }

.panel-body { display: grid; gap: 16px; }
.panel-body > p { margin: 0; }
#panel-dlg .dialog-head { justify-content: flex-start; gap: 6px; }
#panel-dlg .dialog-head h3 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-list { display: grid; gap: 6px; }
.p-row { display: flex; align-items: center; gap: 10px; text-align: left; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--bg); width: 100%; }
.p-row:hover { border-color: var(--muted); }
.p-row.off { opacity: .55; }
.p-row .who { display: grid; line-height: 1.35; min-width: 0; flex: 1; }
.p-row .who b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-row .who small { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; }
.p-card { display: grid; gap: 8px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.p-checks { display: grid; gap: 6px; padding: 4px 2px; }
.p-checks label.check, label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.p-members { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; }
.p-members span { font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-members select { height: 36px; }
.p-add { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.p-add .btn { grid-column: 1 / -1; }
.invite-out { display: grid; gap: 6px; }
.invite-out:empty { display: none; }
.journal { display: grid; gap: 2px; max-height: 60vh; overflow-y: auto; }
.j-row { display: grid; grid-template-columns: 110px 1fr; gap: 10px; font-size: 14px; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.f-file .btn { height: 28px; padding: 0 10px; font-size: 13px; }

.handoff { gap: 8px; border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.handoff-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.handoff-head svg { width: 16px; height: 16px; color: var(--accent); }
.handoff-head b { font-weight: 600; }
.handoff-head .plan-pill { margin-left: auto; }
.handoff-task { white-space: pre-wrap; font-size: 14px; overflow-wrap: anywhere; }
.handoff.result { background: var(--accent-soft); box-shadow: none; }
.handoff.result .msg-text { font-size: 15px; }
@media (max-width: 560px) {
  .p-add { grid-template-columns: 1fr; }
  .j-row { grid-template-columns: 1fr; gap: 2px; }
}

/* ---------- окно настроек с разделами ---------- */
.dialog { max-height: calc(100dvh - 32px); overflow: auto; }
.dialog-body > *, .panel-body > * { min-width: 0; }
#panel-dlg .dialog-head, #folder-dlg .dialog-head { position: sticky; top: 0; z-index: 2; background: var(--surface);
  padding: 4px 0; }
.helper { min-width: 0; }
.helper .who { flex: none; }
.helper small { min-width: 0; overflow-wrap: anywhere; }

.settings-dlg { width: min(880px, calc(100% - 32px)); height: min(680px, calc(100dvh - 32px)); overflow: hidden; }
.settings-dlg[open] { display: flex; }
.settings-wrap { flex: 1; min-height: 0; display: grid; grid-template-columns: 210px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
.settings-head { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 12px 12px 20px; border-bottom: 1px solid var(--line); }
.settings-head h3 { margin: 0; font-size: 17px; }
.set-nav { display: flex; flex-direction: column; gap: 2px; padding: 12px 10px; border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--sidebar) 60%, var(--surface)); overflow-y: auto; }
.set-nav button { display: flex; align-items: center; gap: 10px; border: 0; background: none; text-align: left;
  padding: 9px 12px; border-radius: 9px; font-size: 14.5px; color: var(--muted); }
.set-nav button svg { width: 18px; height: 18px; }
.set-nav button:hover { background: var(--user); color: var(--ink); }
.set-nav button.on { background: var(--user); color: var(--ink); font-weight: 600; }
.set-nav button.on svg { color: var(--accent); }
.set-content { overflow-y: auto; padding: 20px 24px 28px; min-width: 0; }
.set-sec { display: grid; gap: 20px; max-width: 600px; }
.set-sec[hidden] { display: none; }
.set-sec h4 { margin: 0; font-size: 19px; letter-spacing: -.01em; }
.manage-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.manage-card { display: grid; gap: 2px; text-align: left; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--bg); }
.manage-card:hover { border-color: var(--accent); }
.manage-card b { font-weight: 600; font-size: 14.5px; }
.manage-card small { font-size: 12.5px; }
.manage-card.role-hidden { display: none; }

@media (max-width: 640px) {
  .settings-dlg { width: 100%; height: 100dvh; max-width: none; max-height: none; margin: 0; border-radius: 0; border: 0; }
  .settings-wrap { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); }
  .settings-head { padding-top: max(12px, env(safe-area-inset-top)); }
  .set-nav { flex-direction: row; overflow-x: auto; overflow-y: hidden; border-right: 0; border-bottom: 1px solid var(--line);
    padding: 8px 10px; scrollbar-width: none; }
  .set-nav::-webkit-scrollbar { display: none; }
  .set-nav button { flex: none; padding: 8px 12px; }
  .set-nav button svg { display: none; }
  .set-content { padding: 16px 16px max(24px, env(safe-area-inset-bottom)); }
}

/* ---------- сервисы и ключи ---------- */
.svc { display: grid; gap: 20px; }
.svc-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.svc-head > span:first-child { font-weight: 600; }
.svc-saved { color: var(--accent); }
.svc-assign { display: grid; grid-template-columns: minmax(0, 1fr) minmax(150px, 220px) 92px; gap: 8px 12px; align-items: center; }
.svc-task { display: grid; line-height: 1.3; min-width: 0; }
.svc-task b { font-weight: 600; font-size: 14px; }
.svc-task small { font-size: 12px; }
.svc-assign select { height: 38px; min-width: 0; }
.svc-state { font-size: 12.5px; font-weight: 600; color: var(--muted); text-align: right; }
.svc-state.on { color: var(--accent); }
.svc-state.bad { color: var(--warn); }
.svc-card { border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.svc-card + .svc-card { margin-top: 6px; }
.svc-card > summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 10px 12px; cursor: pointer; }
.svc-card > summary::-webkit-details-marker { display: none; }
.svc-card > summary .state { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: none; }
.svc-card.on > summary .state { background: var(--accent); }
.svc-card > summary .who { display: grid; line-height: 1.3; min-width: 0; flex: 1; }
.svc-card > summary .who b { font-weight: 600; }
.svc-card > summary .who small { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.svc-key { font-size: 12.5px; color: var(--muted); text-align: right; flex: none; }
.svc-add { color: var(--accent) !important; font-weight: 600; }
.svc-body { display: grid; gap: 12px; padding: 0 12px 14px; }
.svc-body p { margin: 0; }
.svc-body a { color: var(--accent); }
.svc-keyrow { display: flex; gap: 8px; }
.svc-keyrow input { flex: 1; min-width: 0; }
.svc-keyrow .btn { flex: none; }
.svc-acts { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.svc-acts .btn { height: 34px; font-size: 14px; }
.svc-result { font-size: 13px; }
.svc-result.ok { color: var(--accent); }
.svc-result.bad { color: var(--danger); }
.svc-models { display: grid; gap: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.svc-two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.svc-prices { display: grid; gap: 6px; }
.svc-price-row { display: grid; grid-template-columns: minmax(0, 1.4fr) repeat(3, minmax(0, 1fr)) auto; gap: 6px; align-items: center; }
.svc-price-row code { font: 12.5px var(--mono); overflow: hidden; text-overflow: ellipsis; }
.svc-price-row input { height: 34px !important; padding: 0 8px !important; font-size: 14px !important; }
.svc-custom { display: grid; gap: 12px; padding-top: 4px; }
.svc-custom select { height: 42px; }
.svc-custom label[hidden] { display: none; }
.svc-row { display: contents; }
@media (max-width: 640px) {
  .svc-assign { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .svc-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px; align-items: center; }
  .svc-row select { grid-column: 1 / -1; grid-row: 2; }
  .svc-row .svc-state { grid-column: 2; grid-row: 1; }
  .svc-two { grid-template-columns: 1fr; }
  .svc-price-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .svc-price-row code { grid-column: 1 / -1; }
}

/* ступени моделей и баланс своего сервиса */
.svc-tiers { display: grid; gap: 8px; }
.svc-tier { display: grid; grid-template-columns: 150px 1fr 180px; gap: 8px; align-items: center; }
.svc-tier-name { font-size: 13px; color: var(--muted, #888); }
.svc-bal { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (max-width: 640px) { .svc-tier { grid-template-columns: 1fr; } .svc-tier-name { margin-top: 4px; } }
