/* webui/public/styles.css ------------------------------------------------- */
/*  Admin UI. Dark by default, with a light variant under [data-theme=light]. */
/* -------------------------------------------------------------------------- */

:root {
  /* --- Dark (default) -------------------------------------------------- */
  --bg: #1e1f22;
  --bg-2: #2b2d31;
  --bg-3: #313338;
  --bg-input: #1e1f22;
  --border: #3f4147;
  --text: #dbdee1;
  --text-muted: #949ba4;
  --text-dim: #80848e;
  --accent: #5865f2;
  --accent-dim: #4752c4;
  --danger: #ed4245;
  --warn: #faa61a;
  --ok: #23a55a;
  --radius: 6px;
  --shadow: 0 2px 10px rgba(0,0,0,0.25);
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  /* ReactFlow tweakables (overridden in light mode) */
  --rf-grid: #3f4147;
  --rf-mini-bg: #1e1f22;
}

/* --- Light theme - opt in via <html data-theme="light"> ---------------- */
html[data-theme="light"] {
  --bg: #f6f7f9;
  --bg-2: #ffffff;
  --bg-3: #eef0f3;
  --bg-input: #ffffff;
  --border: #d6d8db;
  --text: #1f2024;
  --text-muted: #5f6470;
  --text-dim: #80848e;
  --accent: #5865f2;
  --accent-dim: #4752c4;
  --danger: #d83b3e;
  --warn: #c87a00;
  --ok: #1e8f4d;
  --shadow: 0 1px 4px rgba(0,0,0,0.08);
  --rf-grid: #d6d8db;
  --rf-mini-bg: #ffffff;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
code { font-family: var(--mono); background: var(--bg); padding: 1px 5px; border-radius: 3px; font-size: 12px; }
.muted  { color: var(--text-muted); }
.dim    { color: var(--text-dim); }
.small  { font-size: 12px; }

/* topbar */
.topbar { display: flex; align-items: center; padding: 10px 18px; background: var(--bg-2); border-bottom: 1px solid var(--border); gap: 24px; }
.brand { font-weight: 600; }
.topnav { display: flex; gap: 16px; flex: 1; }
.topnav a { color: var(--text-muted); padding: 4px 8px; border-radius: var(--radius); }
.topnav a.active { color: var(--text); background: var(--bg-3); }
.topnav a:hover { color: var(--text); text-decoration: none; }
.user { display: flex; align-items: center; gap: 10px; }

/* Theme toggle — circular icon button, no text. */
.theme-toggle {
  width: 30px; height: 30px;
  padding: 0;
  font-size: 14px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
}

/* main view
 *
 * Normal pages cap at 1100px so prose-heavy content (products list, embed
 * template editor) doesn't stretch awkwardly on big monitors. The flow
 * detail page uses the full viewport — :has() lets us conditionally remove
 * the cap when the route renders a .flow-page child. Falls back to the cap
 * everywhere else.
 */
.view { padding: 24px; max-width: 1100px; margin: 0 auto; }
.view:has(.flow-page) { max-width: none; padding: 16px 24px; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; }
.page-header h2, .page-header h3 { margin: 0; }
.back-link { color: var(--text-muted); }

/* card */
.card { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card h3 { margin: 0 0 12px 0; font-size: 15px; }

/* forms */
label { display: block; margin-bottom: 10px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; margin-right: 12px; }
input[type=text], input[type=number], textarea, select {
  width: 100%; background: var(--bg-input); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 10px; font: inherit;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); outline: none; }
textarea { resize: vertical; font-family: var(--font); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row.tight { grid-template-columns: 1fr 1fr 140px 100px auto; align-items: end; }
.flow-actions-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.flow-actions-row input[type="text"] { flex: 1; min-width: 180px; }
.actions { display: flex; gap: 8px; margin-top: 12px; }
.actions > * + * { margin-left: 0; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px;
       padding: 8px 14px; border-radius: var(--radius); border: 1px solid transparent;
       background: var(--bg-3); color: var(--text); cursor: pointer; font: inherit;
       transition: background 0.1s, border-color 0.1s; }
.btn:hover { background: #3a3d44; }
.btn.primary { background: var(--accent); }
.btn.primary:hover { background: var(--accent-dim); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #c93b3e; }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.ghost.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.ghost.danger:hover { background: rgba(237,66,69,0.1); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* product list */
.product-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.product-tile { padding: 14px; cursor: pointer; }
.product-tile:hover { border-color: var(--accent); }
.product-tile .name { font-weight: 600; font-size: 15px; }
.product-tile .key  { font-family: var(--mono); color: var(--text-muted); font-size: 12px; }
.product-tile .meta { color: var(--text-muted); margin-top: 6px; font-size: 12px; }
.product-color { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }

/* RF + flow list rows */
.row { display: flex; align-items: center; padding: 8px 0; gap: 10px; border-bottom: 1px solid var(--border); }
.row:last-child { border-bottom: none; }
.row .grow { flex: 1; min-width: 0; }
.row code { font-size: 12px; }
.row .pill { font-size: 11px; padding: 2px 7px; border-radius: 10px; background: var(--bg-3); color: var(--text-muted); }
.pill.draft { background: rgba(250,166,26,0.15); color: var(--warn); }
.pill.published { background: rgba(35,165,90,0.15); color: var(--ok); }

/* flow editor */
.flow-header { display: flex; align-items: center; justify-content: space-between; }
.flow-actions { display: flex; gap: 8px; }
.question-list { display: flex; flex-direction: column; gap: 0; }
.question-row { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: var(--radius);
                cursor: pointer; border: 1px solid transparent; }
.question-row:hover { background: var(--bg-3); }
.question-row.selected { background: var(--bg-3); border-color: var(--accent); }
.question-row .idx  { font-family: var(--mono); color: var(--text-muted); width: 28px; text-align: right; }
.question-row .key  { font-family: var(--mono); font-size: 12px; }
.question-row .type { font-size: 11px; color: var(--text-muted); }
.question-row .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.question-row .reorder { display: flex; flex-direction: column; gap: 2px; }
.question-row .reorder button { background: transparent; border: 1px solid var(--border); color: var(--text-muted);
                                width: 18px; height: 18px; border-radius: 3px; cursor: pointer; font-size: 10px; line-height: 1; }
.question-row .reorder button:hover { color: var(--text); border-color: var(--text-muted); }

.q-editor-sub { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.q-editor-sub h4 { margin: 0 0 8px 0; font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

.subrow { display: grid; gap: 8px; padding: 8px; margin-bottom: 8px; border: 1px solid var(--border); border-radius: var(--radius); }
.subrow .form-row { gap: 8px; }
.subrow .actions { margin-top: 0; }

/* validate banner */
.validate-result { padding: 12px 16px; margin-bottom: 16px; border-radius: var(--radius); }
.validate-result.ok    { background: rgba(35,165,90,0.1);   border: 1px solid var(--ok); }
.validate-result.error { background: rgba(237,66,69,0.1);  border: 1px solid var(--danger); }
.validate-result ul { margin: 6px 0 0 18px; padding: 0; }

/* login */
.screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { max-width: 420px; text-align: center; }

/* toast */
.toast { position: fixed; bottom: 24px; right: 24px; max-width: 360px;
         padding: 12px 16px; border-radius: var(--radius);
         background: var(--bg-3); border: 1px solid var(--border);
         box-shadow: var(--shadow); z-index: 100; }
.toast.error { border-color: var(--danger); }
.toast.ok    { border-color: var(--ok); }

/* ===========================================================================
 * Modal dialogs
 * ===========================================================================
 * Stack on top of everything; click-outside closes; ESC closes (handled in JS).
 * Stays usable next to ReactFlow because z-index sits above its UI.
 */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  padding: 24px;
}
.modal {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 560px;
  width: 100%;
  max-height: calc(100vh - 48px);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal.wide { max-width: 720px; }
.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-header h3 { margin: 0; font-size: 15px; }
.modal-close {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 20px; line-height: 1; padding: 4px 8px;
}
.modal-close:hover { color: var(--text); }
.modal-body {
  padding: 18px;
  overflow: auto;
  flex: 1;
}
.modal-body label { display: block; margin-bottom: 10px; }
.modal-body label > input,
.modal-body label > textarea,
.modal-body label > select {
  width: 100%;
  margin-top: 4px;
}
.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
  background: var(--bg-1);
}
.template-list {
  display: flex; flex-direction: column; gap: 6px;
  max-height: 360px; overflow: auto;
}
.template-row {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  cursor: pointer;
  background: var(--bg-3);
  transition: border-color 0.1s;
}
.template-row:hover { border-color: var(--accent); }
.template-row.selected { border-color: var(--accent); background: rgba(88, 101, 242, 0.10); }
.template-row .name { font-weight: 600; }
.template-row .meta { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.template-row .badge {
  display: inline-block; margin-left: 6px;
  font-size: 10px; padding: 1px 6px; border-radius: 8px;
  background: var(--bg-1); color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.template-row .badge.builtin { background: rgba(88, 101, 242, 0.20); color: var(--accent); }
.template-row .badge.user    { background: rgba(35,165,90,0.15);    color: var(--ok); }
.template-row .delete-link {
  float: right;
  font-size: 12px;
  color: var(--danger);
  text-decoration: none;
}
.template-row .delete-link:hover { text-decoration: underline; }
.conflict-info {
  background: rgba(250,166,26,0.10);
  border: 1px solid rgba(250,166,26,0.30);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 14px;
  font-size: 13px;
}

/* ===========================================================================
 * Flow editor — node-graph workspace
 * ===========================================================================
 * Two-pane: graph fills most of the viewport, a fixed-width drawer slides
 * in from the right when a node is selected. The view's max-width cap is
 * disabled for this page via .view:has(.flow-page) above.
 */
.flow-page  .page-header { padding-right: 0; }

.flow-workspace {
  display: flex;
  gap: 12px;
  height: calc(100vh - 240px);
  min-height: 520px;
}
.flow-graph {
  flex: 1;
  min-width: 0;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
}
.flow-side {
  width: 420px;
  flex-shrink: 0;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  overflow-y: auto;
}
.side-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 12px;
}

/* React Flow overrides — themed via CSS vars so light mode just works. */
.react-flow__renderer { background: var(--bg); }
.react-flow__attribution { display: none !important; }
.react-flow__controls { box-shadow: var(--shadow); }
.react-flow__controls button {
  background: var(--bg-3); color: var(--text); border-color: var(--border);
  fill: var(--text);
}
.react-flow__controls button:hover { background: var(--bg-2); }
.react-flow__controls button path { fill: var(--text); }
.react-flow__edge-text { font-family: var(--font); }
.react-flow__edge-textbg { fill: var(--bg); }

/* Question node card. */
.rf-node {
  width: 260px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text);
  overflow: hidden;
  position: relative;
  box-shadow: var(--shadow);
}
.rf-node.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(88,101,242,0.35); }
.rf-node.start    { border-top: 3px solid var(--ok); }
.rf-node-header {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 8px 10px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}
.rf-node-key  { font-family: var(--mono); font-size: 12px; font-weight: 600; color: var(--text); }
.rf-node-type { font-family: var(--mono); font-size: 10px; color: var(--text-muted); text-transform: uppercase; }
.rf-node-label {
  padding: 8px 10px 4px 10px;
  font-size: 12px; line-height: 1.35;
  color: var(--text);
}
.rf-node-badge {
  position: absolute; top: -10px; right: 8px;
  font-size: 10px; font-weight: 700;
  background: var(--ok); color: white;
  padding: 1px 6px; border-radius: 3px;
}
.rf-rows {
  padding: 4px 10px 8px 10px;
  display: flex; flex-direction: column; gap: 3px;
}
.rf-row {
  display: flex; align-items: center; gap: 6px;
  position: relative;
  padding: 3px 0;
  font-size: 11px;
  color: var(--text-muted);
}
.rf-row-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.rf-row-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rf-opt .rf-row-label { color: var(--text); }

.rf-default-dot  { background: var(--text-dim); }
.rf-fallback-dot { background: var(--text-dim); opacity: 0.6; }
.rf-branch-dot   { background: var(--warn); }

/* React Flow handles — pinned to the right edge of each row, big enough to grab. */
.rf-handle.rf-handle-in {
  background: var(--bg-2);
  width: 8px; height: 12px;
  border: 1px solid var(--text-muted);
  border-radius: 2px;
  left: -5px !important;
}
.rf-handle {
  width: 10px; height: 10px;
  border: 1px solid var(--bg);
  right: -5px !important;
}
.rf-handle-default  { background: var(--text-dim); }
.rf-handle-fallback { background: var(--text-dim); opacity: 0.7; }
.rf-handle-branch   { background: var(--warn); }
/* Option handles inherit their colour from inline style (set per question). */


/* ---------------------------------------------------------------------------
 * Guild selector (topbar). Hidden via .hidden when only one guild is configured.
 * --------------------------------------------------------------------------- */
.guild-selector {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-right: 6px;
}
.guild-selector-label {
  font-size: 12px;
  color: var(--text-muted);
}
#guild-selector-select {
  font-size: 13px;
  padding: 4px 8px;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  min-width: 140px;
  max-width: 220px;
}

/* ---------------------------------------------------------------------------
 * Admins page
 * --------------------------------------------------------------------------- */
.admin-row {
  align-items: center;
  gap: 10px;
}
.admin-row code {
  font-size: 12px;
}
.admin-row .pill.env {
  background: rgba(250,166,26,0.15);
  color: var(--warn);
}
.admin-row-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
