:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --text: #17201e;
  --muted: #5f6b68;
  --line: #dde3e1;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --accent-soft: #e0f2ef;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --grey-soft: #eceff0;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1413;
    --surface: #182120;
    --text: #e7eeec;
    --muted: #9aa8a5;
    --line: #2a3533;
    --accent: #2dd4bf;
    --accent-text: #062b27;
    --accent-soft: #123a35;
    --ok: #4ade80;
    --ok-soft: #12321f;
    --warn: #fbbf24;
    --warn-soft: #3a2c0b;
    --danger: #f87171;
    --danger-soft: #3d1414;
    --grey-soft: #222c2a;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
#app { max-width: 720px; margin: 0 auto; padding: 0 16px; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }

/* nagłówek */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: calc(10px + env(safe-area-inset-top)) 0 8px; }
.bar { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.bar h1 { font-size: 22px; margin: 0; flex: 1; }
.bar h2 { font-size: 18px; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { border: 0; background: transparent; width: 44px; height: 44px; border-radius: 50%; display: inline-grid; place-items: center; cursor: pointer; color: var(--text); text-decoration: none; font-size: 22px; }
.icon-btn:active { background: var(--grey-soft); }
.link { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 8px; font-size: 14px; }
.search { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); font-size: 16px; }
.search:focus, .field input:focus, .field select:focus, .field textarea:focus, .tag-editor:focus-within { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

/* filtry */
.filters { display: flex; align-items: center; gap: 6px; overflow-x: auto; padding: 8px 0 4px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.pill { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 13px; font-size: 14px; cursor: pointer; white-space: nowrap; }
.pill[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.pill .n { opacity: .7; margin-left: 4px; }
.sep { flex: none; width: 1px; height: 22px; background: var(--line); margin: 0 2px; }

/* banery */
.banner { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: 12px; margin: 8px 0 0; font-size: 14px; cursor: pointer; border: 0; width: 100%; text-align: left; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.danger { background: var(--danger-soft); color: var(--danger); }
.banner b { font-weight: 600; }

/* lista */
.results { margin-top: 10px; display: grid; gap: 8px; }
.card { display: flex; gap: 12px; align-items: center; background: var(--surface); border-radius: var(--radius); padding: 10px; color: inherit; text-decoration: none; box-shadow: var(--shadow); min-width: 0; }
.thumb { flex: none; width: 58px; height: 74px; border-radius: 8px; background: var(--grey-soft); object-fit: cover; display: grid; place-items: center; font-size: 12px; font-weight: 600; color: var(--muted); overflow: hidden; }
.card-body { flex: 1; min-width: 0; }
.card-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.card .chips { flex-wrap: nowrap; overflow: hidden; }
.chip { font-size: 12px; background: var(--grey-soft); border-radius: 999px; padding: 2px 9px; white-space: nowrap; }
.chip.cat { background: var(--accent-soft); color: var(--accent); }
button.chip { border: 0; cursor: pointer; font-size: 13px; padding: 4px 11px; }
.badge { flex: none; font-size: 12px; padding: 4px 8px; border-radius: 8px; text-align: center; line-height: 1.25; max-width: 92px; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.off { background: var(--grey-soft); color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 48px 12px; }
.group { margin-top: 6px; }
.group > summary { list-style: none; cursor: pointer; padding: 10px 2px 6px; font-weight: 600; display: flex; justify-content: space-between; }
.group > summary::-webkit-details-marker { display: none; }
.group > summary .n { color: var(--muted); font-weight: 400; }
.group .results { margin-top: 0; }

/* przycisk dodawania */
.fab { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 10; display: inline-flex; align-items: center; gap: 10px; background: var(--accent); color: var(--accent-text); border: 0; border-radius: 999px; padding: 15px 26px; font-size: 17px; font-weight: 600; box-shadow: 0 6px 20px rgba(15,118,110,.35); text-decoration: none; cursor: pointer; white-space: nowrap; }
.fab svg { width: 22px; height: 22px; }

/* dodawanie i formularz */
.big-actions { display: grid; gap: 10px; margin-top: 16px; }
.big-btn { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 18px; border-radius: var(--radius); border: 0; background: var(--accent); color: var(--accent-text); font-size: 18px; font-weight: 600; cursor: pointer; }
.big-btn.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--line); font-weight: 500; font-size: 16px; }
.big-btn svg { width: 24px; height: 24px; }
.hidden-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.hint { color: var(--muted); font-size: 14px; margin: 14px 2px; }
.working { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 40px 0; color: var(--muted); text-align: center; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.pages { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px; }
.page { position: relative; flex: none; width: 84px; height: 110px; border-radius: 10px; overflow: hidden; background: var(--grey-soft); display: grid; place-items: center; font-weight: 600; color: var(--muted); }
.page img { width: 100%; height: 100%; object-fit: cover; }
.page .x { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; font-size: 15px; line-height: 1; }
.page-add { flex: none; width: 84px; height: 110px; border-radius: 10px; border: 1.5px dashed var(--line); background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; display: grid; place-items: center; text-align: center; }

.form { display: grid; gap: 14px; margin-top: 8px; }
.notice { padding: 10px 14px; border-radius: 12px; font-size: 14px; background: var(--accent-soft); color: var(--accent); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.field { display: grid; gap: 5px; min-width: 0; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 500; }
.field input, .field select, .field textarea { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-size: 16px; min-width: 0; }
.field textarea { min-height: 84px; resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row.money { grid-template-columns: 1fr 90px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-editor { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.tag-editor .chip { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; padding: 4px 6px 4px 11px; background: var(--accent-soft); color: var(--accent); }
.tag-editor .chip button { border: 0; background: none; color: inherit; cursor: pointer; font-size: 16px; line-height: 1; padding: 0 4px; }
.tag-editor input { flex: 1; min-width: 120px; border: 0; outline: 0; background: transparent; padding: 4px; font-size: 16px; }
details.more > summary { cursor: pointer; color: var(--muted); font-size: 14px; padding: 4px 0; }
details.more[open] { display: grid; gap: 14px; }
.actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 18px 0 calc(12px + env(safe-area-inset-bottom)); display: flex; gap: 10px; }
.btn { flex: 1; padding: 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; cursor: pointer; font-size: 16px; text-align: center; text-decoration: none; color: var(--text); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { color: var(--danger); border-color: var(--danger-soft); background: var(--surface); }
.btn:disabled { opacity: .55; }

/* szczegóły */
.doc-images { display: grid; gap: 8px; margin-top: 4px; }
.doc-images img { width: 100%; border-radius: 12px; background: var(--grey-soft); display: block; }
.pdf-link { display: flex; align-items: center; gap: 10px; padding: 16px; border-radius: 12px; background: var(--surface); text-decoration: none; font-weight: 600; }
.info { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px 14px; margin-top: 12px; }
.info-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.info-row:last-child { border-bottom: 0; }
.info-row > span:first-child { color: var(--muted); flex: none; }
.info-row > span:last-child { text-align: right; min-width: 0; overflow-wrap: anywhere; }
.section-title { font-size: 13px; color: var(--muted); font-weight: 600; margin: 18px 2px 6px; text-transform: uppercase; letter-spacing: .04em; }
.items { margin: 0; padding: 10px 14px 10px 32px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.items li { padding: 3px 0; }
.ocr { white-space: pre-wrap; font-size: 13px; color: var(--muted); background: var(--surface); border-radius: var(--radius); padding: 12px 14px; max-height: 320px; overflow: auto; }

/* usuwanie */
.check-card { display: flex; align-items: center; gap: 12px; }
.check-card input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }
.check-card .card { flex: 1; }

/* logowanie */
.login { max-width: 360px; margin: 12vh auto 0; display: grid; gap: 14px; }
.login h1 { margin: 0 0 6px; font-size: 28px; }
.login p { margin: 0; color: var(--muted); }

#toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 12px; font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
