/* ─────────────────────────────────────────────────────────────
   Rozlicz na szybko — paper-ledger aesthetic
   Fraunces (display) · Public Sans (body) · IBM Plex Mono (figures)
   ───────────────────────────────────────────────────────────── */

:root {
    --paper:      #f3ede0;
    --paper-2:    #faf6ec;
    --ink:        #211c16;
    --ink-soft:   #5c5346;
    --muted:      #8c8270;
    --line:       #d8cdb8;
    --line-soft:  #e6ddcc;
    --accent:     #c2562a;   /* terracotta */
    --accent-ink: #9c3f1b;
    --credit:     #2f6b4f;   /* zielony — dostaje zwrot  */
    --credit-bg:  #e3ecdf;
    --debit:      #ad3a2a;   /* czerwony — dopłaca        */
    --debit-bg:   #f1e0d8;

    --shadow: 0 1px 0 rgba(33,28,22,.04), 0 18px 40px -28px rgba(33,28,22,.45);
    --radius: 4px;
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(120% 80% at 50% -10%, var(--paper-2), transparent 60%),
        var(--paper);
    color: var(--ink);
    font-family: "Public Sans", ui-sans-serif, system-ui, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* film-grain overlay for paper texture */
.grain {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    opacity: .5;
    mix-blend-mode: multiply;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.45'/%3E%3C/svg%3E");
}

.num { font-variant-numeric: tabular-nums; }

/* ── Masthead ───────────────────────────────────────────────── */
.masthead {
    position: relative;
    z-index: 1;
    max-width: 1120px;
    margin: 0 auto;
    padding: clamp(2.5rem, 6vw, 5rem) clamp(1.25rem, 4vw, 3rem) 1.5rem;
    animation: rise .7s cubic-bezier(.2,.7,.2,1) both;
}
.masthead__rule {
    height: 3px;
    width: 64px;
    background: var(--accent);
    margin-bottom: 1.4rem;
}
.masthead__kicker {
    margin: 0 0 .5rem;
    font-size: .74rem;
    letter-spacing: .26em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 600;
}
.masthead__title {
    margin: 0;
    font-family: "Fraunces", Georgia, serif;
    font-weight: 600;
    font-size: clamp(2.6rem, 7vw, 4.8rem);
    line-height: .98;
    letter-spacing: -.02em;
}
.masthead__title em {
    font-style: italic;
    font-weight: 500;
    color: var(--accent);
}
.masthead__lede {
    margin: 1.1rem 0 0;
    max-width: 30ch;
    font-size: 1.06rem;
    color: var(--ink-soft);
}
.masthead__actions {
    margin-top: 1.4rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .9rem;
}
.share-btn {
    appearance: none;
    border: 1px solid var(--accent-ink);
    background: var(--accent);
    color: #fdf6ee;
    font: inherit;
    font-weight: 600;
    padding: .62rem 1.15rem;
    border-radius: var(--radius);
    cursor: pointer;
    box-shadow: 0 10px 22px -14px var(--accent-ink);
    transition: transform .08s, box-shadow .15s, background .15s;
}
.share-btn:hover { background: var(--accent-ink); box-shadow: 0 14px 26px -14px var(--accent-ink); }
.share-btn:active { transform: translateY(1px); }
.share-hint {
    font-size: .85rem;
    font-weight: 600;
    color: var(--credit);
    opacity: 0;
    transition: opacity .2s;
}
.share-hint.is-shown { opacity: 1; }
.masthead__note {
    margin: 1rem 0 0;
    max-width: 46ch;
    font-size: .82rem;
    color: var(--muted);
    font-style: italic;
}

/* ── Layout ─────────────────────────────────────────────────── */
.layout {
    position: relative;
    z-index: 1;
    max-width: 1120px;
    margin: 0 auto;
    padding: 1rem clamp(1.25rem, 4vw, 3rem) 2rem;
    display: grid;
    grid-template-columns: minmax(0, 820px);
    justify-content: center;
    gap: clamp(1rem, 2.5vw, 2rem);
    align-items: start;
}

/* ── Panels ─────────────────────────────────────────────────── */
.panel {
    background: var(--paper-2);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: clamp(1.25rem, 2.5vw, 1.9rem);
    animation: rise .7s cubic-bezier(.2,.7,.2,1) both;
}
#panel-wydatki { animation-delay: .08s; }
#panel-podzial { animation-delay: .16s; }

.panel__head {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-areas: "num title" "num sub";
    column-gap: .85rem;
    align-items: baseline;
    padding-bottom: 1.1rem;
    margin-bottom: .4rem;
    border-bottom: 1px solid var(--line-soft);
}
.panel__num {
    grid-area: num;
    align-self: start;
    font-family: "Fraunces", serif;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 50%;
    width: 2.2rem; height: 2.2rem;
    display: grid; place-items: center;
}
.panel__title {
    grid-area: title;
    margin: 0;
    font-family: "Fraunces", serif;
    font-weight: 600;
    font-size: 1.7rem;
    letter-spacing: -.01em;
}
.panel__sub {
    grid-area: sub;
    margin: .1rem 0 0;
    font-size: .86rem;
    color: var(--muted);
}

/* ── Ledger (rows) ──────────────────────────────────────────── */
.ledger { margin-top: .4rem; }

.ledger__head,
.row {
    display: grid;
    align-items: center;
    gap: .5rem;
}
.ledger--wydatki .ledger__head,
.ledger--wydatki .row { grid-template-columns: 1.2fr 1.4fr .9fr 1.6rem; }

.ledger--podzial .ledger__head,
.ledger--podzial .row { grid-template-columns: 1.25fr .62fr .9fr .9fr .95fr 1.6rem; }

.ledger__head {
    padding: 0 .2rem .5rem;
    font-size: .68rem;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 600;
}
.ledger__head .num { text-align: right; }

.row {
    padding: .32rem .2rem;
    border-bottom: 1px dashed var(--line-soft);
    animation: rowin .35s ease both;
}
.row:last-child { border-bottom: 0; }

/* inputs */
.cell {
    font: inherit;
    color: var(--ink);
    background: transparent;
    border: 0;
    border-bottom: 1.5px solid transparent;
    padding: .34rem .15rem;
    width: 100%;
    min-width: 0;
    transition: border-color .15s, background .15s;
}
.cell::placeholder { color: #b6ab95; }
.cell:hover { border-bottom-color: var(--line); }
.cell:focus {
    outline: none;
    border-bottom-color: var(--accent);
}
.cell--num {
    font-family: "IBM Plex Mono", ui-monospace, monospace;
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.cell--share { text-align: center; }

/* opakowania komórek (udział / usuń) — pozwalają dodać nagłówek na mobile */
.ledger--podzial .pcell { display: flex; align-items: center; min-width: 0; }
.ledger--podzial .pcell > .cell { width: 100%; }

/* computed (read-only) figures */
.fig {
    font-family: "IBM Plex Mono", ui-monospace, monospace;
    font-variant-numeric: tabular-nums;
    text-align: right;
    font-size: .92rem;
    color: var(--ink-soft);
    white-space: nowrap;
}

/* saldo chip */
.saldo {
    justify-self: end;
    font-family: "IBM Plex Mono", monospace;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
    font-size: .86rem;
    padding: .16rem .5rem;
    border-radius: 999px;
    white-space: nowrap;
}
.saldo--credit { color: var(--credit); background: var(--credit-bg); }
.saldo--debit  { color: var(--debit);  background: var(--debit-bg); }
.saldo--zero   { color: var(--muted); }

/* delete button */
.del {
    appearance: none;
    border: 0; background: transparent;
    color: var(--muted);
    font-size: 1.15rem; line-height: 1;
    width: 1.6rem; height: 1.6rem;
    border-radius: 50%;
    cursor: pointer;
    display: grid; place-items: center;
    transition: color .15s, background .15s;
}
.del:hover { color: var(--debit); background: var(--debit-bg); }

/* badge marking a manually-added person */
.tag {
    display: inline-block;
    font-size: .58rem;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--muted);
    border: 1px solid var(--line);
    border-radius: 3px;
    padding: .02rem .26rem;
    margin-left: .4rem;
    vertical-align: middle;
}

/* ── Add button ─────────────────────────────────────────────── */
.add-btn {
    margin-top: .9rem;
    appearance: none;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--ink-soft);
    font: inherit;
    font-weight: 500;
    padding: .5rem .9rem;
    cursor: pointer;
    display: inline-flex; align-items: center; gap: .5rem;
    transition: border-color .15s, color .15s, background .15s, transform .08s;
}
.add-btn:hover { border-color: var(--accent); color: var(--accent-ink); }
.add-btn:active { transform: translateY(1px); }
.add-btn__plus { font-family: "Fraunces", serif; font-size: 1.1rem; line-height: 1; }

/* ── Panel footer (suma) ────────────────────────────────────── */
.panel__foot {
    margin-top: 1.2rem;
    padding-top: 1rem;
    border-top: 2px solid var(--ink);
    display: flex;
    align-items: baseline;
    justify-content: space-between;
}
.panel__foot-label {
    font-size: .74rem;
    letter-spacing: .18em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 600;
}
.panel__foot-value {
    font-family: "Fraunces", serif;
    font-weight: 600;
    font-size: 1.6rem;
}

/* ── Empty state ────────────────────────────────────────────── */
.ledger__empty {
    margin: .4rem .2rem;
    font-size: .9rem;
    font-style: italic;
    color: var(--muted);
}

/* ── Settlement ─────────────────────────────────────────────── */
.settlement {
    margin-top: 1.5rem;
    padding-top: 1.2rem;
    border-top: 1px solid var(--line-soft);
}
.settlement__title {
    margin: 0 0 .8rem;
    font-family: "Fraunces", serif;
    font-weight: 600;
    font-size: 1.15rem;
}
.settlement__list { list-style: none; margin: 0; padding: 0; display: grid; gap: .45rem; }

.transfer {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: .75rem;
    padding: .6rem .8rem;
    background: var(--paper);
    border: 1px solid var(--line-soft);
    border-radius: var(--radius);
    animation: rowin .3s ease both;
}
.transfer__who { font-size: .95rem; }
.transfer__from { font-weight: 600; }
.transfer__arrow { color: var(--accent); margin: 0 .4rem; font-family: "IBM Plex Mono", monospace; }
.transfer__to { font-weight: 600; }
.transfer__amt {
    font-family: "IBM Plex Mono", monospace;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--accent-ink);
}
.settlement__done {
    display: flex; align-items: center; gap: .5rem;
    font-style: italic;
    color: var(--credit);
}
.settlement__done::before {
    content: "✓";
    font-style: normal;
    display: grid; place-items: center;
    width: 1.4rem; height: 1.4rem;
    border-radius: 50%;
    background: var(--credit-bg);
    font-size: .85rem;
}

/* ── Docs page ──────────────────────────────────────────────── */
.layout--doc { grid-template-columns: minmax(0, 760px); justify-content: center; }

.backlink {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color .15s, color .15s;
}
.backlink:hover { color: var(--accent-ink); border-bottom-color: var(--accent); }

.prose { padding: clamp(1.5rem, 3vw, 2.6rem); }
.prose p { margin: 0 0 1rem; color: var(--ink-soft); max-width: 64ch; }
.prose strong { color: var(--ink); font-weight: 600; }
.prose em { font-style: italic; }
.prose code {
    font-family: "IBM Plex Mono", ui-monospace, monospace;
    font-size: .88em;
    background: var(--paper);
    border: 1px solid var(--line-soft);
    border-radius: 3px;
    padding: .06em .38em;
}
.prose__h {
    font-family: "Fraunces", Georgia, serif;
    font-weight: 600;
    font-size: 1.55rem;
    letter-spacing: -.01em;
    margin: 2.4rem 0 .8rem;
    padding-top: 1.6rem;
    border-top: 1px solid var(--line-soft);
    display: flex;
    align-items: baseline;
    gap: .7rem;
}
.prose__h:first-of-type { margin-top: .5rem; padding-top: 0; border-top: 0; }
.prose__num {
    font-size: .95rem;
    font-weight: 600;
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 50%;
    width: 2rem; height: 2rem;
    flex: 0 0 auto;
    display: grid; place-items: center;
}
.prose__list { margin: 0 0 1rem; padding-left: 1.2rem; color: var(--ink-soft); max-width: 64ch; }
.prose__list li { margin: .35rem 0; }
.prose__list li::marker { color: var(--accent); }

.formula {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .6rem;
    font-family: "Fraunces", serif;
    font-style: italic;
    font-size: 1.12rem;
    color: var(--ink);
    background: var(--paper);
    border: 1px solid var(--line);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius);
    padding: 1rem 1.2rem;
    margin: 0 0 1.2rem;
}
.formula__eq { color: var(--accent); font-weight: 600; }

.chip {
    display: inline-block;
    font-family: "IBM Plex Mono", monospace;
    font-size: .8rem;
    font-weight: 500;
    padding: .1rem .5rem;
    border-radius: 999px;
    white-space: nowrap;
}
.chip--credit { color: var(--credit); background: var(--credit-bg); }
.chip--debit  { color: var(--debit);  background: var(--debit-bg); }

.prose__cta { margin-top: 2.4rem; }
.prose__cta .share-btn { text-decoration: none; display: inline-block; }

/* ── Colophon ───────────────────────────────────────────────── */
.colophon {
    position: relative;
    z-index: 1;
    max-width: 1120px;
    margin: 0 auto;
    padding: 1rem clamp(1.25rem, 4vw, 3rem) 3rem;
    display: flex; flex-wrap: wrap; gap: .5rem;
    font-size: .78rem;
    color: var(--muted);
}
.colophon__dot { opacity: .6; }

/* Podział na szerokim ekranie: nagłówki i wartości wyśrodkowane,
   spójnie z wyśrodkowanym polem „Udział" (Wydatki bez zmian) */
@media (min-width: 561px) {
    .ledger--podzial .ledger__head .num { text-align: center; }
    .ledger--podzial .fig { text-align: center; }
    .ledger--podzial .saldo { justify-self: center; }
}

/* ── Podział na wąskim ekranie (portret) → dwa wiersze ──────── */
@media (max-width: 560px) {
    /* zbiorczy nagłówek kolumn znika — każda pozycja dostaje własne
       etykiety nad komórkami i układa się w dwa wiersze */
    .ledger--podzial .ledger__head { display: none; }

    .ledger--podzial .row {
        grid-template-columns: 1fr 1fr 1fr;
        grid-template-areas:
            "name  share  del"
            "paid  due    saldo";
        row-gap: .7rem;
        column-gap: .6rem;
        padding: .8rem .2rem;
        align-items: start;
    }

    /* każda komórka: etykieta (::before) nad zawartością */
    .ledger--podzial .row > [data-col] {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: .18rem;
        text-align: left;
        min-width: 0;
        font-weight: 400;
    }
    .ledger--podzial [data-col="name"]  { grid-area: name; font-weight: 600; }
    .ledger--podzial [data-col="share"] { grid-area: share; }
    .ledger--podzial [data-col="del"]   { grid-area: del; align-items: flex-end; }
    .ledger--podzial [data-col="paid"]  { grid-area: paid; }
    .ledger--podzial [data-col="due"]   { grid-area: due; }
    .ledger--podzial [data-col="saldo"] { grid-area: saldo; }

    .ledger--podzial [data-col="share"] .cell--share { text-align: left; }

    /* saldo bez „pigułki" — zostaje sam kolorowy tekst */
    .ledger--podzial .saldo {
        padding: 0;
        background: transparent;
        border-radius: 0;
        font-size: .92rem;
    }

    /* nagłówki nad komórkami */
    .ledger--podzial [data-col]::before {
        font-family: "Public Sans", sans-serif;
        font-size: .58rem;
        letter-spacing: .09em;
        text-transform: uppercase;
        font-weight: 600;
        color: var(--muted);
        line-height: 1;
    }
    .ledger--podzial [data-col="name"]::before  { content: "Kto"; }
    .ledger--podzial [data-col="share"]::before { content: "Udział"; }
    .ledger--podzial [data-col="paid"]::before  { content: "Zapłacono"; }
    .ledger--podzial [data-col="due"]::before   { content: "Należność"; }
    .ledger--podzial [data-col="saldo"]::before { content: "Saldo"; }
}

/* ── Motion ─────────────────────────────────────────────────── */
@keyframes rise {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: none; }
}
@keyframes rowin {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; }
}
