:root {
  --bg: #0a0c10;
  --panel: #11151b;
  --panel2: #171d25;
  --panel3: #1e2731;
  --line: #2c3743;
  --text: #e9eff6;
  --dim: #a9b6c4;
  --accent: #5aa7ff;
  --accent-ink: #04121f;
  --accent-bg: #16314f;
  --ok: #56d98c;
  --warn: #f2b33d;
  --bad: #ff7272;
  --hdr: 48px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 var(--font);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button[disabled] { opacity: .42; cursor: default; }
input { font: inherit; color: inherit; }
h1, h2, p { margin: 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.grow { flex: 1 1 auto; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 42px; padding: 0 14px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 7px;
  color: var(--text); white-space: nowrap;
}
.btn:hover:not([disabled]) { background: var(--panel3); }
.btn.small { height: 40px; padding: 0 11px; font-size: 14px; }
.btn.block { width: 100%; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover:not([disabled]) { background: #78b7ff; }
.btn.danger { border-color: #6b2b2b; color: var(--bad); }
.btn.danger:hover:not([disabled]) { background: #2a1416; }

.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel2);
}
.bars { display: block; width: 18px; height: 2px; background: var(--text); position: relative; }
.bars::before, .bars::after { content: ""; position: absolute; left: 0; width: 18px; height: 2px; background: var(--text); }
.bars::before { top: -6px; }
.bars::after { top: 6px; }

/* boot and login */
.boot { display: grid; place-items: center; height: 100dvh; color: var(--dim); }

.login { display: grid; place-items: center; height: 100dvh; padding: 18px; }
.login-card { width: min(100%, 340px); display: flex; flex-direction: column; gap: 14px; }
.login-title { font-size: 20px; font-weight: 700; letter-spacing: .3px; text-align: center; margin-bottom: 4px; }

.field { display: block; }
.field-label { display: block; font-size: 13px; color: var(--dim); margin-bottom: 5px; }
.inp {
  width: 100%; height: 44px; padding: 0 11px;
  background: #0d1218; border: 1px solid var(--line); border-radius: 7px; color: var(--text);
  font-size: 16px;
}
.inp:focus { border-color: var(--accent); outline: none; }
.hint { font-size: 12.5px; color: var(--dim); margin-top: 5px; }
.form-error { color: #ffb3b3; background: #2b1416; border: 1px solid #6b2b2b; border-radius: 7px; padding: 8px 10px; font-size: 13.5px; }

/* app frame */
.app { display: flex; flex-direction: column; height: 100dvh; min-height: 0; }

.hdr {
  display: flex; align-items: center; gap: 10px;
  height: var(--hdr); flex: 0 0 auto; padding: 0 10px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .3px; }
.nav-only { display: none; }

.banner { flex: 0 0 auto; padding: 8px 12px; font-size: 13.5px; background: #3a2a0f; color: #ffdda3; border-bottom: 1px solid #5c4417; }
.banner.error { background: #3a1417; color: #ffc4c4; border-bottom-color: #6b2b2b; }

.body { flex: 1 1 auto; display: flex; min-height: 0; position: relative; }

/* sidebar */
.sidebar {
  flex: 0 0 292px; width: 292px; min-width: 0;
  display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border-right: 1px solid var(--line);
}
.side-hdr { display: flex; gap: 8px; padding: 8px; border-bottom: 1px solid var(--line); }
.tree { flex: 1 1 auto; overflow: auto; overscroll-behavior: contain; padding-bottom: 40px; }
.scrim { display: none; }

/* tree rows */
.row {
  position: relative;
  display: flex; align-items: center; gap: 7px;
  min-height: 42px;
  padding-left: calc(6px + var(--d, 0) * 15px);
  padding-right: 4px;
  cursor: pointer;
  user-select: none; -webkit-user-select: none;
  touch-action: pan-y;
}
.row:hover { background: #161d26; }
.row.group { color: var(--dim); font-size: 13px; text-transform: uppercase; letter-spacing: .6px; min-height: 36px; }
.row .name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.folder .name { font-weight: 600; }
.row .count { flex: 0 0 auto; font-size: 12px; color: var(--dim); }
.row .age { flex: 0 0 auto; font-size: 11.5px; color: var(--dim); max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tw { flex: 0 0 auto; width: 20px; height: 40px; display: grid; place-items: center; }
.tw::before {
  content: ""; width: 0; height: 0;
  border-left: 6px solid var(--dim);
  border-top: 5px solid transparent; border-bottom: 5px solid transparent;
  transform: rotate(0deg); transition: transform .12s ease;
}
.row.open .tw::before { transform: rotate(90deg); }

.act {
  flex: 0 0 auto; width: 38px; height: 40px;
  display: grid; place-items: center; border-radius: 7px;
  color: var(--dim); font-size: 17px; line-height: 1;
}
.act:hover:not([disabled]) { background: var(--panel3); color: var(--text); }
.act.wide { width: auto; padding: 0 10px; font-size: 13px; border: 1px solid var(--line); color: var(--text); }

.dot { flex: 0 0 auto; width: 9px; height: 9px; border-radius: 50%; background: #55636f; }
.dot.st-running { background: var(--ok); }
.dot.st-exited { background: var(--warn); }
.dot.st-missing { background: transparent; border: 2px solid #6d7b88; }
.dot.st-unknown { background: #55636f; }

.badge {
  flex: 0 0 auto; font-size: 11px; padding: 1px 7px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--dim); white-space: nowrap;
}
.badge.b-exited { color: var(--warn); border-color: #5c4417; }

.empty { color: var(--dim); padding: 18px 14px; text-align: center; }
.empty.small { font-size: 13.5px; }

/* drag */
.dragging, .dragging .tree, .dragging .row { touch-action: none; }
.dragging .row { cursor: grabbing; }
.row.dz-into { background: var(--accent-bg); box-shadow: inset 0 0 0 2px var(--accent); }
.row.dz-before::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 2px; background: var(--accent); }
.row.dz-after::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--accent); }
.row.dz-src { opacity: .45; }
.tree.dz-root { box-shadow: inset 0 0 0 2px var(--accent); }
.ghost {
  position: fixed; left: 0; top: 0; z-index: 90; pointer-events: none;
  background: var(--accent); color: var(--accent-ink);
  padding: 7px 11px; border-radius: 7px; font-size: 13px; font-weight: 600;
  max-width: 62vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  box-shadow: 0 8px 22px rgba(0,0,0,.55);
}

/* terminal area */
.term { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.tabs {
  flex: 0 0 auto; display: flex; overflow-x: auto; overflow-y: hidden;
  background: var(--panel); border-bottom: 1px solid var(--line);
  scrollbar-width: thin;
}
.tab { flex: 0 0 auto; display: flex; align-items: center; border-right: 1px solid var(--line); }
.tab-btn { display: flex; align-items: center; gap: 7px; height: 44px; padding: 0 4px 0 12px; color: var(--dim); max-width: 190px; }
.tab-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab.active { background: var(--panel2); }
.tab.active .tab-btn { color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.tab-x { width: 36px; height: 44px; color: var(--dim); font-size: 19px; line-height: 1; }
.tab-x:hover { color: var(--text); background: var(--panel3); }

.frames { flex: 1 1 auto; position: relative; min-height: 0; background: #000; }
.term-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; background: #000; }
.frames .empty { position: absolute; inset: 0; display: grid; place-items: center; }

/* menu */
.menu {
  position: fixed; z-index: 80; min-width: 194px; max-width: 78vw;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 9px;
  padding: 5px; box-shadow: 0 10px 28px rgba(0,0,0,.6);
}
.menu-item { display: block; width: 100%; text-align: left; height: 42px; padding: 0 11px; border-radius: 6px; }
.menu-item:hover:not([disabled]) { background: var(--panel3); }
.menu-item.danger { color: var(--bad); }
.menu-head { padding: 7px 11px 9px; font-size: 12px; color: var(--dim); border-bottom: 1px solid var(--line); margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* modal */
.modal-back {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(3,5,8,.68);
  display: flex; align-items: center; justify-content: center;
  padding: 14px;
}
.modal-card {
  width: min(100%, 460px); max-height: 88dvh; overflow: hidden;
  background: var(--panel); border: 1px solid var(--line); border-radius: 11px;
  padding: 16px; display: flex; flex-direction: column; gap: 13px;
  box-shadow: 0 14px 40px rgba(0,0,0,.6);
}
.modal-title { font-size: 17px; font-weight: 700; }
.modal-body { display: flex; flex-direction: column; gap: 13px; flex: 1 1 auto; min-height: 0; overflow: auto; }
.modal-foot { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.modal-foot .btn { flex: 1 1 auto; min-width: 116px; }
.modal-text { font-size: 14px; color: var(--text); }
.modal-card.busy { opacity: .75; }

.kv { display: flex; gap: 8px; font-size: 13.5px; }
.kv .k { color: var(--dim); flex: 0 0 96px; }
.kv .v { flex: 1 1 auto; word-break: break-all; font-family: var(--mono); font-size: 12.5px; }

.seg { display: flex; gap: 6px; }
.seg-btn { flex: 1 1 0; height: 44px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel2); }
.seg-btn.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }

.tr-list { max-height: 232px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; overscroll-behavior: contain; }
.tr { display: flex; align-items: flex-start; gap: 9px; padding: 9px 10px; min-height: 44px; border-bottom: 1px solid #1d242d; cursor: pointer; }
.tr:last-child { border-bottom: 0; }
.tr.sel { background: var(--accent-bg); }
.tr input { margin: 3px 0 0; width: 17px; height: 17px; accent-color: var(--accent); flex: 0 0 auto; }
.tr-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tr-title { font-size: 13.5px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.tr-age { font-size: 11.5px; color: var(--dim); }

.pick-list { max-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; overscroll-behavior: contain; }
.pick { display: block; width: 100%; text-align: left; min-height: 44px; padding: 0 10px; border-bottom: 1px solid #1d242d; }
.pick:last-child { border-bottom: 0; }
.pick.on { background: var(--accent-bg); box-shadow: inset 2px 0 0 var(--accent); }

/* toasts */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 14px; z-index: 110; display: flex; flex-direction: column; gap: 8px; width: min(94vw, 420px); }
.toast { background: var(--panel3); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 13.5px; box-shadow: 0 8px 24px rgba(0,0,0,.55); }
.toast.bad { border-color: #6b2b2b; color: #ffc4c4; background: #2b1416; }

.stack { display: flex; flex-direction: column; gap: 8px; }

@media (max-width: 760px) {
  .nav-only { display: grid; }
  .sidebar {
    position: absolute; top: 0; left: 0; bottom: 0; z-index: 30;
    width: min(86%, 320px); flex: 0 0 auto;
    transform: translateX(-102%);
    visibility: hidden;
    transition: transform .16s ease, visibility 0s linear .16s;
    box-shadow: 0 0 30px rgba(0,0,0,.6);
  }
  body.nav-open .sidebar {
    transform: translateX(0);
    visibility: visible;
    transition: transform .16s ease;
  }
  .scrim { display: block; position: absolute; inset: 0; z-index: 20; background: rgba(3,5,8,.6); }
  .tab-btn { max-width: 140px; }
  .modal-foot .btn { min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .tw::before { transition: none; }
  .sidebar { transition: visibility 0s; }
}
