:root {
  --navy: #0f2740;
  --navy-2: #16395c;
  --teal: #0ea5a4;
  --teal-d: #0b827f;
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1b2733;
  --muted: #6b7a8d;
  --line: #e4e9f0;
  --warn: #d98324;
  --warn-bg: #fdf3e7;
  --info: #2f6fbf;
  --info-bg: #eaf2fc;
  --good: #1f9d6b;
  --shadow: 0 1px 3px rgba(15, 39, 64, .08), 0 6px 20px rgba(15, 39, 64, .06);
}

* { box-sizing: border-box; }
/* atrybut hidden musi chowac element nawet gdy ma display:flex/grid w innej regule */
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 28px;
  background: linear-gradient(100deg, var(--navy), var(--navy-2));
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { font-size: 28px; }
.brand-name { font-weight: 700; font-size: 19px; letter-spacing: .3px; }
.brand-sub { font-size: 12px; color: #9fc7d6; }
.client { margin-left: auto; text-align: right; }
.client .c-name { font-weight: 600; }
.client .c-meta { font-size: 12px; color: #9fb3c8; }
.demo-badge {
  background: rgba(255, 255, 255, .12);
  border: 1px solid rgba(255, 255, 255, .25);
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: .5px;
  font-weight: 600;
}

main { max-width: 1180px; margin: 24px auto; padding: 0 20px; }

/* Panels */
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.panel-head { display: flex; align-items: center; margin-bottom: 12px; }
.panel-head h2 { font-size: 18px; margin: 0; }
.panel-head h3 { font-size: 14px; margin: 0; color: var(--navy); text-transform: uppercase; letter-spacing: .4px; }
.tag {
  font-size: 11px; font-weight: 600; color: var(--teal-d);
  background: #e6f6f5; border-radius: 999px; padding: 3px 9px; margin-left: 10px;
  text-transform: none; letter-spacing: 0;
}

/* Narracja */
.narracja { border-left: 4px solid var(--teal); }
.narracja-text { font-size: 16px; margin: 0; color: #28384a; white-space: pre-wrap; }

/* KPI */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 14px;
  margin: 18px 0;
}
.kpi {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  box-shadow: var(--shadow);
}
.kpi .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.kpi .value { font-size: 21px; font-weight: 700; margin-top: 4px; }
.kpi .delta { font-size: 12px; margin-top: 2px; }
.delta.up { color: var(--good); }
.delta.down { color: var(--warn); }

/* Kontener wykresu — sztywna wysokosc lamie petle resize Chart.js
   (responsive + maintainAspectRatio:false wymaga rodzica o ustalonej wysokosci) */
.chart-box { position: relative; width: 100%; height: 280px; }
.chart-box.tall { height: 300px; }

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 18px;
}
.col-2 { grid-column: span 2; }
/* element gridu ma domyslnie min-width:auto — canvas Chart.js rozpychalby kolumny
   w nieskonczonosc; min-width:0 pozwala kolumnom sie kurczyc */
.grid > .panel { min-width: 0; }
.chart-box canvas { max-width: 100%; }

/* Należności */
.naleznosci .nbig { font-size: 24px; font-weight: 700; }
.naleznosci .nsplit { display: flex; gap: 10px; margin-top: 14px; }
.nbar { flex: 1; }
.nbar .bar { height: 8px; border-radius: 6px; background: var(--line); overflow: hidden; margin: 6px 0; }
.nbar .bar > i { display: block; height: 100%; background: var(--teal); }
.nbar .bar.next > i { background: var(--navy-2); }
.nbar small { color: var(--muted); }

/* Anomalie */
.anomalie .a {
  border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; font-size: 13px;
  border: 1px solid var(--line);
}
.a .a-head { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 3px; }
.a .a-okres { font-size: 11px; color: var(--muted); font-weight: 500; }
.a.warning { background: var(--warn-bg); border-color: #f0d8b8; }
.a.warning .a-head { color: var(--warn); }
.a.info { background: var(--info-bg); border-color: #cfe0f5; }
.a.info .a-head { color: var(--info); }

.hint { font-size: 12px; color: var(--muted); margin: 10px 0 0; }

/* Chat */
.chat-log {
  min-height: 80px; max-height: 320px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px;
}
.msg { max-width: 78%; padding: 10px 14px; border-radius: 14px; font-size: 14px; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--navy); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: #eef2f7; color: var(--ink); border-bottom-left-radius: 4px; }
.chat-suggest { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  font-size: 12px; padding: 6px 12px; border-radius: 999px; cursor: pointer;
  background: #fff; border: 1px solid var(--teal); color: var(--teal-d);
}
.chip:hover { background: #e6f6f5; }
.chat-input { display: flex; gap: 10px; }
.chat-input input {
  flex: 1; padding: 11px 14px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px;
}
.chat-input input:focus { outline: 2px solid var(--teal); border-color: var(--teal); }
.chat-input button {
  padding: 11px 20px; border: none; border-radius: 10px; background: var(--teal);
  color: #fff; font-weight: 600; cursor: pointer; font-size: 14px;
}
.chat-input button:hover { background: var(--teal-d); }

/* Podglad danych wysylanych do AI */
.hint-link {
  background: none; border: none; padding: 0; font-size: inherit;
  color: var(--teal-d); text-decoration: underline; cursor: pointer;
}
.summary-dialog {
  max-width: 720px; width: 90vw; max-height: 80vh;
  border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px;
  box-shadow: 0 10px 40px rgba(15, 39, 64, .25);
}
.summary-dialog::backdrop { background: rgba(15, 39, 64, .45); }
.sd-head { display: flex; justify-content: space-between; align-items: center; }
.sd-head h3 { margin: 0; font-size: 16px; color: var(--navy); }
.sd-close { background: none; border: none; font-size: 16px; cursor: pointer; color: var(--muted); }
.summary-dialog pre {
  background: #f4f6f9; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; font-size: 11px; line-height: 1.5; overflow: auto; max-height: 52vh;
}

/* Formularz zgloszenia problemu */
.fb-form { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.fb-form textarea, .fb-form input {
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; font-family: inherit; resize: vertical;
}
.fb-form button {
  align-self: flex-start; padding: 10px 20px; border: none; border-radius: 10px;
  background: var(--teal); color: #fff; font-weight: 600; cursor: pointer; font-size: 14px;
}
.fb-form button:hover { background: var(--teal-d); }
.fb-form button:disabled { opacity: .6; cursor: default; }
.fb-error {
  font-size: 12px; color: var(--warn); background: var(--warn-bg);
  border: 1px solid #f0d8b8; border-radius: 8px; padding: 8px 10px; margin: 10px 0 0;
}
.summary-dialog .lead-status { color: var(--good); }
.summary-dialog .lead-status.err { color: var(--warn); }

/* CTA — design partner */
.cta {
  margin-top: 18px;
  background: linear-gradient(100deg, var(--navy), var(--navy-2));
  color: #fff;
  border: none;
}
.cta h2 { margin: 0 0 10px; font-size: 20px; }
.cta p { margin: 0 0 16px; color: #c9d6e4; max-width: 760px; }
.lead-form { display: flex; flex-wrap: wrap; gap: 10px; }
.lead-form input {
  flex: 1 1 220px; padding: 11px 14px; border: none; border-radius: 10px; font-size: 14px;
}
.lead-form button {
  padding: 11px 22px; border: none; border-radius: 10px; background: var(--teal);
  color: #fff; font-weight: 600; cursor: pointer; font-size: 14px; white-space: nowrap;
}
.lead-form button:hover { background: var(--teal-d); }
.lead-form button:disabled { opacity: .6; cursor: default; }
.lead-consent {
  display: flex; gap: 8px; align-items: flex-start;
  font-size: 12px; color: #9fb3c8; margin-top: 12px; max-width: 760px; cursor: pointer;
}
.lead-consent input { margin-top: 2px; }
.lead-status { margin: 12px 0 0; font-size: 14px; font-weight: 600; color: #7ce3c4; }
.lead-status.err { color: #ffb38a; }

footer {
  max-width: 1180px; margin: 0 auto 40px; padding: 18px 20px;
  display: flex; flex-wrap: wrap; gap: 18px; justify-content: space-between;
  font-size: 12px; color: var(--muted);
}

/* Reset button (topbar) */
.reset-btn {
  background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .25);
  color: #fff; padding: 7px 13px; border-radius: 9px; font-size: 12px; cursor: pointer;
}
.reset-btn:hover { background: rgba(255, 255, 255, .22); }

/* ===== ETAP 1: upload + przetwarzanie ===== */
.upload-stage {
  min-height: calc(100vh - 64px);
  display: flex; align-items: center; justify-content: center; padding: 30px 20px;
}
.upload-card { max-width: 620px; text-align: center; }
.upload-card h1 { font-size: 32px; color: var(--navy); margin: 0 0 12px; }
.upload-card .lead { font-size: 16px; color: var(--muted); margin: 0 0 28px; }

.dropzone {
  display: block; cursor: pointer;
  border: 2px dashed #b9c6d6; border-radius: 16px;
  padding: 44px 24px; background: var(--card);
  transition: border-color .15s, background .15s, transform .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--teal); background: #f0faf9; transform: translateY(-2px); }
.dz-icon { font-size: 40px; }
.dz-main { font-size: 18px; font-weight: 600; color: var(--ink); margin-top: 10px; }
.dz-sub { font-size: 13px; color: var(--muted); margin-top: 4px; }
.link-btn {
  background: none; border: none; color: var(--teal-d); cursor: pointer;
  font-size: 14px; text-decoration: underline; padding: 0;
}
.samples { margin-top: 18px; font-size: 14px; color: var(--muted); }
#errorView .link-btn { display: inline-block; margin: 6px 10px 0 0; }
.dz-note { font-size: 12px; color: var(--muted); margin-top: 22px; }

.processing { max-width: 560px; width: 100%; text-align: center; }
.proc-spinner {
  width: 46px; height: 46px; margin: 0 auto 18px;
  border: 4px solid var(--line); border-top-color: var(--teal); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.proc-file { font-size: 14px; color: var(--navy); font-weight: 600; margin-bottom: 18px; }
.proc-steps { list-style: none; padding: 0; margin: 0 0 22px; text-align: left; }
.proc-steps li {
  display: flex; align-items: center; gap: 10px; padding: 7px 0;
  font-size: 14px; color: var(--muted); opacity: .5; transition: opacity .2s, color .2s;
}
.proc-steps li.active { opacity: 1; color: var(--ink); }
.proc-steps li.done { opacity: 1; color: var(--good); }
.proc-steps .dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line); flex: 0 0 auto; }
.proc-steps li.active .dot { border-color: var(--teal); border-top-color: transparent; animation: spin .7s linear infinite; }
.proc-steps li.done .dot { border-color: var(--good); background: var(--good); }
.proc-steps li.done .dot::after { content: "✓"; color: #fff; font-size: 11px; display: block; text-align: center; line-height: 12px; }
.proc-bar { height: 8px; background: var(--line); border-radius: 6px; overflow: hidden; }
.proc-bar > i { display: block; height: 100%; width: 0; background: var(--teal); transition: width .45s ease; }

/* Chat — wskaznik pisania */
.msg.typing { display: inline-flex; gap: 4px; padding: 14px; }
.msg.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: #9fb3c8;
  animation: blink 1.2s infinite both;
}
.msg.typing span:nth-child(2) { animation-delay: .2s; }
.msg.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }

@media (max-width: 880px) {
  .grid { grid-template-columns: 1fr; }
  .col-2 { grid-column: span 1; }
  .kpi-strip { grid-template-columns: repeat(2, 1fr); }
  .client { display: none; }
  .upload-card h1 { font-size: 26px; }
}
