/* Przeglądy – mobile first */
:root {
    --bg: #f3f5f8;
    --card: #fff;
    --text: #17202b;
    --muted: #647082;
    --line: #dde2ea;
    --primary: #1d4ed8;
    --primary-dark: #1a41b4;
    --danger: #c62828;
    --ok: #15803d;
    --radius: 14px;
    --bar-h: 76px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

/* ---------- górna belka ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--primary);
    color: #fff;
    padding-top: env(safe-area-inset-top);
}
.topbar-in {
    max-width: 680px;
    margin: 0 auto;
    min-height: 54px;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
}
.topbar h1 {
    flex: 1;
    margin: 0;
    padding: 0 8px;
    font-size: 18px;
    font-weight: 650;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.topbar form { margin: 0; }
.topbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    height: 44px;
    border: 0;
    border-radius: 10px;
    background: none;
    color: #fff;
    font: inherit;
    cursor: pointer;
}
.topbar-btn:active { background: rgba(255, 255, 255, .18); }
.topbar-text { padding: 0 10px; font-size: 15px; }

/* ---------- strona ---------- */
.page {
    max-width: 680px;
    margin: 0 auto;
    padding: 14px max(14px, env(safe-area-inset-right)) calc(var(--bar-h) + 24px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 14px;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .06);
}
.card h2 {
    margin: 0 0 12px;
    font-size: 16px;
    font-weight: 650;
    display: flex;
    align-items: center;
    gap: 8px;
}
.count {
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    background: var(--bg);
    border-radius: 999px;
    padding: 1px 9px;
}
.hint { margin: 0; color: var(--muted); font-size: 14.5px; }
.prose { margin: 0; overflow-wrap: anywhere; }

.flash {
    background: #e7f6ec;
    color: #14532d;
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 14px;
    font-weight: 550;
}

.empty { text-align: center; color: var(--muted); padding: 56px 16px; }
.empty .btn { margin-top: 8px; }

/* ---------- formularze ---------- */
.field { display: block; margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field > span { display: block; margin-bottom: 6px; font-size: 14.5px; font-weight: 600; }
.field small { font-weight: 400; color: var(--muted); }

input[type="text"], input[type="date"], input[type="password"], select, textarea {
    display: block;
    width: 100%;
    min-height: 50px;
    padding: 12px 14px;
    border: 1.5px solid var(--line);
    border-radius: 12px;
    background: #fff;
    color: var(--text);
    font: inherit;
    font-size: 16px; /* poniżej 16px iOS przybliża stronę po kliknięciu w pole */
    -webkit-appearance: none;
    appearance: none;
}
input[type="date"] { text-align: left; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
textarea { min-height: 180px; resize: vertical; line-height: 1.5; }
select {
    padding-right: 40px;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23647082' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center / 20px;
    text-overflow: ellipsis;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29, 78, 216, .15); }
.error { display: block; margin-top: 6px; color: var(--danger); font-size: 14px; font-style: normal; }

.help { display: block; margin-top: 6px; color: var(--muted); font-size: 13.5px; font-style: normal; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; overflow-wrap: anywhere; }

.check { display: flex; align-items: center; gap: 12px; min-height: 48px; cursor: pointer; }
.check input { flex: none; width: 24px; height: 24px; accent-color: var(--primary); }
.check small { color: var(--muted); }

.notice {
    background: #fff6dd;
    color: #6b4700;
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 14px;
    font-size: 15px;
}
.notice p { margin: 0 0 10px; }
.notice-error { background: #fdecec; color: #8f1d1d; }

.secret { border: 2px solid var(--primary); }
.secret-value {
    display: block;
    margin-bottom: 10px;
    padding: 12px;
    border-radius: 10px;
    background: var(--bg);
    font-size: 22px;
    font-weight: 650;
    letter-spacing: .04em;
    text-align: center;
    user-select: all;
    -webkit-user-select: all;
}

.gap { margin-bottom: 14px; }
.page > .hint { margin: 0 2px 14px; }

/* ---------- przyciski ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    min-height: 52px;
    padding: 12px 18px;
    border: 0;
    border-radius: 12px;
    font: inherit;
    font-weight: 650;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-secondary { background: #e8eefc; color: var(--primary); }
.btn-secondary:active { background: #d7e1fa; }
.btn-danger { background: #fdecec; color: var(--danger); }
.btn-danger:active { background: #f9d6d6; }
.btn[disabled] { opacity: .55; cursor: default; }

/* dolny pasek akcji – zawsze pod kciukiem */
.actionbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9;
    background: rgba(255, 255, 255, .96);
    border-top: 1px solid var(--line);
    padding: 12px max(14px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}
.actionbar-in { max-width: 652px; margin: 0 auto; }

.actionbar-in.two { display: grid; grid-template-columns: 1fr 1.5fr; gap: 10px; }
.bar-note { max-width: 652px; margin: -4px auto 8px; color: var(--muted); font-size: 13.5px; text-align: center; }

.section-nav {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    min-height: 44px;
    margin: -4px 2px 10px;
    font-size: 15px;
}
.section-nav a { color: var(--primary); text-decoration: none; padding: 10px 0; }
.section-nav a:last-child { text-align: right; }

.card-link { margin-left: auto; color: var(--primary); font-size: 15px; font-weight: 600; text-decoration: none; padding: 6px 0 6px 12px; }
.card-foot { margin: 12px 0 -6px; text-align: right; }
.link-danger { border: 0; background: none; color: var(--danger); font: inherit; font-size: 14.5px; padding: 8px 0 8px 12px; cursor: pointer; }
.prose + .photo-grid { margin-top: 12px; }

.row-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-actions form { margin: 0; }
.export-buttons, .photo-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.photo-buttons { margin-bottom: 14px; }

/* ---------- kroki ---------- */
.steps {
    display: flex;
    gap: 6px;
    list-style: none;
    margin: 0 0 14px;
    padding: 0;
}
.steps li {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
    padding-top: 9px;
    border-top: 3px solid var(--line);
    color: var(--muted);
    font-size: 13px;
}
.steps li.done { border-color: var(--ok); color: var(--text); }
.steps li.current { border-color: var(--primary); color: var(--text); font-weight: 650; }
.steps-num {
    flex: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--line);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    display: grid;
    place-items: center;
}
.done .steps-num { background: var(--ok); color: #fff; }
.current .steps-num { background: var(--primary); color: #fff; }
.steps-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- lista ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { margin-bottom: 10px; }
.list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 68px;
    padding: 12px 10px 12px 16px;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: 0 1px 2px rgba(16, 24, 40, .06);
    color: inherit;
    text-decoration: none;
}
.list-item:active { background: #f7f9fc; }
.list-main { flex: 1; min-width: 0; }
.list-main strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-sub { display: block; color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { flex: none; background: #fff3d6; color: #8a5a00; font-size: 12.5px; font-weight: 650; border-radius: 999px; padding: 3px 10px; }
.badge-admin { background: #e8eefc; color: var(--primary); }
.badge-lock { background: #fdecec; color: var(--danger); }
.badge-off { background: #e9ecf1; color: var(--muted); }
.chev { flex: none; color: #a3adbb; }

/* ---------- dziennik logowań ---------- */
.log { list-style: none; padding: 4px 16px; }
.log li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.log li:last-child { border-bottom: 0; }
.log-main { flex: 1; min-width: 0; }
.log-main strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log time { flex: none; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; }
.dot-ok { background: var(--ok); }
.dot-bad { background: var(--danger); }

/* ---------- dane przeglądu ---------- */
.meta { margin: 0; }
.meta > div { padding: 10px 0; border-bottom: 1px solid var(--line); }
.meta > div:first-child { padding-top: 0; }
.meta > div:last-child { padding-bottom: 0; border-bottom: 0; }
.meta dt { color: var(--muted); font-size: 13.5px; }
.meta dd { margin: 2px 0 0; font-weight: 550; overflow-wrap: anywhere; }

/* ---------- zdjęcia ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.photo-grid:empty { display: none; }
.photo {
    position: relative;
    display: block;
    margin: 0;
    aspect-ratio: 1;
    border-radius: 10px;
    overflow: hidden;
    background: #e6eaf0;
}
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-del {
    position: absolute;
    top: 0;
    right: 0;
    width: 40px;
    height: 40px;
    border: 0;
    background: none;
    cursor: pointer;
    font-size: 0;
}
.photo-del::after {
    content: "×";
    position: absolute;
    top: 5px;
    right: 5px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: rgba(15, 23, 42, .72);
    color: #fff;
    font-size: 19px;
    line-height: 25px;
    text-align: center;
}
.photo.uploading img { opacity: .45; }
.photo.uploading::after {
    content: "";
    position: absolute;
    inset: 0;
    margin: auto;
    width: 28px;
    height: 28px;
    border: 3px solid rgba(255, 255, 255, .7);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
.photo.failed { outline: 2px solid var(--danger); outline-offset: -2px; }
.photo.failed img { opacity: .35; }
.photo-msg {
    position: absolute;
    left: 4px;
    right: 4px;
    bottom: 4px;
    padding: 3px 5px;
    border-radius: 6px;
    background: var(--danger);
    color: #fff;
    font-size: 11.5px;
    line-height: 1.25;
    text-align: center;
}
@keyframes spin { to { transform: rotate(360deg); } }

.login { margin-top: 24px; }
.login .btn { margin-top: 4px; }

@media (min-width: 560px) {
    .photo-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
    .photo.uploading::after { animation-duration: 2.4s; }
}
