:root {
  --bg: #f4f3ef; --panel: #ffffff; --panel2: #faf9f6; --line: #dedbd2; --text: #23231f; --muted: #6d6a60;
  --accent: #2f6b4f; --accent-ink: #ffffff; --accent-soft: #e3efe8; --warn: #a65a12; --warn-soft: #fbefe1;
  --bad: #b3261e; --bad-soft: #fbe9e7; --shadow: 0 8px 28px rgba(30, 30, 20, .16);
  --term-bg: #ffffff; --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1c1a; --panel: #242622; --panel2: #2b2d29; --line: #3a3d37; --text: #e9e8e2; --muted: #a3a197;
    --accent: #6fbf93; --accent-ink: #10140f; --accent-soft: #23372c; --warn: #e0a35c; --warn-soft: #3a2e1f;
    --bad: #f08a80; --bad-soft: #3d2422; --shadow: 0 8px 28px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1c1a; --panel: #242622; --panel2: #2b2d29; --line: #3a3d37; --text: #e9e8e2; --muted: #a3a197;
  --accent: #6fbf93; --accent-ink: #10140f; --accent-soft: #23372c; --warn: #e0a35c; --warn-soft: #3a2e1f;
  --bad: #f08a80; --bad-soft: #3d2422; --shadow: 0 8px 28px rgba(0, 0, 0, .5);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.4 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

/* ---- верхняя полоса ---- */
.top { height: 46px; display: flex; align-items: center; gap: 10px; padding: 0 10px; background: var(--panel); border-bottom: 1px solid var(--line); position: relative; z-index: 5; }
.brand { font-weight: 700; letter-spacing: .2px; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.brand i { width: 22px; height: 22px; border-radius: 5px; background: var(--accent); display: inline-block; position: relative; }
.brand i::after { content: ""; position: absolute; left: 5px; right: 5px; bottom: 5px; height: 8px; border: 2px solid var(--accent-ink); border-top: 0; }
.brand i::before { content: ""; position: absolute; left: 3px; top: 4px; width: 0; height: 0; border: 8px solid transparent; border-bottom-color: var(--accent-ink); border-top: 0; }
#sections { display: flex; gap: 2px; overflow-x: auto; flex: 1; min-width: 0; scrollbar-width: none; }
#sections::-webkit-scrollbar { display: none; }
.tab { border: 0; background: transparent; padding: 6px 8px; border-radius: 6px; white-space: nowrap; color: var(--muted); }
.tab:hover { background: var(--panel2); color: var(--text); }
.tab.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.right { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.btn { border: 1px solid var(--line); background: var(--panel); padding: 5px 10px; border-radius: 6px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.small { padding: 2px 8px; font-size: 13px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: 12px; text-align: center; margin-left: 4px; }
.badge.warn { background: var(--warn); }
#online { display: flex; }
.av { width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); border: 2px solid var(--panel); display: grid; place-items: center; font-size: 11px; font-weight: 700; margin-left: -6px; }
.menu { position: absolute; top: 42px; right: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 230px; padding: 4px; display: none; z-index: 20; }
.menu.open { display: block; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 7px 10px; border-radius: 5px; }
.menu button:hover { background: var(--panel2); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.menu .hint { padding: 6px 10px; color: var(--muted); font-size: 12px; }

/* ---- рабочая область ---- */
.split { position: absolute; top: 46px; left: 0; right: 0; bottom: 0; display: flex; }
#view { flex: 1; min-width: 200px; position: relative; background: #fff; }
#frame { width: 100%; height: 100%; border: 0; display: block; background: #fff; }
#splitter { width: 6px; cursor: col-resize; background: var(--line); flex: none; position: relative; }
#splitter:hover, #splitter.drag { background: var(--accent); }
#termPanel { width: 46%; min-width: 300px; display: flex; flex-direction: column; background: var(--panel); flex: none; }
body.no-term #termPanel, body.no-term #splitter { display: none; }
body.term-max #view, body.term-max #splitter { display: none; }
body.term-max #termPanel { width: 100% !important; }
.drag-cover { position: fixed; inset: 0; z-index: 50; cursor: col-resize; }

.termbar { display: flex; align-items: center; gap: 4px; padding: 5px 6px; border-bottom: 1px solid var(--line); background: var(--panel2); }
#termTabs { display: flex; gap: 3px; overflow-x: auto; flex: 1; min-width: 0; scrollbar-width: thin; }
.ttab { display: flex; align-items: center; gap: 6px; border: 1px solid transparent; background: transparent; padding: 3px 4px 3px 9px; border-radius: 6px; white-space: nowrap; color: var(--muted); }
.ttab.on { background: var(--panel); border-color: var(--line); color: var(--text); }
.ttab .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.ttab.dead .dot { background: var(--muted); }
.ttab .x { border: 0; background: none; padding: 0 4px; color: var(--muted); border-radius: 4px; }
.ttab .x:hover { background: var(--bad-soft); color: var(--bad); }
.icon { border: 0; background: none; padding: 4px 7px; border-radius: 5px; color: var(--muted); }
.icon:hover { background: var(--line); color: var(--text); }
#termHost { flex: 1; position: relative; background: var(--term-bg); min-height: 0; }
.term { position: absolute; inset: 0; padding: 4px 0 0 6px; display: none; }
.term.on { display: block; }
.term .xterm { height: 100%; }
.term-dead { position: absolute; left: 12px; right: 12px; bottom: 12px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: var(--radius); padding: 10px 12px; display: flex; gap: 8px; align-items: center; z-index: 3; }
.term-dead span { flex: 1; }
.term-conn { position: absolute; top: 8px; right: 14px; background: var(--warn-soft); color: var(--warn); padding: 3px 9px; border-radius: 12px; font-size: 12px; z-index: 3; display: none; }
#termEmpty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 20px; }
#termEmpty h3 { color: var(--text); margin: 0 0 6px; font-size: 16px; }
#termEmpty .row { display: flex; gap: 8px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.termfoot { padding: 4px 10px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); background: var(--panel2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; font: 11px/1.5 Consolas, monospace; background: var(--panel); }

/* ---- окна ---- */
dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text); box-shadow: var(--shadow); padding: 0; width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 40px); }
dialog::backdrop { background: rgba(20, 20, 15, .35); }
dialog header { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
dialog header h2 { margin: 0; font-size: 16px; flex: 1; }
dialog .body { padding: 14px 16px; overflow: auto; max-height: calc(100vh - 140px); }
dialog table { width: 100%; border-collapse: collapse; }
dialog td, dialog th { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
dialog th { font-weight: 600; color: var(--muted); font-size: 12px; }
dialog .muted, .muted { color: var(--muted); }
.form { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-top: 12px; }
.form label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
input[type=text], input[type=password], select, textarea { border: 1px solid var(--line); background: var(--panel2); border-radius: 6px; padding: 6px 8px; }
textarea { width: 100%; min-height: 140px; font: 12px/1.4 Consolas, monospace; }
.note { background: var(--accent-soft); border-radius: 6px; padding: 10px 12px; margin: 10px 0; }
.note.warn { background: var(--warn-soft); }
.pw { font: 600 18px Consolas, monospace; letter-spacing: 1px; }
.help h3 { font-size: 14px; margin: 16px 0 4px; }
.help p, .help li { color: var(--text); }
.help ul { padding-left: 18px; margin: 4px 0; }

/* ---- уведомления ---- */
#toasts { position: fixed; right: 14px; bottom: 14px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: min(420px, calc(100vw - 28px)); }
.toast { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: var(--radius); box-shadow: var(--shadow); padding: 9px 12px; display: flex; gap: 10px; align-items: center; }
.toast.warn { border-left-color: var(--warn); }
.toast.bad { border-left-color: var(--bad); }
.toast span { flex: 1; }
.toast .acts { display: flex; gap: 6px; }

#termToggle { display: none; }
body.no-term #termToggle { display: inline-block; }
/* терминал не входит в роли человека */
body.noterm #termToggle, body.noterm #termPanel, body.noterm #splitter, body.noterm .termonly { display: none !important; }
/* терминал только на страницах проектов: на остальных скрыт, процессы работают */
body.term-away #termToggle, body.term-away #termPanel, body.term-away #splitter { display: none !important; }
/* терминал снизу под страницей */
body.dock-bottom .split { flex-direction: column; }
body.dock-bottom #view { min-width: 0; min-height: 120px; }
body.dock-bottom #splitter { width: auto; height: 6px; cursor: row-resize; }
body.dock-bottom #termPanel { width: auto !important; min-width: 0; height: 40%; min-height: 150px; }
body.dock-bottom.term-max #termPanel { height: 100% !important; }
.drag-cover.rows { cursor: row-resize; }
.icon.iconsvg { display: inline-grid; place-items: center; padding: 4px 6px; }
.icon.iconsvg svg { display: block; }
.tab.admtab { color: var(--warn); }
.tab.admtab.on { background: var(--warn-soft); color: var(--warn); }

#sectBtn { display: none; }
@media (max-width: 900px) {
  .brand span { display: none; }
  #sections { display: none; }
  #sectBtn { display: inline-block; flex: 1; min-width: 0; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }
  .top { gap: 6px; }
  .right { margin-left: auto; gap: 6px; }
  #lockBtn .lbl { display: none; }
  #lockBtn::before { content: "В работе"; }
  #online { display: none; }
  #splitter { display: none; }
  #termPanel { position: absolute; inset: 0; width: 100% !important; z-index: 4; }
  body.dock-bottom #termPanel { height: auto !important; }
  #dockBtn { display: none; }
  #termToggle { display: inline-block; }
  body:not(.no-term) #termToggle { background: var(--accent-soft); }
}
