:root {
  --yellow: #ffd22e;
  --yellow-dark: #e4b713;
  --yellow-soft: #fff6d1;
  --ink: #111111;
  --text-2: #4a4a4a;
  --muted: #7a7a7a;
  --line: #e5e3dd;
  --bg: #f5f4f0;
  --card: #ffffff;
  --green: #1d7a3e;
  --green-soft: #e6f4ea;
  --red: #c62828;
  --red-soft: #fdecea;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: Roboto, system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }

/* layout */
.top { background: #fff; border-bottom: 4px solid var(--yellow); position: sticky; top: 0; z-index: 20; }
.top-in { max-width: 1240px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; }
.top-in .logo { height: 52px; width: auto; }
.nav { display: flex; gap: 4px; margin-left: 8px; }
.nav a { text-decoration: none; padding: 8px 12px; border-radius: 8px; font-weight: 500; color: var(--text-2); }
.nav a.on { background: var(--ink); color: #fff; }
.top-in .who { margin-left: auto; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
main { max-width: 1240px; margin: 0 auto; padding: 22px 16px 40px; }
.foot { max-width: 1240px; margin: 0 auto; padding: 10px 16px 30px; color: var(--muted); font-size: 12.5px; display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

h1 { font-size: 26px; font-weight: 900; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 17px; font-weight: 700; margin: 0 0 12px; }
.lead { color: var(--text-2); margin: 0 0 20px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* przyciski */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 10px 16px; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #c9c6bd; }
.btn.primary { background: var(--yellow); border-color: var(--yellow); color: var(--ink); font-weight: 700; }
.btn.primary:hover { background: var(--yellow-dark); border-color: var(--yellow-dark); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: #ecebe6; }
.btn.danger { color: var(--red); }
.btn.big { padding: 16px 20px; font-size: 16px; border-radius: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 20px; height: 20px; flex: none; }

/* start */
.grid-home { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.upload { border: 2px dashed #d6d2c6; border-radius: var(--radius); padding: 22px; text-align: center; background: #fffdf5; transition: .15s; }
.upload.drag { border-color: var(--yellow-dark); background: var(--yellow-soft); }
.upload .row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 14px 0 6px; }
.samples { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.sample { border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 6px; cursor: pointer; text-align: left; transition: .15s; }
.sample:hover { border-color: var(--yellow-dark); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(0,0,0,.06); }
.sample img { aspect-ratio: 3 / 4; object-fit: cover; border-radius: 6px; width: 100%; background: #eee; }
.sample span { display: block; font-size: 12.5px; font-weight: 500; padding: 6px 2px 2px; line-height: 1.25; }
.usage { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-size: 13px; color: var(--muted); }
.usage .bar { flex: 1; height: 6px; border-radius: 3px; background: #ecebe6; overflow: hidden; }
.usage .bar i { display: block; height: 100%; background: var(--yellow-dark); }

.list { display: flex; flex-direction: column; }
.item { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); text-decoration: none; }
.item:last-child { border-bottom: 0; }
.item:hover { background: #faf9f6; }
.item .n { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .k { font-weight: 700; text-align: right; }
.item .d { color: var(--muted); font-size: 13px; }
.pill { display: inline-block; font-size: 12px; font-weight: 500; padding: 2px 8px; border-radius: 99px; background: #ecebe6; color: var(--text-2); }
.pill.do_akceptacji { background: var(--yellow-soft); color: #7a5b00; }
.pill.wystawiona { background: var(--green-soft); color: var(--green); }
.pill.blad, .pill.odrzucona { background: var(--red-soft); color: var(--red); }
.empty { padding: 26px 8px; text-align: center; color: var(--muted); }

.how { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 18px; }
.how div { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px; font-size: 13px; color: var(--text-2); }
.how b { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; margin-bottom: 4px; }
.how b i { font-style: normal; width: 22px; height: 22px; border-radius: 50%; background: var(--yellow); display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 900; }

/* przetwarzanie */
.overlay { position: fixed; inset: 0; background: rgba(17,17,17,.55); backdrop-filter: blur(3px); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; }
.overlay .box { background: #fff; border-radius: 16px; padding: 26px; width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.steps { list-style: none; padding: 0; margin: 16px 0 0; display: flex; flex-direction: column; gap: 10px; }
.steps li { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.steps li .dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: flex; align-items: center; justify-content: center; }
.steps li.on { color: var(--ink); font-weight: 500; }
.steps li.on .dot { border-color: var(--yellow-dark); border-top-color: transparent; animation: spin .8s linear infinite; }
.steps li.done { color: var(--ink); }
.steps li.done .dot { background: var(--yellow); border-color: var(--yellow); }
.steps li.done .dot::after { content: ""; width: 6px; height: 10px; border: solid var(--ink); border-width: 0 2px 2px 0; transform: rotate(45deg) translate(-1px, -1px); }
@keyframes spin { to { transform: rotate(360deg); } }

/* raport */
.back { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.grid-review { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 18px; align-items: start; }
.doc { position: sticky; top: 86px; }
.preview { position: relative; background: #2b2b2b; border-radius: var(--radius); overflow: hidden; cursor: zoom-in; }
.preview img { width: 100%; height: auto; max-height: calc(100vh - 150px); object-fit: contain; display: block; }
@media (max-width: 900px) { .preview img { max-height: 70vh; } }
.preview .pv-btn { position: absolute; top: 10px; right: 10px; background: rgba(17,17,17,.75); color: #fff; font-size: 13px; font-weight: 500; padding: 6px 12px; border-radius: 8px; pointer-events: none; }
.preview:hover .pv-btn { background: var(--ink); }
.lb { position: fixed; inset: 0; z-index: 1000; background: rgba(12,12,12,.94); display: flex; flex-direction: column; }
.lb-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; color: #fff; }
.lb-name { font-size: 14px; color: #ccc; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-tools { display: flex; align-items: center; gap: 4px; }
.lb-tools button { border: 0; background: rgba(255,255,255,.1); color: #fff; font: inherit; font-size: 14px; padding: 7px 12px; border-radius: 8px; cursor: pointer; min-width: 36px; }
.lb-tools button:hover { background: rgba(255,255,255,.2); }
.lb-tools .lb-x { margin-left: 8px; }
.lb-z { font-size: 13px; color: #ccc; min-width: 48px; text-align: center; font-variant-numeric: tabular-nums; }
.lb-stage { position: relative; flex: 1; overflow: hidden; cursor: zoom-in; touch-action: none; }
.lb-stage img { position: absolute; left: 0; top: 0; transform-origin: 0 0; max-width: none; user-select: none; -webkit-user-drag: none; cursor: grab; }
.doc iframe { width: 100%; height: calc(100vh - 160px); border: 0; border-radius: var(--radius); background: #fff; }
.doc .cap { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 13px; margin-top: 8px; }

.banner { border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; display: flex; gap: 12px; align-items: flex-start; }
.banner.ok { background: var(--green-soft); }
.banner.warn { background: var(--yellow-soft); }
.banner.err { background: var(--red-soft); }
.banner b { display: block; }
.banner > div:first-child svg { width: 24px; height: 24px; color: var(--green); display: block; }
.banner ul { margin: 6px 0 0; padding-left: 18px; }
.banner .links { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

.aiinfo { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { font-size: 12.5px; padding: 4px 10px; border-radius: 99px; background: #fff; border: 1px solid var(--line); color: var(--text-2); }
.chip.y { background: var(--yellow-soft); border-color: #f1df9a; color: #6b5000; }

.sec { margin-bottom: 14px; }
.sec h2 { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.fields { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.f { display: flex; flex-direction: column; gap: 4px; grid-column: span 6; }
.f.s3 { grid-column: span 3; } .f.s2 { grid-column: span 2; } .f.s4 { grid-column: span 4; }
.f label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.f input, .f select, .f textarea, .pos input, .pos select { width: 100%; border: 1px solid #d9d6cd; border-radius: 8px; padding: 9px 10px; background: #fff; }
.f input:focus, .f select:focus, .f textarea:focus, .pos input:focus, .pos select:focus { outline: 2px solid var(--yellow); border-color: var(--yellow-dark); }
.f textarea { min-height: 64px; resize: vertical; }
input:disabled, select:disabled, textarea:disabled { background: #f6f5f2; color: var(--text-2); }
.seg { display: inline-flex; background: #ecebe6; border-radius: 9px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 7px; cursor: pointer; font-size: 13px; font-weight: 500; color: var(--text-2); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.nipline { display: flex; gap: 8px; }
.nipline input { flex: 1; }
.mf { font-size: 12.5px; margin-top: 4px; }
.mf.ok { color: var(--green); } .mf.bad { color: var(--red); } .mf.info { color: var(--muted); }

.pos { display: grid; grid-template-columns: minmax(0, 1fr) 72px 64px 96px 72px 30px; gap: 6px; align-items: start; margin-bottom: 8px; }
.pos.head { font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: 4px; }
.pos .hint { grid-column: 1 / -1; font-size: 12px; color: var(--muted); margin-top: -2px; }
.pos .hint.bad { color: var(--red); }
.pos .x { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 18px; padding: 6px 0; }
.pos .x:hover { color: var(--red); }
.addrow { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }

.totals { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.totals .big { font-size: 22px; font-weight: 900; }
.actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 18px 0 6px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.actions .btn.primary { flex: 1; min-width: 220px; }
.err-inline { color: var(--red); font-size: 13.5px; width: 100%; }

details.more { margin-top: 4px; }
details.more summary { cursor: pointer; font-weight: 500; }
table.kv { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 13.5px; }
table.kv td { padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.kv td:first-child { color: var(--muted); width: 38%; }

/* cennik */
.price-row { display: grid; grid-template-columns: minmax(0, 1fr) 90px 110px 40px; gap: 8px; margin-bottom: 8px; }
.price-row input { width: 100%; padding: 9px 10px; border: 1px solid #d9d6cd; border-radius: 8px; background: #fff; }

/* logowanie */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--bg); }
.login .card { width: 100%; max-width: 380px; padding: 26px; border-top: 5px solid var(--yellow); }
.login img { height: 56px; margin: 0 auto 14px; }
.login h1 { font-size: 20px; text-align: center; }
.login p { text-align: center; }
.login form { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 200; font-size: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.2); }

@media (max-width: 900px) {
  .grid-home, .grid-review { grid-template-columns: 1fr; }
  .doc { position: static; }
  .doc iframe { height: 60vh; }
  .how { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .top-in { flex-wrap: wrap; gap: 8px; }
  .top-in .logo { height: 34px; }
  .nav { order: 3; width: 100%; margin-left: 0; }
  .top-in .who span { display: none; }
  h1 { font-size: 22px; }
  .samples { grid-template-columns: repeat(3, 1fr); }
  .fields .f.s3, .fields .f.s2, .fields .f.s4 { grid-column: span 6; }
  .pos { grid-template-columns: 1fr 1fr 1fr 30px; }
  .pos .pn { grid-column: 1 / -1; }
  .pos .pv { display: none; }
  .pos.head { display: none; }
  .price-row { grid-template-columns: 1fr 70px 90px 30px; }
}

/* ---------- faktura (podgląd edytowalny) ---------- */
.grid-review { grid-template-columns: minmax(0, .76fr) minmax(0, 1.24fr); }
.invoice { background: #fff; border: 1px solid #e3e0d7; border-radius: 4px; box-shadow: 0 10px 34px rgba(0,0,0,.08); padding: 28px 30px 24px; font-size: 13px; line-height: 1.4; color: #111; position: relative; }
.invoice::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px; background: var(--yellow); border-radius: 4px 4px 0 0; }
.invoice input, .invoice select, .invoice textarea { font: inherit; color: inherit; background: transparent; border: 0; border-bottom: 1px dashed #d4cfbf; border-radius: 3px; padding: 2px 4px; width: 100%; min-width: 0; }
.invoice input:hover, .invoice select:hover, .invoice textarea:hover { background: var(--yellow-soft); }
.invoice input:focus, .invoice select:focus, .invoice textarea:focus { outline: 2px solid var(--yellow); background: #fff; border-bottom-color: transparent; }
.invoice input::placeholder { color: #b5b0a3; }
.invoice input.missing { background: var(--red-soft); border-bottom: 1px solid var(--red); }
.invoice.locked input, .invoice.locked select, .invoice.locked textarea { border-bottom-color: transparent; background: transparent; -webkit-appearance: none; appearance: none; color: #111; -webkit-text-fill-color: #111; opacity: 1; }
.invoice.locked input[type="date"]::-webkit-calendar-picker-indicator { display: none; }
.invoice textarea { resize: vertical; }
.inv-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.inv-logo { height: 44px; width: auto; }
.inv-dates { border-collapse: collapse; font-size: 12.5px; }
.inv-dates td { padding: 1px 0 1px 8px; white-space: nowrap; }
.inv-dates td:first-child { color: var(--muted); text-align: right; }
.inv-dates input { width: 132px; }
.inv-title { font-size: 21px; font-weight: 900; text-align: center; margin: 18px 0 14px; letter-spacing: -.01em; }
.inv-title span { display: block; font-size: 12.5px; font-weight: 400; color: var(--muted); margin-top: 2px; }
.inv-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 26px; border-top: 2px solid #111; border-bottom: 1px solid #e6e2d8; padding: 12px 0 14px; margin-bottom: 16px; }
.inv-parties .b, .inv-parties input.b { font-weight: 700; }
.inv-parties input { margin-bottom: 2px; }
.inv-lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 700; margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 22px; }
.inv-line { display: flex; align-items: center; gap: 6px; margin-bottom: 2px; }
.inv-line .pre { white-space: nowrap; color: var(--text-2); }
.inv-line .kod { width: 74px; flex: none; }
.inv-line .nip { width: 130px; flex: none; }
.inv-line .days { width: 56px; flex: none; text-align: right; }
.inv-line select { width: auto; }
.seg.sm { padding: 2px; }
.seg.sm button { padding: 2px 8px; font-size: 11px; text-transform: none; letter-spacing: 0; }
.linkbtn { border: 0; background: none; padding: 2px 4px; color: #6b5000; font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: underline; text-underline-offset: 2px; font-size: 12.5px; }
.linkbtn:hover { color: #111; }
.linkbtn:disabled { opacity: .6; cursor: default; }
.inv-table-wrap { overflow-x: auto; }
.inv-table { width: 100%; border-collapse: collapse; font-size: 12.5px; min-width: 560px; table-layout: fixed; }
.inv-table th:nth-child(3) { width: 56px; } .inv-table th:nth-child(4) { width: 46px; } .inv-table th:nth-child(5) { width: 78px; } .inv-table th:nth-child(6) { width: 58px; } .inv-table th:nth-child(7), .inv-table th:nth-child(8) { width: 80px; }
.inv-table th { background: #f4f3ef; font-weight: 500; font-size: 11.5px; text-align: left; padding: 6px 5px; border: 1px solid #e2dfd6; color: var(--text-2); }
.inv-table td { border: 1px solid #ebe8e0; padding: 4px 5px; vertical-align: top; }
.inv-table .num { text-align: right; white-space: nowrap; }
.inv-table td.num input, .inv-table td.num select { text-align: right; }
.inv-table .c-lp { width: 28px; text-align: center; color: var(--muted); }
.inv-table th { white-space: normal; line-height: 1.2; vertical-align: bottom; }
.inv-table .c-x { width: 24px; text-align: center; border-left: 0; }
.inv-table .c-net, .inv-table .c-gross { padding-top: 6px; }
.inv-table td input, .inv-table td select { width: 100%; }
.inv-table .hint { font-size: 11px; color: var(--muted); padding: 2px 4px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inv-table .hint.bad { color: var(--red); font-weight: 500; }
.inv-table .x { border: 0; background: transparent; color: #b5b0a3; cursor: pointer; font-size: 17px; line-height: 1; padding: 4px 0; }
.inv-table .x:hover { color: var(--red); }
.invoice .addrow { margin-top: 6px; }
.inv-bottom { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 20px; margin-top: 16px; align-items: start; }
.inv-sum { border-collapse: collapse; font-size: 12.5px; }
.inv-sum th { font-weight: 500; color: var(--muted); font-size: 11.5px; text-align: right; padding: 2px 8px; }
.inv-sum td { padding: 3px 8px; text-align: right; white-space: nowrap; }
.inv-sum td:first-child { color: var(--muted); text-align: left; }
.inv-sum tr.tot td { border-top: 1px solid #111; font-weight: 700; color: #111; }
.inv-pay-box { margin-top: 14px; padding: 10px 14px; background: var(--yellow-soft); border-radius: 4px; font-size: 15px; }
.inv-pay-box b { font-size: 19px; font-weight: 900; }
.inv-pay-box .small { color: var(--text-2); margin-top: 2px; }
.inv-notes { margin-top: 14px; }
.inv-notes textarea { border: 1px dashed #d4cfbf; min-height: 40px; }
.invoice.locked .inv-notes textarea { border-color: transparent; }
.inv-hint { margin: 8px 2px 0; }
@media (max-width: 900px) { .grid-review, .grid-home { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 560px) {
  .invoice { padding: 18px 14px; }
  .inv-top { flex-direction: column; }
  .inv-parties { grid-template-columns: 1fr; gap: 14px; }
  .inv-bottom { grid-template-columns: 1fr; }
}


/* aktywność */
.act-users { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.act-user.adm { opacity: .75; }
.act-name { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.act-dot { width: 10px; height: 10px; border-radius: 50%; background: #cfcbc0; margin-left: auto; }
.act-dot.on { background: #2fb35a; box-shadow: 0 0 0 4px rgba(47,179,90,.18); }
.act-grid { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.act-grid b { font-weight: 500; }
.act-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.act-table td { padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.act-table a { color: var(--ink); }
.nowrap { white-space: nowrap; }
@media (max-width: 560px) { .act-table td:first-child { font-size: 12px; } }
