:root {
  --ink: #1c2228;
  --muted: #5d6874;
  --faint: #8a939c;
  --line: #dfe3e7;
  --canvas: #f2f4f6;
  --surface: #ffffff;
  --accent: #1f5f8b;
  --accent-ink: #ffffff;
  --accent-soft: #e6eff6;
  --ok: #2e7d4f;
  --ok-soft: #e5f3ea;
  --warn: #9a5a12;
  --warn-soft: #fbf0e1;
  --danger: #b3261e;
  --radius: 8px;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; font-weight: 650; }
h2 { font-size: 15px; font-weight: 650; }
h3 { font-size: 13.5px; font-weight: 650; }
p { margin: 0; }
[hidden] { display: none !important; }

/* --- Układ --- */
.shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.rail { background: var(--ink); color: #d7dde3; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-weight: 650; font-size: 15px; }
.brand svg { flex: none; }
.rail-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 18px 6px; color: #9aa5b0; font-size: 12.5px; }
.rail-head button { background: none; border: 1px solid #3a4550; color: #d7dde3; border-radius: 6px; padding: 3px 9px; font: inherit; cursor: pointer; }
.rail-head button:hover { border-color: #6a7682; color: #fff; }
.sites { list-style: none; margin: 0; padding: 4px 8px; overflow-y: auto; flex: 1; }
.sites a { display: block; padding: 8px 10px; border-radius: 6px; color: #d7dde3; text-decoration: none; }
.sites a:hover { background: #26303a; }
.sites a.current { background: #2c3843; color: #fff; }
.sites .meta { display: flex; gap: 6px; align-items: center; font-size: 12px; color: #8f9aa5; margin-top: 1px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: #6b7782; flex: none; }
.dot.live { background: #58b37f; } .dot.draft { background: #e0a14a; } .dot.off { background: #6b7782; }
.rail-foot { border-top: 1px solid #2c3843; padding: 12px 18px; display: flex; justify-content: space-between; font-size: 12.5px; color: #9aa5b0; }
.rail-foot a { color: #c5ccd3; text-decoration: none; } .rail-foot a:hover { color: #fff; }

.main { min-width: 0; }
.page-head { background: var(--surface); border-bottom: 1px solid var(--line); padding: 20px 28px 0; }
.page-head .row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.page-head .sub { color: var(--muted); margin-top: 4px; display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.tabs { display: flex; gap: 2px; margin-top: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--ink); }
.tabs a.current { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.content { padding: 24px 28px 96px; }

/* --- Elementy --- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.card + .card { margin-top: 16px; }
.card > h2 { margin-bottom: 4px; }
.card > .hint { margin-bottom: 14px; }
.hint { color: var(--muted); font-size: 13px; }
.stack > * + * { margin-top: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--canvas); color: var(--muted); }
.chip.live { background: var(--ok-soft); color: var(--ok); }
.chip.draft { background: var(--warn-soft); color: var(--warn); }
.chip.off { background: #eceef0; color: var(--muted); }

label.field { display: block; }
label.field > span { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
label.field > small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=url], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: #fff; border: 1px solid #c9d0d6; border-radius: 6px; padding: 8px 10px;
}
textarea { resize: vertical; min-height: 72px; }
input::placeholder, textarea::placeholder { color: #a3abb3; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.color-row { display: flex; gap: 8px; align-items: center; }
.color-row input[type=color] { width: 38px; height: 36px; padding: 2px; border: 1px solid #c9d0d6; border-radius: 6px; background: #fff; flex: none; cursor: pointer; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { margin-top: 3px; accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
.check small { display: block; color: var(--muted); font-size: 12.5px; }

button, .btn {
  font: inherit; font-weight: 600; font-size: 13.5px; border-radius: 6px; padding: 8px 14px; cursor: pointer;
  border: 1px solid #c3cad1; background: #fff; color: var(--ink); text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
button:hover, .btn:hover { border-color: #9ba5ae; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.08); }
button.quiet { border-color: transparent; background: transparent; color: var(--accent); padding-left: 6px; padding-right: 6px; }
button:disabled { opacity: .55; cursor: default; }
button:focus-visible, a:focus-visible, .check input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg { display: inline-flex; border: 1px solid #c3cad1; border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 6px 12px; font-weight: 500; }
.seg button + button { border-left: 1px solid #c3cad1; }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 650; }

.alert { border-radius: 6px; padding: 10px 14px; font-size: 13.5px; }
.alert.warn { background: var(--warn-soft); color: #6d3f0b; }
.alert.err { background: #fbe9e8; color: var(--danger); }
.alert.ok { background: var(--ok-soft); color: #1f5a37; }

.copybox { display: flex; gap: 8px; align-items: stretch; }
.copybox code, pre.code { flex: 1; display: block; background: #f6f7f9; border: 1px solid var(--line); border-radius: 6px; padding: 9px 11px; overflow-x: auto; white-space: pre; }
pre.code { margin: 0; font-family: var(--mono); font-size: 12.5px; line-height: 1.55; }

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data td { padding: 9px 10px; border-bottom: 1px solid #eef0f2; vertical-align: top; }
table.data tr.clickable { cursor: pointer; } table.data tr.clickable:hover td { background: #f8f9fa; }
.table-wrap { overflow-x: auto; }
.yes { color: var(--ok); font-weight: 600; } .no { color: var(--faint); }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; color: var(--muted); }

/* --- Konfiguracja + podgląd --- */
.config-layout { display: grid; grid-template-columns: minmax(380px, 1fr) minmax(360px, 1.05fr); gap: 20px; align-items: start; }
.preview-pane { position: sticky; top: 16px; }
.preview-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.preview-frame { background: #e3e6ea; border-radius: var(--radius); padding: 14px; display: flex; justify-content: center; }
.preview-frame iframe { width: 100%; height: 560px; border: 0; border-radius: 6px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.12); transition: width .2s; }
.preview-frame.mobile iframe { width: 375px; height: 640px; }
.lang-tabs { margin-bottom: 12px; }
.cat-texts { border-top: 1px solid var(--line); padding-top: 14px; }

.savebar { position: fixed; left: 260px; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); padding: 12px 28px; display: flex; justify-content: space-between; align-items: center; gap: 12px; z-index: 5; }
.savebar .status { color: var(--muted); }

/* --- Statystyki --- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi b { display: block; font-size: 24px; font-weight: 650; letter-spacing: -.01em; }
.kpi span { color: var(--muted); font-size: 12.5px; }
.chart svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 12.5px; margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.bars .bar { display: grid; grid-template-columns: 120px 1fr 48px; gap: 10px; align-items: center; margin-top: 8px; }
.bars .track { height: 8px; background: #edf0f2; border-radius: 4px; overflow: hidden; }
.bars .fill { height: 100%; background: var(--accent); }

/* --- Okna dialogowe --- */
dialog { border: 0; border-radius: 10px; padding: 0; width: min(480px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); color: var(--ink); }
dialog::backdrop { background: rgba(20, 26, 32, .45); }
dialog form, dialog .dlg { padding: 20px 22px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* --- Logowanie --- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login .card { width: min(380px, 100%); padding: 26px 26px 22px; }
.login .brand { color: var(--ink); padding: 0 0 18px; }

.empty { text-align: center; padding: 64px 24px; color: var(--muted); }
.empty h2 { color: var(--ink); margin-bottom: 6px; font-size: 17px; }
.toast { position: fixed; right: 20px; bottom: 76px; background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 6px; font-size: 13.5px; z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.2); }

@media (max-width: 1100px) {
  .config-layout { grid-template-columns: 1fr; }
  .preview-pane { position: static; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; }
  .sites { max-height: 200px; }
  .savebar { left: 0; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .content, .page-head { padding-left: 16px; padding-right: 16px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Wybór układu banera */
.layout-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.layout-opt { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; padding: 10px; background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius); cursor: pointer; font: inherit; color: inherit; }
.layout-opt:hover { border-color: var(--muted); }
.layout-opt.on { border-color: var(--accent); background: var(--accent-soft); }
.layout-opt:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.layout-opt small { color: var(--muted); font-size: 12px; line-height: 1.35; }
.layout-thumb { position: relative; display: block; width: 100%; aspect-ratio: 16 / 10; margin-bottom: 6px; border-radius: 4px; background: repeating-linear-gradient(#eef1f4 0 6px, #f7f8fa 6px 12px); border: 1px solid var(--line); overflow: hidden; }
.layout-thumb i { position: absolute; background: #fff; border: 1px solid #9aa4ae; border-radius: 2px; }
.layout-thumb.corner i { left: 6%; bottom: 8%; width: 38%; height: 34%; }
.layout-thumb.corner.right i { left: auto; right: 6%; }
.layout-thumb.bar i { left: -1px; right: -1px; bottom: -1px; height: 24%; border-radius: 0; }
.layout-thumb.modal { background: #6b7280; }
.layout-thumb.modal i { left: 27%; top: 22%; width: 46%; height: 56%; }
@media (max-width: 560px) { .layout-pick { grid-template-columns: 1fr; } .layout-thumb { max-width: 160px; } }
