:root {
  color-scheme: light;
  --bg: #ebe4d8;
  --bg-raised: #f7f3eb;
  --ink: #1e1a16;
  --muted: #6f675c;
  --line: #ddd4c6;
  --line-strong: #cfc4b2;
  --accent: #c4511a;
  --accent-dark: #9a3d12;
  --pine: #1d6b48;
  --pine-soft: #e6f3ec;
  --wine: #8d2e2e;
  --wine-soft: #f8e7e3;
  --amber-soft: #f8efd8;
  --shadow: 0 16px 40px rgba(55, 38, 18, 0.08);
  --sans: "Microsoft JhengHei UI", "PingFang TC", "Noto Sans CJK TC", "Segoe UI", sans-serif;
  --mono: "Cascadia Mono", "Sarasa Mono TC", Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  background:
    radial-gradient(900px 320px at 0% -10%, rgba(196, 81, 26, 0.12), transparent 55%),
    var(--bg);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, p { margin: 0; }
.is-hidden { display: none !important; }

.layout { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  gap: 22px;
  min-height: 64px;
  padding: 10px 22px;
  background: rgba(247, 243, 235, 0.92);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.brand strong { display: block; font-size: 15px; letter-spacing: 0.01em; }
.brand span, .version { color: var(--muted); font-size: 12px; }
.mark { width: 32px; height: 32px; flex: none; }
.nav { display: flex; gap: 6px; flex: 1; }
.nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 999px;
}
.nav a.is-active { color: var(--ink); background: #fff; box-shadow: inset 0 0 0 1px var(--line); }
.who { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.who-name { font-weight: 650; }

.main { width: min(1280px, calc(100% - 28px)); margin: 18px auto 28px; flex: 1; }
.workspace {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.panel {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.panel-head, .page-head {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.panel-head { position: sticky; top: 64px; background: var(--bg-raised); z-index: 2; border-radius: 14px 14px 0 0; }
.title-row, .toolbar, .dialog-actions, .leaf-actions { display: flex; align-items: center; gap: 8px; }
.title-row { justify-content: space-between; }
.title-row h1, .page-head h1, .empty-pane h2, .dialog h2 { font-size: 18px; font-weight: 720; letter-spacing: 0.01em; }
.panel-body { padding: 8px 10px 14px; }
.page-block { padding: 16px; }
.hint, .help { color: var(--muted); font-size: 12.5px; }
.lead { color: var(--muted); margin-top: 4px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field span, .check { font-size: 13px; }
input[type="text"], input[type="password"], input[type="number"], input[type="search"], select, textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 8px;
  padding: 8px 10px;
  min-height: 38px;
}
textarea { min-height: 74px; resize: vertical; }
input:disabled, select:disabled { background: #f1ece4; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; margin: 4px 0 12px; }
.check input { width: auto; accent-color: var(--accent); }

.btn {
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 8px;
  min-height: 34px;
  padding: 6px 12px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn:hover { border-color: #b7aa96; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff8f4; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger { background: var(--wine); border-color: var(--wine); color: #fff; }
.btn-ghost { background: transparent; }
.btn-small { min-height: 28px; padding: 3px 8px; font-size: 12.5px; }
.btn[disabled] { opacity: 0.6; cursor: wait; }

.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { margin-left: 16px; padding-left: 12px; border-left: 1px solid var(--line-strong); }
.tree ul > li { position: relative; }
.tree ul > li::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 17px;
  width: 12px;
  border-top: 1px solid var(--line-strong);
}
.node-btn, .zone-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 8px;
  min-height: 34px;
  padding: 4px 6px;
}
.zone-btn:hover, .node-btn:hover { background: rgba(255, 255, 255, 0.8); }
.zone-btn.is-current { background: #fff; box-shadow: inset 0 0 0 1px var(--line-strong); font-weight: 700; }
.node-name { min-width: 0; overflow-wrap: anywhere; }
.node-count, .tag {
  color: var(--muted);
  font-size: 12px;
  background: #efe8dc;
  border-radius: 999px;
  padding: 1px 7px;
  flex: none;
}
.node-count { margin-left: auto; }
.zone-btn .tag { margin-left: 8px; }
.tag-proxy { background: #fde6d8; color: var(--accent-dark); }
.tag-ok { background: var(--pine-soft); color: var(--pine); }
.tag-bad { background: var(--wine-soft); color: var(--wine); }
.chev { width: 16px; height: 16px; flex: none; }
.is-collapsed > .node-btn .chev, .is-collapsed > .leaf-wrap { }
.is-collapsed > ul, .tree-node.is-collapsed > ul { display: none; }
.tree-node.is-collapsed > .node-btn .chev { transform: rotate(-90deg); }
.node-error { color: var(--wine); font-size: 12.5px; margin: 0 8px 8px 28px; }

.leaf { padding: 8px 8px 10px; border-radius: 10px; }
.leaf:hover { background: rgba(255, 255, 255, 0.7); }
.leaf-main {
  display: grid;
  grid-template-columns: minmax(88px, 180px) minmax(0, 1fr) auto;
  gap: 8px 12px;
  align-items: start;
}
.leaf-name { font-weight: 720; overflow-wrap: anywhere; }
.leaf-content { font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; }
.leaf-side { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.meta-line { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 6px; }
.meta-item { display: inline-flex; gap: 6px; align-items: baseline; font-size: 12.5px; }
.meta-label { color: var(--muted); }
.meta-value { overflow-wrap: anywhere; }

.empty, .empty-pane, .banner, .form-status { padding: 14px; }
.empty, .empty-pane { color: var(--muted); }
.empty-pane { min-height: 240px; display: flex; flex-direction: column; gap: 8px; justify-content: center; }
.banner, .form-status.is-error { color: var(--wine); background: var(--wine-soft); border-radius: 8px; }
.form-status.is-ok { color: var(--pine); background: var(--pine-soft); border-radius: 8px; }
.stack { display: flex; flex-direction: column; gap: 2px; }
.auth-card .stack { margin-top: 18px; }
.confirm-copy { margin: 10px 0 16px; }
.version { display: block; margin-top: 16px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 12px; font-weight: 700; }
.mono { font-family: var(--mono); font-size: 12.5px; }

.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: min(440px, 100%);
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px 26px 22px;
}
.auth-card h1 { font-size: 26px; line-height: 1.25; margin: 12px 0 8px; }
.auth-card .btn-primary { width: 100%; margin-top: 6px; min-height: 40px; }

.backdrop { position: fixed; inset: 0; background: rgba(36, 28, 20, 0.46); z-index: 20; }
.dialog {
  position: fixed;
  z-index: 21;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  overflow: auto;
  background: var(--bg-raised);
  border-radius: 16px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 20px 20px 16px;
}
.dialog-actions { justify-content: flex-end; margin-top: 8px; }
.section-label { margin: 8px 0; font-size: 13px; font-weight: 720; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 30; }
.toast {
  background: var(--ink);
  color: #f7f3eb;
  border-radius: 10px;
  padding: 10px 14px;
  max-width: min(360px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}
.toast.is-error { background: var(--wine); }
.fatal { margin: 24px; }

@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; position: static; }
  .panel-head { position: static; }
  .workspace { grid-template-columns: 1fr; }
  .domain-panel { max-height: 360px; overflow: auto; }
  .who { width: 100%; margin-left: 0; }
  .leaf-main { grid-template-columns: 1fr; }
  .leaf-side { justify-content: flex-start; }
  .main { width: min(100% - 16px, 1280px); }
}

@media (prefers-reduced-motion: reduce) {
  .chev { transition: none; }
}
