:root {
  --bg: #0f1220;
  --bg-soft: #171a2b;
  --card: #1c2036;
  --card-2: #232843;
  --line: #2c3257;
  --text: #e8eaf3;
  --muted: #9aa2c0;
  --accent: #6c8cff;
  --accent-2: #4cd6b4;
  --danger: #ff6b7a;
  --ok: #4cd6b4;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #1d2342 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 14px 28px;
  background: rgba(20,23,40,.7);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 50;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand .logo { color: var(--accent); font-size: 22px; }
.nav { display: flex; gap: 6px; margin-left: 12px; }
.nav a { color: var(--muted); padding: 8px 14px; border-radius: 10px; font-weight: 500; }
.nav a:hover { color: var(--text); background: var(--card); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--card-2); }
.userbox { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.uname { color: var(--muted); font-size: 14px; display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.badge { background: var(--accent); color: #fff; border-radius: 6px; padding: 1px 7px; font-size: 11px; }
.badge-view { background: #e6a23c; }
.view-mode-form { margin: 0; display: inline-flex; }
.view-mode-select {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  border-radius: 6px;
  padding: 2px 22px 2px 8px;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  line-height: 1.4;
  cursor: pointer;
  color: #fff;
  background-repeat: no-repeat;
  background-position: right 6px center;
  background-size: 10px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23ffffff' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.view-mode-select.view-mode-admin { background-color: var(--accent); }
.view-mode-select.view-mode-employee { background-color: #e6a23c; }
.view-mode-select:hover { filter: brightness(1.08); }
.view-mode-select:focus { outline: 2px solid rgba(108, 140, 255, 0.45); outline-offset: 1px; }

/* ---------- Impersonation banner ---------- */
.impersonation-banner {
  display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px;
  background: rgba(230,162,60,.15);
  border-bottom: 1px solid rgba(230,162,60,.45);
  font-size: 14px;
}
.impersonation-form { margin: 0; }

/* ---------- Formula docs ---------- */
.formula-block {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  font-family: "Cascadia Code", "Consolas", monospace;
  font-size: 13px;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre-wrap;
  margin: 0 0 16px;
}
.formula-example { margin-bottom: 28px; padding-bottom: 20px; border-bottom: 1px dashed var(--line); }
.formula-example:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.formula-example h3 { font-size: 16px; margin: 0 0 12px; }
.formula-calc { font-family: "Cascadia Code", "Consolas", monospace; font-size: 12px; color: var(--accent-2); }
.formula-params { margin-top: 8px; }
.formula-total td { border-top: 2px solid var(--line); }

/* ---------- Layout ---------- */
.container { max-width: 1100px; margin: 0 auto; padding: 28px; }
.container:has(.calc-grid--quarterly) { max-width: 1280px; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-bottom: 22px; }
.page-head h1 { margin: 0; font-size: 26px; }
.accent, .page-head .accent { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- Cards ---------- */
.card {
  background: linear-gradient(180deg, var(--card) 0%, var(--bg-soft) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  margin-bottom: 22px;
}
.card h2 { margin: 0 0 16px; font-size: 18px; }

/* ---------- Forms ---------- */
label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
input, select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px 12px;
  border-radius: 10px;
  font-size: 15px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(108,140,255,.18); }
.field { margin-bottom: 16px; }
.field-checkbox { margin-bottom: 16px; }
.field-checkbox .checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 0;
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
}
.field-checkbox .checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-width: 18px;
  min-height: 18px;
  margin: 0;
  padding: 0;
  flex-shrink: 0;
  accent-color: var(--accent);
}
.field-checkbox .checkbox-label span {
  line-height: 18px;
}
#banner-options-field .field-checkbox {
  margin-bottom: 12px;
}
#banner-options-field .field-checkbox:last-child {
  margin-bottom: 0;
}
.custom-material-box {
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 16px;
}
.custom-material-box.hidden { display: none !important; }
.custom-material-box .field { margin-bottom: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.brochure-section {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px 6px;
  margin-bottom: 18px;
  background: var(--card-2);
}
.brochure-section > legend {
  padding: 0 8px;
  font-weight: 600;
  font-size: 15px;
}
.brochure-section-note { margin: 0 0 12px; }
.brochure-form-subhead {
  margin: 20px 0 12px;
  font-size: 1rem;
  font-weight: 600;
}

button { cursor: pointer; font-family: inherit; }
.btn-primary {
  background: linear-gradient(180deg, var(--accent), #5577f0);
  color: #fff; border: none; padding: 12px 20px; border-radius: 10px;
  font-size: 15px; font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.07); }
.btn-block { width: 100%; margin-top: 6px; }
.btn-ghost {
  background: transparent; border: 1px solid var(--line); color: var(--text);
  padding: 9px 14px; border-radius: 10px; font-size: 14px;
}
.btn-ghost:hover { background: var(--card-2); text-decoration: none; }
.btn-ghost:disabled { opacity: .4; cursor: not-allowed; }
.btn-danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); padding: 7px 12px; border-radius: 8px; }
.btn-danger:hover { background: rgba(255,107,122,.12); }
.small { font-size: 13px; }
button.small { padding: 5px 10px; font-size: 13px; }

/* ---------- Calculator ---------- */
.calc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; align-items: start; }
.calc-grid--quarterly,
.calc-grid--paper-bags,
.calc-grid--papki {
  grid-template-columns: minmax(0, 1fr) minmax(200px, 260px) minmax(0, 1fr);
}
.quarterly-preview-card {
  position: sticky;
  top: 86px;
  padding: 18px 16px;
}
.quarterly-preview-title {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 600;
}
.quarterly-preview-frame {
  position: relative;
  min-height: 240px;
}
.quarterly-illus { margin: 0; }
.quarterly-illus.hidden { display: none !important; }
.quarterly-illus-caption {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  text-align: center;
  line-height: 1.35;
}
.quarterly-illus-svg {
  display: block;
  width: 100%;
  height: auto;
  color: var(--text);
}
.quarterly-illus-svg .qc-ad-label-box {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.1;
  color: #c8cfe0;
  text-align: center;
  opacity: 0.88;
  pointer-events: none;
}
.quarterly-illus-note {
  margin: 10px 0 0;
  line-height: 1.45;
  text-align: center;
}
@media (max-width: 1100px) {
  .calc-grid--quarterly,
  .calc-grid--paper-bags,
  .calc-grid--papki { grid-template-columns: 1fr 1fr; }
  .quarterly-preview-card,
  .paper-bag-preview-card,
  .papki-preview-card { grid-column: 1 / -1; position: static; }
}
@media (max-width: 720px) {
  .calc-grid,
  .calc-grid--quarterly,
  .calc-grid--paper-bags,
  .calc-grid--papki { grid-template-columns: 1fr; }
}
.papki-illus { margin: 0; }
.papki-illus-svg {
  color: var(--accent);
  opacity: 0.9;
  max-height: 220px;
  width: 100%;
  height: auto;
}
.paper-bag-illus { margin: 0; }
.paper-bag-illus-svg .pb-dim line,
.paper-bag-illus-svg .pb-dim path {
  stroke: var(--accent);
  stroke-opacity: 0.85;
  fill: none;
}
.paper-bag-illus-svg .pb-dim text {
  fill: var(--accent);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 11px;
  font-weight: 600;
}
.calendar-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}
.calendar-nav-item {
  display: inline-flex;
  align-items: center;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}
.calendar-nav-item:hover {
  border-color: var(--accent);
  text-decoration: none;
}
.calendar-nav-item.active {
  border-color: var(--accent);
  background: rgba(108, 140, 255, 0.12);
  color: var(--accent);
}
.options-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.opt-item {
  display: flex; align-items: center; gap: 8px; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px;
  font-size: 15px; cursor: pointer; margin: 0;
}
.opt-item input { width: auto; }
.opt-item input[type="number"] {
  font: inherit;
  color: var(--text);
}
.opt-item.opt-count {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 52px 96px;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  cursor: default;
}
.opt-item .opt-count-input { width: 52px; text-align: center; cursor: text; justify-self: center; }
.opt-item span { color: var(--text); }
.opt-price { margin-left: auto; color: var(--muted); font-size: 12px; }
.opt-item.opt-count .opt-price {
  margin-left: 0;
  width: 96px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.result-card { position: sticky; top: 86px; }
.result-actions { margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--line); }
.result-actions .btn-primary { width: 100%; }
.result-head { display: flex; align-items: center; justify-content: space-between; }
.result-empty { color: var(--muted); padding: 30px 0; text-align: center; }
.res-block { padding: 12px 0; border-bottom: 1px dashed var(--line); }
.res-block:last-child { border-bottom: none; }
.res-block.highlight { background: var(--card-2); margin: 6px -10px; padding: 14px 12px; border-radius: 10px; border: none; }
.res-block.muted-block .res-row span { color: var(--muted); }
.res-row { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; font-size: 14px; }
.res-row span:first-child { color: var(--muted); }
.res-row span:last-child { text-align: right; }
.res-row.section-title span:first-child { color: var(--text); font-weight: 600; }
.res-row.big { font-size: 17px; font-weight: 600; }
.res-row.big span:first-child { color: var(--text); }
.res-row.total span:last-child { color: var(--accent-2); font-size: 20px; }

/* ---------- Tables ---------- */
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); }
.data-table th { color: var(--muted); font-weight: 600; font-size: 13px; }
.data-table input, .data-table select { padding: 7px 9px; max-width: 180px; }
.row-form { margin: 0; }

.inline-form { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; }
.inline-form label { margin: 0; }
.inline-form input { max-width: 150px; }

/* ---------- Admin tiles ---------- */
.admin-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 22px; }
.calc-picker { max-width: 900px; }
.markup-sub { margin: 16px 0 8px; font-size: 14px; color: var(--muted); font-weight: 600; line-height: 1.45; }
.markup-cluster-title { line-height: 1.45; font-weight: 600; }
.add-block { margin-top: 20px; }
.add-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.add-form-grid .field { margin: 0; }
.field-check { display: flex; align-items: flex-end; padding-bottom: 4px; }
.checkbox-row { display: flex; flex-wrap: wrap; gap: 12px 20px; }
.tile {
  display: flex; gap: 14px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; color: var(--text);
}
.tile:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-2px); transition: .15s; }
.tile-ic { font-size: 28px; }
.product-icon {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.product-icon svg { width: 56px; height: 56px; display: block; }
.tile b { display: block; }
.tile span { color: var(--muted); font-size: 13px; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 36px; width: 100%; max-width: 380px; box-shadow: var(--shadow); text-align: center; }
.auth-logo { font-size: 40px; color: var(--accent); }
.auth-card h1 { font-size: 22px; margin: 12px 0 4px; }
.auth-form { text-align: left; margin-top: 20px; }
.auth-form label { margin-bottom: 12px; }
.auth-form .btn-primary { width: 100%; margin-top: 8px; }

/* ---------- Flash ---------- */
.flashes { margin-bottom: 18px; }
.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 8px; font-size: 14px; }
.flash-error { background: rgba(255,107,122,.14); border: 1px solid var(--danger); color: #ffc2c8; }
.flash-ok { background: rgba(76,214,180,.14); border: 1px solid var(--ok); color: #b6f0e2; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal.hidden { display: none !important; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); }
.modal-box { position: relative; width: 100%; max-width: 420px; margin: 0; z-index: 1; }
.modal-box-wide { max-width: 480px; }
.modal-box-wide .result { margin-top: 8px; }
body.modal-open { overflow: hidden; }
.history-table .history-row { cursor: pointer; }
.history-table .history-row:hover { background: var(--card-2); }
.history-table .history-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.modal-box h2 { margin: 0 0 8px; font-size: 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* ---------- Options preview accordion ---------- */
.preview-section { margin-top: 22px; }
.preview-section > h2 { margin-bottom: 8px; font-size: 18px; }
.preview-panel { margin-bottom: 12px; padding: 0; overflow: hidden; }
.preview-panel[open] { border-color: var(--accent); }
.preview-summary {
  list-style: none; cursor: pointer; padding: 18px 22px;
  font-weight: 600; font-size: 16px; user-select: none;
}
.preview-summary::-webkit-details-marker { display: none; }
.preview-summary::before {
  content: "▸"; display: inline-block; margin-right: 10px;
  color: var(--accent); transition: transform .15s;
}
.preview-panel[open] .preview-summary::before { transform: rotate(90deg); }
.preview-body { padding: 0 22px 18px; border-top: 1px dashed var(--line); }
.preview-size { margin-top: 18px; }
.preview-size:first-child { margin-top: 14px; }
.preview-size h3 { margin: 0 0 4px; font-size: 15px; }

@media (max-width: 880px) {
  .calc-grid { grid-template-columns: 1fr; }
  .admin-tiles { grid-template-columns: 1fr; }
  .result-card { position: static; }
  .nav { display: none; }
}
