:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #1e40af;
  --accent2: #2563eb;
  --ok: #059669;
  --err: #dc2626;
  --warn: #d97706;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w, 230px) minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns .2s ease;
}
.sidebar {
  background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
  color: #e2e8f0;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}
.sidebar-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 4px 8px;
}
.sidebar-search {
  padding: 0 10px 10px;
}
.sidebar-search input {
  width: 100%;
  box-sizing: border-box;
  height: 34px;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(15, 23, 42, 0.45);
  color: #e2e8f0;
  padding: 0 10px;
  font-size: 13px;
}
.sidebar-search input::placeholder { color: #94a3b8; }
.sidebar-search input:focus {
  outline: none;
  border-color: #60a5fa;
}
.nav-icon {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  fill: currentColor;
  opacity: 0.95;
}
.nav-label { min-width: 0; }
.nav a, .nav-group-toggle, .nav-feedback-btn {
  justify-content: flex-start;
}
.nav-group-toggle .nav-chevron { margin-left: auto; }
.nav-feedback-btn {
  display: flex;
  align-items: center;
  gap: 8px;
}
html.sidebar-collapsed .sidebar-search { display: none; }
tr.stock-low td { background: rgba(185, 28, 28, 0.06); }
.brand { font-size: 18px; font-weight: 700; color: #fff; padding: 4px 6px 8px; min-width: 0; }
.brand small, .brand-sub { display: block; font-size: 11px; font-weight: 500; color: #94a3b8; margin-top: 4px; }
.sidebar-toggle {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border: 1px solid #334155;
  border-radius: 8px;
  background: rgba(255,255,255,.04);
  color: #cbd5e1;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0;
}
.sidebar-toggle:hover { background: rgba(59,130,246,.2); color: #fff; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a, .nav-group-toggle {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  color: #cbd5e1;
  padding: 10px 12px;
  border-radius: 10px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  border: 0;
  background: transparent;
  width: 100%;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}
.nav a:hover, .nav a.active,
.nav-group-toggle:hover, .nav-group-toggle.active {
  background: rgba(59,130,246,.18);
  color: #fff;
  text-decoration: none;
}
.nav-chevron {
  font-size: 11px;
  opacity: .75;
  transition: transform .15s ease;
}
.nav-group.is-open .nav-chevron { transform: rotate(180deg); }
.nav-sub {
  display: none;
  flex-direction: column;
  gap: 1px;
  padding: 2px 0 6px 8px;
  margin: 0 0 4px;
  border-left: 2px solid #334155;
  margin-left: 10px;
}
.nav-group.is-open .nav-sub {
  display: flex;
}
.nav-sub[hidden] {
  display: none !important;
}
.nav-sub a {
  font-size: 13px;
  font-weight: 550;
  padding: 8px 10px;
  color: #94a3b8;
}
.nav-sub a:hover, .nav-sub a.active {
  color: #fff;
}
.nav-feedback-btn {
  display: block;
  width: 100%;
  text-align: left;
  font-size: 13px;
  font-weight: 550;
  padding: 8px 10px;
  color: #94a3b8;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
}
.nav-feedback-btn:hover { color: #fff; background: #1e293b; }
.feedback-modal {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.55);
  padding: 16px;
}
#feedbackModal[hidden] { display: none !important; }
.feedback-modal-card {
  background: var(--surface, #fff);
  color: var(--text, #0f172a);
  border-radius: 14px;
  padding: 18px;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.feedback-field { display: block; margin: 0; }
.feedback-field textarea,
.feedback-field input[type="file"] {
  width: 100%;
  box-sizing: border-box;
}
.feedback-field textarea {
  min-height: 160px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  resize: vertical;
  background: var(--surface, #fff);
  color: var(--text);
}
.feedback-field input[type="file"] {
  font-size: 13px;
}
.feedback-modal-card .actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin: 0;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}
html[data-theme="dark"] .feedback-modal-card {
  background: #0f1b2d;
  color: var(--text);
}
html[data-theme="dark"] .feedback-field textarea {
  background: #0b1524;
  border-color: var(--border);
  color: var(--text);
}
.sidebar .user {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid #334155;
  font-size: 12px;
  color: #94a3b8;
}
.sidebar .user a, .sidebar .user .theme-toggle { color: #93c5fd; }
.user-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
}
.user-links a,
.user-links .theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 0;
  padding: 0;
  color: #93c5fd;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
}
.user-links .nav-icon { width: 14px; height: 14px; }
.user-name { margin-bottom: 4px; color: #cbd5e1; }
.user-license { font-size: 11px; color: #94a3b8; margin-bottom: 6px; }
.license-banner {
  background: #fff7ed;
  border: 1px solid #fdba74;
  color: #9a3412;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 600;
}
.backup-remind-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #eff6ff;
  border: 1px solid #93c5fd;
  color: #1e3a8a;
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 600;
}
.backup-remind-text { flex: 1 1 220px; line-height: 1.4; }
.backup-remind-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
html[data-theme="dark"] .backup-remind-banner {
  background: #0c1a33;
  border-color: #1e40af;
  color: #bfdbfe;
}

/* Kopia — zwarta zawartość bazy */
.backup-db-details {
  margin: 0;
}
.backup-db-details > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 14px;
  user-select: none;
}
.backup-db-details > summary::-webkit-details-marker { display: none; }
.backup-db-details > summary::before {
  content: '▸';
  color: var(--muted);
  font-size: 12px;
  width: 1em;
}
.backup-db-details[open] > summary::before { content: '▾'; }
.backup-db-details > summary .sub { margin: 0; }
.backup-db-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 6px 10px;
  margin-top: 12px;
}
.backup-db-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface, #fff);
  font-size: 13px;
  line-height: 1.25;
}
.backup-db-name {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.backup-db-count {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  flex-shrink: 0;
}
html[data-theme="dark"] .backup-db-item {
  background: #0f1b2d;
  border-color: #243349;
}
.license-modal {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.55);
  padding: 16px;
}
.license-modal-card {
  background: var(--surface, #fff);
  color: var(--text, #0f172a);
  border-radius: 14px;
  padding: 22px 24px;
  max-width: 460px;
  width: 100%;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.license-modal-card h2 { margin: 0 0 10px; font-size: 18px; }
.license-modal-card p { margin: 0 0 10px; font-size: 14px; line-height: 1.45; }
html[data-theme="dark"] .license-banner { background: #3b1f0b; border-color: #9a3412; color: #fed7aa; }
.storage-banner {
  background: #eff6ff;
  border: 1px solid #93c5fd;
  color: #1e3a8a;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 600;
}
.storage-banner a { margin-left: 8px; color: inherit; text-decoration: underline; }
.storage-banner-over {
  background: #fef2f2;
  border-color: #fca5a5;
  color: #991b1b;
}
html[data-theme="dark"] .storage-banner {
  background: #0c1a33;
  border-color: #1e40af;
  color: #bfdbfe;
}
html[data-theme="dark"] .storage-banner-over {
  background: #3f1d1d;
  border-color: #991b1b;
  color: #fecaca;
}
.sidebar-expand-fab {
  display: none !important;
}
html.sidebar-collapsed {
  --sidebar-w: 72px;
}
html.sidebar-collapsed .app {
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
}
html.sidebar-collapsed .sidebar {
  display: flex;
  padding: 12px 8px;
  align-items: stretch;
}
html.sidebar-collapsed .sidebar-top {
  justify-content: center;
  padding: 0 0 8px;
}
html.sidebar-collapsed .brand {
  display: none;
}
html.sidebar-collapsed .sidebar-toggle {
  width: 100%;
}
html.sidebar-collapsed .sidebar-toggle-icon {
  display: inline-block;
  transform: rotate(180deg);
}
html.sidebar-collapsed .nav {
  align-items: stretch;
}
html.sidebar-collapsed .nav a,
html.sidebar-collapsed .nav-group-toggle,
html.sidebar-collapsed .nav-feedback-btn {
  justify-content: center;
  padding: 11px 8px;
  gap: 0;
}
html.sidebar-collapsed .nav-label,
html.sidebar-collapsed .nav-chevron {
  display: none;
}
html.sidebar-collapsed .nav-sub {
  border-left: 0;
  margin-left: 0;
  padding: 2px 0 4px;
}
html.sidebar-collapsed .nav-sub a,
html.sidebar-collapsed .nav-feedback-btn {
  justify-content: center;
  padding: 10px 8px;
}
html.sidebar-collapsed .user {
  padding: 8px 0 0;
  text-align: center;
}
html.sidebar-collapsed .user-name,
html.sidebar-collapsed .user-license {
  display: none;
}
html.sidebar-collapsed .user-links {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  font-size: 0;
}
html.sidebar-collapsed .user-links a,
html.sidebar-collapsed .user-links .theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 10px 8px;
  border-radius: 10px;
  color: #93c5fd;
  background: transparent;
  border: 0;
  cursor: pointer;
}
html.sidebar-collapsed .user-links a:hover,
html.sidebar-collapsed .user-links .theme-toggle:hover {
  background: rgba(59,130,246,.18);
  color: #fff;
  text-decoration: none;
}
html.sidebar-collapsed .main { padding-left: 22px; }
.main { padding: 22px 24px 40px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
h1 { margin: 0; font-size: 22px; }
.sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.card .num { font-size: 28px; font-weight: 700; color: var(--accent); }
.card .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; margin-top: 4px; }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 14px;
}
.panel h2 { margin: 0 0 12px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.pdf-layout-tools {
  display: inline-flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  vertical-align: middle;
}
.pdf-layout-pick {
  display: inline-flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}
.pdf-layout-pick-lbl {
  margin: 0;
  font-size: 12px;
  white-space: nowrap;
  line-height: 1;
}
.pdf-layout-select {
  min-width: 180px;
  max-width: 260px;
  height: 34px;
  box-sizing: border-box;
  margin: 0;
}
.topbar .toolbar {
  align-items: center;
}
.subtabs {
  display: flex;
  gap: 4px;
  margin: -6px 0 14px;
  padding: 4px;
  background: #e2e8f0;
  border-radius: 12px;
  width: fit-content;
  max-width: 100%;
  flex-wrap: wrap;
}
.subtabs a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: 9px;
  color: #334155;
  font-size: 14px;
  font-weight: 650;
  text-decoration: none;
}
.subtabs a:hover { background: rgba(255,255,255,.55); text-decoration: none; color: #0f172a; }
.subtabs a.active {
  background: #fff;
  color: #1e40af;
  box-shadow: 0 1px 3px rgba(15,23,42,.08);
}
.subtab-count {
  display: inline-flex;
  min-width: 1.4em;
  justify-content: center;
  padding: 1px 7px;
  border-radius: 999px;
  background: #cbd5e1;
  color: #334155;
  font-size: 12px;
  font-weight: 700;
}
.subtabs a.active .subtab-count { background: #dbeafe; color: #1e40af; }
html[data-theme="dark"] .subtabs { background: #1e293b; }
html[data-theme="dark"] .subtabs a { color: #cbd5e1; }
html[data-theme="dark"] .subtabs a:hover { background: rgba(255,255,255,.06); color: #fff; }
html[data-theme="dark"] .subtabs a.active { background: #0f172a; color: #93c5fd; }
html[data-theme="dark"] .subtab-count { background: #334155; color: #e2e8f0; }
html[data-theme="dark"] .subtabs a.active .subtab-count { background: #1e3a8a; color: #bfdbfe; }
input, select, textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  background: #fff;
  color: var(--text);
  font-weight: 550;
}
input::placeholder,
textarea::placeholder {
  color: #94a3b8;
  opacity: 1;
  font-weight: 400;
  font-style: italic;
}
/* Puste pole z placeholderem vs wypełnione — wyraźniejsza różnica */
input:not(:placeholder-shown),
textarea:not(:placeholder-shown) {
  color: var(--text);
  font-weight: 600;
  border-color: #94a3b8;
  background: #f8fafc;
}
input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(37, 99, 235, .25);
  border-color: var(--accent2);
  background: #fff;
}
textarea { min-height: 90px; width: 100%; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.field-hint { font-size: 11px; color: var(--muted); font-weight: 500; margin-top: 2px; }
.field-hint-ok { color: #047857; }
html[data-theme="dark"] .field-hint-ok { color: #6ee7b7; }

/* Pytajnik z chmurką pomocy przy etykiecie pola */
.label-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.help-tip {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.help-tip-btn {
  width: 18px;
  height: 18px;
  padding: 0;
  border: 1px solid #94a3b8;
  border-radius: 50%;
  background: #f1f5f9;
  color: #334155;
  font: 700 11px/1 inherit;
  cursor: help;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.help-tip-btn:hover,
.help-tip-btn:focus {
  background: var(--accent2, #2563eb);
  border-color: var(--accent2, #2563eb);
  color: #fff;
  outline: none;
}
.help-tip-bubble {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  transform: translateX(-50%);
  width: min(280px, 72vw);
  padding: 10px 12px;
  border-radius: 10px;
  background: #0f172a;
  color: #f8fafc;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.45;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .28);
  z-index: 40;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .12s ease, visibility .12s ease;
}
.help-tip-bubble::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -6px;
  border: 6px solid transparent;
  border-top-color: #0f172a;
}
.help-tip-bubble strong { color: #fff; font-weight: 700; }
.help-tip:hover .help-tip-bubble,
.help-tip:focus-within .help-tip-bubble {
  opacity: 1;
  visibility: visible;
}
html[data-theme="dark"] .help-tip-btn {
  background: #334155;
  border-color: #64748b;
  color: #e2e8f0;
}
html[data-theme="dark"] .help-tip-bubble {
  background: #1e293b;
  border: 1px solid #475569;
}
html[data-theme="dark"] .help-tip-bubble::after {
  border-top-color: #1e293b;
}
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: 8px; padding: 8px 14px;
  background: var(--accent); color: #fff; font-weight: 650; font-size: 13px; cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--accent2); text-decoration: none; color: #fff; }
.btn-ghost { background: #fff; color: var(--accent); border: 1px solid var(--border); }
.btn-ghost:hover { background: #eff6ff; color: var(--accent); }
.btn-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  line-height: 1.2;
  background: #e2e8f0;
  color: #334155;
  white-space: nowrap;
  align-self: center;
}
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-green { background: #d1fae5; color: #065f46; }
.badge-red { background: #fee2e2; color: #991b1b; }
.timeline { display: flex; flex-direction: column; gap: 0; }
.timeline-item {
  display: grid; grid-template-columns: 110px 1fr; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border, #e2e8f0);
}
.timeline-date { font-size: 13px; color: var(--muted, #64748b); font-weight: 600; }
.timeline-title { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 4px; }
.timeline-item.kind-mt .timeline-date { color: #b45309; }
.timeline-item.kind-offer .timeline-date { color: #1d4ed8; }
.timeline-item.kind-protocol .timeline-date { color: #047857; }
.timeline-item.kind-inspection .timeline-date { color: #7c3aed; }
@media (max-width: 700px) {
  .timeline-item { grid-template-columns: 1fr; gap: 4px; }
}
.badge-amber { background: #fef3c7; color: #92400e; }

/* Blokada edycji oferty / protokołu po statusie */
.doc-lock-banner {
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: 10px;
  background: #fff7ed;
  border: 1px solid #fdba74;
  color: #9a3412;
  font-size: 14px;
  line-height: 1.45;
}
form.doc-locked .doc-lock-body {
  opacity: 0.55;
  filter: grayscale(0.15);
  pointer-events: none;
  user-select: none;
}
form.doc-locked .doc-lock-status {
  opacity: 1;
  filter: none;
  pointer-events: auto;
}
.sig-pad-locked {
  cursor: not-allowed !important;
  pointer-events: none;
  opacity: 0.7;
}

/* Historia aktualizacji (admin) */
.updates-group { margin-bottom: 14px; }
.updates-date {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text, #0f172a);
}
.updates-list {
  margin: 0;
  padding-left: 1.2em;
  line-height: 1.55;
}
.updates-list li { margin: 0 0 8px; }
.updates-list li:last-child { margin-bottom: 0; }
html[data-theme="dark"] .updates-date { color: #e2e8f0; }
.dash-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.flash {
  padding: 10px 12px; border-radius: 10px; margin-bottom: 14px; font-size: 13px;
}
.flash.ok { background: #d1fae5; color: #065f46; }
.flash.error { background: #fee2e2; color: #991b1b; }
.mp-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(16px);
  z-index: 9999;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: 12px;
  background: #065f46;
  color: #ecfdf5;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.28);
  opacity: 0;
  pointer-events: none;
  transition: opacity .28s ease, transform .28s ease;
}
.mp-toast.is-on {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}
.login-wrap {
  min-height: 100vh; display: grid; place-items: center;
  background: linear-gradient(145deg, #0f172a, #1e3a8a 55%, #1e40af);
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  background: #fff; border-radius: 16px; padding: 28px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.login-logo {
  display: flex;
  justify-content: center;
  margin: 0 0 16px;
}
.login-logo img {
  max-height: 72px;
  max-width: 240px;
  width: auto;
  height: auto;
  object-fit: contain;
}
.login-card h1 { margin: 0 0 4px; text-align: center; }
.login-card .sub { text-align: center; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.confirm-page {
  min-height: 50vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 12px;
}
.confirm-card {
  width: min(440px, 100%);
  background: var(--surface, #fff);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 24px;
  box-shadow: 0 12px 36px rgba(15, 23, 42, .12);
}
.confirm-card h1 {
  margin: 0 0 8px;
  font-size: 20px;
}
.confirm-name {
  margin: 0 0 14px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}
.confirm-warn {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 10px;
  background: #fff7ed;
  border: 1px solid #fdba74;
  color: #9a3412;
  font-size: 14px;
  line-height: 1.45;
}
.confirm-warn p { margin: 0 0 8px; }
.confirm-warn p:last-child { margin-bottom: 0; }
.confirm-warn ul {
  margin: 0 0 8px;
  padding-left: 18px;
}
.confirm-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  margin: 0;
}
html[data-theme="dark"] .confirm-warn {
  background: #3b1f0b;
  border-color: #9a3412;
  color: #fed7aa;
}
html[data-theme="dark"] .confirm-card {
  background: #0f1b2d;
}
.bar-row { display: grid; grid-template-columns: minmax(90px, 200px) 1fr 48px; gap: 10px; align-items: center; margin-bottom: 8px; font-size: 13px; }
.bar-track { height: 10px; background: #e2e8f0; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, #1e40af, #3b82f6); }
.side-list { display: flex; flex-direction: column; gap: 4px; }
.side-list a {
  padding: 10px 12px; border-radius: 10px; color: inherit; border: 1px solid transparent;
}
.side-list a.active { background: #eff6ff; border-color: #93c5fd; color: #1e40af; font-weight: 650; }
.layout-2 { display: grid; grid-template-columns: 240px 1fr; gap: 16px; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
  .sidebar .user { margin-top: 0; border-top: none; }
  .nav { flex-direction: row; flex-wrap: wrap; width: 100%; }
  .nav-group { width: 100%; }
  .nav-sub { border-left: 0; margin-left: 0; padding-left: 0; flex-direction: row; flex-wrap: wrap; }
  .layout-2 { grid-template-columns: 1fr; }
  html.sidebar-collapsed {
    --sidebar-w: 230px;
  }
  html.sidebar-collapsed .brand,
  html.sidebar-collapsed .nav-label,
  html.sidebar-collapsed .nav-chevron,
  html.sidebar-collapsed .user-name,
  html.sidebar-collapsed .user-license,
  html.sidebar-collapsed .sidebar-search {
    display: revert;
  }
  html.sidebar-collapsed .nav a,
  html.sidebar-collapsed .nav-group-toggle,
  html.sidebar-collapsed .nav-feedback-btn {
    justify-content: flex-start;
    padding: 10px 12px;
    gap: 10px;
  }
}
.sig-pad {
  display: block;
  width: 100%;
  max-width: 560px;
  height: 220px;
  touch-action: none;
  cursor: crosshair;
  background: #fff;
  border: 1px solid var(--border, #cbd5e1);
  border-radius: 8px;
}
.sig-fs {
  position: fixed;
  inset: 0;
  z-index: 12000;
  background: rgba(15, 23, 42, 0.72);
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 12px;
}
.sig-fs[hidden] { display: none !important; }
.sig-fs-inner {
  width: min(1100px, 100%);
  background: var(--panel, #fff);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 20px 50px rgba(0,0,0,.35);
}
.sig-fs-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 14px;
}
.sig-pad-fs {
  max-width: none;
  width: 100%;
  height: min(62vh, 560px);
  flex: 1 1 auto;
}
.sig-fs-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
body.sig-fs-open { overflow: hidden; }

/* Widok dla klienta (protokół) — parytet z EXE */
body.client-view .sidebar { display: none !important; }
body.client-view .app { display: block; }
body.client-view .chat-fab { display: none !important; }
body.client-view .cv-admin,
body.client-view .cv-hide-price { display: none !important; }
/* Uprawnienie „Ceny” wyłączone dla bieżącej zakładki */
body.hide-prices .cv-hide-price { display: none !important; }
body.client-view #btnClientView,
body.client-view .js-client-view-toggle { display: inline-flex !important; }
body.client-view input[readonly],
body.client-view textarea[readonly],
body.client-view select:disabled {
  background: #f1f5f9;
  color: #64748b;
  cursor: default;
}
body.client-view .ss-wrap { pointer-events: none; opacity: 0.95; }
body.client-view #signaturesPanel {
  border: 2px solid #93c5fd;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.08);
}
body.client-view .topbar .sub { display: none; }
#itemsTable {
  table-layout: fixed;
  width: 100%;
}
#itemsTable th:nth-child(1),
#itemsTable td:nth-child(1) { width: 46%; }
#itemsTable th:nth-child(2),
#itemsTable td:nth-child(2) { width: 90px; }
#itemsTable th:nth-child(3),
#itemsTable td:nth-child(3) { width: 70px; }
#itemsTable th:nth-child(4),
#itemsTable td:nth-child(4) { width: 110px; }
#itemsTable th:nth-child(5),
#itemsTable td:nth-child(5) { width: 70px; }
#itemsTable th:nth-child(6),
#itemsTable td:nth-child(6) { width: 48px; }
#itemsTable input { width: 100%; min-width: 0; }
#itemsTable td { vertical-align: top; }
#itemsTable textarea.item-nazwa {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 34px;
  height: auto;
  max-height: none;
  resize: none;
  overflow: hidden;
  line-height: 1.35;
  padding: 7px 10px;
  box-sizing: border-box;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  field-sizing: content;
}

/* Tryb ciemny (opcjonalny, przełącznik w pasku bocznym) */
html[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #0f1b2d;
  --border: #243349;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent2: #60a5fa;
}
html[data-theme="dark"] body { background: var(--bg); color: var(--text); }
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea { background: #0f1b2d; color: var(--text); border-color: var(--border); }
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder { color: #64748b; opacity: 1; }
html[data-theme="dark"] input:not(:placeholder-shown),
html[data-theme="dark"] textarea:not(:placeholder-shown) {
  background: #152238;
  border-color: #475569;
  color: #f1f5f9;
}
html[data-theme="dark"] input:focus,
html[data-theme="dark"] select:focus,
html[data-theme="dark"] textarea:focus { background: #0f1b2d; }
html[data-theme="dark"] .btn-ghost { background: #0f1b2d; color: #93c5fd; }
html[data-theme="dark"] .btn-ghost:hover { background: #16233a; color: #bfdbfe; }
html[data-theme="dark"] .badge { background: #1e293b; color: #cbd5e1; }
html[data-theme="dark"] .flash.ok { background: #052e2b; color: #a7f3d0; }
html[data-theme="dark"] .flash.error { background: #3f1d1d; color: #fecaca; }
html[data-theme="dark"] .mp-toast { background: #064e3b; color: #a7f3d0; box-shadow: 0 12px 32px rgba(0,0,0,.45); }
/* Podpis zawsze na białym tle (czytelność przy składaniu, niezależnie od motywu) */
html[data-theme="dark"] .sig-pad { background: #fff; }
.theme-toggle { background: none; border: 0; color: #93c5fd; cursor: pointer; font: inherit; padding: 0; }

/* Searchable select: jeden wygląd jak <select>; lista/szukaj tylko po otwarciu */
.ss-wrap { position: relative; width: 100%; }
.toolbar .ss-wrap { min-width: 220px; flex: 1 1 220px; max-width: 420px; }
select.ss-native {
  display: none !important;
}
.ss-trigger {
  display: block;
  width: 100%;
  box-sizing: border-box;
  text-align: left;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 28px 8px 10px;
  font: inherit;
  background-color: #fff;
  color: inherit;
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, #64748b 50%),
                    linear-gradient(135deg, #64748b 50%, transparent 50%);
  background-position: calc(100% - 14px) calc(50% + 2px), calc(100% - 9px) calc(50% + 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.ss-trigger.ss-placeholder { color: var(--text, #0f172a); }
.ss-wrap.ss-open .ss-trigger { border-color: var(--accent); }
.ss-panel[hidden],
.ss-wrap:not(.ss-open) .ss-panel {
  display: none !important;
}
.ss-panel {
  display: block;
  position: absolute;
  z-index: 50;
  left: 0; right: 0;
  top: calc(100% + 2px);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  overflow: hidden;
}
.ss-search { padding: 6px; border-bottom: 1px solid var(--border); }
.ss-search-input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font: inherit;
  background: #fff;
  color: inherit;
}
.ss-list { max-height: 240px; overflow: auto; padding: 4px; }
.ss-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  box-sizing: border-box;
  text-align: left;
  border: 0;
  background: transparent;
  color: inherit;
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
  font: inherit;
}
.ss-item:hover, .ss-item.ss-active { background: #eff6ff; }
.ss-item.ss-selected .ss-title { color: var(--accent); font-weight: 650; }
.ss-title { font-size: 13px; color: var(--text, #0f172a); }
.ss-meta { font-size: 11px; color: var(--muted); line-height: 1.35; }
.ss-empty-msg { padding: 10px; font-size: 12px; color: var(--muted); }
html[data-theme="dark"] .ss-trigger,
html[data-theme="dark"] .ss-search-input,
html[data-theme="dark"] .ss-panel { background: #0f1b2d; color: var(--text); border-color: var(--border); }
html[data-theme="dark"] .ss-item:hover,
html[data-theme="dark"] .ss-item.ss-active { background: #16233a; }

/* Rich-text e-mail */
.rte-toolbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  background: #f8fafc;
}
.rte-toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-start;
}
.rte-block {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  min-height: 42px;
}
.rte-block-label {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-right: 2px;
  white-space: nowrap;
}
.rte-toolbar .rte-group {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  padding: 0;
  margin: 0;
  border: 0;
}
.rte-toolbar .rte-group + .rte-group {
  padding-left: 6px;
  margin-left: 2px;
  border-left: 1px solid var(--border);
}
.rte-toolbar button,
.rte-toolbar select {
  padding: 4px 8px; border: 1px solid var(--border); background: #fff;
  border-radius: 6px; cursor: pointer; font-size: 12px; color: var(--text);
  font-weight: 550; height: 30px;
}
.rte-toolbar select { max-width: 140px; }
.rte-toolbar button:hover,
.rte-toolbar select:hover { background: #eff6ff; }
.rte-group-color,
.rte-group-table,
.rte-block.rte-group-table { position: relative; }
.rte-color-wrap { position: relative; display: inline-flex; }
.rte-color-btn {
  width: 30px; min-width: 30px; padding: 0 !important;
  font-weight: 700;
}
.rte-color-btn-bg { color: #ca8a04; }
.rte-color-panel,
.rte-table-panel,
.rte-table-size-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 50;
  width: min(280px, 86vw);
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(15, 23, 42, .18);
}
.rte-table-panel,
.rte-table-size-panel { width: min(260px, 86vw); }
.rte-color-none {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 0 0 8px;
  padding: 6px 8px !important;
  height: auto !important;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}
.rte-color-none:hover { background: rgba(15, 23, 42, .04); }
.rte-color-none-swatch {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  border: 1px solid #94a3b8;
  border-radius: 3px;
  background:
    linear-gradient(45deg, #e2e8f0 25%, transparent 25%),
    linear-gradient(-45deg, #e2e8f0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e2e8f0 75%),
    linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0;
  position: relative;
}
.rte-color-none-swatch::after {
  content: '';
  position: absolute;
  left: 1px;
  right: 1px;
  top: 50%;
  height: 2px;
  background: #dc2626;
  transform: rotate(-45deg);
}
.rte-color-palette {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  margin-bottom: 10px;
}
.rte-swatch {
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 0 !important;
  height: auto !important;
  min-height: 22px;
  cursor: pointer;
}
.rte-swatch.is-active { outline: 2px solid var(--accent2, #2563eb); outline-offset: 1px; }
.rte-color-custom {
  display: grid;
  grid-template-columns: auto 1fr 1fr 1fr 1fr;
  gap: 6px;
  align-items: center;
  margin-bottom: 10px;
  font-size: 11px;
  color: var(--muted);
}
.rte-color-custom label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0;
  font-size: 11px;
}
.rte-color-custom input[type="text"],
.rte-color-custom input[type="number"] {
  width: 100%;
  min-width: 0;
  padding: 4px 6px;
  font-size: 12px;
  height: 28px;
}
.rte-color-native-wrap {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  padding: 0 !important;
}
.rte-color-native-wrap input[type="color"] {
  width: 48px;
  height: 48px;
  border: 0;
  padding: 0;
  transform: translate(-6px, -6px);
  cursor: pointer;
}
.rte-color-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.rte-color-actions .btn { height: 30px; padding: 4px 12px; }
.rte-table-panel-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}
.rte-table-panel-fields {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}
.rte-table-panel-fields label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  margin: 0;
}
.rte-table-panel-fields input[type="number"] {
  height: 30px;
  padding: 4px 8px;
}
.rte-table-border-lab {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
  font-size: 12px !important;
  color: var(--text);
}
.rte-size-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.rte-size-row input[type="number"] { flex: 1; min-width: 0; }
.rte-size-row select { width: 64px; max-width: 64px; height: 30px; }
.rte-size-hint {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.35;
}
.rte-editor table[data-rte-table="1"] {
  position: relative;
}
.rte-editor table[data-rte-table="1"] td,
.rte-editor table[data-rte-table="1"] th {
  min-width: 24px;
  position: relative;
}
html[data-theme="dark"] .rte-color-panel,
html[data-theme="dark"] .rte-table-panel,
html[data-theme="dark"] .rte-table-size-panel {
  background: #0f1b2d;
  border-color: var(--border);
}
.rte-toolbar .rte-tokens { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; border-right: 0; padding-right: 0; }
.rte-toolbar .tok { color: #2563eb; }
.token-cheat-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0 0 8px;
  max-width: min(100%, 420px);
}
.token-cheat-title { font-size: 12px; color: var(--muted); }
.rte-token-pick,
.token-cheat {
  min-width: min(100%, 320px);
  max-width: 100%;
  font-size: 12px;
}
.token-insert-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: stretch;
}
.token-insert-row > input { flex: 1 1 220px; min-width: 0; }
.token-insert-row > select { flex: 0 1 280px; }
.rte-editor {
  min-height: 200px; padding: 12px; border: 1px solid var(--border);
  border-radius: 0 0 8px 8px; background: #fff; font-size: 14px; line-height: 1.5;
  color: var(--text); overflow-x: auto;
}
.rte-source {
  display: none;
  width: 100%;
  box-sizing: border-box;
  min-height: 280px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 0 0 8px 8px;
  background: #0f172a;
  color: #e2e8f0;
  font-family: Consolas, 'Courier New', monospace;
  font-size: 12.5px;
  line-height: 1.45;
  resize: vertical;
  tab-size: 2;
}
.rte-source[hidden] { display: none !important; }
.rte-box.is-source .rte-source:not([hidden]) {
  display: block;
}
.rte-source:focus { outline: 2px solid #93c5fd; }
.rte-source-btn.is-active {
  background: #dbeafe !important;
  color: #1d4ed8;
  font-weight: 700;
}
.rte-box.is-source .rte-toolbar button:not(.rte-source-btn),
.rte-box.is-source .rte-toolbar select {
  opacity: .45;
  pointer-events: none;
}
.rte-editor:focus { outline: 2px solid #93c5fd; }
.rte-editor img { max-width: none; height: auto; }
.rte-editor img[data-sig-logo="1"] { max-width: 110px; width: 110px; height: auto; display: block; }
.rte-editor table[data-mp-signature="1"] {
  max-width: 100%;
  width: auto;
  border-collapse: collapse;
  table-layout: auto;
}
.rte-editor table {
  border-collapse: collapse;
}
.rte-editor td, .rte-editor th { vertical-align: top; }
.rte-editor p { margin: 0 0 .55em; }
.rte-editor h1 { font-size: 1.6em; margin: .4em 0; }
.rte-editor h2 { font-size: 1.35em; margin: .4em 0; }
.rte-editor h3 { font-size: 1.15em; margin: .4em 0; }
.rte-paste-hint { font-size: 11px; color: var(--muted); margin: 6px 0 0; }
html[data-theme="dark"] .rte-toolbar { background: #16233a; }
html[data-theme="dark"] .rte-block { background: #0f1b2d; border-color: var(--border); }
html[data-theme="dark"] .rte-toolbar button,
html[data-theme="dark"] .rte-toolbar select,
html[data-theme="dark"] .rte-editor { background: #0f1b2d; color: var(--text); border-color: var(--border); }
html[data-theme="dark"] .rte-source { background: #020617; color: #e2e8f0; border-color: var(--border); }
html[data-theme="dark"] .rte-source-btn.is-active { background: #1e3a5f !important; color: #93c5fd; }
html[data-theme="dark"] .rte-toolbar button:hover,
html[data-theme="dark"] .rte-toolbar select:hover { background: #1e293b; }

/* Global busy / loading overlay */
#mpBusy {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  color: #fff;
  cursor: wait;
}
#mpBusy.is-on { display: flex; }
#mpBusy .mp-busy-spin {
  width: 44px;
  height: 44px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: mp-busy-rotate 0.7s linear infinite;
}
#mpBusy .mp-busy-msg {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.2px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}
@keyframes mp-busy-rotate {
  to { transform: rotate(360deg); }
}
body.mp-busy-lock {
  overflow: hidden;
}
@media print {
  #mpBusy { display: none !important; }
}

@media print {
  .sidebar, .toolbar, .no-print { display: none !important; }
  .app { display: block; }
  .main { padding: 0; }
  .client-card-head { break-inside: avoid; }
  .client-card-section { break-inside: avoid; }
}

/* Kalendarz przeglądów */
.client-related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  margin-top: 8px;
}
.cal-wrap { overflow-x: auto; }
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(110px, 1fr));
  gap: 4px;
}
.cal-head {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
  padding: 6px 4px;
}
.cal-cell {
  min-height: 96px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  background: var(--surface, #fff);
  color: var(--text);
}
.cal-empty { border-color: transparent; background: transparent; }
.cal-today { outline: 2px solid var(--accent, #2563eb); outline-offset: -1px; }
.cal-past { opacity: 0.88; }
.cal-daynum { font-size: 12px; font-weight: 700; margin-bottom: 4px; color: var(--text); }
.cal-items { display: flex; flex-direction: column; gap: 3px; }
.cal-item {
  display: block;
  font-size: 11px;
  line-height: 1.25;
  padding: 3px 5px;
  border-radius: 6px;
  background: #eff6ff;
  color: #1e3a8a;
  text-decoration: none;
}
.cal-item:hover { filter: brightness(0.97); }
.cal-item span { display: block; color: #64748b; }
.cal-item.cal-overdue { background: #fef2f2; color: #991b1b; }
.cal-item.cal-overdue span { color: #b91c1c; }
.cal-item.cal-done { background: #f1f5f9; color: #475569; opacity: 0.85; }
.cal-item.cal-done span { color: #64748b; }

html[data-theme="dark"] .cal-cell {
  background: var(--surface);
  border-color: var(--border);
}
html[data-theme="dark"] .cal-empty {
  background: transparent;
  border-color: transparent;
}
html[data-theme="dark"] .cal-today {
  outline-color: var(--accent2, #60a5fa);
  background: #132337;
}
html[data-theme="dark"] .cal-item {
  background: #1e3a5f;
  color: #bfdbfe;
}
html[data-theme="dark"] .cal-item:hover { filter: brightness(1.08); }
html[data-theme="dark"] .cal-item span { color: #93c5fd; }
html[data-theme="dark"] .cal-item.cal-overdue {
  background: #3f1d1d;
  color: #fecaca;
}
html[data-theme="dark"] .cal-item.cal-overdue span { color: #fca5a5; }
html[data-theme="dark"] .cal-item.cal-done {
  background: #1e293b;
  color: #94a3b8;
  opacity: 0.9;
}
html[data-theme="dark"] .cal-item.cal-done span { color: #64748b; }

/* Zdjęcia */
.attachments-panel { margin-top: 14px; }
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.photo-card {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}
.photo-card img {
  display: block;
  width: 100%;
  height: 120px;
  object-fit: cover;
}
.photo-card figcaption {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 8px;
  font-size: 11px;
}
.photo-card.file-card .file-card-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  background: #f8fafc;
  text-decoration: none;
  color: inherit;
  position: relative;
  gap: 6px;
}
.photo-card.file-card video {
  width: 100%;
  height: 120px;
  object-fit: cover;
  background: #0f172a;
}
.file-card-ext {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent, #1e40af);
  letter-spacing: 0.04em;
}
.file-card-badge {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.file-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}
html[data-theme="dark"] .photo-card.file-card .file-card-body {
  background: #132337;
}
html[data-theme="dark"] .photo-card {
  background: var(--surface, #0f1b2d);
}
.btn-tiny {
  font-size: 11px;
  padding: 2px 8px;
  height: auto;
}

/* ---- Czat firmowy ---- */
.nav-badge {
  flex: 0 0 auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

/* Pływająca ikona czatu (prawy dolny róg) */
.chat-fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 90;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #1d4ed8;
  color: #fff;
  box-shadow: 0 10px 28px rgba(29, 78, 216, 0.38);
  text-decoration: none;
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.chat-fab:hover {
  background: #1e40af;
  color: #fff;
  text-decoration: none;
  transform: translateY(-2px);
  box-shadow: 0 14px 32px rgba(29, 78, 216, 0.45);
}
.chat-fab-icon { display: block; }
.chat-fab-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ef4444;
  border: 2px solid #fff;
  box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.55);
  animation: chat-fab-blink 1.1s ease-in-out infinite;
}
.chat-fab-dot[hidden] { display: none !important; }
.chat-fab-count {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: #b91c1c;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  border: 2px solid #fff;
}
.chat-fab-count[hidden] { display: none !important; }
@keyframes chat-fab-blink {
  0%, 100% { opacity: 1; transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.55); }
  50% { opacity: 0.45; transform: scale(0.85); box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}
html[data-theme="dark"] .chat-fab {
  background: #2563eb;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}
html[data-theme="dark"] .chat-fab:hover { background: #3b82f6; }
@media (max-width: 640px) {
  .chat-fab { right: 14px; bottom: 14px; width: 52px; height: 52px; }
}

.chat-app {
  display: grid;
  grid-template-columns: minmax(220px, 280px) 1fr;
  gap: 0;
  min-height: calc(100vh - 180px);
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 12px;
  overflow: hidden;
}
.chat-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
}
.chat-sidebar {
  border-right: 1px solid var(--border, #e2e8f0);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg, #f8fafc);
}
.chat-sidebar-head {
  padding: 12px 14px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--muted, #64748b);
  border-bottom: 1px solid var(--border, #e2e8f0);
}
.chat-list {
  overflow-y: auto;
  flex: 1;
  padding: 6px;
}
.chat-list-item {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 2px 8px;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.chat-list-item:hover { background: rgba(37, 99, 235, 0.08); }
.chat-list-item.is-active { background: rgba(37, 99, 235, 0.14); }
.chat-list-title {
  font-weight: 600;
  font-size: 14px;
  grid-column: 1;
  grid-row: 1;
}
.chat-list-badge {
  grid-column: 2;
  grid-row: 1;
  align-self: start;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}
.chat-list-preview {
  grid-column: 1 / -1;
  grid-row: 2;
  font-size: 12px;
  color: var(--muted, #64748b);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-list-item.has-unread .chat-list-title { font-weight: 700; }
.chat-main {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
}
.chat-main-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border, #e2e8f0);
}
.chat-main-title { min-width: 0; flex: 1 1 auto; }
.chat-main-title strong { display: block; font-size: 15px; }
.chat-main-title .sub { margin: 0; font-size: 12px; }
.chat-list-item.is-observer .chat-list-title { font-style: italic; }
.chat-list-item.is-observer .chat-list-preview { opacity: 0.85; }
.chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg, #f1f5f9);
}
.chat-day {
  align-self: center;
  font-size: 11px;
  color: var(--muted, #64748b);
  background: rgba(148, 163, 184, 0.25);
  padding: 3px 10px;
  border-radius: 999px;
  margin: 6px 0;
}
.chat-bubble {
  max-width: min(520px, 85%);
  align-self: flex-start;
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 12px 12px 12px 4px;
  padding: 8px 12px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.chat-bubble.is-mine {
  align-self: flex-end;
  background: #dbeafe;
  border-color: #93c5fd;
  border-radius: 12px 12px 4px 12px;
}
.chat-bubble-author {
  font-size: 11px;
  font-weight: 700;
  color: #2563eb;
  margin-bottom: 2px;
}
.chat-bubble-body {
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-bubble-time {
  margin-top: 4px;
  font-size: 10px;
  color: var(--muted, #64748b);
  text-align: right;
}
.chat-composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 12px;
  border-top: 1px solid var(--border, #e2e8f0);
  background: var(--surface, #fff);
}
.chat-composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 140px;
  resize: vertical;
  margin: 0;
}
.chat-composer .btn { flex: 0 0 auto; }
.chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  color: var(--muted, #64748b);
  text-align: center;
}
.chat-empty[hidden],
.chat-main[hidden] { display: none !important; }
html[data-theme="dark"] .chat-sidebar { background: #0b1220; }
html[data-theme="dark"] .chat-messages { background: #0b1220; }
html[data-theme="dark"] .chat-bubble { background: #152238; border-color: #243349; }
html[data-theme="dark"] .chat-bubble.is-mine { background: #1e3a5f; border-color: #3b82f6; }
html[data-theme="dark"] .chat-list-item:hover { background: rgba(59, 130, 246, 0.12); }
html[data-theme="dark"] .chat-list-item.is-active { background: rgba(59, 130, 246, 0.22); }

@media (max-width: 820px) {
  .chat-app {
    grid-template-columns: 1fr;
    min-height: calc(100vh - 160px);
  }
  .chat-app.chat-show-thread .chat-sidebar { display: none; }
  .chat-app:not(.chat-show-thread) .chat-panel { display: none; }
}

/* Karta klienta */
.client-card { max-width: 960px; }
.client-card-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border);
}
.client-card-head h1 { margin: 4px 0; font-size: 26px; }
.client-card-meta { text-align: right; font-size: 14px; }
.client-card-section { margin-bottom: 18px; }
.client-card-section h2 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .4px;
}

@media (max-width: 800px) {
  .cal-grid { grid-template-columns: repeat(7, minmax(72px, 1fr)); }
  .cal-cell { min-height: 72px; }
  .client-card-meta { text-align: left; }
}
