:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #6b7280;
  --border: #e2e2e2;
  --accent: #2563eb;
  --ok-bg: #ecfdf5;
  --ok-fg: #065f46;
  --err-bg: #fef2f2;
  --err-fg: #991b1b;
  --code-bg: #f5f5f5;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --fg: #e6e6e6;
    --muted: #9aa0a6;
    --border: #33363c;
    --accent: #60a5fa;
    --ok-bg: #06281c;
    --ok-fg: #7fe3b4;
    --err-bg: #2b1414;
    --err-fg: #ff9b9b;
    --code-bg: #1f2126;
  }
}

* { box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--fg);
  margin: 0;
  line-height: 1.5;
}
header {
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}
header h1 { font-size: 1.1rem; margin: 0; }
header h1 a { color: var(--fg); text-decoration: none; }
nav a {
  color: var(--muted);
  text-decoration: none;
  margin-right: 1rem;
  font-size: 0.9rem;
}
nav a:hover { color: var(--accent); }
main { max-width: 960px; margin: 0 auto; padding: 1.5rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; margin-top: 2rem; }
table { width: 100%; border-collapse: collapse; margin: 1rem 0; }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { color: var(--muted); font-weight: 600; }
code { background: var(--code-bg); padding: 0.1rem 0.35rem; border-radius: 4px; font-size: 0.85em; }
textarea {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--code-bg);
  color: var(--fg);
}
input[type="text"], input[type="number"] {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font-size: 0.9rem;
}
button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}
button.secondary { background: var(--muted); }
button:hover { opacity: 0.9; }
form { margin: 0.75rem 0; }
.actions form { display: inline; margin: 0 0.25rem; }
pre.result {
  background: var(--code-bg);
  padding: 1rem;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.8rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.ok, .error {
  padding: 0.6rem 0.9rem;
  border-radius: 6px;
  margin: 0.75rem 0;
  font-size: 0.9rem;
}
.ok { background: var(--ok-bg); color: var(--ok-fg); }
.error { background: var(--err-bg); color: var(--err-fg); }
.muted { color: var(--muted); }
.field { margin-bottom: 0.75rem; }
label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.25rem; }

/* Zakładki (Diagram / JSON) na stronie szczegółów flow */
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tab-btn {
  background: none;
  color: var(--muted);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 0.5rem 0.9rem;
  font-size: 0.9rem;
  cursor: pointer;
}
.tab-btn.active { color: var(--fg); border-bottom-color: var(--accent); }
.tab-btn:hover { opacity: 1; color: var(--fg); }

/* Diagram grafu (SVG generowane po stronie serwera, panel/graph_diagram.py) */
.diagram-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 6px; padding: 0.5rem; }
.diagram-svg .node-group { cursor: pointer; }
.diagram-svg .node-group:hover .node-box { stroke: var(--accent); }
.diagram-svg .node-group.selected .node-box { stroke: var(--accent); stroke-width: 2.5; }
.diagram-svg .node-box { fill: var(--code-bg); stroke: var(--border); stroke-width: 1.5; }
.diagram-svg .node-id { fill: var(--fg); font: 600 12px ui-monospace, monospace; }
.diagram-svg .node-atom { fill: var(--accent); font: 600 12px -apple-system, sans-serif; }
.diagram-svg .node-mode { fill: var(--muted); font: 11px -apple-system, sans-serif; }
.diagram-svg .edge-line { fill: none; stroke: var(--muted); stroke-width: 1.5; }
.diagram-svg .edge-arrow { fill: var(--muted); }
.diagram-svg .edge-label {
  fill: var(--muted);
  font: 10px ui-monospace, monospace;
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 3px;
}

/* Formularz konfiguracji pól wejściowych atomu (po kliknięciu węzła w diagramie) */
.node-form-hint { margin-top: 0.5rem; font-size: 0.8rem; }

.source-description {
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  border-left: 3px solid var(--accent);
  background: var(--code-bg);
  border-radius: 0 6px 6px 0;
}
.source-description label { margin-bottom: 0.35rem; }
.source-description p { margin: 0; font-size: 0.9rem; white-space: pre-wrap; }
.node-form {
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  background: var(--code-bg);
}
.node-form h4 { margin: 0 0 0.75rem; font-size: 0.95rem; }
.node-form-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.node-form-row label { display: inline; color: var(--fg); font-size: 0.85rem; min-width: 140px; margin: 0; }
.node-form-mode { display: flex; gap: 0.75rem; font-size: 0.8rem; color: var(--muted); }
.radio-inline { display: flex; align-items: center; gap: 0.25rem; min-width: 0; color: var(--muted); }
.node-form-literal, .node-form-ref { flex: 1; min-width: 180px; display: flex; gap: 0.5rem; }
.node-form-literal-input { flex: 1; }
.node-form-ref select, .node-form-ref input { flex: 1; }
.node-form textarea.node-form-literal-input {
  width: 100%;
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
}
.node-form-actions { margin-top: 0.75rem; display: flex; gap: 0.5rem; }
