:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-2: #f1f3f8;
  --text: #141824;
  --muted: #5b6475;
  --border: #dfe3eb;
  --accent: #4f46e5;
  --accent-soft: #eceafe;
  --accent-text: #ffffff;
  --code-bg: #f1f3f8;
  --safe-bg: #ecfdf3;
  --safe-text: #14532d;
  --warn-bg: #fff7e6;
  --warn-text: #7a4b00;
  --bad-bg: #fdecec;
  --bad-text: #8a1c1c;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #151b24;
    --surface-2: #1b2330;
    --text: #e6e9ef;
    --muted: #9aa4b5;
    --border: #2a3342;
    --accent: #8b85ff;
    --accent-soft: #24224a;
    --accent-text: #0d1117;
    --code-bg: #0f141c;
    --safe-bg: #0f2a1b;
    --safe-text: #a7f3c4;
    --warn-bg: #2d2210;
    --warn-text: #fcd58a;
    --bad-bg: #2e1414;
    --bad-text: #fca5a5;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }
code { font-family: var(--mono); font-size: 0.9em; }
h1 { font-size: 1.75rem; margin: 0 0 0.4rem; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; margin: 0 0 0.25rem; }
h3 { font-size: 0.95rem; margin: 1rem 0 0.4rem; }
[hidden] { display: none !important; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.hint { font-weight: 400; color: var(--muted); font-size: 0.85rem; margin: 4px 0; }

.top { background: var(--surface); border-bottom: 1px solid var(--border); }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; flex-wrap: wrap; }
.logo { width: 26px; height: 26px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; }
.links { display: flex; gap: 16px; font-size: 0.9rem; }
.links a { text-decoration: none; }

.badge { font-size: 0.75rem; font-weight: 600; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge.warn { background: var(--warn-bg); color: var(--warn-text); }
.badge.safe { background: var(--safe-bg); color: var(--safe-text); }
.badge.bad { background: var(--bad-bg); color: var(--bad-text); }

.intro { padding: 28px 0 8px; max-width: 820px; }

.notice { background: var(--warn-bg); color: var(--warn-text); border-radius: var(--radius); padding: 10px 14px; margin: 12px 0 0; font-size: 0.9rem; }
.notice.safe { background: var(--safe-bg); color: var(--safe-text); }

.keybox { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-top: 12px; }

.tabs { display: flex; gap: 4px; margin: 18px 0 0; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted);
  padding: 10px 14px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; border-radius: 0;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

.subtabs { display: flex; gap: 2px; flex-wrap: wrap; margin: 10px 0 6px; }
.subtabs button { background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0; padding: 6px 10px; color: var(--muted); font-size: 0.85rem; }
.subtabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.subtabs button .count { color: var(--muted); font-weight: 400; margin-left: 4px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-top: 0; border-radius: 0 0 var(--radius) var(--radius); padding: 20px; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.panel-head p { margin: 0; max-width: 760px; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.col { min-width: 0; display: flex; flex-direction: column; }
@media (max-width: 900px) { .grid { grid-template-columns: 1fr; } }

.http-layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 20px; }
@media (max-width: 900px) { .http-layout { grid-template-columns: 1fr; } }
.sidebar { border-right: 1px solid var(--border); padding-right: 16px; min-width: 0; }
@media (max-width: 900px) { .sidebar { border-right: 0; border-bottom: 1px solid var(--border); padding: 0 0 12px; } }
.sidebar select { width: 100%; }
.env-row { margin-top: 16px; }
.tree { list-style: none; padding: 0; margin: 8px 0; font-size: 0.85rem; }
.tree li.col-name { font-weight: 600; margin-top: 8px; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.tree li.req { display: flex; align-items: center; gap: 6px; padding: 3px 6px; border-radius: 6px; cursor: pointer; }
.tree li.req:hover, .tree li.req.on { background: var(--accent-soft); }
.tree .m { font-family: var(--mono); font-size: 0.7rem; font-weight: 700; color: var(--accent); min-width: 42px; }
.tree .x { margin-left: auto; background: none; border: 0; padding: 0 4px; color: var(--muted); font-size: 0.85rem; }

label { font-weight: 600; font-size: 0.85rem; margin: 10px 0 4px; display: block; }
label.inline { display: inline-flex; align-items: center; gap: 8px; margin: 0; }
label.check { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; margin: 6px 12px 6px 0; }
label.check input { width: auto; }
.link-btn { color: var(--accent); cursor: pointer; font-weight: 600; margin: 10px 0 4px; }

textarea, input, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; width: 100%;
}
select { width: auto; max-width: 100%; }
label.inline { max-width: 100%; }
label.inline select { min-width: 0; flex: 0 1 auto; }
input.num { width: 90px; }
textarea.code, input.code, .code { font-family: var(--mono); font-size: 0.85rem; }
textarea { resize: vertical; background: var(--code-bg); }
textarea:focus, input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.row.between { justify-content: space-between; }
.url-row { margin-top: 10px; }
.url-row select { flex: none; }
.url-row input { flex: 1; min-width: 0; }
.name-input { border-color: transparent; background: transparent; font-weight: 600; padding-left: 0; flex: 1; min-width: 160px; }
#http-dest { white-space: normal; }
.name-input:hover { border-color: var(--border); }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 12px; }

button {
  font: inherit; font-weight: 600; border-radius: 8px; padding: 7px 14px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); white-space: nowrap;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button:disabled { opacity: 0.6; cursor: progress; }
.small-btn { padding: 2px 8px; font-size: 0.8rem; }

.kv { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.kv .kv-row { display: grid; grid-template-columns: 22px minmax(0, 1fr) minmax(0, 1.4fr) 30px; gap: 6px; align-items: center; }
.kv .kv-row input[type="checkbox"] { width: auto; }
.kv .kv-row button { padding: 4px 0; font-weight: 400; color: var(--muted); }
.auth-fields { display: grid; grid-template-columns: minmax(120px, max-content) minmax(0, 1fr); gap: 6px 10px; align-items: center; margin-top: 10px; }
.auth-fields label { margin: 0; font-weight: 400; color: var(--muted); }

.status { font-size: 0.85rem; color: var(--muted); }
.status.bad { color: var(--bad-text); }

.result { margin-top: 14px; }
pre.out {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px;
  margin: 0; overflow: auto; max-height: 480px; white-space: pre-wrap; word-break: break-word;
}

.facts { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.chip { background: var(--code-bg); border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; font-size: 0.8rem; }
.chip.yes { background: var(--safe-bg); color: var(--safe-text); border-color: transparent; }
.chip.no { background: var(--bad-bg); color: var(--bad-text); border-color: transparent; }
.chip.warn { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }

.table-wrap { overflow: auto; max-height: 360px; border: 1px solid var(--border); border-radius: 8px; margin: 8px 0; }
table { border-collapse: collapse; width: 100%; font-size: 0.85rem; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--surface); }
td { font-family: var(--mono); font-size: 0.8rem; }

.advice { list-style: none; padding: 0; margin: 0 0 8px; display: flex; flex-direction: column; gap: 6px; }
.advice li { border-radius: 8px; padding: 8px 12px; font-size: 0.9rem; background: var(--code-bg); }
.advice li.warn { background: var(--warn-bg); color: var(--warn-text); }
.advice li.block { background: var(--bad-bg); color: var(--bad-text); }
.advice li.ok { background: var(--safe-bg); color: var(--safe-text); }
.advice .suggest { display: block; font-family: var(--mono); font-size: 0.8rem; margin-top: 2px; }

.pairs { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 8px 0; font-size: 0.85rem; }
.pairs dt { font-weight: 600; color: var(--muted); }
.pairs dd { margin: 0; font-family: var(--mono); font-size: 0.8rem; word-break: break-word; }

.conn-row { margin-bottom: 8px; }
.connstring { background: var(--code-bg); border-radius: 8px; padding: 8px 12px; word-break: break-all; margin-bottom: 4px; }
.manage { background: var(--surface-2); border-radius: var(--radius); padding: 12px 14px; margin: 10px 0; display: flex; flex-direction: column; gap: 8px; }
.manage .row input { flex: 1; min-width: 160px; }
.list { list-style: none; padding: 0; margin: 4px 0; font-size: 0.85rem; display: flex; flex-direction: column; gap: 4px; }
.list li { display: flex; gap: 8px; align-items: center; justify-content: space-between; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; }
.list li .code { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#files-entries li { cursor: pointer; }

.fair { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; margin-top: 12px; font-size: 0.85rem; }

dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 0; width: min(640px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialog { padding: 18px; display: flex; flex-direction: column; gap: 8px; }
.dialog h3 { margin: 0; }

.limits { margin: 28px 0; }
.limits td { font-family: inherit; }

.foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-bottom: 32px; }
