:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --sidebar: #1e2a32;
  --sidebar-2: #26343d;
  --text: #1a242b;
  --muted: #6b7a85;
  --line: #e4e9ed;
  --accent: #20a53a;
  --accent-hover: #189433;
  --danger: #d93025;
  --warn: #c47d00;
  --info: #1a73e8;
  --shadow: 0 10px 30px rgba(30, 42, 50, 0.08);
  --radius: 10px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }
html {
  height: 100%;
  width: 100%;
  overflow-x: hidden;
}
html, body { margin: 0; }
body {
  min-height: 100%;
  min-height: 100dvh;
  width: 100%;
  overflow-x: hidden;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 500px at 10% -10%, #d9efe0 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, #dce7ef 0%, transparent 50%),
    var(--bg);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

.app {
  display: grid;
  grid-template-columns: 220px 1fr;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
  color: #edf2f5;
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand { display: flex; gap: 12px; align-items: center; padding: 0 8px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  object-fit: contain; display: block; flex-shrink: 0;
}
.brand-name { font-weight: 700; letter-spacing: .02em; }
.brand-sub { font-size: 12px; color: #9aadb8; margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 6px; }
.nav-item {
  border: 0; background: transparent; color: #c5d2da;
  text-align: left; padding: 10px 12px; border-radius: 8px;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: rgba(32,165,58,.22); color: #fff; }

.sidebar-foot { margin-top: auto; padding: 0 8px; display: grid; gap: 8px; }
.meta { font-size: 12px; color: #8ea0ab; }
.badge {
  display: inline-flex; width: fit-content; padding: 4px 8px;
  border-radius: 999px; font-size: 12px; font-weight: 600;
}
.badge.ok { background: rgba(32,165,58,.2); color: #7dff9a; }
.badge.warn { background: rgba(196,125,0,.25); color: #ffd48a; }

.main { padding: 22px 28px 40px; min-width: 0; }
.topbar, .detail-top {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 18px;
}
.topbar h1, .detail-title h1 { margin: 0; font-size: 24px; }
.topbar p { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.topbar-actions, .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.gap { gap: 12px; margin-bottom: 12px; }
.grow { flex: 1; }

.btn {
  border: 1px solid var(--line); background: var(--surface);
  color: var(--text); border-radius: 8px; padding: 8px 14px;
  transition: .15s ease;
}
.btn:hover { border-color: #c9d3da; }
.btn.primary {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600;
}
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #f0c2be; }
.btn.sm { padding: 4px 8px; font-size: 12px; }

.toolbar {
  display: flex; gap: 10px; margin-bottom: 12px; align-items: center;
}
.toolbar input[type="search"],
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  background: #fff;
  outline: none;
}
.toolbar input[type="search"] { max-width: 360px; }
input:focus, select:focus, textarea:focus {
  border-color: #8fd59d;
  box-shadow: 0 0 0 3px rgba(32,165,58,.12);
}

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: auto;
}
.table-wrap.tight { box-shadow: none; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; background: #f8fafb; position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
.empty { text-align: center; color: var(--muted); padding: 36px !important; }
.ops { display: flex; flex-wrap: wrap; gap: 6px; }
.btn.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 7px;
  min-width: 30px;
}
.btn.icon-btn .file-ico {
  width: 16px;
  height: 16px;
  display: block;
}
.btn.icon-btn .file-ico.folder { color: #e8a317; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.file-name,
.file-name-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  min-width: 0;
  text-align: left;
  vertical-align: middle;
}
.file-name-btn {
  border: 0;
  background: transparent;
  padding: 2px 4px;
  margin: -2px -4px;
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font: inherit;
}
.file-name-btn:hover { background: #eef6f0; color: var(--accent); }
.file-name span,
.file-name-btn span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-ico {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}
.file-ico.folder { color: #e8a317; }
.file-ico.file { color: #7a8792; }
.file-ico.code { color: #3b82c4; }
.file-ico.image { color: #8b5cf6; }
.file-ico.zip { color: #b45309; }
.state {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 999px;
}
.state::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.state.started { color: #148a2e; background: #e8f8ec; }
.state.stopped { color: #8a4b00; background: #fff3e0; }
.state.other { color: #445; background: #eef1f4; }

.bindings { color: var(--muted); font-size: 12px; line-height: 1.5; }
.path { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; color: #445866; word-break: break-all; }

.toast {
  position: fixed; right: 24px; top: 24px; z-index: 50;
  background: #1e2a32; color: #fff; padding: 12px 16px;
  border-radius: 10px; box-shadow: var(--shadow); max-width: 420px;
}
.toast.err { background: #8b1e18; }
.toast.ok { background: #146c28; }

dialog {
  border: 0; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 32px));
  box-shadow: 0 24px 60px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(18, 28, 34, .45); }
dialog form { padding: 22px; }
dialog h2 { margin: 0 0 16px; }
.form-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.form-grid label, .stack-form label, .inline-form label, .row label {
  display: grid; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 500;
}
.form-grid .span-2 { grid-column: span 2; }
.check {
  display: flex !important; align-items: center; gap: 8px;
  margin: 12px 0; color: var(--text); font-weight: 500;
}
.check input { width: auto; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.path-pick {
  display: flex; gap: 8px; align-items: stretch;
}
.path-pick input { flex: 1; min-width: 0; }
.path-pick .btn { flex-shrink: 0; white-space: nowrap; }
.field-hint {
  display: block; margin-top: 4px;
  color: var(--muted); font-size: 12px; font-weight: 400;
}
dialog.folder-picker-dialog {
  width: min(720px, calc(100vw - 24px));
  padding: 0;
  border: 1px solid #c5ced6;
  border-radius: 8px;
  box-shadow: 0 16px 48px rgba(20, 30, 40, 0.22);
  overflow: hidden;
}
dialog.folder-picker-dialog::backdrop {
  background: rgba(20, 30, 40, 0.45);
}
.folder-picker-form {
  display: grid;
  gap: 0;
  max-width: none;
}
.folder-picker-head {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fafbfc, #f3f5f7);
}
.folder-picker-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
}
.folder-picker-sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}
.folder-picker-toolbar {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 10px 12px;
  background: #f7f9fa;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.fp-nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  flex-shrink: 0;
}
.fp-nav:hover:not(:disabled) { background: #eef6f0; border-color: #b7dcc0; color: var(--accent); }
.fp-nav:disabled { opacity: 0.4; cursor: default; }
.folder-picker-address {
  position: relative;
  flex: 1;
  min-width: 160px;
  height: 32px;
}
.folder-picker-crumbs {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font-size: 12.5px;
  white-space: nowrap;
  pointer-events: none;
}
.folder-picker-crumbs.is-editing { opacity: 0; }
.folder-picker-crumbs button {
  pointer-events: auto;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: inherit;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.folder-picker-crumbs button:hover { background: #e8f5ec; color: var(--accent); }
.folder-picker-crumbs .sep {
  color: var(--muted);
  user-select: none;
  flex-shrink: 0;
}
.folder-picker-path {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  opacity: 0;
}
.folder-picker-path:focus,
.folder-picker-address.is-editing .folder-picker-path {
  opacity: 1;
  background: #fff;
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 2px rgba(32, 165, 58, 0.18);
}
.folder-picker-cols {
  display: grid;
  grid-template-columns: 1fr 110px;
  gap: 8px;
  padding: 6px 14px;
  border-bottom: 1px solid var(--line);
  background: #fafbfc;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.folder-picker-list {
  background: #fff;
  max-height: min(420px, 52vh);
  overflow: auto;
  min-height: 220px;
  outline: none;
}
.folder-picker-item {
  display: grid;
  grid-template-columns: 1fr 110px;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 7px 14px;
  color: var(--text);
  font-size: 13.5px;
  cursor: default;
  border-bottom: 1px solid #f0f3f5;
  user-select: none;
}
.folder-picker-item:last-child { border-bottom: 0; }
.folder-picker-item:hover { background: #f3faf5; }
.folder-picker-item.is-selected {
  background: #e3f3e8;
  outline: 1px solid #b7dcc0;
  outline-offset: -1px;
}
.folder-picker-item .name {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.folder-picker-item .name span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.folder-picker-item .ico {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: block;
}
.folder-picker-item .ico.folder { color: #e8a317; }
.folder-picker-item .ico.drive { color: #5b8def; }
.folder-picker-item .kind {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.folder-picker-empty {
  padding: 48px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.folder-picker-hint {
  margin: 0;
  padding: 8px 16px;
  border-top: 1px solid var(--line);
  background: #fafbfc;
}
.folder-picker-dialog .dialog-actions {
  margin: 0;
  padding: 12px 16px 14px;
  border-top: 1px solid var(--line);
  background: #fff;
}
.stack-form { display: grid; gap: 12px; max-width: 720px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
.inline-form input, .inline-form select { width: auto; min-width: 120px; }
.inline-form.wrap select { min-width: 280px; }

.detail-title { display: flex; align-items: center; gap: 12px; flex: 1; }
.detail-layout {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 560px;
  overflow: hidden;
}
.detail-tabs {
  display: flex; flex-direction: column; gap: 2px;
  padding: 12px 8px; background: #f7f9fa; border-right: 1px solid var(--line);
}
.tab {
  border: 0; background: transparent; text-align: left;
  padding: 10px 12px; border-radius: 8px; color: #4d5e6a;
}
.tab:hover { background: #eef3f5; }
.tab.active { background: #fff; color: var(--accent); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }

.detail-panels { padding: 22px; min-width: 0; }
.panel { display: none; }
.panel.active { display: block; animation: fade .18s ease; }
.panel-head { margin-bottom: 16px; }
.panel-head h2 { margin: 0 0 6px; font-size: 18px; }
.panel-head p { margin: 0; color: var(--muted); font-size: 13px; }
.hint { color: var(--muted); font-size: 13px; }

textarea.code, .code-block {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.5;
}
.code-block {
  background: #152028; color: #d7e2ea; padding: 16px; border-radius: 10px;
  overflow: auto; max-height: 480px; white-space: pre-wrap; word-break: break-word;
}

.rule-list { display: grid; gap: 10px; margin-bottom: 14px; }
.rule-item {
  display: grid; grid-template-columns: 1.2fr 1.4fr 120px auto;
  gap: 8px; align-items: center;
  padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #fafbfc;
}
.rule-item.proxy { grid-template-columns: 1.2fr 1.6fr auto; }

.info-grid {
  display: grid; grid-template-columns: 140px 1fr; gap: 10px 16px;
  font-size: 14px; margin-bottom: 16px;
}
.info-grid .k { color: var(--muted); }

.file-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 8px;
}
.file-crumb {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
  font-size: 13px; color: var(--muted);
}
.file-crumb button {
  border: 0; background: transparent; color: var(--accent); padding: 2px 4px; border-radius: 4px;
}
.file-crumb button:hover { background: #eef6f0; }
.file-crumb .sep { color: #b0bbc3; }
.file-upload-btn { display: inline-flex; align-items: center; margin: 0; }
.file-drop-zone {
  position: relative;
  border: 1px dashed transparent;
  border-radius: 10px;
  transition: border-color .15s, background .15s;
}
.file-drop-zone.dragover {
  border-color: var(--accent);
  background: rgba(20, 120, 70, .06);
}
.file-drop-hint {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 2;
  place-items: center;
  pointer-events: none;
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(255, 255, 255, .72);
  border-radius: 10px;
}
.file-drop-zone.dragover .file-drop-hint { display: grid; }
.file-upload-progress {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 1800;
  width: min(560px, calc(100vw - 32px));
  margin: 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 10px 32px rgba(20, 30, 36, .18);
}
.file-upload-progress[hidden] { display: none !important; }
.file-upload-progress-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 10px; font-size: 14px; font-weight: 600;
}
.file-upload-progress-bar {
  height: 10px; border-radius: 999px; background: #e8eef1; overflow: hidden;
}
.file-upload-progress-bar > div {
  height: 100%; width: 0%;
  background: var(--accent, #20a53a);
  transition: width .12s linear;
}
.file-upload-progress-meta {
  margin: 10px 0 0; font-size: 12px; color: var(--muted);
}
#fileEditDialog { width: min(840px, 94vw); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; }
#fileEditDialog::backdrop { background: rgba(20, 30, 36, .35); }
#fileEditContent { width: 100%; min-height: 320px; }

.auth-gate {
  position: fixed; inset: 0; z-index: 2000;
  display: grid; place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 420px at 20% 0%, #d9efe0 0%, transparent 55%),
    radial-gradient(700px 360px at 100% 10%, #dce7ef 0%, transparent 50%),
    var(--bg);
}
.auth-gate[hidden] { display: none !important; }
.auth-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 28px 26px;
  display: grid;
  gap: 12px;
}
.auth-card h1 { margin: 0; font-size: 22px; }
.auth-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.auth-card input {
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; color: var(--text);
}
.auth-error { color: var(--danger); font-size: 13px; margin: 0; }
.region-buttons { display: grid; gap: 10px; }
.region-buttons .btn { width: 100%; padding: 12px 14px; font-size: 15px; text-align: left; }
.region-buttons .btn .region-meta { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; font-weight: 400; }
#regionGate[hidden] { display: none !important; }
#appShell[hidden] { display: none !important; }

.terminal-toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: end;
  margin-bottom: 10px;
}
.terminal-field {
  display: grid; gap: 4px; font-size: 12px; color: var(--muted);
}
.terminal-field.grow { flex: 1; min-width: 220px; }
.terminal-field input,
.terminal-field select {
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; color: var(--text); background: #fff;
  min-width: 0;
}
.terminal-field input[type="number"] { width: 88px; }
.terminal-quick {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px;
}
.terminal-quick button {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  border-radius: 999px; padding: 4px 10px; font-size: 12px;
}
.terminal-quick button:hover { border-color: var(--accent); color: var(--accent); }
.terminal-panel {
  background: #0f171c;
  border-radius: 12px;
  border: 1px solid #1c2a33;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: min(62vh, 560px);
}
.terminal-output {
  margin: 0; flex: 1; min-height: 320px; max-height: min(58vh, 520px);
  overflow: auto; padding: 14px 16px;
  font-family: Consolas, "Cascadia Mono", ui-monospace, monospace;
  font-size: 13px; line-height: 1.45; color: #d7e2ea;
  white-space: pre-wrap; word-break: break-word;
}
.terminal-output .term-cmd { color: #7dff9a; }
.terminal-output .term-meta { color: #8ea0ab; }
.terminal-output .term-err { color: #ff8f86; }
.terminal-input-row {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-top: 1px solid #24333d;
  background: #132029;
}
.terminal-prompt {
  font-family: Consolas, "Cascadia Mono", monospace;
  color: #7dff9a; font-size: 13px; white-space: nowrap;
}
#terminalCmd {
  flex: 1; min-width: 0;
  border: 0; background: transparent; color: #edf2f5;
  padding: 6px 4px; outline: none;
  font-family: Consolas, "Cascadia Mono", monospace; font-size: 13px;
}
#terminalCmd::placeholder { color: #6b7a85; }

@keyframes fade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; align-items: center; gap: 16px; padding: 12px 14px; }
  .nav { flex-direction: row; }
  .sidebar-foot { margin: 0 0 0 auto; }
  .detail-layout { grid-template-columns: 1fr; }
  .detail-tabs { flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--line); }
  .form-grid { grid-template-columns: 1fr; }
  .rule-item, .rule-item.proxy { grid-template-columns: 1fr; }
}
