:root {
  --bg: #f4f6f8; --card: #ffffff; --text: #161b22; --muted: #667085; --line: #e4e7ec;
  --accent: #0f9d8a; --on-accent: #ffffff;
  --fuel: #e08600; --charge: #1d8fe1; --cost: #7c5cd6;
  --good: #1a9d57; --bad: #d6453d; --field: #f0f2f5;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1318; --card: #1a2028; --text: #eef1f5; --muted: #9aa4b2; --line: #2a323d;
    --accent: #2dd4bf; --on-accent: #06312c;
    --fuel: #fbbf24; --charge: #4cb4ff; --cost: #a78bfa;
    --good: #4ade80; --bad: #f87171; --field: #232b35;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
#app { max-width: 640px; margin: 0 auto; padding: 0 16px calc(150px + env(safe-area-inset-bottom)); }
a { color: inherit; text-decoration: none; }
h1, h2 { margin: 0; }
small { color: var(--muted); }
.muted { color: var(--muted); margin: 6px 0 0; font-size: .92rem; }
svg { width: 24px; height: 24px; flex: none; }

/* Nagłówek */
.top { display: flex; align-items: center; gap: 8px; padding: calc(14px + env(safe-area-inset-top)) 0 10px; }
.top h1 { font-size: 1.5rem; font-weight: 700; }
.ico-btn { display: grid; place-items: center; width: 40px; height: 40px; margin-left: -8px; border-radius: 50%; }
.ico-btn:active { background: var(--field); }

/* Karta pojazdu */
.vcard {
  position: relative; display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
}
.vcard b { display: block; font-size: 1.1rem; }
.vcard .chev { margin-left: auto; color: var(--muted); }
.vcard select { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; font-size: 16px; }
.vico {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent);
}
.vsmall { color: var(--muted); margin: 0 0 12px; }

/* Karty i statystyki */
.card {
  margin-top: 14px; padding: 14px 16px; background: var(--card);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
}
.card h2 { font-size: 1rem; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
.big { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.big small { font-size: 1rem; font-weight: 500; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0 4px; }
.kpis div span { display: block; font-size: .8rem; color: var(--muted); }
.kpis div b { font-size: 1.05rem; }
.good { color: var(--good); } .bad { color: var(--bad); }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.cols h3 { margin: 0 0 4px; font-size: .85rem; font-weight: 600; color: var(--muted); }
.cols .tot { font-size: 1.3rem; font-weight: 700; margin-bottom: 4px; }
.line { display: flex; justify-content: space-between; font-size: .92rem; padding: 2px 0; }
.line span:first-child { color: var(--muted); }
.stat { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.stat:last-child { border-bottom: 0; }
.stat span { color: var(--muted); }
.stat b { text-align: right; }

/* Wykresy */
.chart { width: 100%; height: auto; margin-top: 8px; overflow: visible; }
.chart .area { fill: currentColor; opacity: .12; }
.chart .ln { fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .avg { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; }
.chart .dot { fill: currentColor; }
.chart text { fill: var(--muted); font-size: 10px; }
.legend { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); margin-top: 4px; }
.c-fuel { color: var(--fuel); } .c-charge { color: var(--charge); } .c-cost { color: var(--cost); }
.mb-f { fill: var(--fuel); } .mb-c { fill: var(--charge); } .mb-o { fill: var(--cost); }

/* Paski podziału */
.bar { margin: 10px 0; }
.bar-h { display: flex; justify-content: space-between; font-size: .9rem; margin-bottom: 4px; }
.bar-t { height: 8px; border-radius: 4px; background: var(--field); overflow: hidden; }
.bar-t i { display: block; height: 100%; background: var(--charge); border-radius: 4px; }

/* Lista wpisów */
.sec { margin: 20px 4px 6px; font-size: .85rem; font-weight: 600; color: var(--muted); text-transform: capitalize; }
.list { background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item:active { background: var(--field); }
.cico {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; flex: none;
  background: color-mix(in srgb, currentColor 16%, transparent);
}
.cico.fuel { color: var(--fuel); } .cico.charge { color: var(--charge); } .cico.cost { color: var(--cost); }
.item .mid { flex: 1; min-width: 0; }
.item .mid b { display: block; }
.item .mid small { display: block; }
.item .right { text-align: right; }
.item .right b { display: block; white-space: nowrap; }
.empty { margin-top: 14px; padding: 28px 16px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--text); font-size: 1.1rem; margin-bottom: 6px; }

/* Wybór rodzaju wpisu */
.choice {
  display: flex; align-items: center; gap: 14px; padding: 16px; margin-top: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
}
.choice:active { background: var(--field); }
.choice b { display: block; font-size: 1.1rem; }
.choice .cico { width: 48px; height: 48px; }

/* Zakładki statystyk */
.seg { display: flex; gap: 6px; padding: 4px; margin-top: 8px; background: var(--field); border-radius: 12px; }
.seg button {
  flex: 1; padding: 9px 6px; border: 0; border-radius: 9px; background: transparent;
  color: var(--muted); font: inherit; font-weight: 600; cursor: pointer;
}
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

/* Formularze */
form.entry { display: flex; flex-direction: column; gap: 12px; margin-top: 4px; }
.fld { display: block; }
.fld > span { display: block; margin: 0 0 4px 2px; font-size: .85rem; color: var(--muted); }
.fld input, .fld select {
  width: 100%; min-height: 48px; padding: 10px 12px; font: inherit; font-size: 16px; color: var(--text);
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; appearance: none;
}
.fld input:focus, .fld select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.fld select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 21px, calc(100% - 15px) 21px; background-size: 5px 5px; background-repeat: no-repeat;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sw {
  position: relative; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; cursor: pointer;
}
.sw small { display: block; }
.sw input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.sw i { position: relative; flex: none; width: 46px; height: 28px; border-radius: 14px; background: var(--line); transition: background .15s; }
.sw i::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .15s;
}
.sw input:checked + i { background: var(--accent); }
.sw input:checked + i::after { transform: translateX(18px); }
.sw input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }
form[data-type="ice"] .only-ev, form[data-type="bev"] .only-fuel { display: none; }
.btn {
  min-height: 48px; padding: 12px 18px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--text); font: inherit; font-weight: 600; text-align: center; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--bad); }
.btn:active { filter: brightness(.92); }
.btns { display: grid; gap: 10px; margin-top: 12px; }
.note { font-size: .85rem; color: var(--muted); margin: 10px 2px 0; }

/* Dolna nawigacja i przycisk dodawania */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs div { display: flex; max-width: 640px; margin: 0 auto; }
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 7px;
  font-size: .72rem; font-weight: 600; color: var(--muted);
}
.tabs a.on { color: var(--accent); }
.fab {
  position: fixed; z-index: 6; right: max(16px, calc(50% - 304px));
  bottom: calc(78px + env(safe-area-inset-bottom)); width: 58px; height: 58px; border-radius: 18px;
  display: grid; place-items: center; background: var(--accent); color: var(--on-accent);
  box-shadow: 0 6px 16px rgba(0, 0, 0, .28);
}
.fab:active { transform: scale(.96); }
.fab svg { width: 28px; height: 28px; }

#toast {
  position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); z-index: 10;
  transform: translate(-50%, 12px); max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px;
  background: #222a33; color: #fff; font-size: .92rem; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Zdjęcia dokumentów i odczyt paragonów */
.scan { padding: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.scan-title { font-weight: 700; margin-bottom: 4px; }
.scan .btn { min-height: 44px; padding: 8px 10px; font-size: .95rem; }
.scan .btn svg { width: 20px; height: 20px; }
#scan-status:empty { display: none; }
#scan-status.ok { color: var(--good); }
#scan-status.warn { color: var(--fuel); }
#scan-status.bad { color: var(--bad); }
.thumbs { display: flex; flex-wrap: wrap; gap: 10px; }
.thumbs:not(:empty) { margin-top: 12px; }
.thumb { position: relative; width: 86px; height: 86px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); cursor: zoom-in; }
.thumb-x {
  position: absolute; top: -8px; right: -8px; width: 26px; height: 26px; padding: 0; border: 0; border-radius: 50%;
  background: var(--bad); color: #fff; font-size: 18px; line-height: 26px; cursor: pointer;
}
.fld input.filled, .fld select.filled { outline: 2px solid var(--accent); outline-offset: -1px; }
.item .right .clip { display: block; color: var(--muted); margin-top: 2px; }
.item .right .clip svg { width: 16px; height: 16px; }
.viewer {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(0, 0, 0, .92); padding: 16px;
}
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }
.viewer button {
  position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 14px; width: 44px; height: 44px; border: 0;
  border-radius: 50%; background: rgba(255, 255, 255, .2); color: #fff; font-size: 28px; cursor: pointer;
}
