:root {
  /* Paleta "Ekoenergia" - zielony rebranding (spojny z ekranem logowania).
     Tlo wyraznie odrozniamy od bialych kart (mniej "sciany bieli"). */
  --bg: #e8f2ec;
  --card: #ffffff;
  --ink: #1c2a22;
  --muted: #6b7d73;
  --line: #dde7e0;
  --primary: #16a34a;
  --primary-d: #15803d;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(20,50,35,.08);
}
* { box-sizing: border-box; }

/* Delikatne "wejscie" przy kazdym zaladowaniu strony - dzieki temu przejscie
   po zalogowaniu (z auth-page na reszte aplikacji) tez plynnie sie pojawia,
   zamiast twardego przeskoku. Tylko opacity (bez transform!) - transform na
   <body> zamienia je w punkt odniesienia dla position:fixed potomkow (czat),
   co psulo pozycje widgetu czatu na krotszych stronach. */
@keyframes pageFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  body { animation: none !important; }
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  animation: pageFadeIn .4s ease both;
}

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .9rem 1.5rem;
  background: linear-gradient(135deg, #0b1220 0%, #14532d 130%);
  color: #fff;
  flex-wrap: wrap;
  box-shadow: 0 4px 18px rgba(0,0,0,.2);
  position: relative;
  z-index: 10;
}
.brand {
  color: #fff; text-decoration: none;
  display: flex; align-items: center; justify-content: center;
  height: 40px; padding: 0 .6rem; border-radius: 10px; background: rgba(255,255,255,.08);
  transition: background .15s ease;
}
.brand:hover { background: rgba(255,255,255,.16); }
.brand-logo { height: 22px; width: auto; display: block; }
.nav { display: flex; align-items: center; gap: .3rem; flex-wrap: wrap; }
.nav a {
  color: #cbd5e1; text-decoration: none; font-size: .9rem; font-weight: 600;
  padding: .5rem 1rem; border-radius: 999px;
  transition: background .15s ease, color .15s ease;
}
.nav a:hover { color: #fff; background: rgba(255,255,255,.1); }
.nav a.nav-active { color: #fff; background: rgba(34,197,94,.25); }
.inline { display: inline; margin: 0; }

/* Layout */
.container { max-width: 900px; margin: 1.5rem auto; padding: 0 1rem; flex: 1 0 auto; width: 100%; }
.container.container-wide { max-width: 1600px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
h1 { font-size: 1.6rem; margin: .2rem 0; }
h2 { font-size: 1.25rem; margin: 2rem 0 .7rem; padding-left: .65rem; border-left: 4px solid var(--primary); }
h3 { font-size: 1.05rem; margin: 1.2rem 0 .3rem; }
.back { color: var(--muted); text-decoration: none; font-size: .9rem; }
.hint, .empty { color: var(--muted); font-size: .92rem; }
.muted { color: var(--muted); }
.lbl { display: block; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin-top: .6rem; }

/* Card / forms */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.2rem; box-shadow: var(--shadow); margin-bottom: 1rem;
}
label { display: block; margin: .6rem 0; font-weight: 600; font-size: .92rem; }
input, select, textarea {
  width: 100%; margin-top: .3rem; padding: .55rem .7rem; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 8px; font-family: inherit; font-weight: 400;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }
.actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1rem; }
.pozycja-card { border: 1px solid var(--line); border-radius: 8px; padding: .7rem; margin: .5rem 0; background: #fafbfc; }
.pozycja-card input, .pozycja-card textarea { margin-top: .3rem; }
.item-field { margin: .4rem 0; }
.item-field div { white-space: pre-wrap; }

/* Karta zamowienia (uklad jak papierowy formularz) */
.karta-zamowienia { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 1px;
  background: var(--line); border: none; border-top: 3px solid var(--primary); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow); margin-bottom: 1rem; }
.karta-cell { background: var(--card); padding: .8rem 1rem; }
.karta-cell label { margin: 0; }
.karta-span2 { grid-column: span 2; }
.karta-full { grid-column: 1 / -1; }
.karta-readonly { margin-top: .3rem; padding: .55rem .7rem; background: var(--bg);
  border: 1px dashed var(--line); border-radius: 8px; color: var(--muted); font-weight: 600; }
@media (max-width: 700px) {
  .karta-zamowienia { grid-template-columns: 1fr; }
  .karta-span2, .karta-full { grid-column: 1; }
}

/* Karta pozycji (per piec) - siatka 2-kolumnowa, wewnatrz bloku pozycji */
.pozycja-blok { border: 1px solid var(--line); border-radius: var(--radius);
  padding: .8rem; margin: .8rem 0; background: #fafbfc; }
.pozycja-blok h4 { margin: 0 0 .6rem; display: flex; align-items: center; gap: .6rem; }
.karta-pozycja { display: grid; grid-template-columns: 1fr 1fr; gap: 1px;
  background: var(--line); border: none; border-radius: 8px; overflow: hidden; }
.karta-pozycja .karta-cell { background: var(--card); padding: .6rem .8rem; }
.karta-pozycja-view { margin: .8rem 0; }
@media (max-width: 640px) { .karta-pozycja { grid-template-columns: 1fr; } }

/* Popup wiadomosci */
.popup-modal { border: none; border-radius: var(--radius); box-shadow: 0 10px 40px rgba(0,0,0,.25);
  padding: 1.2rem; max-width: 420px; width: 90%; }
.popup-modal::backdrop { background: rgba(15,23,42,.5); }
.popup-head { font-weight: 700; margin-bottom: .6rem; }
.popup-body { white-space: pre-wrap; margin-bottom: 1rem; }

/* Sortowalne naglowki tabeli */
.table th a { color: inherit; text-decoration: none; }
.table th a:hover { color: var(--primary); }

/* Buttons */
.btn {
  display: inline-block; padding: .55rem 1rem; border-radius: 8px; border: 1px solid transparent;
  font-size: 1rem; font-weight: 600; cursor: pointer; text-decoration: none; text-align: center;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: #eef2f7; }
.btn-danger { background: #fff; border-color: #f5c2c2; color: #b91c1c; }
.btn-danger:hover { background: #fdeaea; }
.btn-block { width: 100%; }
.order-actions { margin: -.4rem 0 1rem; }

/* Stopka - cienki pasek z danymi firmy, na wszystkich stronach poza logowaniem */
.app-footer {
  margin-top: 2.5rem;
  border-top: 1px solid var(--line);
  background: var(--card);
  padding: .65rem 1rem;
}
.app-footer-inner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: .25rem .5rem;
  font-size: .76rem; color: var(--muted); text-align: center;
}
.app-footer-brand { display: inline-flex; align-items: center; gap: .35rem;
  font-weight: 800; letter-spacing: .04em; color: var(--primary-d); }
.app-footer-dot { width: .32rem; height: .32rem; border-radius: 50%; background: var(--primary);
  box-shadow: 0 0 0 3px rgba(34,197,94,.18); }
.app-footer-sep { color: var(--line); }
.app-footer a { color: var(--muted); text-decoration: none; }
.app-footer a:hover { color: var(--primary); text-decoration: underline; }

/* Na ekranie logowania (ciemny gradient) stopka musi byc przezroczysta,
   zeby nie wygladala jak biały pasek doklejony na spodzie. */
body.auth-page .app-footer {
  position: relative; z-index: 1;
  background: transparent; border-top: 1px solid rgba(255,255,255,.14);
  margin-top: 0;
}
body.auth-page .app-footer-inner { color: rgba(255,255,255,.65); }
body.auth-page .app-footer-brand { color: #4ade80; }
body.auth-page .app-footer-sep { color: rgba(255,255,255,.25); }
body.auth-page .app-footer a { color: rgba(255,255,255,.65); }
body.auth-page .app-footer a:hover { color: #fff; }

/* Flash */
.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: .8rem; font-size: .95rem; }
.flash-ok { background: #e7f6ec; color: #14653a; border: 1px solid #bfe6cd; }
.flash-error { background: #fdeaea; color: #9b1c1c; border: 1px solid #f5c2c2; }
.flash-message { background: #eef2ff; color: #3730a3; border: 1px solid #c7d2fe; }

/* Login (stary styl - nieuzywany od redesignu logowania, zostawiony na wszelki wypadek) */
.login-box { max-width: 360px; margin: 3rem auto; background: var(--card); padding: 2rem;
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.login-box h1 { text-align: center; }

/* ===========================================================================
   Strona logowania (redesign) - dotyczy WYLACZNIE body.auth-page, czyli
   szablonu login.html. Zadna z tych regul nie rusza wygladu reszty aplikacji.
   Kopia poprzedniej wersji: backup_login_redesign_2026-07-30/
   =========================================================================== */

@keyframes authGradient {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
@keyframes authFadeUp {
  from { opacity: 0; transform: translateY(16px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes authFloat {
  0%, 100% { transform: translate(0, 0); }
  50%      { transform: translate(14px, -20px); }
}
@keyframes authFlashIn {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes authSpin { to { transform: rotate(360deg); } }

body.auth-page {
  min-height: 100vh;
  margin: 0;
  display: flex;
  flex-direction: column;
  background: linear-gradient(135deg, #0b1220 0%, #14532d 48%, #0b1220 100%);
  background-size: 220% 220%;
  animation: authGradient 16s ease infinite;
}
body.auth-page .topbar { display: none; }
body.auth-page .container {
  flex: 1;
  max-width: none;
  margin: 0;
  padding: 2rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
body.auth-page .flash {
  width: 100%;
  max-width: 380px;
  margin: 0 auto 1.2rem;
  animation: authFlashIn .45s ease both;
}

.auth-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: .35;
  pointer-events: none;
}
.auth-blob-1 { width: 340px; height: 340px; background: #22c55e; top: -90px; left: -70px;
  animation: authFloat 11s ease-in-out infinite; }
.auth-blob-2 { width: 300px; height: 300px; background: #2563eb; bottom: -100px; right: -60px;
  animation: authFloat 13s ease-in-out infinite reverse; }

.auth-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 380px;
  background: rgba(255, 255, 255, .98);
  border-radius: 18px;
  padding: 2.4rem 2.2rem 2.1rem;
  box-shadow: 0 24px 70px rgba(0,0,0,.35), 0 2px 8px rgba(0,0,0,.15);
  animation: authFadeUp .55s cubic-bezier(.16,1,.3,1) both;
}
.auth-logo { height: 34px; width: auto; display: block; margin: 0 auto .9rem; }
.auth-title { text-align: center; margin: 0 0 .35rem; font-size: 1.55rem; letter-spacing: -.01em; }
.auth-subtitle { text-align: center; color: var(--muted); font-size: .88rem; margin: 0 0 1.7rem; }

.auth-field { display: block; margin: 0 0 1rem; font-weight: 600; font-size: .85rem; }
.auth-field span { display: block; margin-bottom: .3rem; }
.auth-field input { transition: border-color .18s ease, box-shadow .18s ease; }
.auth-field input:focus {
  outline: none; border-color: #22c55e; box-shadow: 0 0 0 4px rgba(34,197,94,.16);
}

.btn.auth-submit {
  display: flex; align-items: center; justify-content: center; gap: .55rem;
  margin-top: .5rem;
  transition: transform .15s ease, box-shadow .15s ease;
}
.btn.auth-submit:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(37,99,235,.35); }
.btn.auth-submit:active { transform: translateY(0); }
.btn.auth-submit.is-loading { cursor: progress; }
.btn.auth-submit .auth-submit-label { transition: opacity .15s ease; }
.btn.auth-submit.is-loading .auth-submit-label { opacity: .75; }
.auth-spinner {
  display: none; width: 15px; height: 15px; flex: 0 0 auto;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%;
}
.btn.auth-submit.is-loading .auth-spinner { display: inline-block; animation: authSpin .6s linear infinite; }

@media (max-width: 460px) {
  .auth-card { padding: 2rem 1.4rem 1.8rem; }
  .auth-blob { display: none; }
}

.auth-error-modal {
  border: none; border-radius: 16px; padding: 1.6rem 1.6rem 1.4rem;
  max-width: 360px; width: 90%;
  box-shadow: 0 24px 60px rgba(0,0,0,.35);
  animation: authFadeUp .3s cubic-bezier(.16,1,.3,1) both;
}
.auth-error-modal::backdrop { background: rgba(11,18,32,.55); }
.auth-error-modal .popup-head { color: #b91c1c; font-size: 1.05rem; margin-bottom: .5rem; }
.auth-error-modal .popup-body { color: var(--ink); margin-bottom: 1.1rem; }
.auth-error-modal .popup-body p { margin: 0; }

@media (prefers-reduced-motion: reduce) {
  body.auth-page, .auth-card, .auth-blob, .btn.auth-submit, body.auth-page .flash, .auth-error-modal {
    animation: none !important; transition: none !important;
  }
}

/* Table */
.table { width: 100%; border-collapse: collapse; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.table th, .table td { text-align: left; padding: .7rem .9rem; border-bottom: 1px solid var(--line); }
.table th { background: #f8fafc; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.table tr:last-child td { border-bottom: none; }
.clickable { cursor: pointer; }
.clickable:hover { background: #eef5f0; }

/* Badges (statusy) */
.badge { display: inline-block; padding: .2rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 700; }
.badge-lg { font-size: .95rem; padding: .35rem .9rem; }
.badge-oczekujacy { background: #eef2f7; color: #475569; }
.badge-w_realizacji { background: #dbeafe; color: #1e40af; }
.badge-problem { background: #fee2e2; color: #b91c1c; }
.badge-zakonczone { background: #dcfce7; color: #166534; }
.badge-wyslane { background: #cffafe; color: #0e7490; }
.badge-anulowano { background: #e5e7eb; color: #6b7280; text-decoration: line-through; }
.badge-historyczne { background: #ede9fe; color: #6d28d9; }

/* Items */
.items { display: grid; gap: .8rem; }
.item-card { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--line);
  border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.item-card-oczekujacy { border-left-color: #94a3b8; }
.item-card-w_realizacji { border-left-color: #1e40af; }
.item-card-problem { border-left-color: #b91c1c; }
.item-card-zakonczone { border-left-color: #166534; }
.item-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.item-name { font-weight: 700; font-size: 1.05rem; }
.item-serial { margin: .5rem 0; }
.item-form { display: flex; align-items: flex-end; gap: .7rem; margin-top: .8rem;
  padding-top: .8rem; border-top: 1px dashed var(--line); flex-wrap: wrap; }
.item-form .f { flex: 1 1 180px; margin: 0; }
.item-form button { flex: 0 0 auto; }

/* Historia zmian */
.historia { display: grid; gap: 0; margin-bottom: 1rem; border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; background: var(--card); }
.hist-row { display: flex; gap: .9rem; padding: .7rem .9rem; border-bottom: 1px solid var(--line); }
.hist-row:last-child { border-bottom: none; }
.hist-row:nth-child(even) { background: #fafbfc; }
.hist-time { flex: 0 0 120px; color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.hist-type { font-weight: 700; }
.hist-item { color: var(--muted); }
.hist-detail { margin-top: .25rem; }
.hist-author { font-size: .82rem; margin-top: .2rem; }
.hist-anulowano .hist-type { color: #b91c1c; }
.hist-utworzenie .hist-type { color: #166534; }
@media (max-width: 640px) { .hist-row { flex-direction: column; gap: .2rem; } .hist-time { flex-basis: auto; } }

/* Row forms (admin uzytkownicy) */
.row-form { display: flex; gap: .4rem; align-items: center; }
.row-form-wrap { flex-wrap: wrap; }
.row-form-wrap input { width: auto; flex: 1 1 100px; }
.row-form select, .row-form input { width: auto; margin-top: 0; }

/* Dashboard */
.page-head-col { margin-bottom: 1rem; }
.filter-compact { display: flex; align-items: flex-end; gap: .7rem; flex-wrap: wrap; margin-top: .5rem; }
.filter-compact .f { margin: 0; font-size: .82rem; }
.filter-compact input { width: auto; padding: .4rem .55rem; }
.btn-sm { padding: .4rem .8rem; font-size: .92rem; }

.dashboard-layout { display: grid; grid-template-columns: 1fr 420px; gap: 1.25rem; align-items: stretch; }
@media (max-width: 1000px) { .dashboard-layout { grid-template-columns: 1fr; } }
.dash-side { display: flex; }

.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat-tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.2rem; box-shadow: var(--shadow); }
.stat-value { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: .85rem; margin-top: .3rem; }
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 700px) { .dash-grid { grid-template-columns: 1fr; } }
.chart-card h3 { margin-top: 0; }
.chart-wrap { position: relative; height: 320px; }
.chart-wrap-pie { height: 320px; margin-top: 2.2rem; }
.table-mini { margin-top: .8rem; box-shadow: none; border: none; }
.table-mini td { padding: .3rem .2rem; border-bottom: 1px solid var(--line); font-size: .88rem; }
.table-mini tr:last-child td { border-bottom: none; }
.table-mini .num { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; margin-right: .4rem; }

/* Asystent (czat) */
.chat-card { display: flex; flex-direction: column; flex: 1; }
.chat-log { flex: 1; min-height: 300px; overflow-y: auto; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: .6rem; margin: .5rem 0; display: flex; flex-direction: column; gap: .4rem; }
.chat-msg { padding: .4rem .6rem; border-radius: 8px; font-size: .88rem; max-width: 88%; }
.chat-msg-user { background: var(--primary); color: #fff; align-self: flex-end; }
.chat-msg-bot { background: var(--card); border: 1px solid var(--line); align-self: flex-start; }
.chat-form { display: flex; gap: .5rem; }
.chat-form input { flex: 1; margin: 0; }

/* Tablica produkcji (kolumny per status) - siatka, mieści się na jednym ekranie, bez poziomego scrolla */
.board { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 1rem; }
@media (max-width: 1100px) { .board { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 640px) { .board { grid-template-columns: 1fr; } }
.board-col { min-width: 0; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column;
  max-height: calc(100vh - 220px); }
.board-col-head { padding: .7rem .9rem; font-weight: 700; border-radius: var(--radius) var(--radius) 0 0;
  display: flex; align-items: center; justify-content: space-between; }
.board-count { background: rgba(0,0,0,.08); border-radius: 999px; padding: .05rem .55rem; font-size: .82rem; }
.board-col-body { padding: .7rem; display: grid; gap: .6rem; overflow-y: auto; }
.board-card { display: block; background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: .6rem .7rem; text-decoration: none; color: var(--ink); }
.board-card:hover { border-color: var(--primary); background: #eef2f7; }
.board-card-num { font-weight: 700; }
.board-card-customer { color: var(--ink); font-size: .92rem; margin-top: .15rem; }
.board-card-meta { color: var(--muted); font-size: .8rem; margin-top: .35rem; }

.historia-block { margin-top: 1.5rem; }
.historia-block summary { cursor: pointer; font-weight: 700; color: var(--muted);
  padding: .6rem .2rem; list-style: none; display: flex; align-items: center; gap: .6rem; }
.historia-block summary::-webkit-details-marker { display: none; }
.historia-block summary::before { content: "▸"; }
.historia-block[open] summary::before { content: "▾"; }
.historia-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: .6rem; padding-top: .6rem; }
.historia-filtry { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem .9rem; padding: .3rem .2rem .6rem; }
.historia-filtry .klienci-search { flex: 1 1 260px; margin: 0; }
.historia-data-lbl { display: flex; align-items: center; gap: .4rem; margin: 0;
  font-size: .85rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
.historia-data-lbl input { width: auto; margin: 0; }

/* Comments */
.comments { display: grid; gap: .6rem; margin-bottom: 1rem; }
.comment { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .7rem .9rem; }
.comment-head { display: flex; gap: .6rem; align-items: baseline; font-size: .9rem; margin-bottom: .3rem; }
.comment-body { white-space: pre-wrap; }

/* Plywajacy widget czatu (produkcja / ksiegowosc) - prawy dolny rog */
.fchat-toggle {
  position: fixed; right: 1.2rem; bottom: 1.2rem; z-index: 1000;
  width: 54px; height: 54px; border-radius: 50%; border: none;
  background: #0f172a; color: #fff; font-size: 1.4rem; cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.fchat-toggle:hover { background: #1e293b; }
.fchat-toggle.fchat-unread {
  background: #b91c1c;
  animation: fchatPulse 1.4s ease-in-out infinite;
}
.fchat-badge {
  position: absolute; top: -3px; right: -3px; z-index: 1;
  min-width: 20px; height: 20px; padding: 0 4px; border-radius: 999px;
  background: #dc2626; color: #fff; font-size: .72rem; font-weight: 700;
  line-height: 20px; text-align: center; box-shadow: 0 0 0 2px #0f172a;
}
@keyframes fchatPulse {
  0%, 100% { box-shadow: 0 4px 16px rgba(185,28,28,.5); }
  50% { box-shadow: 0 4px 24px rgba(185,28,28,.9); }
}

.fchat-panel {
  position: fixed; right: 1.2rem; bottom: 5.2rem; z-index: 1000;
  width: 340px; max-width: calc(100vw - 2.4rem); height: 440px; max-height: 70vh;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0,0,0,.25); display: flex; flex-direction: column; overflow: hidden;
}
.fchat-panel[hidden] { display: none; }
.fchat-head { display: flex; align-items: center; gap: .4rem;
  padding: .7rem .9rem; background: #0f172a; color: #fff; font-weight: 700; font-size: .92rem; }
.fchat-head #fchatTitleText { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fchat-back { background: none; border: none; color: #fff; font-size: 1.1rem; cursor: pointer; line-height: 1; padding: 0 .2rem 0 0; }
.fchat-new { background: none; border: 1px solid rgba(255,255,255,.4); border-radius: 6px; color: #fff;
  font-size: 1rem; font-weight: 700; cursor: pointer; line-height: 1; padding: .15rem .5rem; }
.fchat-close { background: none; border: none; color: #fff; font-size: 1.3rem; cursor: pointer; line-height: 1; }
.fchat-log { flex: 1; overflow-y: auto; padding: .7rem; display: flex; flex-direction: column; gap: .5rem; background: var(--bg); }
.fchat-msg { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .6rem; font-size: .88rem; max-width: 92%; }
.fchat-msg-mine { align-self: flex-end; background: #eefbf1; border-color: #bfe6cd; }
.fchat-msg-head { display: flex; align-items: baseline; gap: .4rem; flex-wrap: wrap; margin-bottom: .2rem; font-size: .78rem; }
.fchat-msg-head strong { font-size: .82rem; }
.fchat-tag { background: rgba(37,99,235,.1); color: var(--primary); border-radius: 999px; padding: 0 .5rem; font-weight: 600; }
.fchat-time { color: var(--muted); margin-left: auto; }
.fchat-msg-body { white-space: pre-wrap; }
.fchat-form { display: flex; gap: .5rem; padding: .6rem; border-top: 1px solid var(--line); flex-wrap: wrap; }
.fchat-form input { flex: 1; margin: 0; min-width: 6rem; }
@media (max-width: 480px) { .fchat-panel { width: calc(100vw - 1.6rem); right: .8rem; } .fchat-toggle { right: .8rem; } }

/* Lista "spraw" (watkow czatu per zamowienie + Ogolne) */
.fchat-sprawy { flex: 1; overflow-y: auto; background: var(--bg); display: flex; flex-direction: column; }
.fchat-sprawy-empty { padding: 1rem; margin: 0; text-align: center; }
.fchat-sprawa { display: block; width: 100%; text-align: left; background: var(--card); border: none;
  border-bottom: 1px solid var(--line); padding: .6rem .9rem; cursor: pointer; font-family: inherit; }
.fchat-sprawa:hover { background: #f3f6f4; }
.fchat-sprawa-unread { background: #eefbf1; }
.fchat-sprawa-unread:hover { background: #e3f6ea; }
.fchat-sprawa-top { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.fchat-sprawa-title { font-weight: 700; font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fchat-badge-inline { flex: 0 0 auto; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: #dc2626; color: #fff; font-size: .7rem; font-weight: 700; line-height: 18px; text-align: center; }
.fchat-sprawa-preview { font-size: .82rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; margin-top: .15rem; }
.fchat-sprawa-meta { font-size: .74rem; color: var(--muted); margin-top: .15rem; }
.fchat-thread { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.fchat-thread[hidden], .fchat-sprawy[hidden] { display: none; }

/* Na waskich ekranach przycisk Asystenta AI potrafi zachodzic na otwarty
   panel czatu (obydwa plywajace w tym samym rogu) i zaslaniac przycisk
   Wyslij - gdy czat jest otwarty, chowamy przycisk AI. */
#fchatPanel:not([hidden]) ~ #aiToggle { display: none; }

/* Plywajacy widget Asystenta AI - obok czatu (dalej w prawo od ikonki czatu) */
.ai-toggle {
  position: fixed; right: 5.8rem; bottom: 1.2rem; z-index: 1000;
  width: 54px; height: 54px; border-radius: 50%; border: none;
  background: #166534; color: #fff; font-size: 1.4rem; cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.ai-toggle:hover { background: #14532d; }
.ai-panel {
  position: fixed; right: 5.8rem; bottom: 5.2rem; z-index: 1000;
  width: 340px; max-width: calc(100vw - 2.4rem); height: 440px; max-height: 70vh;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0,0,0,.25); display: flex; flex-direction: column; overflow: hidden;
}
.ai-panel[hidden] { display: none; }
.ai-category-choice { padding: 1rem; display: flex; flex-direction: column; gap: .6rem; }
.ai-chat-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.ai-category-choice[hidden], .ai-chat-area[hidden] { display: none; }
.ai-chat-topbar { display: flex; align-items: center; justify-content: space-between;
  padding: .4rem .7rem; border-bottom: 1px solid var(--line); background: #f8fafc; }
.ai-category-label { font-size: .82rem; font-weight: 700; color: var(--muted); }
.ai-back { background: none; border: none; color: var(--primary); font-size: .8rem; cursor: pointer; padding: 0; }
.ai-suggestions { display: flex; flex-direction: column; gap: .4rem; margin-top: .3rem; }
.ai-chip { background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: .45rem .8rem; font-size: .82rem; text-align: left; cursor: pointer; color: var(--ink); }
.ai-chip:hover { border-color: var(--primary); background: #eef2f7; }
@media (max-width: 480px) {
  .ai-panel { width: calc(100vw - 1.6rem); right: .8rem; }
  .ai-toggle { right: .8rem; bottom: 5.8rem; }
}

/* Aktualizacje (changelog) */
.changelog-list { display: grid; gap: 1rem; }
.changelog-entry { margin-bottom: 0; }
.changelog-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .4rem; }
.changelog-head h2 { margin: 0; font-size: 1.1rem; }
.changelog-body { white-space: pre-wrap; margin-bottom: .6rem; }
.changelog-img { max-width: 100%; border-radius: 8px; border: 1px solid var(--line); display: block; }
.changelog-roles { font-size: .82rem; color: var(--muted); margin-bottom: .6rem; }
.changelog-roles .badge { margin-left: .4rem; background: #ede9fe; color: #6d28d9; }
.role-checks { display: flex; gap: 1.2rem; margin-top: .3rem; }
.role-check { display: flex; align-items: center; gap: .4rem; font-weight: 400; margin: 0; }
.role-check input { width: auto; margin: 0; }

.klienci-search {
  margin: 0 0 .9rem; padding: .6rem .9rem .6rem 2.3rem; font-size: .95rem;
  background: var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7d73' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") no-repeat .7rem center;
  background-size: 16px 16px;
}

/* Panel Uzytkownicy (redesign) - karty zamiast plaskiej tabeli */
.user-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 1rem; margin-bottom: 1.4rem; }
.user-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .7rem; }
.user-card-top { display: flex; align-items: center; gap: .7rem; }
.user-avatar { flex: 0 0 auto; width: 42px; height: 42px; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; font-weight: 700; font-size: .85rem; color: #fff; }
.role-avatar-admin { background: #0f172a; }
.role-avatar-ksiegowa { background: #1e40af; }
.role-avatar-produkcja { background: #166534; }
.user-card-id { flex: 1; min-width: 0; }
.user-card-name { font-weight: 700; line-height: 1.25; overflow-wrap: break-word; }
.user-card-login { color: var(--muted); font-size: .82rem; }
.user-card-status { flex: 0 0 auto; }
.user-card-row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.user-card-row .row-form { flex-wrap: nowrap; width: 100%; }
.user-card-row .row-form select { width: auto; flex: 1; }
.user-card-row .row-form input { width: auto; flex: 1; }
.user-card-footer { margin-top: auto; padding-top: .3rem; border-top: 1px dashed var(--line); }
.role-badge-admin { background: #e2e8f0; color: #0f172a; }
.role-badge-ksiegowa { background: #dbeafe; color: #1e40af; }
.role-badge-produkcja { background: #dcfce7; color: #166534; }

/* Ustawienia SMTP */
.smtp-card code { background: var(--bg); border-radius: 4px; padding: 0 .3rem; }
.smtp-tls-row { display: flex; align-items: center; gap: .5rem; font-weight: 600; font-size: .92rem; }
.smtp-tls-row input { width: auto; margin: 0; }
.smtp-status { margin-top: 1rem; padding: .7rem .9rem; background: var(--bg); border: 1px dashed var(--line);
  border-radius: 8px; font-size: .9rem; }
.smtp-actions { justify-content: flex-start; flex-wrap: wrap; }
.smtp-test-form input { width: 220px; max-width: 60vw; }

/* Pasek marki pod topbarem (masthead) */
.masthead {
  text-align: center; padding: 1.4rem 1rem 1.3rem;
  background: linear-gradient(180deg, #eefaf1 0%, #e3f1e8 100%);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 8px rgba(20,50,35,.05);
}
.masthead-logo { height: 30px; width: auto; display: block; margin: 0 auto .5rem; }
.masthead-title { font-weight: 800; font-size: 1.4rem; letter-spacing: -.01em; color: var(--ink); }

/* Rozwijane menu konta w topbarze */
.user-menu { position: relative; }
.user-menu-trigger {
  display: flex; align-items: center; gap: .6rem; background: transparent; border: 1px solid transparent;
  color: #e2e8f0; font: inherit; cursor: pointer; padding: .35rem .8rem .35rem .35rem; border-radius: 999px;
}
.user-menu-trigger:hover, .user-menu-trigger[aria-expanded="true"] { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.18); }
.user-menu-avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  font-size: .72rem; font-weight: 700; color: #fff;
}
.user-menu-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.2; }
.user-menu-text small { color: #94a3b8; font-weight: 500; font-size: .74rem; }
.user-menu-caret { font-size: .65rem; color: #94a3b8; }
.user-menu-dropdown {
  position: absolute; right: 0; top: calc(100% + .4rem); z-index: 1000;
  min-width: 160px; background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0,0,0,.2); overflow: hidden;
}
.user-menu-dropdown[hidden] { display: none; }
.user-menu-item {
  display: block; width: 100%; text-align: left; background: none; border: none; cursor: pointer;
  padding: .6rem .9rem; font: inherit; font-weight: 600; color: var(--ink);
}
.user-menu-item:hover { background: var(--bg); }

/* Drag & drop statusow na tablicy */
.board-card[draggable="true"] { cursor: grab; }
.board-card[draggable="true"]:active { cursor: grabbing; }
.board-card:not([draggable="true"]) { opacity: .7; }
.board-col-body.drag-over { background: #eafbf0; outline: 2px dashed var(--primary); outline-offset: -2px; }
