:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --border: #e3e6ea;
  --text: #1f2733;
  --muted: #6b7480;
  --primary: #2f6fed;
  --primary-d: #2356c4;
  --danger: #d23b3b;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }
.topbar .right { display: flex; gap: 10px; align-items: center; }
.container { max-width: 1200px; margin: 24px auto; padding: 0 20px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 20px; margin-bottom: 16px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  padding: 7px 14px; border-radius: 8px; font-size: 14px; text-decoration: none;
}
.btn:hover { background: #f0f2f5; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-d); }
.btn-danger { color: var(--danger); border-color: #f1c9c9; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
input[type=text], input[type=email], input[type=password] {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.table-scroll { overflow-x: auto; }
.table-scroll table { width: auto; min-width: 100%; }
.table-scroll th, .table-scroll td { white-space: nowrap; }
.table-scroll th:last-child, .table-scroll td:last-child { position: sticky; right: 0; background: var(--card); box-shadow: -6px 0 8px -8px rgba(0,0,0,.18); }
.muted { color: var(--muted); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.msg { padding: 10px 14px; border-radius: 8px; margin: 12px 0; font-size: 14px; }
.msg-err { background: #fdecec; color: var(--danger); }
.msg-ok { background: #e7f6ec; color: #1d7a3e; }
.center-box { max-width: 380px; margin: 8vh auto; }
.fill-wrap { max-width: 760px; margin: 24px auto; padding: 0 16px; }
.full-height { position: absolute; top: 49px; left: 0; right: 0; bottom: 0; }
.rename { cursor: pointer; border-bottom: 1px dashed var(--border); }
.rename:hover { color: var(--primary); }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: var(--card); border-radius: 10px; max-width: 680px; width: 92%; max-height: 85vh; overflow: auto; padding: 22px; }
.modal-wide { max-width: 920px; }
.dlg-title { font-size: 17px; font-weight: 600; margin: 0 0 8px; letter-spacing: -.01em; }
.dlg-msg { font-size: 15px; line-height: 1.55; color: var(--text); margin: 0; }
.dlg-msg + input { margin-top: 14px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 22px; }
.dlg-actions .btn { padding: 8px 18px; }
.modal h3 { margin: 0 0 6px; }
.kv { display: grid; grid-template-columns: minmax(120px, 1fr) 2fr; gap: 8px 16px; font-size: 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.dropdown { position: relative; display: inline-block; }
.menu { position: absolute; right: 0; top: calc(100% + 4px); background: var(--card); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.12); min-width: 150px; z-index: 50; padding: 4px; }
.menu button { display: block; width: 100%; text-align: left; padding: 7px 10px; border: none; background: none; font-size: 14px; border-radius: 6px; cursor: pointer; color: var(--text); }
.menu button:hover { background: #f0f2f5; }
.menu button.danger { color: var(--danger); }
.menu label { display: flex; align-items: center; gap: 8px; padding: 6px 10px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.menu label:hover { background: #f0f2f5; border-radius: 6px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin: 22px 0 8px; font-weight: 600; }
.stat { padding: 12px 0; border-bottom: 1px solid var(--border); }
.stat:last-child { border-bottom: none; }
.stat-q { font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.stat-num b { font-size: 20px; }
.stat-meta { color: var(--muted); font-size: 13px; }
.dist-row { display: grid; grid-template-columns: minmax(80px,1fr) 140px 34px; gap: 10px; align-items: center; font-size: 13px; margin: 4px 0; }
.dist-bar { background: #eef0f3; border-radius: 4px; height: 14px; overflow: hidden; }
.dist-bar > span { display: block; height: 100%; background: var(--primary); }
.dist-n { text-align: right; color: var(--muted); }
.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px 18px; }
.chk { display: flex; align-items: center; gap: 8px; margin: 5px 0 0; color: var(--text); font-size: 14px; cursor: pointer; }
.chk input { width: auto; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.row-between > div { display: flex; gap: 6px; flex-wrap: wrap; }
.editor-split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .editor-split { grid-template-columns: 1fr; } }
#jsonEditor { width: 100%; min-height: 360px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.5; resize: vertical; background: #fbfcfd; color: var(--text); }
.preview-pane { border: 1px solid var(--border); border-radius: 8px; padding: 14px; background: #fff; min-height: 360px; max-height: 72vh; overflow: auto; }
.preview-label { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
.app-footer { max-width: 1200px; margin: 32px auto 24px; padding: 16px 20px 0; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; line-height: 1.6; }
.app-footer a { color: var(--muted); text-decoration: underline; }
.app-footer a:hover { color: var(--primary); }
.license-pre { white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; line-height: 1.5; color: var(--text); background: #fbfcfd; border: 1px solid var(--border); border-radius: 8px; padding: 14px; margin: 0; }
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.app-shell .container { flex: 1 0 auto; }
.app-shell .app-footer { flex-shrink: 0; }

/* ── Przełącznik motywu (w górnym toolbarze) ───────────────── */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0; border-radius: 8px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  cursor: pointer; transition: background .15s ease;
}
.theme-toggle:hover { background: #f0f2f5; }
.theme-toggle svg { display: block; }
/* fallback dla stron bez toolbara (fill.html) — prawy górny róg */
.theme-toggle-floating { position: fixed; top: 12px; right: 16px; z-index: 200; box-shadow: 0 2px 8px rgba(0,0,0,.15); }

/* ── Dark mode ──────────────────────────────────────────────── */
html[data-theme="dark"] {
  --bg: #0f141a;
  --card: #1a212b;
  --border: #2b3441;
  --text: #e6e9ee;
  --muted: #9aa3af;
  --primary: #4d8bf5;
  --primary-d: #6fa2f7;
  --danger: #f0707a;
  color-scheme: dark;
  /* SurveyJS v2 (survey-core) — render formularzy w ciemnym */
  --sjs-general-backcolor: #1a212b;
  --sjs-general-backcolor-dim: #0f141a;
  --sjs-general-backcolor-dim-light: #1a212b;
  --sjs-general-backcolor-dark: #141a21;
  --sjs-general-forecolor: #e6e9ee;
  --sjs-general-forecolor-light: #9aa3af;
  --sjs-general-dim-forecolor: #e6e9ee;
  --sjs-general-dim-forecolor-light: #9aa3af;
  --sjs-primary-backcolor: #4d8bf5;
  --sjs-primary-backcolor-light: rgba(77,139,245,.12);
  --sjs-primary-backcolor-dark: #6fa2f7;
  --sjs-primary-forecolor: #ffffff;
  --sjs-border-default: #2b3441;
  --sjs-border-light: #232c38;
  --sjs-question-background: #1a212b;
  --sjs-editorpanel-backcolor: #141a21;
  --sjs-editorpanel-hovercolor: #232c38;
  --sjs-shadow-small: 0 1px 2px rgba(0,0,0,.4);
  --sjs-shadow-inner: inset 0 1px 2px rgba(0,0,0,.4);
}
html[data-theme="dark"] .btn:hover,
html[data-theme="dark"] .theme-toggle:hover { background: #232c38; }
html[data-theme="dark"] .menu button:hover,
html[data-theme="dark"] .menu label:hover { background: #232c38; }
html[data-theme="dark"] .btn-danger { border-color: #5a2f2f; }
html[data-theme="dark"] .msg-err { background: #361d20; color: #f1a5a5; }
html[data-theme="dark"] .msg-ok { background: #15301f; color: #6fd49a; }
html[data-theme="dark"] .dist-bar { background: #232c38; }
html[data-theme="dark"] input[type=text],
html[data-theme="dark"] input[type=email],
html[data-theme="dark"] input[type=password],
html[data-theme="dark"] #jsonEditor,
html[data-theme="dark"] .preview-pane,
html[data-theme="dark"] .license-pre { background: #141a21; color: var(--text); }
