:root {
  --bg: #f6f7f9; --panel: #ffffff; --line: #d9dde3; --text: #1f2328; --muted: #656d76;
  --accent: #2f6feb; --accent-text: #fff; --hover: #eef1f5; --tab: #e7eaef; --danger: #c93c37; --ok: #1a7f37;
  --mono: ui-monospace, "JetBrains Mono", "DejaVu Sans Mono", "Liberation Mono", monospace;
  --split: 50%;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1216; --panel: #161b22; --line: #2d333b; --text: #e6edf3; --muted: #8d96a0;
          --accent: #4c8dff; --hover: #1f262e; --tab: #1c2128; --danger: #f47067; --ok: #57ab5a; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { display: flex; flex-direction: column; background: var(--bg); color: var(--text);
       font: 14px/1.4 system-ui, "Ubuntu", "Segoe UI", sans-serif; overflow: hidden; }
button, select { font: inherit; color: inherit; }
button { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; white-space: nowrap; }
button:hover { background: var(--hover); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.primary.busy { background: var(--danger); border-color: var(--danger); }
button.ghost { border-color: transparent; background: transparent; color: var(--muted); }
button.ghost:hover { background: var(--hover); color: var(--text); }
button.icon { padding: 4px 9px; }
kbd { font: 11px var(--mono); opacity: .75; border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; margin-left: 4px; }
select { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; max-width: 260px; }
.spacer { flex: 1; }

/* ---------- topbar & tabs */
#topbar { display: flex; align-items: center; gap: 6px; padding: 6px 8px 0; border-bottom: 1px solid var(--line); background: var(--bg); }
#topbar > :not(#tabs) { margin-bottom: 6px; }
#tabs { display: flex; gap: 2px; overflow-x: auto; overflow-y: hidden; min-width: 0; scrollbar-width: thin; align-self: flex-end; }
.tab { display: flex; align-items: center; gap: 4px; padding: 6px 6px 6px 12px; border: 1px solid var(--line); border-bottom: none;
       border-radius: 8px 8px 0 0; background: var(--tab); color: var(--muted); cursor: pointer; max-width: 220px; user-select: none; }
.tab.active { background: var(--panel); color: var(--text); box-shadow: inset 0 2px 0 var(--accent); }
.tab .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab .title[contenteditable="true"] { outline: 1px solid var(--accent); border-radius: 3px; padding: 0 3px; background: var(--panel); color: var(--text); cursor: text; }
.tab .close { border: none; background: transparent; padding: 0 5px; border-radius: 4px; color: inherit; opacity: .6; line-height: 1.2; }
.tab .close:hover { opacity: 1; background: var(--hover); }
.tab .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite; flex: none; }
@keyframes pulse { 50% { opacity: .25; } }

/* ---------- panes */
#panes { flex: 1; display: grid; grid-template-columns: var(--split) 6px 1fr; grid-template-rows: minmax(0, 1fr); min-height: 0; }
/* колонки закреплены явно: при скрытии одной панели другая не «съезжает» в колонку нулевой ширины */
#srcPane { grid-column: 1; } #divider { grid-column: 2; } #dstPane { grid-column: 3; }
#panes.layout-src { grid-template-columns: 1fr 0 0; }
#panes.layout-dst { grid-template-columns: 0 0 1fr; }
#panes.layout-src #dstPane, #panes.layout-dst #srcPane, #panes:not(.layout-split) #divider { display: none; }
.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--panel); }
.pane-head { display: flex; align-items: center; gap: 4px; padding: 5px 8px; border-bottom: 1px solid var(--line); min-height: 38px; }
.lang { font: 600 12px var(--mono); padding: 2px 7px; border-radius: 5px; background: var(--hover); color: var(--muted); min-width: 34px; text-align: center; }
.lang.auto::after { content: " · авто"; font-weight: 400; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; margin-left: 6px; }
.seg button { border: none; border-radius: 0; padding: 3px 10px; background: transparent; color: var(--muted); }
.seg button.on { background: var(--hover); color: var(--text); font-weight: 600; }
#divider { cursor: col-resize; background: var(--line); }
#divider:hover, #divider.drag { background: var(--accent); }
textarea#src, textarea#dst { flex: 1; resize: none; border: none; outline: none; padding: 16px 20px; background: var(--panel); color: var(--text);
                             font: 13.5px/1.6 var(--mono); tab-size: 4; }
.preview { flex: 1; overflow: auto; padding: 24px 32px 64px; }
.markdown-body { background: transparent !important; font-size: 15.5px; }
.markdown-body > * { max-width: var(--read-width, 1300px); margin-left: auto !important; margin-right: auto !important; }
.markdown-body .empty { color: var(--muted); font-style: italic; }
.markdown-body pre { position: relative; }
.markdown-body pre code.hljs { padding: 0; background: transparent; overflow: visible; }
@media (prefers-color-scheme: dark) { .markdown-body pre { background-color: #0b0e12 !important; border: 1px solid var(--line); } }
.markdown-body .copy-code { position: absolute; top: 6px; right: 6px; font-size: 12px; padding: 1px 7px; opacity: 0; transition: opacity .15s; }
.markdown-body pre:hover .copy-code { opacity: .9; }
.markdown-body .markdown-alert { padding: 8px 16px; border-left: .25em solid var(--accent); margin-bottom: 16px; }
.markdown-body .markdown-alert-title { font-weight: 600; margin-bottom: 4px; }
.streaming .markdown-body::after, #dstPreview.streaming::after { content: "▍"; color: var(--accent); animation: pulse .8s infinite; }

/* ---------- status, toast */
#status { display: flex; gap: 12px; padding: 3px 10px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); background: var(--bg); }
#status.error #statusText { color: var(--danger); }
#status.warn #statusText { color: #b7791f; }
#toast { position: fixed; bottom: 34px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 7px 14px;
         border-radius: 8px; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 70vw; }
#toast.show { opacity: .95; }

/* ---------- settings dialog */
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); width: min(640px, 92vw); padding: 20px 24px; }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h2 { margin: 0 0 12px; font-size: 18px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field small { color: var(--muted); }
.field textarea { font: 13px/1.5 var(--mono); padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); resize: vertical; }
.check { display: flex; gap: 8px; align-items: flex-start; margin: 8px 0; }
.row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
details { margin-top: 12px; color: var(--muted); }
.keys td { padding: 2px 10px 2px 0; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
code { font-family: var(--mono); }
.account { margin-top: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.mobile-only, .client-only { display: none !important; }
body.client-store .client-only { display: flex !important; }

/* ---------- страница входа */
body.login-page { align-items: center; justify-content: center; overflow: auto; padding: 16px; }
.login-box { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px 24px; width: min(420px, 100%);
             display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-box img { align-self: center; border-radius: 14px; }
.login-box h1 { margin: 0; font-size: 22px; }
.login-box p { margin: 0; color: var(--muted); }
.login-box input { font: 15px var(--mono); padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); }
.login-box button { padding: 10px; font-size: 15px; }
.login-box .err { color: var(--danger); min-height: 1.2em; }

/* ---------- телефон */
@media (max-width: 760px) {
  .mobile-only { display: inline-flex !important; }
  kbd, #divider, .max, #openFile, #swap, #srcSeg, #counts { display: none !important; }
  #topbar { flex-wrap: wrap; padding: 6px 6px 0; gap: 4px; padding-top: max(6px, env(safe-area-inset-top)); }
  #tabs { order: 10; flex: 1 1 calc(100% - 48px); }
  #newTab { order: 11; }
  #topbar > .spacer { display: none; }
  #mobSeg { margin-left: 0; }
  select { max-width: 42vw; }
  #direction { max-width: 86px; }
  #translateBtn { flex: 1; }
  #panes.layout-split { grid-template-columns: 1fr 0 0; }
  #panes.layout-split #dstPane { display: none; }
  .pane-head { overflow-x: auto; scrollbar-width: none; }
  .preview { padding: 14px 14px 48px; }
  textarea#src, textarea#dst { padding: 12px 14px; font-size: 14px; }
  .markdown-body { font-size: 15px; }
  #status { padding-bottom: max(3px, env(safe-area-inset-bottom)); }
  .tab { max-width: 160px; }
}
