:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273549;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --danger: #f43f5e;
  --ok: #22c55e;
  --warn: #f59e0b;
  --selected: #334155;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
/* Make sure the [hidden] attribute always wins over our display:flex rules. */
[hidden] { display: none !important; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  display: flex; flex-direction: column;
  overflow: hidden;   /* the editor body scrolls internally — never the whole page */
}
button {
  cursor: pointer; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 12px; font: inherit;
}
button:hover { background: var(--border); }
button.primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
button.primary:hover { background: var(--accent); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.danger:hover { filter: brightness(1.1); }
button.ghost { background: transparent; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
input, select, textarea {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 10px; font: inherit;
}
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); }
a { color: var(--accent); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: #0b1220; padding: 1px 5px; border-radius: 4px; }

/* ─── login overlay ─── */
#login-overlay {
  position: fixed; inset: 0; display: flex;
  align-items: center; justify-content: center;
  background: rgba(15, 23, 42, 0.95); z-index: 50;
}
#login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 32px; width: 360px; max-width: 90vw;
  box-shadow: 0 30px 80px rgba(0,0,0,0.4);
}
#login-card h1 { margin: 0 0 8px; font-size: 20px; }
#login-card p { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
#login-card label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; }
#login-card input { width: 100%; }
#login-card button { width: 100%; margin-top: 16px; }
#login-error { color: var(--danger); margin-top: 12px; font-size: 13px; min-height: 1.2em; }

/* ─── app shell ─── */
header.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px; border-bottom: 1px solid var(--border);
  background: var(--panel);
}
header .title { font-weight: 600; }
header .spacer { flex: 1; }
header .user { color: var(--muted); font-size: 13px; }
header .role { font-size: 11px; padding: 2px 6px; border-radius: 4px;
               background: var(--panel-2); color: var(--accent); margin-left: 6px; }
header .role.admin { color: var(--warn); }

main.shell {
  display: flex; flex: 1; min-height: 0;
}

/* ─── left rail: profile list ─── */
aside.rail {
  width: 320px; min-width: 240px;
  border-right: 1px solid var(--border); background: var(--panel);
  display: flex; flex-direction: column;
}
.rail-header {
  padding: 12px; border-bottom: 1px solid var(--border);
  display: flex; gap: 8px; align-items: center;
}
.rail-header input { flex: 1; }
.rail-list { overflow-y: auto; flex: 1; }
.rail-list .item {
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  cursor: pointer; display: flex; flex-direction: column; gap: 3px;
}
.rail-list .item:hover { background: var(--panel-2); }
.rail-list .item.active { background: var(--selected); border-left: 3px solid var(--accent); }
.rail-list .key { font-family: ui-monospace, monospace; font-size: 13px; color: var(--text); word-break: break-all; }
.rail-list .meta { font-size: 11px; color: var(--muted); }
.rail-list .meta .badge {
  display: inline-block; padding: 1px 5px; border-radius: 3px;
  background: var(--panel-2); color: var(--accent); margin-right: 4px;
}
.rail-list .desc {
  font-size: 12px; color: var(--muted); line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; text-overflow: ellipsis;
}
.rail-list .empty { padding: 16px; color: var(--muted); font-size: 13px; text-align: center; }

/* ─── editor ─── */
section.editor {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
}
.editor-header {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  flex-shrink: 0;
}
.editor-header input.key { font-family: ui-monospace, monospace; min-width: 260px; }
.editor-header .owner-tag {
  font-size: 12px; color: var(--muted); padding: 4px 8px;
  border: 1px dashed var(--border); border-radius: 4px;
}
.editor-body {
  flex: 1 1 auto;
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
  min-height: 0;
  overflow-y: auto;   /* scroll the body, keep header + footer visible */
}
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.presets .pill {
  padding: 4px 10px; border-radius: 999px; background: var(--panel-2);
  border: 1px solid var(--border); font-size: 12px;
}
.presets .pill:hover { background: var(--border); }
.presets .pill.active {
  background: var(--accent-strong); border-color: var(--accent-strong); color: #fff;
}
.presets .pill.active:hover { background: var(--accent); }
textarea.json {
  flex: 1 1 auto;
  min-height: 220px;
  background: #0b1220; padding: 12px; font-size: 13px; line-height: 1.45;
}
.editor-footer {
  border-top: 1px solid var(--border); padding: 10px 16px;
  display: flex; gap: 8px; align-items: center;
  flex-shrink: 0;
  background: var(--panel);   /* solid bar so scrolling content can't bleed through */
}
.editor-footer .status { flex: 1; font-size: 13px; }
.editor-footer .status.ok { color: var(--ok); }
.editor-footer .status.err { color: var(--danger); }
.editor-footer .status.muted { color: var(--muted); }

.placeholder {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 14px; text-align: center; padding: 24px;
}

.docs {
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  padding: 14px 16px; font-size: 13px; color: var(--text);
  line-height: 1.55;
}
.docs h4 {
  margin: 0 0 10px; font-size: 13px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600;
}
.docs .field {
  padding: 8px 0; border-top: 1px solid var(--border);
}
.docs .field:first-of-type { border-top: none; padding-top: 0; }
.docs .field-key {
  font-family: ui-monospace, monospace; color: var(--accent);
  font-size: 12.5px; font-weight: 600;
}
.docs .field-type {
  font-family: ui-monospace, monospace; color: var(--muted);
  font-size: 11.5px; margin-left: 8px;
}
.docs .field-desc {
  color: var(--text); margin-top: 4px; font-size: 12.5px; line-height: 1.5;
}
.docs .field-example {
  margin-top: 6px; font-size: 12px; color: var(--muted);
}
.docs .field-example code {
  background: var(--bg); color: var(--accent); padding: 2px 6px;
  border-radius: 3px; font-size: 11.5px;
}
.docs .empty-docs { color: var(--muted); font-size: 12.5px; font-style: italic; }

/* ─── examples panel ─── */
.examples {
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  display: flex; flex-direction: column;
}
.examples .tabs {
  display: flex; gap: 4px; flex-wrap: wrap; align-items: center;
  padding: 8px 8px 0; border-bottom: 1px solid var(--border);
}
.examples .tab {
  padding: 6px 12px; border: 1px solid transparent; border-bottom: none;
  background: transparent; color: var(--muted);
  border-radius: 6px 6px 0 0; font-size: 12.5px; cursor: pointer;
}
.examples .tab:hover { color: var(--text); }
.examples .tab.active {
  color: var(--text); background: #0b1220;
  border-color: var(--border); border-bottom: 1px solid #0b1220;
  margin-bottom: -1px;
}
.examples .tab-spacer { flex: 1; }
.examples .copy-btn {
  margin: 4px 6px; font-size: 12px; padding: 4px 10px;
}
.examples .tip {
  padding: 8px 14px; font-size: 12px;
  background: rgba(56, 189, 248, 0.08); color: var(--accent);
  border-bottom: 1px solid var(--border);
}
.examples .tip:empty { display: none; }
.examples pre {
  margin: 0; padding: 12px 14px; background: #0b1220;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px; line-height: 1.5; color: var(--text);
  border-radius: 0 0 6px 6px;
  overflow-x: auto;
  white-space: pre;
  max-height: 360px; overflow-y: auto;
}
