:root {
  color-scheme: dark;
  --bg: #0f1117;
  --top: #181b22;
  --side: #141821;
  --panel: #1b2029;
  --panel-2: #11151c;
  --line: #2a313d;
  --line-soft: #202733;
  --text: #e7edf4;
  --muted: #93a0af;
  --accent: #2d8cff;
  --accent-2: #1f6fca;
  --good: #1f9d67;
  --bad: #d94d4d;
  --warn: #d6a243;
  --shadow: 0 24px 70px rgba(0, 0, 0, .35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #202632;
  color: var(--text);
  cursor: pointer;
  padding: 0 11px;
}

button:hover {
  border-color: var(--accent);
  background: #253044;
}

button:disabled {
  cursor: not-allowed;
  opacity: .48;
}

input,
textarea,
select {
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #0d1016;
  color: var(--text);
  outline: none;
}

input,
select {
  height: 34px;
  padding: 0 10px;
}

textarea {
  width: 100%;
  min-height: 0;
  resize: none;
  padding: 14px;
  line-height: 1.55;
  font: 13px/1.55 "Cascadia Code", Consolas, "SFMono-Regular", monospace;
}

.hidden {
  display: none !important;
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
}

.login-box {
  display: grid;
  gap: 16px;
  width: min(410px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 28px;
  box-shadow: var(--shadow);
}

.login-box h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: 0;
}

.brand-kicker {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .12em;
}

.login-box label {
  display: grid;
  gap: 7px;
  color: var(--muted);
}

.full {
  width: 100%;
}

.primary {
  border-color: var(--accent-2);
  background: var(--accent-2);
}

.success {
  border-color: var(--good);
  background: var(--good);
}

.warn {
  border-color: var(--warn);
  background: #8f6a1f;
}

.danger {
  border-color: var(--bad);
  background: var(--bad);
}

.ghost {
  background: transparent;
}

.message {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
}

.app {
  position: relative;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  height: 100vh;
  min-height: 0;
}

.operation-bar {
  grid-row: 2;
  display: grid;
  grid-template-columns: minmax(120px, 240px) minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 32px;
  border-bottom: 1px solid var(--line);
  background: #10151e;
  padding: 6px 14px;
  color: var(--muted);
  font-size: 12px;
}

.operation-track,
.inline-progress {
  position: relative;
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: #0a0d12;
}

.operation-track span,
.inline-progress span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width .18s ease, background .18s ease;
}

.operation-bar.indeterminate .operation-track span,
.inline-progress span {
  width: 42%;
  animation: progress-slide 1.1s ease-in-out infinite;
}

.operation-bar.done .operation-track span {
  background: var(--good);
}

.operation-bar.error .operation-track span {
  background: var(--bad);
}

@keyframes progress-slide {
  0% {
    transform: translateX(-110%);
  }
  100% {
    transform: translateX(260%);
  }
}

.topbar {
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 48px;
  border-bottom: 1px solid var(--line);
  background: var(--top);
  padding: 0 14px;
}

.brand {
  display: flex;
  flex: 1 1 260px;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 6px;
  background: var(--accent-2);
  font-weight: 800;
}

.brand div {
  display: grid;
  min-width: 0;
}

#workspacePath {
  max-width: 52vw;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-actions,
.button-row,
.icon-row,
.drawer-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-actions {
  flex: 1 1 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 280px;
}

.serve-picker {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.serve-picker select {
  width: clamp(140px, 18vw, 260px);
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.status.running {
  border-color: rgba(31, 157, 103, .55);
  color: #86efac;
}

.status.stopped {
  border-color: rgba(217, 77, 77, .45);
  color: #f3a3a3;
}

.status.busy {
  border-color: rgba(214, 162, 67, .62);
  color: #f8d889;
}

.status.failed {
  border-color: rgba(217, 77, 77, .72);
  color: #ffc2c2;
}

.workbench {
  grid-row: 3;
  display: grid;
  grid-template-columns: var(--sidebar-width, 310px) 6px minmax(0, 1fr);
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: var(--side);
}

.sidebar-resizer {
  width: 6px;
  min-width: 6px;
  border-right: 1px solid var(--line);
  background: #0d1016;
  cursor: col-resize;
}

.sidebar-resizer:hover,
.sidebar-resizer.resizing {
  background: var(--accent-2);
}

.sidebar-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--line-soft);
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.icon-row {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
}

.icon-row button {
  height: 26px;
  padding: 0 7px;
  font-size: 11px;
  letter-spacing: 0;
  text-transform: none;
}

.tree {
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  overflow-x: auto;
  padding: 6px 0 18px;
  scrollbar-gutter: stable;
  scrollbar-color: #4b586b #10141b;
  scrollbar-width: thin;
}

.tree::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.tree::-webkit-scrollbar-track {
  background: #10141b;
}

.tree::-webkit-scrollbar-thumb {
  border: 2px solid #10141b;
  border-radius: 999px;
  background: #4b586b;
}

.tree-row {
  display: grid;
  grid-template-columns: 18px 22px minmax(0, 1fr) 28px;
  align-items: center;
  height: 28px;
  gap: 2px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  padding: 0 6px;
  text-align: left;
  width: 100%;
  min-width: 0;
}

.tree-row:hover,
.tree-row.drag-over {
  background: #202838;
}

.tree-row.selected {
  background: #263a59;
}

.twisty {
  color: var(--muted);
  text-align: center;
}

.file-icon {
  color: var(--muted);
  font-size: 12px;
}

.file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.more {
  justify-self: end;
  visibility: visible;
  color: var(--muted);
  opacity: .45;
}

.tree-row:hover .more,
.tree-row.selected .more,
.more:hover {
  opacity: 1;
}

.children {
  margin: 0;
}

.editor-area {
  display: grid;
  grid-template-rows: 48px minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  padding: 0 12px;
}

.editor-toolbar > div:first-child {
  min-width: 0;
}

.editor-toolbar .button-row {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.save-state {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.save-state.dirty,
.save-state.saving {
  color: #f8d889;
}

.save-state.error {
  color: #ffc2c2;
}

#editorTitle,
#editorMeta {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#editorMeta {
  color: var(--muted);
  font-size: 12px;
}

#editor {
  border: 0;
  border-radius: 0;
  background: #0f131b;
}

.drawer {
  position: fixed;
  top: 48px;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-rows: 44px 1fr;
  width: min(720px, 92vw);
  border-left: 1px solid var(--line);
  background: #0b0e13;
  box-shadow: var(--shadow);
  transform: translateX(105%);
  transition: transform .18s ease;
  z-index: 20;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  padding: 0 10px;
}

.tabs {
  display: flex;
  gap: 4px;
}

.tabs button.active {
  border-color: var(--accent);
  background: #263a59;
}

.drawer-pane {
  display: none;
  min-height: 0;
}

.drawer-pane.active {
  display: grid;
  grid-template-rows: 42px 1fr;
  min-height: 0;
}

.drawer-tools {
  border-bottom: 1px solid var(--line);
  padding: 0 10px;
  color: var(--muted);
  font-size: 12px;
}

.drawer-tools input {
  width: min(260px, 45vw);
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.terminal-output {
  min-height: 0;
  margin: 0;
  overflow: auto;
  background: #05070a;
  color: #dce8f6;
  font: 13px/1.45 "Cascadia Code", Consolas, "SFMono-Regular", monospace;
  outline: none;
}

.terminal-output .xterm {
  height: 100%;
  padding: 10px;
}

.terminal-output .xterm-viewport {
  overflow-y: auto;
}

.logs-output {
  padding: 12px;
  white-space: pre-wrap;
}

.logs-output mark {
  background: var(--warn);
  color: #101318;
}

.context-menu {
  position: fixed;
  z-index: 40;
  min-width: 180px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #1d2430;
  padding: 5px;
  box-shadow: var(--shadow);
}

.context-menu button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
}

.context-menu button:hover {
  background: #2b3546;
}

.modal {
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
}

.modal::backdrop {
  background: rgba(0, 0, 0, .55);
}

.modal-box {
  display: grid;
  gap: 14px;
  width: min(720px, 94vw);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
  box-shadow: var(--shadow);
}

.modal-box header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-box h2 {
  margin: 0;
  font-size: 18px;
}

.modal-grid {
  display: grid;
  grid-template-columns: 1fr 180px 160px;
  gap: 10px;
}

.modal-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.password-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.wrap {
  flex-wrap: wrap;
}

.modal-output {
  max-height: 280px;
  min-height: 120px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #090c11;
  padding: 10px;
  white-space: pre-wrap;
}

.inline-progress {
  width: 100%;
}

.inline-progress span {
  background: var(--accent);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  max-width: min(420px, calc(100vw - 36px));
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #202838;
  color: var(--text);
  padding: 10px 12px;
  box-shadow: var(--shadow);
}

@media (max-width: 860px) {
  body {
    overflow: auto;
  }

  .app {
    min-height: 100vh;
    height: auto;
  }

  .topbar,
  .top-actions {
    align-items: stretch;
    flex-direction: column;
    height: auto;
  }

  .topbar {
    padding: 10px;
  }

  .top-actions {
    width: 100%;
  }

  .top-actions button,
  .status {
    justify-content: center;
    width: 100%;
  }

  .workbench {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .sidebar-resizer {
    display: none;
  }

  .sidebar {
    min-height: 360px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .editor-area {
    min-height: 720px;
  }

  .modal-grid {
    grid-template-columns: 1fr;
  }
}
