:root {
  --bg: #f6f7f9;
  --fg: #14171a;
  --muted: #666e78;
  --line: #e2e5ea;
  --card: #fff;
  --accent: #111827;
  --ok: #067647;
  --warn: #92400e;
  --err: #b42318;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101215;
    --fg: #e8eaed;
    --muted: #9aa3ad;
    --line: #262b31;
    --card: #181b1f;
    --accent: #e8eaed;
    --ok: #4ade80;
    --warn: #fbbf24;
    --err: #f87171;
  }
}

* { box-sizing: border-box; }

/* The `nav { display: flex }` below overrode the `hidden` attribute (an author style beats the
   browser stylesheet), so the navigation was visible on the login screen too. We fix it with
   SPECIFICITY, not `!important`: `nav[hidden]` (0,1,1) beats `nav` (0,0,1).

   There is deliberately NO global `[hidden] { display: none !important }` here. Such a rule also
   beats an inline `style="display:…"`, so any third-party widget that reveals its element with an
   inline style without removing the `hidden` attribute would stay invisible forever — and we
   inject third-party code into the login page (Turnstile). The other elements carrying `hidden`
   in app.js have no `display` rule of their own, so the browser's default `[hidden]` suffices. */
nav[hidden] { display: none; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--card);
}
.brand { display: flex; align-items: center; text-decoration: none; }
.brand img { display: block; height: 30px; width: auto; }

/* The logo is black artwork on a transparent background (see scripts/prepare-logo.mjs).
   In dark mode we invert it to white — without the transparent background that would come out
   as a black rectangle. */
@media (prefers-color-scheme: dark) {
  .brand img,
  .login-logo { filter: invert(1); }
}

.login-logo { display: block; height: 56px; width: auto; margin: 0 0 20px; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
.navlink {
  background: none; border: 0; color: var(--fg); font: inherit; cursor: pointer;
  padding: 6px 10px; border-radius: 6px;
}
.navlink:hover { background: var(--bg); }
.navlink.active { background: var(--bg); font-weight: 600; }
.navlink.muted { color: var(--muted); }

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

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; margin-bottom: 16px;
}
h1 { font-size: 22px; margin: 0 0 6px; }
h2 { font-size: 16px; margin: 0 0 12px; }
p { margin: 0 0 12px; }
.lead { color: var(--muted); margin-bottom: 20px; }

label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
input[type=text], input[type=email], input[type=number], input[type=password], select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--fg); font: inherit;
}
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 200px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

button.primary, button.secondary, button.danger {
  font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 6px;
  cursor: pointer; border: 1px solid transparent;
}
button.primary { background: var(--accent); color: var(--card); }
button.secondary { background: transparent; color: var(--fg); border-color: var(--line); }
button.danger { background: transparent; color: var(--err); border-color: var(--err); }
button:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }

.status { padding: 10px 12px; border-radius: 6px; font-size: 14px; margin: 12px 0 0; }
.status.ok { background: color-mix(in srgb, var(--ok) 12%, transparent); color: var(--ok); }
.status.warn { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); }
.status.err { background: color-mix(in srgb, var(--err) 12%, transparent); color: var(--err); }
.status.busy { background: var(--bg); color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
     color: var(--muted); font-weight: 600; padding: 6px 8px 6px 0; }
td { padding: 9px 8px 9px 0; border-top: 1px solid var(--line); vertical-align: top; }
td.num, th.num { text-align: right; white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--muted); }

.pill { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 999px;
        border: 1px solid var(--line); color: var(--muted); }
.pill.ok { color: var(--ok); border-color: currentColor; }
.pill.err { color: var(--err); border-color: currentColor; }

.foot { max-width: 860px; margin: 0 auto; padding: 0 20px 30px; font-size: 12px; color: var(--muted); }
#env-badge { font-weight: 700; margin-right: 6px; }
.loading { color: var(--muted); }
.empty { color: var(--muted); padding: 20px 0; }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; }
details p { margin-top: 8px; font-size: 13px; }

/* The PDF cell now holds two actions — download, and refresh the visualisation. */
.pdf-cell { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }

/* A button that should look like a link, not like a box.
   `.navlink` is the NAVIGATION BAR style: it has padding and a hover background, so inside a
   table or a status message it stood out as a bright rectangle. What matters here is that the
   action sits next to the "Pobierz" link and is visually indistinguishable from it.
   `background: transparent` explicitly, not `none` — so there is no doubt about what the element
   inherits in either theme. */
.linkbtn {
  background: transparent; border: 0; padding: 0; margin: 0;
  color: var(--fg); font: inherit; cursor: pointer;
  text-decoration: underline; text-underline-offset: 2px;
}
.linkbtn:hover { color: var(--muted); }
.linkbtn:disabled { text-decoration: none; opacity: .5; cursor: not-allowed; }

/* --- invoice list ----------------------------------------------------------
   The list is the one view that is a table of money, so it gets the width: at 860px the
   counterparty column wrapped to four lines and the amounts were squeezed against the PDF cell. */
main.wide { max-width: 1240px; }

.muted { color: var(--muted); }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.spacer { flex: 1; }

.icon { width: 18px; height: 18px; flex: none; display: block; }
.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation-duration: 3s; } }

.inv-head { display: flex; align-items: center; justify-content: space-between; gap: 14px;
            flex-wrap: wrap; margin-bottom: 16px; }
.inv-head h1 { margin: 0; }
.inv-filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.chips { display: inline-flex; padding: 3px; gap: 2px; border: 1px solid var(--line);
         border-radius: 8px; background: var(--bg); }
.chip { font: inherit; font-size: 13px; padding: 5px 11px; border: 0; border-radius: 6px;
        background: transparent; color: var(--muted); cursor: pointer; }
.chip:hover { color: var(--fg); }
.chip.active { background: var(--card); color: var(--fg); font-weight: 600;
               box-shadow: 0 1px 2px rgb(0 0 0 / .12); }

.search-box { display: flex; align-items: center; gap: 8px; margin: 0; padding: 0 10px;
              border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
              color: var(--muted); min-width: 260px; }
.search-box:focus-within { border-color: var(--muted); }
.search-box .icon { width: 16px; height: 16px; }
.inv-search { border: 0; outline: 0; background: transparent; color: var(--fg); font: inherit;
              font-size: 14px; padding: 8px 0; width: 100%; }

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; background: var(--bg); }
.tile-label { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.tile-value { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.35; }

.inv-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px;
               font-size: 13px; }
button.sm { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; font-size: 13px; }
button.sm .icon { width: 16px; height: 16px; }

.table-wrap { border: 1px solid var(--line); border-radius: 8px; overflow: auto; }
.inv-table { font-size: 14px; }
.inv-table th { position: sticky; top: 0; background: var(--card); padding: 10px 12px;
                border-bottom: 1px solid var(--line); white-space: nowrap; }
.inv-table td { padding: 11px 12px; vertical-align: middle; font-variant-numeric: tabular-nums; }
.inv-table tbody tr:first-child td { border-top: 0; }
.inv-table tbody tr:hover td { background: color-mix(in srgb, var(--fg) 4%, transparent); }
.inv-table th.num, .inv-table td.num { text-align: right; white-space: nowrap; }
.inv-table th.center, .inv-table td.center { text-align: center; }

.cp { min-width: 240px; max-width: 420px; }
.cp-name { font-weight: 600; line-height: 1.35; }
.cp-meta { display: flex; align-items: center; gap: 6px; margin-top: 2px; font-size: 12px; color: var(--muted); }
.mono-num { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; white-space: nowrap; }

.pdf-cell { display: inline-flex; align-items: center; justify-content: center; gap: 4px; flex-wrap: nowrap; }
.iconbtn { display: inline-grid; place-items: center; width: 32px; height: 32px; padding: 0;
           border-radius: 7px; border: 1px solid var(--line); background: var(--card);
           color: var(--fg); cursor: pointer; text-decoration: none; }
.iconbtn:hover { background: var(--bg); }
.iconbtn:disabled { opacity: .6; cursor: progress; }
.iconbtn.primary-ic { background: var(--accent); border-color: var(--accent); color: var(--card); }
.iconbtn.primary-ic:hover { opacity: .85; }
.iconbtn.accent { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.iconbtn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.iconbtn.ghost:hover { color: var(--fg); background: var(--bg); }
.iconbtn.static { border-color: transparent; background: transparent; cursor: help; }
.iconbtn.static.err { color: var(--err); }
.iconbtn.static.muted { color: var(--muted); }
.iconbtn.xs { width: 22px; height: 22px; border-radius: 5px; }
.iconbtn.xs .icon { width: 13px; height: 13px; }
.pdf-cell > .spin { color: var(--muted); }

/* Phone: a seven-column money table does not fit, so each row becomes a card with labels. */
@media (max-width: 760px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile-value { font-size: 17px; }
  .search-box { min-width: 0; flex: 1 1 100%; }
  .table-wrap { border: 0; overflow: visible; }
  .inv-table thead { display: none; }
  .inv-table, .inv-table tbody, .inv-table tr, .inv-table td { display: block; width: 100%; }
  .inv-table tr { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; }
  .inv-table td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px;
                  text-align: right; max-width: none; }
  .inv-table td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: left; }
  .inv-table td.cp { display: block; text-align: left; padding-bottom: 6px; }
  .inv-table td.cp::before { content: none; }
  .inv-table td.center { justify-content: space-between; }
  .inv-table tbody tr:hover td { background: transparent; }
  .inv-table td.cp { min-width: 0; }
  .mono-num { white-space: normal; overflow-wrap: anywhere; }
  main.wide { padding-left: 12px; padding-right: 12px; }
  main.wide .card { padding: 16px 14px; }
}

/* The top bar did not wrap: on a phone the four nav buttons pushed the page wider than the
   viewport, and everything below scrolled sideways with it. */
@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; padding: 10px 12px; gap: 8px; }
  nav { width: 100%; justify-content: space-between; }
  .navlink { padding: 6px 8px; }
}
