:root {
  --bg: #f3f5f9;
  --panel: #ffffff;
  --side: #fbfcfe;
  --top: #1c2130;
  --top-text: #e8ebf3;
  --border: #e4e8ef;
  --border-strong: #d3d9e3;
  --text: #1b2232;
  --muted: #6b7486;
  --faint: #9aa2b3;
  --accent: #3b6cff;
  --accent-hover: #2d5ae6;
  --accent-soft: #ebf0ff;
  --ok: #15a05a;
  --ok-soft: #e4f6ec;
  --warn: #c97a06;
  --warn-soft: #fdf3e2;
  --err: #d9363e;
  --err-soft: #fdeaeb;
  --row-hover: #f7f9fc;
  --code-bg: #0f1420;
  --code-text: #d7deea;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 20px 50px rgba(16, 24, 40, .18);
  --radius: 12px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, "SF Mono", Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1117; --panel: #161a22; --side: #12151c; --top: #0b0d12; --top-text: #e6e9f0;
    --border: #252a35; --border-strong: #323949; --text: #e5e8ef; --muted: #8e97aa; --faint: #646d80;
    --accent: #5b86ff; --accent-hover: #7398ff; --accent-soft: rgba(91, 134, 255, .14);
    --ok: #34c77b; --ok-soft: rgba(52, 199, 123, .13); --warn: #e8a33a; --warn-soft: rgba(232, 163, 58, .13);
    --err: #f06068; --err-soft: rgba(240, 96, 104, .13); --row-hover: #1b2029;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 20px 50px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1117; --panel: #161a22; --side: #12151c; --top: #0b0d12; --top-text: #e6e9f0;
  --border: #252a35; --border-strong: #323949; --text: #e5e8ef; --muted: #8e97aa; --faint: #646d80;
  --accent: #5b86ff; --accent-hover: #7398ff; --accent-soft: rgba(91, 134, 255, .14);
  --ok: #34c77b; --ok-soft: rgba(52, 199, 123, .13); --warn: #e8a33a; --warn-soft: rgba(232, 163, 58, .13);
  --err: #f06068; --err-soft: rgba(240, 96, 104, .13); --row-hover: #1b2029;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 20px 50px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
svg.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
svg.i.sm { width: 15px; height: 15px; }
svg.i.lg { width: 22px; height: 22px; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; grid-template-rows: 52px 1fr; height: 100vh; }
.topbar { grid-column: 1 / -1; background: var(--top); color: var(--top-text); display: flex; align-items: center; gap: 10px; padding: 0 14px; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; letter-spacing: -.01em; color: #fff; min-width: 220px; }
.brand-logo { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, #4d7cff, #2b55e0); display: grid; place-items: center; }
.brand-logo svg { stroke: #fff; width: 16px; height: 16px; }
.brand small { font-weight: 500; color: #8e98b3; font-size: 12px; }
.top-host { color: #9aa4bd; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.top-spacer { flex: 1; }
.top-btn { background: transparent; border: 0; color: var(--top-text); height: 34px; min-width: 34px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer; padding: 0 8px; font: inherit; position: relative; }
.top-btn:hover { background: rgba(255, 255, 255, .08); }
.top-btn .dot { position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: #ffb020; box-shadow: 0 0 0 2px var(--top); }
.menu-toggle { display: none; }
.dev-badge { background: #ffb020; color: #3a2600; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px; }

.sidebar { background: var(--side); border-right: 1px solid var(--border); overflow-y: auto; padding: 10px 10px 30px; }
.nav-group { padding: 6px 0; border-bottom: 1px solid var(--border); }
.nav-group:last-child { border-bottom: 0; }
.nav-item { display: flex; align-items: center; gap: 11px; padding: 7px 10px; border-radius: 8px; color: var(--text); font-size: 13.5px; cursor: pointer; text-decoration: none !important; }
.nav-item svg { color: var(--muted); }
.nav-item:hover { background: var(--row-hover); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 550; }
.nav-item.active svg { color: var(--accent); }
.nav-item .tag { margin-left: auto; font-size: 10.5px; color: var(--faint); border: 1px solid var(--border); border-radius: 10px; padding: 0 6px; }

.main { overflow-y: auto; padding: 24px 28px 48px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 23px; }
.page-head .sub { color: var(--muted); font-size: 13px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- cards ---------- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px 0; }
.card-head h2 { font-size: 17px; }
.card-head .actions { margin-left: auto; display: flex; gap: 6px; }
.card-body { padding: 16px 20px 20px; }
.card + .card { margin-top: 18px; }
.grid { display: grid; gap: 18px; }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.quick { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.quick-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; min-height: 92px; display: flex; flex-direction: column; justify-content: space-between; cursor: pointer; color: var(--text); text-align: left; font: inherit; transition: border-color .15s, transform .15s, box-shadow .15s; }
.quick-card:hover { border-color: var(--accent); box-shadow: 0 6px 18px rgba(59, 108, 255, .12); transform: translateY(-1px); }
.quick-card span { font-weight: 550; }
.quick-card svg { align-self: flex-end; color: var(--accent); width: 22px; height: 22px; }

.stat-row { display: flex; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--border); gap: 12px; }
.stat-row:last-child { border-bottom: 0; }
.stat-row .k { width: 44%; color: var(--text); }
.stat-row .v { flex: 1; color: var(--accent); min-width: 0; }
.stat-row .v.plain { color: var(--text); }
.bar { height: 6px; background: var(--border); border-radius: 6px; overflow: hidden; margin-top: 5px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 6px; transition: width .4s; }
.bar.warn > i { background: var(--warn); }
.bar.err > i { background: var(--err); }

.donut-wrap { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; }
.donut-wrap svg { flex: none; }
.legend { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 1px solid var(--border); display: grid; gap: 7px; font-size: 13px; }
.legend li { display: flex; align-items: center; gap: 9px; }
.legend i { width: 13px; height: 13px; border-radius: 4px; flex: none; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.t th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--panel); position: sticky; top: 0; }
table.t td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr:hover td { background: var(--row-hover); }
table.t tr.sel td { background: var(--accent-soft) !important; }
table.t td.actions { text-align: right; white-space: nowrap; }
table.t .cb { width: 34px; }
.card > .table-wrap table.t th:first-child, .card > .table-wrap table.t td:first-child { padding-left: 20px; }
.card > .table-wrap table.t th:last-child, .card > .table-wrap table.t td:last-child { padding-right: 20px; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--panel); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--row-hover); border-color: var(--faint); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--row-hover); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 7px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--row-hover); color: var(--text); }
.icon-btn.danger:hover { color: var(--err); background: var(--err-soft); }
.icon-btn:disabled { opacity: .4; cursor: default; }

input.in, select.in, textarea.in { width: 100%; height: 36px; padding: 0 11px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--panel); color: var(--text); font: inherit; outline: none; transition: border-color .12s, box-shadow .12s; }
textarea.in { height: auto; min-height: 90px; padding: 9px 11px; resize: vertical; font-family: var(--mono); font-size: 13px; }
input.in:focus, select.in:focus, textarea.in:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input.in.sm, select.in.sm { height: 30px; font-size: 13px; }
.form { display: grid; gap: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 500; margin-bottom: 5px; color: var(--muted); }
.field .help { font-size: 12px; color: var(--faint); margin-top: 4px; }
.field-inline { display: flex; gap: 6px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.checklist { display: grid; gap: 6px; max-height: 180px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.form-error { color: var(--err); font-size: 13px; white-space: pre-wrap; }
.form-error:empty { display: none; }

.switch { position: relative; width: 36px; height: 20px; display: inline-block; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border-strong); border-radius: 20px; cursor: pointer; transition: .15s; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { transform: translateX(16px); }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 500; padding: 2px 9px; border-radius: 20px; background: var(--row-hover); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.err { background: var(--err-soft); color: var(--err); border-color: transparent; }
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.dot-s { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tab { padding: 9px 14px; border: 0; background: none; font: inherit; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 550; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; color: var(--faint); margin-bottom: 10px; }
.empty h3 { color: var(--text); font-size: 16px; margin-bottom: 6px; }
.notice { display: flex; gap: 12px; padding: 13px 16px; border-radius: 10px; background: var(--accent-soft); color: var(--text); font-size: 13.5px; margin-bottom: 18px; }
.notice svg { color: var(--accent); margin-top: 1px; }
.notice.warn { background: var(--warn-soft); }
.notice.warn svg { color: var(--warn); }
.prose p { margin: 0 0 10px; }
.prose ol, .prose ul { margin: 0 0 12px; padding-left: 20px; }
.prose li { margin: 4px 0; }
.prose code { background: var(--row-hover); border: 1px solid var(--border); padding: 1px 6px; border-radius: 5px; }

.spinner { width: 18px; height: 18px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 40px 0; justify-content: center; }

/* ---------- modal & toast ---------- */
.modal-wrap { position: fixed; inset: 0; background: rgba(10, 14, 24, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; z-index: 100; overflow-y: auto; animation: fade .12s; backdrop-filter: blur(2px); }
.modal { background: var(--panel); border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 480px; border: 1px solid var(--border); animation: pop .15s; }
.modal.wide { max-width: 860px; }
.modal.full { max-width: none; width: calc(100vw - 48px); height: calc(100vh - 7vh - 24px); display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 16px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-body { padding: 18px 20px; }
.modal.full .modal-body { flex: 1; padding: 0; min-height: 0; display: flex; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); align-items: center; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }
#toasts { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 200; }
.toast { background: var(--top); color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 13.5px; max-width: 380px; display: flex; gap: 10px; align-items: flex-start; animation: pop .15s; white-space: pre-wrap; }
.toast.err { background: var(--err); }
.toast.ok svg { color: #5fe39a; }

pre.log { background: var(--code-bg); color: var(--code-text); margin: 0; padding: 14px 16px; border-radius: 10px; max-height: 60vh; overflow: auto; font-size: 12.5px; line-height: 1.55; white-space: pre-wrap; word-break: break-all; }
pre.log .e { color: #ff8a8f; }
pre.log .w { color: #f5c26b; }
pre.log .s { color: #7be0a6; }
.secret { display: flex; align-items: center; gap: 8px; background: var(--row-hover); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-family: var(--mono); font-size: 13px; word-break: break-all; }
.secret span { flex: 1; }

/* ---------- file manager ---------- */
.fm-toolbar { display: flex; gap: 6px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; align-items: center; }
.fm-toolbar .sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.crumbs { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; padding: 10px 16px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.crumbs a { padding: 2px 7px; border-radius: 6px; color: var(--text); }
.crumbs a:hover { background: var(--row-hover); text-decoration: none; }
.crumbs .slash { color: var(--faint); }
.crumbs .root-path { color: var(--faint); margin-right: 6px; font-family: var(--mono); font-size: 12px; }
.fm-name { display: flex; align-items: center; gap: 10px; cursor: pointer; color: var(--text); min-width: 0; }
.fm-name:hover span { color: var(--accent); }
.fm-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fm-ico { width: 30px; height: 30px; border-radius: 7px; display: grid; place-items: center; flex: none; }
.fm-ico.dir { background: #fff3d6; color: #d99a0b; }
.fm-ico.file { background: var(--row-hover); color: var(--muted); }
.fm-ico.code { background: #e9f0ff; color: #3b6cff; }
.fm-ico.img { background: #e7f7ef; color: #15a05a; }
.fm-ico.arc { background: #f6e9ff; color: #9b4dd8; }
:root[data-theme="dark"] .fm-ico.dir { background: rgba(217, 154, 11, .15); }
:root[data-theme="dark"] .fm-ico.code { background: rgba(59, 108, 255, .15); }
:root[data-theme="dark"] .fm-ico.img { background: rgba(21, 160, 90, .15); }
:root[data-theme="dark"] .fm-ico.arc { background: rgba(155, 77, 216, .15); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .fm-ico.dir { background: rgba(217, 154, 11, .15); }
  :root:not([data-theme="light"]) .fm-ico.code { background: rgba(59, 108, 255, .15); }
  :root:not([data-theme="light"]) .fm-ico.img { background: rgba(21, 160, 90, .15); }
  :root:not([data-theme="light"]) .fm-ico.arc { background: rgba(155, 77, 216, .15); }
}
.fm-row-actions { opacity: 0; transition: opacity .1s; }
tr:hover .fm-row-actions { opacity: 1; }
.dropzone { position: relative; }
.dropzone.drag::after { content: "Отпустите файлы для загрузки"; position: absolute; inset: 8px; border: 2px dashed var(--accent); border-radius: 12px; background: color-mix(in srgb, var(--accent-soft) 85%, transparent); display: grid; place-items: center; font-weight: 600; color: var(--accent); font-size: 16px; z-index: 5; }
.upload-bar { padding: 10px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
.editor-host { flex: 1; min-height: 0; position: relative; }
.editor-host textarea { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; resize: none; padding: 14px; background: var(--code-bg); color: var(--code-text); font-family: var(--mono); font-size: 13px; line-height: 1.55; outline: none; tab-size: 4; }
.editor-host .ace_editor { position: absolute; inset: 0; font-size: 13px; }

/* ---------- disk / logs / terminal ---------- */
.du-row { display: grid; grid-template-columns: minmax(140px, 1.2fr) 2fr 90px; gap: 14px; align-items: center; padding: 9px 20px; border-bottom: 1px solid var(--border); }
.du-row:last-child { border-bottom: 0; }
.du-row .bar { margin: 0; height: 8px; }
.log-layout { display: grid; grid-template-columns: 290px 1fr; gap: 18px; }
.log-list { max-height: calc(100vh - 190px); overflow: auto; padding: 8px; }
.log-file { display: block; padding: 7px 10px; border-radius: 8px; cursor: pointer; font-size: 13px; color: var(--text); word-break: break-all; }
.log-file:hover { background: var(--row-hover); text-decoration: none; }
.log-file.active { background: var(--accent-soft); color: var(--accent); }
.log-file small { display: block; color: var(--faint); }
.log-view pre.log { max-height: calc(100vh - 250px); min-height: 300px; border-radius: 0 0 var(--radius) var(--radius); }
.term-card { background: #0f1420; border-radius: var(--radius); padding: 10px; height: calc(100vh - 170px); min-height: 320px; border: 1px solid var(--border); }
.term-card .xterm { height: 100%; }

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(1200px 600px at 10% -10%, rgba(59, 108, 255, .18), transparent), radial-gradient(900px 500px at 110% 110%, rgba(155, 77, 216, .14), transparent), var(--bg); }
.login-card { width: 100%; max-width: 380px; padding: 32px 30px 28px; }
.login-card .brand { color: var(--text); justify-content: center; margin-bottom: 6px; font-size: 20px; min-width: 0; }
.login-card p { text-align: center; color: var(--muted); margin: 0 0 22px; }

/* ---------- responsive ---------- */
@media (max-width: 1280px) { .quick { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 1100px) { .grid-3 { grid-template-columns: 1fr 1fr; } .log-layout { grid-template-columns: 1fr; } .log-list { max-height: 220px; } }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; top: 52px; bottom: 0; left: 0; width: 264px; z-index: 30; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  .shell.nav-open .sidebar { transform: none; }
  .menu-toggle { display: inline-flex; }
  .brand { min-width: 0; }
  .brand small, .top-host { display: none; }
  .main { padding: 18px 16px 40px; }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .quick { grid-template-columns: 1fr 1fr; }
  .fm-row-actions { opacity: 1; }
  .hide-m { display: none; }
  .du-row { grid-template-columns: 1fr 80px; padding: 9px 16px; }
  .du-row .bar { grid-column: 1 / -1; grid-row: 2; }
  .modal.full { width: calc(100vw - 16px); }
}
