:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2330;
  --muted: #5d6675;
  --border: #d9dde4;
  --border-strong: #b9c0cb;
  --accent: #1f4e8c;
  --accent-soft: #e6eef8;
  --ok: #1d6b3a;
  --ok-soft: #e3f3e8;
  --warn: #8a5a00;
  --warn-soft: #fff4d6;
  --bad: #a3221c;
  --bad-soft: #fde8e6;
  --demo: #6b2fa0;
  --radius: 6px;
  font-size: 15px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
a { color: var(--accent); }
.env-banner {
  background: var(--demo);
  color: #fff;
  padding: 6px 16px;
  font-size: 0.87rem;
  text-align: center;
}
.env-banner-test { background: #b42318; font-size: 0.95rem; letter-spacing: .02em; }
.shell { display: flex; min-height: calc(100vh - 32px); }
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: #17253a;
  color: #cfd8e6;
  padding: 18px 0;
}
.brand { padding: 0 18px 18px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; }
.brand-mark { font-weight: 700; color: #fff; letter-spacing: 0.04em; }
.brand-name { color: #fff; font-weight: 600; }
.brand-stage { font-size: 0.75rem; color: #8fa0b8; width: 100%; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar a {
  display: block;
  padding: 9px 18px;
  color: #cfd8e6;
  text-decoration: none;
  border-left: 3px solid transparent;
}
.sidebar a:hover { background: #20324d; color: #fff; }
.sidebar a[aria-current="page"] { background: #20324d; color: #fff; border-left-color: #6fa3e6; font-weight: 600; }
.sidebar-note { font-size: 0.75rem; color: #8fa0b8; padding: 18px; margin: 0; }
.content { flex: 1; padding: 22px 28px 48px; min-width: 0; }
h1 { font-size: 1.45rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 26px 0 10px; }
h3 { font-size: 1rem; margin: 18px 0 8px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.subtitle { color: var(--muted); margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tabs { display: flex; gap: 4px; margin: 0 0 14px; border-bottom: 1px solid var(--border); }
.tabs a { padding: 7px 12px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.btn {
  display: inline-block;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font: inherit;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #173d70; }
.btn-danger { color: var(--bad); border-color: #e3a19c; }
.btn-danger:hover { background: var(--bad-soft); border-color: var(--bad); }
.btn-small { padding: 3px 9px; font-size: 0.85rem; }
.link-btn { background: none; border: none; color: var(--accent); padding: 0; font: inherit; cursor: pointer; text-decoration: underline; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; }
.filters label { display: flex; flex-direction: column; font-size: 0.8rem; color: var(--muted); gap: 3px; }
input[type=text], input[type=search], input[type=number], input[type=date], select, textarea {
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: #fff;
  color: var(--text);
  max-width: 100%;
}
input.qty { width: 90px; }
textarea { width: 100%; }

table.data { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table.data th, table.data td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.data thead th { background: #eef1f5; font-size: 0.82rem; font-weight: 600; color: #3a4453; position: sticky; top: 0; }
table.data tbody tr:hover { background: #f8fafc; }
table.data tr.sub td { background: #fafbfc; font-size: 0.88rem; }
table.data tr.sub td:first-child { padding-left: 28px; }
table.data tr.row-bad td { background: var(--bad-soft); }
table.data tfoot td { font-weight: 600; background: #f3f5f8; }
.table-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 0.78rem; font-weight: 600; white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-neutral { background: #eceff3; color: #4a5361; }
.badge-pkg { background: var(--accent-soft); color: var(--accent); }

.msg { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 8px; border: 1px solid; }
.msg-success { background: var(--ok-soft); border-color: #a9d8b8; color: var(--ok); }
.msg-info { background: var(--accent-soft); border-color: #b8cde8; color: var(--accent); }
.msg-error { background: var(--bad-soft); border-color: #ecb1ac; color: var(--bad); }
.msg-warning { background: var(--warn-soft); border-color: #ecd28f; color: var(--warn); }

.callout { border-left: 4px solid var(--accent); background: var(--accent-soft); padding: 10px 14px; border-radius: 0 var(--radius) var(--radius) 0; margin: 0 0 14px; }
.callout-bad { border-left-color: var(--bad); background: var(--bad-soft); }
.callout-ok { border-left-color: var(--ok); background: var(--ok-soft); }
.callout-warn { border-left-color: var(--warn); background: var(--warn-soft); }

.stock-split { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.stat { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; background: #fff; }
.stat .label { font-size: 0.8rem; color: var(--muted); }
.stat .value { font-size: 1.4rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: 0.78rem; color: var(--muted); }
.stat-card { border-top: 3px solid #8b96a8; }
.stat-period { border-top: 3px solid var(--accent); }

.bar { height: 10px; background: #e6eaf0; border-radius: 5px; overflow: hidden; min-width: 120px; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.bar.full > span { background: var(--bad); }

form.stacked .field { margin-bottom: 12px; }
form.stacked label { display: block; font-weight: 600; font-size: 0.88rem; margin-bottom: 3px; }
form.stacked .help { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.errorlist { color: var(--bad); margin: 4px 0; padding-left: 18px; font-size: 0.85rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 18px; }
.checkbox-field label { display: inline-flex; gap: 6px; align-items: center; font-weight: 600; }
.pagination { margin-top: 12px; display: flex; gap: 10px; align-items: center; }

@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; padding: 10px 0; }
  .sidebar ul { display: flex; flex-wrap: wrap; }
  .sidebar-note { display: none; }
  .content { padding: 16px; }
}

.sidebar li.nav-sep { border-top: 1px solid #2b3d58; margin-top: 6px; padding-top: 6px; }
.price-table td.label { width: 60%; }


/* --- Etap 3B: plan edycji i layout rezerwowy (rysunek SVG w metrach) --- */
.plan-svg { width: 100%; max-height: 70vh; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.plan-svg .hall { fill: #fafbfc; stroke: #50596a; stroke-width: 0.15; }
.plan-svg .hall.closed-bg { fill: url(#closed-hatch); }
.plan-svg .open { fill: #fafbfc; stroke: #2b6cb0; stroke-width: 0.12; stroke-dasharray: 0.6 0.4; }
.plan-svg .pav { fill: none; stroke: #9aa3b1; stroke-width: 0.08; stroke-dasharray: 0.5 0.5; }
.plan-svg .pav-label { fill: #4b5563; font-weight: 800; text-anchor: end; }
.plan-svg rect.field { stroke: #333; stroke-width: 0.06; }
.plan-svg rect.free { fill: #cdeccf; }
.plan-svg rect.occupied { fill: #f3b8b3; }
.plan-svg rect.closed { fill: #d8d8d8; }
.plan-svg rect.unmapped { fill: #ffffff; stroke-dasharray: 0.3 0.2; }
.plan-svg rect.notready { fill: #fff0c2; }
.plan-svg rect.placement { fill: #e9ddf6; stroke: #6b2fa0; stroke-width: 0.08; fill-opacity: 0.85; }
.plan-svg a:hover rect { stroke: var(--accent); stroke-width: 0.2; }
.plan-svg text { font-family: inherit; text-anchor: middle; dominant-baseline: middle; fill: #1c2330; pointer-events: none; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin: 8px 0 14px; font-size: 0.85rem; }
.legend span::before { content: ""; display: inline-block; width: 14px; height: 14px; margin-right: 5px; vertical-align: -2px; border: 1px solid #333; }
.legend .free::before { background: #cdeccf; } .legend .occupied::before { background: #f3b8b3; }
.legend .closed::before { background: #d8d8d8; } .legend .unmapped::before { background: #fff; border-style: dashed; }
.legend .notready::before { background: #fff0c2; } .legend .placement::before { background: #e9ddf6; border-color: #6b2fa0; }
.inline-form { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 0; }
.inline-form input[type=text] { width: 7em; }
.plan-svg rect.conflict { fill: #f6d3a8; stroke: #a3221c; stroke-dasharray: 0.4 0.2; }
.legend .conflict::before { background: #f6d3a8; border-color: #a3221c; border-style: dashed; }

/* --- Etap 5C: podgląd planu — obszary planu (styl jak w edytorze), zoom/przesuwanie, szczegóły pola --- */
.plan-svg .area polygon { fill: var(--c); fill-opacity: .45; stroke: var(--c); stroke-width: 0.12; }
.plan-svg .area-event_mark polygon { fill-opacity: .12; stroke-dasharray: 1 0.6; stroke-width: 0.2; }
.plan-svg .area-aisle polygon { fill-opacity: .5; stroke: #aaa; }
.plan-svg .area-architecture polygon { fill: url(#closed-hatch); fill-opacity: 1; stroke: #555; }
.plan-svg .area.inactive polygon { fill: #9aa3b1; fill-opacity: .12; stroke: #6b7280; stroke-dasharray: 0.4 0.3; }
.plan-svg .area-label { fill: #5a1e1b; font-weight: 600; }
.plan-svg .area-event_mark .area-label { fill: rgba(40, 80, 170, .6); font-weight: 800; }
.plan-svg .area.inactive .area-label { fill: #6b7280; font-style: italic; font-weight: 400; }
.plan-svg.hide-areas .plan-areas, .plan-svg.hide-inactive .area.inactive { display: none; }
.plan-svg .lod-hidden { display: none; }
.plan-svg rect.field.picked { stroke: var(--accent); stroke-width: 0.3; }
.plan-svg.panning { cursor: grabbing; }
.plan-viewer .plan-svg { touch-action: none; cursor: grab; height: 70vh; }
.plan-toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 6px; }
.plan-toolbar[hidden] { display: none; }
.plan-stage { display: flex; gap: 12px; align-items: flex-start; }
.plan-stage .plan-svg { flex: 1 1 auto; min-width: 0; }
.plan-detail { flex: 0 0 300px; margin: 0; }
.plan-detail[hidden] { display: none; }
.plan-detail h3 { margin: 0 0 2px; }
.plan-detail-list { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 0.85rem; margin: 8px 0; }
.plan-detail-list dt { color: var(--muted, #6b7280); }
.plan-detail-list dd { margin: 0; }
@media (max-width: 900px) { .plan-stage { flex-direction: column; } .plan-detail { flex-basis: auto; width: 100%; } }
tr:target { background: #fff5d6; outline: 2px solid var(--accent); }
.legend .zone::before { background: rgba(141, 85, 36, .45); border-color: #8d5524; }
.legend .zone-off::before { background: rgba(154, 163, 177, .15); border: 1px dashed #6b7280; }

/* --- Etap 4: konto w menu, logowanie, historia --- */
.sidebar-user { margin: 14px 12px 0; padding-top: 10px; border-top: 1px solid rgba(255,255,255,0.15); font-size: 0.85rem; color: #dfe6f0; display: flex; flex-direction: column; gap: 4px; }
.sidebar-user a, .sidebar-logout { color: #cfe0ff; font-size: 0.85rem; text-align: left; }
.login-box { max-width: 380px; margin: 40px auto; }
.changes td { vertical-align: top; }
.changes .before { color: var(--bad); }
.changes .after { color: var(--ok); }
.author-other { background: var(--warn-soft); border-radius: 4px; padding: 0 4px; }
