:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --text: #1b1f24;
  --text-dim: #5c6672;
  --border: #dde1e6;
  --accent: #3b5bdb;
  --accent-text: #ffffff;
  --danger: #c92a2a;
  --code-bg: #f0f2f5;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --panel: #1e2126;
    --panel-2: #24282e;
    --text: #e7e9ec;
    --text-dim: #98a1ad;
    --border: #31363d;
    --accent: #7189ec;
    --accent-text: #10131a;
    --danger: #ff8787;
    --code-bg: #24282e;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
code { font-family: var(--mono); font-size: 0.88em; }

/* ---------------------------------------------------------------- layout */

.shell { display: flex; align-items: flex-start; min-height: 100vh; }

.sidebar {
  width: 280px;
  flex: 0 0 280px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 18px 14px;
  background: var(--panel);
  border-right: 1px solid var(--border);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 20px;
}

.brand { font-weight: 650; letter-spacing: -0.01em; }
.brand-mark { margin-right: 4px; }

.sidebar-label {
  margin: 0 0 6px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.prompt-list { display: flex; flex-direction: column; gap: 2px; }

.prompt-item {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  border-left: 3px solid transparent;
}
.prompt-item:hover { background: var(--panel-2); }
.prompt-item.is-active { background: var(--panel-2); border-left-color: var(--accent); }
.prompt-item-name { display: block; font-weight: 500; }
.prompt-item-meta { display: block; font-size: 11.5px; color: var(--text-dim); }

.sidebar-empty { color: var(--text-dim); font-size: 13.5px; padding: 0 6px; }

.main {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 880px;
  padding: 28px 32px 80px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.main-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.main-head h1 { margin: 0; font-size: 22px; letter-spacing: -0.01em; }
.head-actions { display: flex; align-items: center; gap: 8px; }

.subtle { color: var(--text-dim); margin: 4px 0 0; }
.small { font-size: 13px; }

/* ----------------------------------------------------------------- cards */

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.card-title { margin: 0 0 14px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card-head .card-title { margin-bottom: 14px; }

.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--danger);
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 8%, transparent);
}

/* ---------------------------------------------------------------- fields */

.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 5px; font-weight: 550; font-size: 13.5px; }
.field-note { font-weight: 400; color: var(--text-dim); font-size: 12.5px; margin-left: 6px; }

input[type="text"], textarea {
  width: 100%;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
textarea { font-family: var(--mono); font-size: 13px; line-height: 1.5; resize: vertical; }
input[type="text"]:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.form-actions { display: flex; gap: 10px; margin-top: 16px; }

/* --------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 550;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--text-dim); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); background: transparent; border-color: var(--danger); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg-btn {
  padding: 5px 11px;
  font-family: inherit;
  font-size: 12.5px;
  color: var(--text-dim);
  background: transparent;
  border: 0;
  cursor: pointer;
}
.seg-btn.is-on { background: var(--panel-2); color: var(--text); font-weight: 550; }

/* ---------------------------------------------------- placeholder editor */

.placeholder-fields {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--panel-2);
}
.fields-label { margin: 0 0 10px; font-size: 12px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-dim); }
.pill {
  display: inline-block;
  min-width: 18px;
  padding: 0 6px;
  margin-left: 6px;
  font-size: 11px;
  text-align: center;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
}

.meta-table { width: 100%; border-collapse: collapse; }
.meta-table th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 0 8px 6px 0;
}
.meta-table td { padding: 4px 8px 4px 0; vertical-align: middle; }
.meta-table td:first-child { white-space: nowrap; }
.meta-table .tight { width: 1%; text-align: center; padding-right: 0; }

/* ---------------------------------------------------------------- output */

.output { display: block; }
.output-placeholder { border-style: dashed; }
.raw-body {
  margin: 0;
  padding: 14px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--code-bg);
  border-radius: 8px;
}
.output-tools { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.copy-btn.is-copied { color: var(--accent); border-color: var(--accent); }

.markdown-body > :first-child { margin-top: 0; }
.markdown-body > :last-child { margin-bottom: 0; }
.markdown-body h1, .markdown-body h2, .markdown-body h3 { line-height: 1.3; margin: 1.4em 0 0.5em; }
.markdown-body h1 { font-size: 1.4em; }
.markdown-body h2 { font-size: 1.2em; }
.markdown-body h3 { font-size: 1.05em; }
.markdown-body p, .markdown-body ul, .markdown-body ol { margin: 0 0 0.9em; }
.markdown-body li + li { margin-top: 0.25em; }
.markdown-body code { padding: 1px 5px; background: var(--code-bg); border-radius: 4px; }
.markdown-body pre {
  padding: 12px 14px;
  overflow-x: auto;
  background: var(--code-bg);
  border-radius: 8px;
}
.markdown-body pre code { padding: 0; background: none; }
.markdown-body blockquote {
  margin: 0 0 0.9em;
  padding: 2px 14px;
  border-left: 3px solid var(--border);
  color: var(--text-dim);
}
.markdown-body table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; }
.markdown-body th, .markdown-body td { padding: 6px 10px; border: 1px solid var(--border); }
.markdown-body hr { border: 0; border-top: 1px solid var(--border); margin: 1.4em 0; }
.markdown-body a { color: var(--accent); text-decoration: underline; }

/* --------------------------------------------------------------- history */

.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.history-item { display: block; padding: 9px 11px; border-radius: 8px; border: 1px solid transparent; }
.history-item:hover { background: var(--panel-2); border-color: var(--border); }
.history-when { display: block; font-size: 12px; color: var(--text-dim); }
.history-values { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 3px; }
.chip {
  display: inline-flex;
  gap: 5px;
  align-items: baseline;
  max-width: 100%;
  padding: 1px 8px;
  font-size: 12.5px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.chip code { color: var(--text-dim); }

.value-list { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.value-list dt { color: var(--text-dim); }
.value-list dd { margin: 0; white-space: pre-wrap; word-break: break-word; }

/* ----------------------------------------------------------- empty state */

.empty-state { padding: 60px 0; max-width: 520px; }
.empty-state h1 { margin: 0 0 8px; font-size: 26px; }
.empty-state p { color: var(--text-dim); }
.empty-hint { padding: 12px 14px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.empty-state .btn { margin-top: 14px; }

/* ------------------------------------------------------------ responsive */

@media (max-width: 800px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex: 0 0 auto;
    height: auto;
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .main { padding: 20px 16px 60px; max-width: none; width: 100%; }
}

/* htmx: dim content while a request is in flight */
.htmx-request.value-form { opacity: 0.65; }
