/* Faktury Online – arkusz stylów */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1d2433;
  --muted: #6b7486;
  --line: #e1e5ec;
  --accent: #1f5fbf;
  --accent-soft: #e8f0fc;
  --ok: #1e7b4a; --ok-bg: #e5f5ec;
  --warn: #8a5a00; --warn-bg: #fff4dc;
  --err: #b42318; --err-bg: #fdeceb;
  --info: #1f5fbf; --info-bg: #e8f0fc;
  --radius: 8px;
  font-size: 14px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 1rem/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.2rem 0 .6rem; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
code { background: #eef1f5; padding: 0 .3em; border-radius: 4px; }

/* układ: zakładki u góry jak w Faktury Ekspress */
.topbar { display: flex; align-items: stretch; gap: 1rem; background: linear-gradient(#ffffff, #eef2f7); border-bottom: 1px solid #c9d2df; padding: 0 1rem; position: sticky; top: 0; z-index: 40; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.05rem; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand.center { justify-content: center; color: var(--text); margin-bottom: 1rem; }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 7px; background: #d7262e; color: #fff; font-weight: 800; }
.tabs { display: flex; align-items: flex-end; gap: 2px; flex: 1; overflow-x: auto; padding-top: .45rem; scrollbar-width: none; }
.tab { display: flex; align-items: center; gap: .45rem; padding: .55rem .95rem; color: var(--text); border: 1px solid transparent; border-bottom: 0; border-radius: 7px 7px 0 0; white-space: nowrap; font-weight: 500; }
.tab .ico { color: var(--accent); }
.tab:hover { background: #e3eaf4; text-decoration: none; }
.tab.active { background: var(--bg); border-color: #c9d2df; margin-bottom: -1px; padding-bottom: calc(.55rem + 1px); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: .6rem; white-space: nowrap; }
.topbar-right form { margin: 0; }
.pill { font-size: .78rem; font-weight: 700; padding: .2rem .55rem; border-radius: 99px; background: var(--accent); color: #fff; text-transform: uppercase; }
.pill:hover { text-decoration: none; background: #2a6fd6; }
.user { display: flex; align-items: center; gap: .3rem; color: var(--text); }
.iconbtn { display: inline-grid; place-items: center; background: none; border: 1px solid transparent; border-radius: 6px; padding: .3rem; color: var(--muted); cursor: pointer; }
.iconbtn:hover { background: #e3eaf4; color: var(--text); }
.ico { flex: none; vertical-align: middle; }
.subtabs { display: flex; gap: .25rem; padding: .5rem 1.25rem 0; overflow-x: auto; }
.subtabs a { padding: .35rem .8rem; border: 1px solid var(--line); border-bottom: 0; border-radius: 6px 6px 0 0; background: #e9edf3; color: var(--text); white-space: nowrap; font-size: .92rem; }
.subtabs a.active { background: var(--surface); font-weight: 600; }
.subtabs a:hover { text-decoration: none; background: #f6f8fb; }
.main { padding: 1rem 1.25rem 3rem; max-width: 1600px; }

/* bloki */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1rem; }
.narrow { max-width: 640px; }
.head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .75rem; margin-bottom: 1rem; }
.head h1 { margin: 0; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.stack { display: flex; flex-direction: column; gap: .75rem; }
.grid2, .grid3, .grid4 { display: grid; gap: .75rem 1rem; margin-bottom: .5rem; }
.grid2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }
.muted, .dim { color: var(--muted); }
.r { text-align: right; }
.note { background: var(--warn-bg); padding: .5rem .75rem; border-radius: 6px; }
.inline { display: inline-flex; gap: .4rem; align-items: center; margin: 0; }

/* formularze */
label { display: flex; flex-direction: column; gap: .25rem; font-size: .88rem; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: .45rem; color: var(--text); }
input, select, textarea { font: inherit; color: var(--text); background: #fff; border: 1px solid #c9d0db; border-radius: 6px; padding: .45rem .55rem; width: 100%; min-width: 0; }
input[type=checkbox], input[type=radio] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[readonly], .readonly { background: #f2f4f7; }
.error { color: var(--err); font-size: .82rem; }
label:has(.error) input, label:has(.error) select { border-color: var(--err); }
.btn { display: inline-flex; align-items: center; gap: .3rem; font: inherit; font-weight: 500; padding: .45rem .9rem; border-radius: 6px; border: 1px solid #c9d0db; background: #fff; color: var(--text); cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f2f4f7; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #2a6fd6; }
.btn.danger { background: #fff; border-color: var(--err); color: var(--err); }
.btn.danger:hover { background: var(--err-bg); }
.btn.small { padding: .25rem .6rem; font-size: .85rem; }
.btn:disabled { opacity: .6; cursor: progress; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.linkbtn:hover { text-decoration: underline; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; margin-bottom: 1rem; }
.filters label { min-width: 140px; }
.filters label:first-child { flex: 1; min-width: 200px; }
.sticky-actions { position: sticky; bottom: 0; background: rgba(244,246,249,.95); padding: .75rem 0; display: flex; gap: .5rem; border-top: 1px solid var(--line); z-index: 5; }
.danger-zone { margin-top: 2rem; padding-top: 1rem; border-top: 1px dashed var(--line); display: flex; gap: .75rem; align-items: center; }

/* komunikaty i plakietki */
.flash { padding: .65rem .9rem; border-radius: 6px; margin-bottom: 1rem; border: 1px solid transparent; }
.flash.ok { background: var(--ok-bg); color: var(--ok); border-color: #bfe5cf; }
.flash.err { background: var(--err-bg); color: var(--err); border-color: #f5c6c2; }
.flash.warn { background: var(--warn-bg); color: var(--warn); border-color: #f1dca8; }
.flash.info { background: var(--info-bg); color: var(--info); border-color: #c8daf6; }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 99px; font-size: .78rem; font-weight: 600; background: #eef1f5; color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.err { background: var(--err-bg); color: var(--err); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.muted { background: #eef1f5; color: var(--muted); }
.statusbar { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem 1rem; margin-bottom: 1rem; }
.statusbar input[type=date] { width: auto; padding: .2rem .4rem; }

/* tabele */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1rem; }
.table { width: 100%; border-collapse: collapse; background: var(--surface); }
.table th, .table td { padding: .5rem .65rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th.r, .table td.r { text-align: right; }
.table thead th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #f8f9fb; white-space: nowrap; }
.table tbody tr:hover { background: #f8fafd; }
.table tfoot th { border-bottom: 0; border-top: 2px solid var(--line); }
.table td.r, .table th.r { font-variant-numeric: tabular-nums; white-space: nowrap; }
.table.compact th, .table.compact td { padding: .3rem .5rem; }
.card .table, .grid2 > .table { border: 1px solid var(--line); border-radius: 6px; }
.table.items td { padding: .3rem; vertical-align: middle; }
.table.items input, .table.items select { padding: .35rem .4rem; }
.table.items .lp { color: var(--muted); text-align: center; width: 2.5rem; }
.table.items .w-name { min-width: 240px; width: 34%; }
.table.items .i-qty, .table.items .i-disc { width: 5.5rem; }
.table.items .i-unit { width: 5rem; }
.table.items .i-price { width: 7.5rem; }
.table.items .i-vat { width: 6.5rem; }
.table.items .del-row { border: 0; background: none; color: var(--err); font-size: 1.2rem; cursor: pointer; }
.summary-wrap { display: flex; justify-content: flex-end; margin: 1rem 0; }
.summary-wrap .summary { max-width: 480px; }
.pager { display: flex; gap: .3rem; flex-wrap: wrap; margin: 1rem 0; }
.pager a, .pager span { padding: .3rem .65rem; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.pager .active, .pager span.current { background: var(--accent); color: #fff; border-color: var(--accent); }

/* pulpit */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem 1rem; }
.kpi-label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.kpi-value { font-size: 1.45rem; font-weight: 700; margin-top: .15rem; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: .82rem; color: var(--muted); }
.kpi.alert { border-color: #f5c6c2; background: var(--err-bg); }
.delta.up { color: var(--ok); }
.delta.down { color: var(--err); }

/* podpowiedzi */
.autocomplete { position: relative; }
.ac-list { display: none; position: absolute; left: 0; right: 0; top: 100%; z-index: 20; background: #fff; border: 1px solid #c9d0db; border-radius: 6px; box-shadow: 0 6px 18px rgba(20,30,50,.15); max-height: 280px; overflow-y: auto; min-width: 280px; }
.ac-list.open { display: block; }
.ac-item { padding: .45rem .65rem; cursor: pointer; font-size: .9rem; color: var(--text); }
.ac-item small { color: var(--muted); display: block; }
.ac-item:hover, .ac-item.active { background: var(--accent-soft); }

/* strona logowania / instalacji */
body.guest { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.guest-box { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 1.75rem; box-shadow: 0 10px 30px rgba(20,30,50,.07); }
.guest-box.wide { max-width: 760px; }
.center { text-align: center; }

details summary { cursor: pointer; color: var(--accent); margin: .5rem 0; }

@media (max-width: 1100px) {
  .grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .topbar { padding: 0 .5rem; gap: .5rem; }
  .brand-name, .user span, .tab span, .pill { display: none; }
  .tab { padding: .55rem .7rem; }
  .main { padding: 1rem .75rem; }
  .grid2, .grid3, .grid4 { grid-template-columns: minmax(0, 1fr); }
  .span2, .span3 { grid-column: auto; }
}
@media print {
  .topbar, .subtabs, .btn, .noprint, .sticky-actions { display: none !important; }
  .main { padding: 0; }
  body { background: #fff; }
}
.nw, .table td:first-child a { white-space: nowrap; }
.grid2 > .card, .grid3 > .card { min-width: 0; overflow-x: auto; }

/* lista faktur (układ jak w Faktury Ekspress) */
.doc-tabs { display: flex; gap: 2px; border-bottom: 1px solid #c9d2df; margin-bottom: .5rem; overflow-x: auto; }
.doc-tabs a { padding: .4rem .9rem; border: 1px solid transparent; border-bottom: 0; border-radius: 6px 6px 0 0; color: var(--text); white-space: nowrap; }
.doc-tabs a:hover { background: #e3eaf4; text-decoration: none; }
.doc-tabs a.active { background: var(--surface); border-color: #c9d2df; margin-bottom: -1px; font-weight: 600; }
.ex-top { display: grid; grid-template-columns: minmax(0, 1fr) 190px; gap: .6rem; }
.ex-list { background: var(--surface); border: 1px solid #c9d2df; border-radius: 6px; max-height: 48vh; min-height: 220px; overflow: auto; }
.ex-side { display: flex; flex-direction: column; gap: .4rem; }
.ex-side .btn { justify-content: center; }
.grid-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.grid-table th { position: sticky; top: 0; z-index: 1; background: #f3f6fa; color: #2457a6; font-weight: 600; text-align: left; padding: .35rem .5rem; border-bottom: 1px solid #c9d2df; white-space: nowrap; }
.grid-table td { padding: .28rem .5rem; border-bottom: 1px solid #edf0f4; }
.grid-table .r { text-align: right; white-space: nowrap; }
.grid-table td.ellipsis { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid-table.selectable tbody tr { cursor: default; }
.grid-table.selectable tbody tr:hover { background: #f1f6fd; }
.grid-table tbody tr.overdue td, .grid-table tbody tr.overdue a { color: #c8102e; }
.grid-table tbody tr.selected td { background: #cfe3fb; font-weight: 600; }
.grid-table tbody tr.selected td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.ex-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.25rem; padding: .5rem .25rem; }
.pager-mini { display: flex; align-items: center; gap: .15rem; }
.pager-mini .iconbtn { color: var(--accent); font-size: .95rem; text-decoration: none; }
.paid-toggle { font-size: 1rem; }
.left-info strong.neg { color: #c8102e; }
.ex-toolbar .sums { margin-left: auto; }
.ex-filters { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: .6rem; margin-bottom: .6rem; }
.ex-filters fieldset { border: 1px solid #c9d2df; border-radius: 6px; padding: .4rem .75rem .6rem; margin: 0; background: var(--surface); min-width: 0; }
.ex-filters legend { padding: 0 .3rem; font-weight: 600; font-size: .9rem; }
.ex-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .5rem; }
.ex-checks { display: flex; flex-wrap: wrap; gap: .3rem 1.2rem; margin-top: .5rem; }
.ex-search .row { margin-bottom: .45rem; }
.row.nowrap { flex-wrap: nowrap; }
.ex-items { background: var(--surface); border: 1px solid #c9d2df; border-radius: 6px; max-height: 32vh; overflow: auto; margin-bottom: .6rem; }
.ex-items > p { padding: .6rem .75rem; margin: 0; }
.ex-actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.ex-actions .spacer { flex: 1; }
.btn.disabled { opacity: .45; pointer-events: none; }
.btn .ico { color: var(--accent); }
.btn.primary .ico { color: #fff; }
@media (max-width: 1100px) {
  .ex-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ex-filters { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .ex-top { grid-template-columns: minmax(0, 1fr); }
  .ex-side { flex-direction: row; flex-wrap: wrap; }
  .ex-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ex-toolbar .sums { margin-left: 0; }
}

/* formularz „Wystaw” (układ jak w Faktury Ekspress) */
.wy-title { font-size: 1.2rem; margin-bottom: .6rem; }
.panel { background: var(--surface); border: 1px solid #c9d2df; border-radius: 6px; padding: .7rem .85rem; display: flex; flex-direction: column; gap: .55rem; min-width: 0; }
.panel h3 { margin: 0; font-size: .95rem; }
.wy-top { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr) minmax(0, .7fr); gap: .6rem; margin-bottom: .6rem; align-items: start; }
.wy-row { display: flex; gap: .5rem; align-items: flex-end; }
.wy-row.tight { gap: .3rem; align-items: center; }
.wy-row .grow, .grow { flex: 1; min-width: 0; }
.wy-row label:not(.grow) { width: 9.5rem; }
input.strong { font-weight: 700; font-size: 1.05rem; }
.btn.gus { font-weight: 800; letter-spacing: .02em; }
.btn.icon-only { padding: .45rem .5rem; }
.buyer-box { border: 1px dashed #c9d2df; border-radius: 6px; padding: .35rem .6rem; background: #fafbfd; }
.buyer-box summary { color: var(--text); font-weight: 600; margin: .15rem 0; }
.buyer-box[open] summary { margin-bottom: .5rem; }
.buyer-box .grid4 { margin-bottom: .4rem; }
.panel .checks { display: flex; flex-direction: column; gap: .35rem; margin-top: .2rem; }
.items-panel { padding: 0; }
.items-panel .table-wrap { border: 0; margin: 0; max-height: 50vh; overflow: auto; }
.items-panel .error { padding: .4rem .7rem 0; }
.table.items.grid-table th { font-size: .85rem; text-transform: none; letter-spacing: 0; }
.table.items .i-pkwiu { width: 6rem; }
.table.items td.r { min-width: 6rem; }
.wy-actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin: .6rem 0; position: sticky; bottom: 0; background: rgba(244,246,249,.96); padding: .45rem 0; z-index: 5; border-top: 1px solid var(--line); }
.wy-actions .spacer { flex: 1; }
.wy-bottom { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, .9fr) minmax(0, 1.3fr); gap: .6rem; align-items: start; }
.totals { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .5rem; }
.totals > div { display: flex; flex-direction: column; gap: .15rem; font-size: .82rem; color: var(--muted); text-align: right; }
.totals strong { font-size: 1.05rem; color: var(--text); border: 1px solid #c9d2df; border-radius: 5px; padding: .3rem .5rem; background: #fafbfd; font-variant-numeric: tabular-nums; min-height: 2.1rem; }
.totals .big strong { font-size: 1.2rem; }
.totals input { text-align: right; }
.small { font-size: .8rem; margin: .3rem 0 0; }
@media (max-width: 1200px) {
  .wy-top { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .wy-bottom { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .wy-bottom > .panel:last-child { grid-column: span 2; }
}
@media (max-width: 860px) {
  .wy-top, .wy-bottom { grid-template-columns: minmax(0, 1fr); }
  .wy-bottom > .panel:last-child { grid-column: auto; }
  .totals { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
