:root {
  --bg: #0c0c0d; --panel: #17171a; --panel2: #202024; --line: #2c2c31;
  --fg: #f2f2f3; --muted: #9a9aa3; --accent: #ffb22e; --accent-fg: #1a1200;
  --ok: #4cd07d; --warn: #ffb22e; --err: #ff5f57;
  --st: env(safe-area-inset-top, 0px); --sb: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { overscroll-behavior: none; }
/* Jak w natywnej aplikacji: zaznaczanie tekstu i menu przytrzymania tylko w polach do wpisywania */
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input, textarea { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
html, body { touch-action: manipulation; }  /* bez powiekszania podwojnym stuknieciem */
/* 16px: przy mniejszej czcionce iOS powieksza strone po stuknieciu w pole */
input, textarea { font: inherit; font-size: 16px; color: var(--fg); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; width: 100%; outline: none; }
input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 90px; }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.err { color: var(--err); }
.grow { flex: 1; }

.view { position: fixed; inset: 0; display: flex; flex-direction: column; }
.page { overflow-y: auto; padding-bottom: calc(var(--sb) + 16px); }

/* --- przyciski */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line);
  background: var(--panel2); border-radius: 10px; padding: 10px 14px; }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--err); }
.btn:disabled { opacity: .5; }
.btn svg.i { width: 18px; height: 18px; }
.ibtn { display: inline-grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; padding: 0; }
.ibtn.sm { width: 32px; height: 32px; }
.ibtn.on { color: var(--accent); }

/* --- logowanie */
.login { margin: auto; width: min(340px, 88vw); display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login h1 { margin: 0; font-size: 26px; }
.login p { margin: 0 0 8px; }
.login-logo img { width: 84px; height: 84px; border-radius: 20px; }

/* --- aparat */
#v-camera { background: #000; }
#video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
#video.mirror { transform: scaleX(-1); }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .25s; }
.flash.go { opacity: .8; transition: none; }
.cam-msg { position: absolute; left: 24px; right: 24px; top: 40%; transform: translateY(-50%); text-align: center;
  background: rgba(23,23,26,.9); border-radius: 14px; padding: 18px; }
.cam-top { position: absolute; top: 0; left: 0; right: 0; padding: calc(var(--st) + 6px) 8px 6px; display: flex; align-items: center; gap: 4px;
  background: linear-gradient(rgba(0,0,0,.55), transparent); }
.cam-top .pill { margin-right: auto; }
.cam-top .ibtn { background: rgba(0,0,0,.35); }
.pill { display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 99px; padding: 6px 12px; font-size: 13px;
  background: rgba(0,0,0,.45); }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.ok .dot { background: var(--ok); }
.pill.busy .dot { background: var(--warn); animation: pulse 1s infinite; }
.pill.off .dot { background: var(--muted); }
.pill.bad { color: var(--err); } .pill.bad .dot { background: var(--err); }
@keyframes pulse { 50% { opacity: .3; } }
#b-gps.on { color: var(--ok); }
#b-gps.wait { color: var(--warn); }
.cam-bottom { position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 28px calc(var(--sb) + 22px);
  display: flex; align-items: center; justify-content: space-between; background: linear-gradient(transparent, rgba(0,0,0,.6)); }
.shutter { width: 76px; height: 76px; border-radius: 50%; border: 4px solid #fff; background: transparent; padding: 5px; }
.shutter span { display: block; width: 100%; height: 100%; border-radius: 50%; background: #fff; transition: transform .1s; }
.shutter:active span { transform: scale(.88); }
.shutter:disabled { opacity: .4; }
.last { width: 52px; height: 52px; border-radius: 12px; border: 2px solid rgba(255,255,255,.8); padding: 0; overflow: hidden; background: #222; }
.last img { width: 100%; height: 100%; object-fit: cover; display: block; }
.last img:not([src]), .last img[src=""] { visibility: hidden; }
.last.pop { animation: pop .35s; }
@keyframes pop { 40% { transform: scale(1.15); } }
.ibtn.big { width: 52px; height: 52px; background: rgba(0,0,0,.35); }
.ibtn.big svg.i { width: 26px; height: 26px; }

/* --- paski stron */
.bar { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 2px; padding: calc(var(--st) + 4px) 6px 4px;
  background: rgba(12,12,13,.92); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.bar h2 { flex: 1; margin: 0 6px; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar h2 small { font-size: 13px; font-weight: 400; }

/* --- galeria */
.search { display: flex; align-items: center; gap: 6px; margin: 4px 12px 8px; padding: 0 6px 0 12px; background: var(--panel2);
  border: 1px solid var(--line); border-radius: 12px; color: var(--muted); }
.search input { border: 0; background: transparent; padding: 10px 0; }
.chips { display: flex; gap: 6px; padding: 0 12px; }
.chips.scroll { overflow-x: auto; scrollbar-width: none; padding-bottom: 8px; }
.chips.wrap { flex-wrap: wrap; padding: 0; margin-bottom: 10px; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); background: var(--panel);
  border-radius: 99px; padding: 5px 11px; font-size: 13px; }
.chip.on { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.chip.ai { border-style: dashed; color: #d9c79f; }
.chip .x { opacity: .7; margin-left: 2px; }
.chip small { opacity: .6; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 3px; padding: 0 3px; }
.grid h4 { grid-column: 1 / -1; margin: 12px 9px 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
.tile { position: relative; aspect-ratio: 1; border: 0; padding: 0; background: var(--panel); overflow: hidden; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .badges { position: absolute; right: 4px; bottom: 4px; display: flex; gap: 3px; }
.tile .badges span { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: rgba(0,0,0,.6); }
.tile .badges svg.i { width: 13px; height: 13px; stroke-width: 2.2; }
.tile .badges .ai-run { color: var(--accent); animation: pulse 1.2s infinite; }
.tile .badges .ai-err { color: var(--err); }
.tile .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 6px 4px; font-size: 11px; line-height: 1.25; text-align: left;
  background: linear-gradient(transparent, rgba(0,0,0,.75)); max-height: 3.6em; overflow: hidden; }
.tile.sel::after { content: ""; position: absolute; inset: 0; border: 3px solid var(--accent); background: rgba(255,178,46,.18); }
.tile .tick { position: absolute; top: 5px; left: 5px; width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; background: rgba(0,0,0,.3); }
.tile.sel .tick { background: var(--accent); border-color: var(--accent); }
.empty { text-align: center; padding: 40px 24px; }
.selbar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 8px;
  padding: 10px 12px calc(var(--sb) + 10px); background: var(--panel); border-top: 1px solid var(--line); }

/* --- szczegoly */
.detail, .settings { display: flex; flex-direction: column; gap: 12px; padding: 0 12px; max-width: 760px; width: 100%; margin: 0 auto; }
.photo { margin: 0 -12px; background: #000; display: grid; place-items: center; min-height: 200px; }
.photo img { max-width: 100%; max-height: 70vh; display: block; -webkit-user-drag: none; will-change: transform; }
.photo { touch-action: pan-y; overflow: hidden; }  /* poziome gesty obsluguje aplikacja (poprzednie/nastepne zdjecie) */
#d-pos { flex: none; margin-right: 4px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.card h3 { margin: 0; font-size: 14px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.card h3 small { text-transform: none; letter-spacing: 0; font-weight: 400; }
.ai h4 { margin: 0; font-size: 18px; }
.ai p { margin: 0; white-space: pre-wrap; }
.ai .head { display: flex; align-items: center; gap: 8px; color: var(--accent); }
.ai .head h3 { flex: 1; color: var(--accent); }
.ai .wait { color: var(--muted); display: flex; align-items: center; gap: 8px; }
.ai .wait svg { animation: pulse 1.2s infinite; color: var(--accent); }
.info dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; }
.info dt { color: var(--muted); }
.info dd { margin: 0; word-break: break-word; }
.info a { color: var(--accent); }
.settings .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.settings .row input { width: 22px; height: 22px; accent-color: var(--accent); }
.settings p { margin: 0; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }

.toast { position: fixed; left: 50%; bottom: calc(var(--sb) + 215px); transform: translateX(-50%); max-width: 88vw; z-index: 10;
  background: rgba(32,32,36,.96); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; text-align: center; }

.viewer { position: fixed; inset: 0; z-index: 20; background: #000; display: grid; place-items: center; overflow: auto; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* --- albumy */
.album-chip { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--sb) + 120px); z-index: 2;
  display: inline-flex; align-items: center; gap: 6px; max-width: 70vw; border: 0; border-radius: 99px; padding: 7px 14px;
  background: rgba(0,0,0,.5); font-size: 14px; }
.album-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.album-chip svg.i { width: 18px; height: 18px; flex: none; }
.album-chip.on { background: var(--accent); color: var(--accent-fg); font-weight: 600; }
.chip svg.i { width: 15px; height: 15px; }
#g-albums { padding-bottom: 6px; }
.album-row { flex-direction: row; align-items: center; gap: 10px; color: var(--fg); text-align: left; padding: 12px 14px; }
.album-row > span:first-of-type { flex: 1; font-weight: 600; }
.album-row svg.i { color: var(--accent); }
.sheet-wrap { position: fixed; inset: 0; z-index: 15; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; max-height: 80vh; display: flex; flex-direction: column; background: var(--panel);
  border-radius: 18px 18px 0 0; border: 1px solid var(--line); padding: 10px 14px calc(var(--sb) + 14px); }
.sheet-head { display: flex; align-items: center; }
.sheet-head h3 { flex: 1; margin: 6px 0; font-size: 16px; }
.sheet-list { overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 4px 0 10px; }
.sheet-list p { margin: 8px 4px; }
.srow { display: flex; align-items: center; border-radius: 10px; }
.srow.on { background: var(--panel2); }
.srow.on .pick span { color: var(--accent); font-weight: 600; }
.srow .pick { flex: 1; display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 12px 8px; text-align: left; min-width: 0; }
.srow .pick span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-new { display: flex; gap: 8px; }
.sheet-new input { flex: 1; }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
#b-light.on { color: #ffd84a; }
/* --- obiektywy */
.lens-bar { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--sb) + 166px); z-index: 2;
  display: flex; align-items: center; gap: 6px; padding: 4px; border-radius: 99px; background: rgba(0,0,0,.4); }
.lens-bar button { min-width: 38px; height: 38px; border-radius: 99px; border: 0; background: rgba(255,255,255,.12); font-size: 13px; font-weight: 600; padding: 0 8px; }
.lens-bar button.on { background: rgba(0,0,0,.6); color: #ffd84a; font-size: 14px; }
.lens-val { padding: 0 8px; color: #ffd84a; font-weight: 600; font-size: 14px; }
