@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,600;9..144,700&family=Source+Sans+3:wght@400;500;600;700&display=swap');

:root {
    --bg: #eef1e8;
    --bg-deep: #dde3d4;
    --surface: #fbfcf8;
    --surface-2: #f3f6ee;
    --ink: #1a2620;
    --muted: #5a6a61;
    --forest: #2a4336;
    --forest-mid: #3a5948;
    --moss: #5f7f66;
    --line: rgba(42, 67, 54, 0.12);
    --line-strong: rgba(42, 67, 54, 0.22);
    --cream: #f8f6f0;
    --danger: #8f3d32;
    --ok: #2d6a47;
    --warn: #8a6a22;
    --radius: 1.1rem;
    --radius-sm: 0.75rem;
    --shadow: 0 1px 2px rgba(26, 38, 32, 0.04), 0 10px 28px rgba(26, 38, 32, 0.07);
    --shadow-soft: 0 1px 0 rgba(26, 38, 32, 0.04);
    --touch: 2.85rem;
    --font-display: "Fraunces", Georgia, serif;
    --font-body: "Source Sans 3", system-ui, sans-serif;
    --nav-h: 4.35rem;
    --top-h: 3.65rem;
    --space-1: 0.35rem;
    --space-2: 0.65rem;
    --space-3: 1rem;
    --space-4: 1.5rem;
    --space-5: 2.25rem;
    --page-max: 44rem;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-family: var(--font-body);
    color: var(--ink);
    line-height: 1.45;
    -webkit-text-size-adjust: 100%;
}

body {
    background: var(--bg);
}

.app-body {
    min-height: 100vh;
    padding-bottom: calc(var(--nav-h) + 1.75rem);
    position: relative;
}

.bg-atmosphere {
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(ellipse 70% 40% at 0% 0%, rgba(95, 127, 102, 0.16), transparent 55%),
        radial-gradient(ellipse 55% 35% at 100% 5%, rgba(42, 67, 54, 0.08), transparent 50%),
        linear-gradient(180deg, #f4f6f0 0%, var(--bg) 38%, var(--bg-deep) 100%);
    pointer-events: none;
}

/* —— chrome —— */
.top-bar {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: var(--top-h);
    padding: 0.7rem 1.1rem;
    background: rgba(251, 252, 248, 0.92);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
}

.brand {
    font-family: var(--font-display);
    font-size: 1.65rem;
    font-weight: 700;
    color: var(--forest);
    text-decoration: none;
    letter-spacing: -0.03em;
    line-height: 1;
}

.nav-toggle,
.bn-more {
    font: inherit;
    border: 1px solid var(--line-strong);
    background: var(--surface);
    color: var(--forest);
    min-height: 2.6rem;
    padding: 0 1rem;
    border-radius: 999px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
}

/* On phones the bottom bar already has „Więcej” — hide the duplicate top control. */
.nav-toggle {
    display: none;
}

.site-nav {
    position: fixed;
    inset: var(--top-h) 0 auto 0;
    z-index: 35;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: var(--space-3);
    background: rgba(26, 38, 32, 0.97);
    border-bottom: 1px solid rgba(248, 246, 240, 0.08);
    max-height: calc(100vh - var(--top-h) - var(--nav-h));
    overflow-y: auto;
}

.site-nav[hidden] {
    display: none !important;
}

.site-nav a {
    color: var(--cream);
    text-decoration: none;
    font-weight: 600;
    font-size: 1.05rem;
    padding: 0.9rem 1rem;
    border-radius: var(--radius-sm);
    min-height: var(--touch);
    display: flex;
    align-items: center;
}

.site-nav a:hover,
.site-nav a:focus-visible {
    background: rgba(248, 246, 240, 0.1);
}

.bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.15rem;
    min-height: var(--nav-h);
    padding: 0.45rem 0.45rem calc(0.45rem + env(safe-area-inset-bottom));
    background: rgba(42, 67, 54, 0.98);
    border-top: 1px solid rgba(248, 246, 240, 0.08);
}

.bottom-nav a,
.bottom-nav .bn-more {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--cream);
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    min-height: 3.1rem;
}

.bottom-nav a:hover,
.bottom-nav .bn-more:hover {
    background: rgba(248, 246, 240, 0.1);
}

/* —— page shell —— */
.flash-stack {
    width: min(var(--page-max), calc(100% - 1.5rem));
    margin: var(--space-3) auto 0;
    display: grid;
    gap: var(--space-2);
}

.flash {
    padding: 0.85rem 1.05rem;
    border-radius: var(--radius-sm);
    background: var(--surface);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-soft);
    font-weight: 600;
}

.flash-error {
    background: #faf0ed;
    border-color: rgba(143, 61, 50, 0.25);
    color: var(--danger);
}

.flash-success {
    background: #eaf5ee;
    border-color: rgba(45, 106, 71, 0.22);
    color: var(--ok);
}

.flash-warning {
    background: #f8f3e6;
    border-color: rgba(138, 106, 34, 0.25);
    color: var(--warn);
}

.page {
    width: min(var(--page-max), calc(100% - 1.5rem));
    margin: var(--space-4) auto var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.page > h1 {
    font-family: var(--font-display);
    font-size: clamp(1.75rem, 5vw, 2.35rem);
    color: var(--forest);
    text-align: center;
    letter-spacing: -0.03em;
    line-height: 1.15;
    margin-bottom: calc(var(--space-2) * -0.35);
}

.page > p {
    text-align: center;
    color: var(--muted);
    max-width: 34rem;
    margin-inline: auto;
    font-size: 1.02rem;
}

/* —— identity strip —— */
.login-as {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: 0.85rem 1rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
}

.login-as p {
    color: var(--muted);
    font-size: 0.95rem;
    line-height: 1.35;
}

.login-as span {
    color: var(--ink);
    font-weight: 700;
}

.login-as img {
    width: 2.9rem;
    height: 2.9rem;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px var(--line);
}

/* —— panels / sections —— */
.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: calc(var(--radius) + 0.15rem);
    padding: var(--space-4);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.panel > h2,
.page h2 {
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--forest);
    background: none;
    padding: 0 0 var(--space-2);
    margin: 0;
    border-radius: 0;
    text-align: left;
    border-bottom: 1px solid var(--line);
    letter-spacing: -0.02em;
}

.panel-nested {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: var(--space-3);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.panel-nested > h3,
.page h3 {
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    background: none;
    padding: 0;
    margin: 0 0 var(--space-1);
    border-radius: 0;
    text-align: left;
}

.panel-nested + .panel-nested {
    margin-top: var(--space-1);
}

.panel ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.item-row:not(:has(form)) {
    padding: 0.85rem 1rem;
    color: var(--muted);
    background: var(--surface-2);
    border: 1px dashed var(--line);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
}

/* —— list items —— */
.item-row {
    list-style: none;
}

.item-row form {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: var(--space-2) var(--space-3);
    align-items: center;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.85rem;
}

.item-row form:not(:has(.qty-controls)) {
    grid-template-columns: minmax(0, 1fr) auto;
}

.item-row form:not(:has(.qty-controls)):not(:has(.avatar-stack img)) {
    grid-template-columns: 1fr;
}

.qty-controls {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.qty-btn {
    width: 2.5rem;
    height: 2.5rem;
    border: 1px solid var(--line-strong);
    border-radius: 0.65rem;
    background: var(--surface-2);
    color: var(--forest);
    font-size: 1.25rem;
    font-weight: 700;
    cursor: pointer;
    user-select: none;
    display: grid;
    place-items: center;
    line-height: 1;
}

.qty-btn:hover {
    background: var(--forest);
    color: var(--cream);
    border-color: var(--forest);
}

.qty-controls input[type="number"] {
    width: 4.25rem;
    height: 2.5rem;
    text-align: center;
    font-size: 1.05rem;
    font-weight: 600;
    border: 1px solid var(--line);
    border-radius: 0.65rem;
    background: var(--surface);
    color: var(--ink);
    /* Hide native spinner — we use +/- buttons instead */
    -moz-appearance: textfield;
    appearance: textfield;
}

.qty-controls input[type="number"]::-webkit-outer-spin-button,
.qty-controls input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.btn-item,
.btn-item-done {
    min-height: var(--touch);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 0.7rem 0.95rem;
    font-size: 1.02rem;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem 0.5rem;
    line-height: 1.3;
}

.btn-item {
    background: var(--forest-mid);
    color: var(--cream);
}

.btn-item:hover {
    background: var(--forest);
}

.btn-item-done {
    background: var(--surface-2);
    color: var(--muted);
    text-decoration: line-through;
    border-color: var(--line);
}

.btn-item-done:not(:disabled):hover {
    background: #e6e9e2;
    color: var(--muted);
    text-decoration: line-through;
    border-color: var(--line-strong);
}

.btn-item-done:disabled {
    cursor: default;
    opacity: 0.75;
}

.personal-item-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.45rem;
    align-items: stretch;
}

.personal-item-row .personal-done-form {
    display: block;
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    grid-template-columns: 1fr;
}

.personal-item-row .personal-delete-form {
    display: flex;
    align-items: stretch;
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    grid-template-columns: auto;
}

.btn-icon-delete {
    min-width: 2.5rem;
    min-height: var(--touch);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--muted);
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    padding: 0 0.55rem;
}

.btn-icon-delete:hover {
    background: #f3e8e6;
    border-color: #c47a6a;
    color: #8a3b2c;
}

.item-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    background: rgba(248, 246, 240, 0.2);
    border: 1px solid rgba(248, 246, 240, 0.35);
    color: inherit;
    text-decoration: none;
    white-space: nowrap;
}

.btn-item-done .item-badge {
    border-color: var(--line);
    background: rgba(42, 67, 54, 0.06);
}

.avatar-stack {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    justify-content: flex-end;
    max-width: 7rem;
}

.avatar-stack img {
    width: 2.15rem;
    height: 2.15rem;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px var(--line);
}

/* —— actions / forms / cards —— */
.btn,
button.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--touch);
    padding: 0.7rem 1.35rem;
    border-radius: 999px;
    border: none;
    background: var(--forest);
    color: var(--cream);
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    text-decoration: none;
    align-self: start;
}

.btn:hover {
    background: var(--forest-mid);
}

.btn-secondary {
    background: var(--surface);
    color: var(--forest);
    border: 1px solid var(--line-strong);
}

.btn-secondary:hover {
    background: var(--surface-2);
}

.btn-danger {
    background: var(--danger);
}

.card-link {
    display: block;
    padding: 1.05rem 1.15rem;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--ink);
    text-decoration: none;
    font-weight: 600;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.card-link + .card-link {
    margin-top: var(--space-2);
}

.card-link:hover {
    transform: translateY(-1px);
    border-color: var(--line-strong);
    box-shadow: var(--shadow);
}

.card-link .meta {
    display: block;
    margin-top: 0.35rem;
    color: var(--muted);
    font-weight: 500;
    font-size: 0.92rem;
}

.form-stack {
    display: grid;
    gap: var(--space-2);
}

.form-stack label {
    font-weight: 600;
    color: var(--muted);
    font-size: 0.92rem;
    margin-top: var(--space-1);
}

.form-stack label:first-child {
    margin-top: 0;
}

.form-stack input,
.form-stack select,
.form-stack textarea {
    width: 100%;
    min-height: var(--touch);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 0.65rem 0.85rem;
    font: inherit;
    background: #fff;
    color: var(--ink);
}

.form-stack input:focus,
.form-stack select:focus,
.form-stack textarea:focus {
    outline: 2px solid rgba(58, 89, 72, 0.35);
    outline-offset: 1px;
    border-color: var(--forest-mid);
}

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 18rem;
}

th,
td {
    padding: 0.85rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--line);
}

th {
    background: var(--surface-2);
    color: var(--forest);
    font-size: 0.82rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.stat-grid {
    display: grid;
    gap: var(--space-4);
}

.choice-row {
    display: grid;
    gap: 0.65rem;
}

.choice-card {
    display: flex;
    gap: 0.65rem;
    align-items: center;
    padding: 0.85rem 1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fff;
    cursor: pointer;
    font-weight: 600;
}

.choice-card:has(input:checked) {
    border-color: var(--forest-mid);
    background: var(--surface-2);
}

/* —— responsive —— */
@media (max-width: 719px) {
    .page {
        width: calc(100% - 1.25rem);
        gap: var(--space-3);
        margin-top: var(--space-3);
    }

    .panel {
        padding: var(--space-3);
        gap: var(--space-3);
    }

    .item-row form {
        grid-template-columns: 1fr;
        gap: var(--space-2);
    }

    .qty-controls {
        justify-content: flex-start;
    }

    .avatar-stack {
        justify-content: flex-start;
        max-width: none;
        padding-top: 0.15rem;
        border-top: 1px dashed var(--line);
        margin-top: 0.15rem;
        padding-top: 0.55rem;
    }

    .avatar-stack:empty {
        display: none;
    }
}

@media (min-width: 720px) {
    .bottom-nav {
        display: none;
    }

    .app-body {
        padding-bottom: var(--space-5);
    }

    .top-bar {
        padding-inline: 1.5rem;
    }

    .site-nav {
        position: static;
        flex-direction: row;
        flex-wrap: wrap;
        background: transparent;
        border: none;
        box-shadow: none;
        max-height: none;
        padding: var(--space-3) 1.5rem 0;
        gap: 0.45rem;
        justify-content: center;
    }

    .site-nav[hidden] {
        display: flex !important;
    }

    .site-nav a {
        color: var(--forest);
        background: var(--surface);
        border: 1px solid var(--line);
        padding: 0.55rem 0.95rem;
        font-size: 0.92rem;
        min-height: 2.5rem;
        box-shadow: var(--shadow-soft);
    }

    .site-nav a:hover,
    .site-nav a:focus-visible {
        background: var(--forest);
        color: var(--cream);
        border-color: var(--forest);
    }

    .nav-toggle {
        display: none;
    }

    .stat-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .page {
        width: min(var(--page-max), calc(100% - 3rem));
    }
}
