:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --surface-2: #fafbfd;
  --accent-bg: #eef2ff;
  --border: #e7eaf1;
  --text: #1a202c;
  --muted: #667085;
  --primary: #3b6fe0;
  --primary-dark: #2b53b0;
  --danger: #d8342c;
  --danger-bg: #fdeaea;
  --good: #1a7f37;
  --warn: #9a6700;
  --input-bg: #ffffff;
  --code-bg: #f0f2f7;
  --shadow: 0 1px 3px rgba(16,24,40,0.06);
  --radius: 12px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0f1420;
  --card: #171d2c;
  --surface-2: #1d2436;
  --accent-bg: #202a48;
  --border: #2a3247;
  --text: #e8ebf3;
  --muted: #93a0bd;
  --primary: #6d8dff;
  --primary-dark: #a9bcff;
  --danger: #ff6b6b;
  --danger-bg: #3a1e24;
  --good: #4ade80;
  --warn: #fbbf24;
  --input-bg: #10151f;
  --code-bg: #0d1117;
  --shadow: 0 1px 3px rgba(0,0,0,0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(circle at 1px 1px, var(--border) 1px, transparent 0) 0 0/22px 22px,
    var(--bg);
  color: var(--text);
  transition: background 0.2s ease, color 0.2s ease;
}
:root[data-theme="dark"] body {
  background:
    radial-gradient(circle at 1px 1px, rgba(255,255,255,0.05) 1px, transparent 0) 0 0/22px 22px,
    var(--bg);
}

@keyframes brand-shake {
  0%, 100% { transform: rotate(0deg); }
  20% { transform: rotate(-14deg); }
  40% { transform: rotate(10deg); }
  60% { transform: rotate(-8deg); }
  80% { transform: rotate(6deg); }
}
.brand-icon { display: inline-block; cursor: default; }
.brand-icon:hover { animation: brand-shake 0.5s ease; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}
.status-pill.pill-pulse::before {
  content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--primary-dark); margin-right: 7px; animation: pulse-dot 1.1s ease-in-out infinite;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--card); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand-group { display: flex; align-items: baseline; gap: 10px; }
.brand { font-weight: 700; font-size: 18px; }
.tagline { font-size: 12px; color: var(--muted); font-style: italic; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.theme-toggle {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  width: 34px; height: 34px; border-radius: 9px; cursor: pointer; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center;
}
.tabs { display: flex; gap: 6px; }
.tab-btn {
  border: none; background: transparent; padding: 8px 16px; border-radius: 8px;
  font-size: 14px; cursor: pointer; color: var(--muted); font-weight: 600;
}
.tab-btn.active { background: var(--accent-bg); color: var(--primary-dark); }
main { max-width: 1200px; margin: 0 auto; padding: 24px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .grid { grid-template-columns: 1fr; } }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 22px; margin-bottom: 18px;
}
.card h2 { font-size: 15px; margin: 0 0 14px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.field span { font-weight: 600; color: var(--text); }
.field input, .field select, .field textarea {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
  font-family: inherit; color: var(--text); background: var(--input-bg);
}
.field textarea { font-family: 'SFMono-Regular', Consolas, monospace; font-size: 12.5px; min-height: 70px; resize: vertical; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.hint { font-size: 13px; color: var(--muted); margin: -4px 0 14px; }

.btn {
  border: none; border-radius: 9px; padding: 10px 16px; font-size: 14px; font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--danger-bg); color: var(--danger); }
.btn.large { width: 100%; justify-content: center; padding: 13px; font-size: 15px; margin-bottom: 8px; }
.btn.small { padding: 6px 10px; font-size: 12.5px; }
.hidden { display: none !important; }

.error-msg { background: var(--danger-bg); color: var(--danger); padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-top: 8px; }

.request-block { border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 12px; background: var(--surface-2); }
.request-block .req-header { display: flex; gap: 8px; margin-bottom: 10px; }
.request-block select.method { flex: 0 0 100px; }
.request-block input.url { flex: 1; }
.request-block .req-remove { flex: 0 0 auto; background: none; border: none; color: var(--danger); cursor: pointer; font-size: 13px; }
.req-name { width: 100%; margin-bottom: 8px; }
.headers-body-toggle { display: flex; gap: 14px; font-size: 12.5px; margin-bottom: 8px; }
.headers-body-toggle a { color: var(--primary); cursor: pointer; }

.preset-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.preset-row select { flex: 1; min-width: 140px; padding: 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text); }

.mode-switch { display: flex; gap: 6px; margin-bottom: 16px; background: var(--surface-2); border-radius: 9px; padding: 4px; }
.mode-btn { flex: 1; border: none; background: transparent; padding: 9px; border-radius: 7px; cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--muted); }
.mode-btn.active { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(16,24,40,0.08); }
.mode-panel.hidden { display: none; }

.empty-state { text-align: center; color: var(--muted); padding: 60px 20px; font-size: 14px; }
.empty-emoji { font-size: 32px; margin-bottom: 10px; }

.status-pill { display: inline-block; padding: 5px 14px; border-radius: 999px; font-size: 13px; font-weight: 700; margin-bottom: 16px; }
.status-pill.running { background: var(--accent-bg); color: var(--primary-dark); }
.status-pill.stopped { background: var(--danger-bg); color: var(--danger); }

.live-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.lm { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.lm-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.lm-value { font-size: 18px; font-weight: 700; margin-top: 2px; }

.muted { color: var(--muted); font-size: 13px; }

.history-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.history-table th, .history-table td { text-align: left; padding: 10px; border-bottom: 1px solid var(--border); }
.history-table th { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.history-table a { color: var(--primary); text-decoration: none; font-weight: 600; }

/* ---- tooltips ---- */
.tip-icon {
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--primary); font-size: 13px; cursor: help; margin-left: 4px; position: relative;
  font-style: normal;
}
.tip-icon:hover::after, .tip-icon:focus::after {
  content: attr(data-tip);
  position: absolute; left: 0; top: 140%; width: 260px; z-index: 30;
  background: #1a202c; color: #fff; padding: 10px 12px; border-radius: 8px;
  font-size: 12px; font-weight: 400; line-height: 1.45; box-shadow: 0 6px 18px rgba(0,0,0,0.18);
}

/* ---- misc layout helpers ---- */
.opt { font-weight: 400; color: var(--muted); font-size: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.section-head h2 { margin: 0; }
.link-btn { border: none; background: none; color: var(--primary); font-size: 13px; font-weight: 600; cursor: pointer; }
.small { font-size: 12px; }
.btn.ghost { background: transparent; border: 1px solid var(--danger); }

/* ---- key/value editors (headers, form fields) ---- */
.kv-editor { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.kv-row { display: flex; gap: 6px; align-items: center; }
.kv-row input[type="text"], .kv-row input.kv-key, .kv-row input.kv-value {
  flex: 1; padding: 7px 9px; border: 1px solid var(--border); border-radius: 7px; font-size: 13px;
  background: var(--input-bg); color: var(--text);
}
.kv-row input.kv-key { flex: 0 0 38%; }
.kv-remove { flex: 0 0 auto; background: none; border: none; color: var(--danger); cursor: pointer; font-size: 15px; padding: 2px 6px; }

/* ---- request block extras ---- */
.body-type-switch { display: flex; gap: 6px; margin-bottom: 8px; }
.body-type-btn { border: 1px solid var(--border); background: var(--card); padding: 5px 11px; border-radius: 7px; font-size: 12px; font-weight: 600; cursor: pointer; color: var(--muted); }
.body-type-btn.active { background: var(--accent-bg); color: var(--primary-dark); border-color: var(--primary); }
.body-panel.hidden { display: none; }
.file-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; font-size: 12.5px; }
.file-row .file-status { color: var(--muted); }
.file-row .file-status.ok { color: var(--good); }
.file-row .file-status.err { color: var(--danger); }
.name-preview { font-size: 11.5px; color: var(--muted); margin: -4px 0 8px; }

/* ---- stop-mode / checkbox fields ---- */
.mode-switch.small { padding: 3px; margin-bottom: 10px; }
.mode-switch.small .stop-mode-btn { flex: 1; border: none; background: transparent; padding: 7px; border-radius: 6px; cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.mode-switch.small .stop-mode-btn.active { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(16,24,40,0.08); }
.stop-panel.hidden { display: none; }
.checkbox-field { flex-direction: row; align-items: center; gap: 8px; }
.checkbox-field input[type="checkbox"] { width: 16px; height: 16px; }

/* ---- live tail (recent requests) ---- */
.live-tail { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; font-size: 12.5px; }
.live-tail-row { display: flex; gap: 10px; padding: 6px 10px; border-bottom: 1px solid var(--border); align-items: center; }
.live-tail-row:last-child { border-bottom: none; }
.live-tail-row .dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; }
.live-tail-row .dot.ok { background: var(--good); }
.live-tail-row .dot.fail { background: var(--danger); }
.live-tail-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-tail-row .status { color: var(--muted); flex: 0 0 auto; }
.live-tail-row .lat { color: var(--muted); flex: 0 0 auto; width: 52px; text-align: right; }
.live-tail-empty { padding: 20px; text-align: center; color: var(--muted); }

.download-row { display: flex; gap: 10px; }
.download-row .btn { width: auto; margin-bottom: 0; }
