:root {
  --bg: #f6f5f2;
  --card: #ffffff;
  --ink: #1c1b19;
  --muted: #77736c;
  --line: #e2dfd8;
  --accent: #9a5b2e;
  --accent-ink: #ffffff;
  --ok: #2f7a4d;
  --warn: #a9761b;
  --bad: #a53a2c;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16150f;
    --card: #201e18;
    --ink: #ece7dc;
    --muted: #948d80;
    --line: #322f26;
    --accent: #c98244;
    --accent-ink: #191710;
    --ok: #6bbb87;
    --warn: #d7ab5a;
    --bad: #dd8272;
  }
}

* { box-sizing: border-box; }

/* display у .item и #topbar перебивает атрибут hidden — возвращаем ему силу. */
[hidden] { display: none !important; }

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

main { max-width: 880px; margin: 0 auto; padding: 24px 20px 64px; }

h1, h2, h3 { margin: 0 0 4px; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 24px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }

a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.spacer { flex: 1; }

/* --- шапка --- */
#topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-size: 15px; }
.brand span { color: var(--muted); font-weight: 400; }
#topbar nav { display: flex; gap: 14px; flex-wrap: wrap; }
#topbar nav a {
  color: var(--muted); text-decoration: none; font-size: 14px;
  padding: 4px 0; border-bottom: 2px solid transparent;
}
#topbar nav a:hover { color: var(--ink); }
#topbar nav a.active { color: var(--ink); border-bottom-color: var(--accent); }

/* --- блоки --- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card.narrow { max-width: 380px; margin: 12vh auto; }
.head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.head h2 { margin: 0; }
.list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }

.item {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px;
  display: flex; align-items: center; gap: 12px;
}
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 600; }
.item .sub-line { font-size: 13px; color: var(--muted); margin-top: 2px; }
.item.clickable { cursor: pointer; }
.item.clickable:hover { border-color: var(--accent); }

.empty { color: var(--muted); padding: 20px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }

/* --- формы --- */
label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; }
label.check input { margin: 0; }

input[type=text], input[type=email], input[type=password], input[type=url],
input[type=number], textarea, select {
  display: block; width: 100%; margin-top: 4px;
  padding: 8px 10px;
  font: inherit; font-size: 14px;
  color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
select.inline { width: auto; margin: 0; }

button {
  font: inherit; font-size: 14px; font-weight: 500;
  padding: 8px 14px; border-radius: 8px; border: 1px solid transparent;
  background: var(--accent); color: var(--accent-ink); cursor: pointer;
}
button:hover { filter: brightness(1.08); }
button.secondary { background: transparent; color: var(--ink); border-color: var(--line); }
button.link { background: none; border: none; color: var(--accent); padding: 4px; }
button.danger { color: var(--bad); }
.row { display: flex; gap: 8px; align-items: flex-start; }
.row > input { flex: 1; }

fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 0 0 14px; }
legend { font-size: 13px; color: var(--muted); padding: 0 6px; }

.sub { margin-top: 8px; }
.sub-head { display: flex; align-items: center; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.pair { display: flex; gap: 8px; margin-bottom: 8px; }
.pair input { margin-top: 0; }
.pair .btn-title { flex: 0 0 34%; }
.pair .btn-url { flex: 1; }
.pair button { flex: 0 0 auto; }

pre { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow-x: auto; font-size: 13px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

details.card summary { cursor: pointer; font-weight: 500; }
details.card[open] summary { margin-bottom: 10px; }

/* --- статусы --- */
.badge { font-size: 12px; padding: 2px 8px; border-radius: 20px; border: 1px solid var(--line); white-space: nowrap; }
.badge.ok { color: var(--ok); border-color: currentColor; }
.badge.warn { color: var(--warn); border-color: currentColor; }
.badge.bad { color: var(--bad); border-color: currentColor; }
.badge.off { color: var(--muted); }

/* --- диалог --- */
dialog {
  width: min(680px, 94vw); padding: 0; border: 1px solid var(--line);
  border-radius: 14px; background: var(--card); color: var(--ink);
  max-height: 90vh;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
#scenario-form { display: flex; flex-direction: column; max-height: 90vh; }
.dialog-head, .dialog-foot {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.dialog-foot { border-bottom: none; border-top: 1px solid var(--line); }
.dialog-body { padding: 18px; overflow-y: auto; }

#test-result { margin-top: 10px; font-size: 13px; }
#test-result ul { margin: 6px 0 0; padding-left: 18px; }
#test-result li { margin-bottom: 3px; }

/* --- уведомление --- */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg);
  padding: 10px 18px; border-radius: 8px; font-size: 14px;
  max-width: 90vw; z-index: 20;
}
#toast.bad { background: var(--bad); color: #fff; }
