/*
 * Zbiórki online — "The Trust Ledger" design system.
 * Tokens and components mirror DESIGN.md. Loaded via AssetMapper (assets/app.js).
 */

:root {
    --primary: #0d47a1;
    --primary-deep: #09356f;
    --green: #2e7d32;
    --ink: #1a1a1a;
    --muted: #55616f;
    --line: #e6e9ef;
    --surface: #ffffff;
    --canvas: #f6f8fb;
    --track: #eef1f6;
    --hero-ink: #dbe6ff;
    --success-bg: #e8f5e9;
    --success-ink: #1b5e20;
    --error-bg: #ffebee;
    --error-ink: #b71c1c;
    --shadow-rest: 0 1px 2px rgba(16, 24, 40, .04);
    --shadow-lift: 0 8px 24px rgba(16, 24, 40, .10);
    --ease-out: cubic-bezier(.16, 1, .3, 1);
}

* { box-sizing: border-box; }

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

body {
    font-family: system-ui, sans-serif;
    margin: 0;
    color: var(--ink);
    background: var(--canvas);
    line-height: 1.5;
}

/* Browser surfaces themed from the palette — the ledger owns its chrome. */
::selection { background: var(--primary); color: #fff; }
::-moz-selection { background: var(--primary); color: #fff; }
:root { accent-color: var(--primary); caret-color: var(--primary); }
* { scrollbar-width: thin; scrollbar-color: #c3cbd8 transparent; }
*::-webkit-scrollbar { width: 11px; height: 11px; }
*::-webkit-scrollbar-thumb { background: #c3cbd8; border-radius: 999px; border: 3px solid var(--canvas); }
*::-webkit-scrollbar-thumb:hover { background: #a7b2c2; }

a { color: var(--primary); text-underline-offset: .15em; }

:where(a, button, input, [tabindex]):focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: 4px;
}

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

/* Icons default to 1em (flow with text); explicit per-context sizes override. */
.icon { flex: none; vertical-align: -0.125em; }
.btn .icon { width: 1.05em; height: 1.05em; }

/* ── Header ─────────────────────────────────────────────── */
.site-header {
    background: var(--primary);
    color: #fff;
    padding: 1rem 1.5rem;
    display: flex;
    gap: 1.5rem;
    align-items: center;
}
.site-header a { color: #fff; text-decoration: none; }
.brand { display: inline-flex; align-items: center; gap: .55rem; font-weight: 700; font-size: 1.1rem; letter-spacing: -.01em; }
.brand svg { width: 22px; height: 22px; }
.site-nav { margin-left: auto; display: flex; gap: 1.25rem; align-items: center; }
.site-nav a { opacity: .92; }
.site-nav a:hover { opacity: 1; text-decoration: underline; }

main { max-width: 1060px; margin: 0 auto; padding: 1.5rem; }
h1 { line-height: 1.2; letter-spacing: -.02em; }

/* ── Hero ───────────────────────────────────────────────── */
.hero {
    position: relative;
    overflow: hidden;
    background: linear-gradient(135deg, var(--primary), var(--primary-deep));
    color: #fff;
    border-radius: 16px;
    padding: 2.75rem 2rem;
    margin-bottom: 1.5rem;
}
.hero::after {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(90% 140% at 100% 0%, rgba(255, 255, 255, .10), transparent 60%);
    pointer-events: none;
}
.hero h1 { margin: 0 0 .75rem; font-size: clamp(1.9rem, 4.5vw, 2.8rem); letter-spacing: -.025em; }
.hero p { margin: 0 0 1.5rem; max-width: 46ch; color: var(--hero-ink); font-size: 1.1rem; line-height: 1.55; }

/* ── Ledger band (aggregate totals) ─────────────────────── */
.ledger {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow-rest);
    margin-bottom: 2.25rem;
    overflow: hidden;
}
.ledger-cell { padding: 1.1rem 1.25rem; border-left: 1px solid var(--line); }
.ledger-cell:first-child { border-left: 0; }
.ledger-figure { display: block; font-size: clamp(1.25rem, 2.6vw, 1.6rem); font-weight: 700; color: var(--primary); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.ledger-label { display: block; margin-top: .15rem; color: var(--muted); font-size: .82rem; }
@media (max-width: 620px) {
    .ledger { grid-template-columns: 1fr 1fr; }
    .ledger-cell:nth-child(3) { border-left: 0; }
    .ledger-cell:nth-child(n+3) { border-top: 1px solid var(--line); }
}

/* ── Search ─────────────────────────────────────────────── */
.search {
    display: flex;
    align-items: center;
    gap: .5rem;
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 999px;
    box-shadow: var(--shadow-rest);
    padding: .4rem .5rem .4rem 1rem;
    margin-bottom: 0;
}
.search-icon { display: inline-flex; color: var(--muted); font-size: 1.25rem; }
.search input {
    flex: 1 1 auto;
    width: 100%;
    max-width: none;           /* override the global 360px field cap so it fills the bar */
    min-width: 0;
    border: 0;
    background: transparent;
    font: inherit;
    color: var(--ink);
    padding: .5rem 0;
}
.search input,
.search input:focus,
.search input:focus-visible { outline: none; box-shadow: none; }
.search input::placeholder { color: #b9c4d6; }
.search .btn { flex: none; border-radius: 999px; }

/* ── Search results (typeahead dropdown) ────────────────── */
.searchbox { position: relative; margin-bottom: 1.75rem; z-index: 40; }

/* no-JS fallback: results sit inline under the bar */
.search-results { margin-top: .75rem; }

/* JS: floating dropdown anchored under the input */
.search-results.js {
    position: absolute;
    top: calc(100% + .4rem);
    left: 0;
    right: 0;
    margin-top: 0;
    max-height: min(60vh, 26rem);
    overflow-y: auto;
    padding: .4rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow-lift);
    z-index: 50;
    display: none;
}
.search-results.js.is-open { display: flex; gap: .6rem; align-items: flex-start; }
.search-results.js turbo-frame { display: none; } /* server fallback hidden when JS owns it */
.search-results-main { flex: 1 1 auto; min-width: 0; }

/* ── "Recently added" carousel (right of results, room permitting) ── */
.search-aside {
    display: none;                 /* JS-only widget: never in the pre-JS fallback flow */
    flex: 0 0 13rem;
    align-self: stretch;
    border-left: 1px solid var(--line);
    padding-left: .7rem;
}
.search-results.js.is-open .search-aside { display: block; }
@media (max-width: 680px) { .search-results.js.is-open .search-aside { display: none; } }

.search-aside-head {
    margin: .2rem 0 .5rem;
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
}
.mini-slide {
    display: none;
    flex-direction: column;
    gap: .35rem;
    padding: .6rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    color: var(--ink);
    text-decoration: none;
}
.mini-slide.is-active { display: flex; }
.mini-slide:hover { border-color: var(--primary); }
.mini-title { font-weight: 600; font-size: .9rem; line-height: 1.3; }
.mini-cat { font-size: .74rem; color: var(--muted); }
.mini-slide .progress { height: 7px; }
.mini-meta { font-size: .76rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.mini-dots { display: flex; justify-content: center; gap: .35rem; margin-top: .55rem; }
.mini-dot {
    width: .45rem;
    height: .45rem;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: var(--line);
    cursor: pointer;
}
.mini-dot.is-active { background: var(--primary); }

.search-results-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .5rem .65rem;
    color: var(--muted);
    font-size: .85rem;
}
.search-clear {
    border: 0;
    background: transparent;
    padding: 0;
    color: var(--primary);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
.search-clear:hover { text-decoration: underline; }

.search-list { list-style: none; margin: 0; padding: 0; }
.search-item {
    display: flex;
    flex-direction: column;
    gap: .15rem;
    padding: .6rem .65rem;
    border-radius: 8px;
    color: var(--ink);
    text-decoration: none;
}
.search-item:hover,
.search-item:focus-visible { background: var(--canvas); }
.search-item-title { font-weight: 600; }
.search-item-meta { font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.search-empty { margin: 0; padding: .9rem .65rem; color: var(--muted); }

/* ── Section heading ────────────────────────────────────── */
.section-head { margin: 2.25rem 0 1.1rem; font-size: 1.35rem; letter-spacing: -.015em; }
.section-head:first-child { margin-top: 0; }

/* ── Closing-soon row: banner + horizontal card carousel ── */
.closing-row { display: flex; gap: 1.25rem; align-items: stretch; margin-bottom: 1rem; }
.closing-banner {
    flex: 0 0 300px;
    display: flex;
    flex-direction: column;
    gap: .6rem;
    background: linear-gradient(135deg, var(--primary), var(--primary-deep));
    color: #fff;
    border-radius: 14px;
    padding: 1.5rem;
    box-shadow: var(--shadow-rest);
}
.closing-banner-eyebrow { display: inline-flex; align-items: center; gap: .4rem; font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--hero-ink); }
.closing-banner-eyebrow svg { width: 15px; height: 15px; }
.closing-banner-title { margin: 0; font-size: 1.3rem; font-weight: 700; line-height: 1.25; letter-spacing: -.015em; }
.closing-banner-text { margin: 0; color: var(--hero-ink); font-size: .95rem; line-height: 1.5; }
.closing-banner .btn { margin-top: auto; align-self: flex-start; }

.closing-carousel { position: relative; flex: 1 1 0; min-width: 0; }
.slider-track { display: flex; gap: 1.25rem; overflow-x: auto; scroll-snap-type: x mandatory; scroll-behavior: smooth; padding: .25rem; margin: -.25rem; scrollbar-width: thin; }
.slider-track > .card { flex: 0 0 300px; scroll-snap-align: start; }
.slider-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    width: 40px;
    height: 40px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-lift);
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: opacity .18s var(--ease-out);
}
.slider-arrow svg { width: 18px; height: 18px; }
.slider-prev { left: -10px; }
.slider-next { right: -10px; }
.slider-arrow:disabled { opacity: 0; pointer-events: none; }

@media (max-width: 720px) {
    .closing-row { flex-direction: column; }
    .closing-banner { flex-basis: auto; }
    .slider-arrow { display: none; }
    .slider-track > .card { flex-basis: 85%; }
}

/* ── Card grid ──────────────────────────────────────────── */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.25rem; }
.card {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 1.25rem;
    box-shadow: var(--shadow-rest);
    transition: box-shadow .18s var(--ease-out), transform .18s var(--ease-out);
}
.card-link { text-decoration: none; color: inherit; }
a.card:hover, .card:focus-within { box-shadow: var(--shadow-lift); transform: translateY(-2px); }
.card-title { margin: 0 0 .75rem; font-size: 1.15rem; font-weight: 700; line-height: 1.35; letter-spacing: -.01em; }
.card-title a { color: var(--ink); text-decoration: none; }
.card-title a:hover { color: var(--primary); }
.spacer { flex: 1; }

/* ── Progress ───────────────────────────────────────────── */
.progress { background: var(--track); border-radius: 6px; height: 10px; overflow: hidden; margin: .5rem 0; }
.progress > span { display: block; height: 100%; background: var(--green); border-radius: 6px; transform-origin: left; animation: tally .9s var(--ease-out) both; }
@keyframes tally { from { transform: scaleX(0); } to { transform: scaleX(1); } }

.amounts { display: flex; justify-content: space-between; gap: .5rem; font-size: .95rem; margin: .35rem 0 1rem; font-variant-numeric: tabular-nums; }
.amounts .collected { font-weight: 700; color: var(--green); }
.amounts .remaining { color: var(--muted); }

.goal-reached {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    background: var(--success-bg);
    color: var(--success-ink);
    font-weight: 600;
    font-size: .9rem;
    padding: .3rem .65rem;
    border-radius: 999px;
    margin: .35rem 0 1rem;
}
.goal-reached svg { width: 15px; height: 15px; }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    background: var(--primary);
    color: #fff;
    padding: .62rem 1.2rem;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    text-decoration: none;
    font: inherit;
    font-weight: 600;
    transition: background .18s var(--ease-out);
}
.btn:hover { background: var(--primary-deep); }
.btn:active { transform: translateY(1px); }
.btn-light { background: #fff; color: var(--primary); }
.btn-light:hover { background: #eaf0fb; }
.btn-block { display: flex; width: 100%; }

/* ── Trust row (flat, border-separated) ─────────────────── */
.trust-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 1.25rem 2rem;
    margin: 2.75rem 0 1rem;
    padding-top: 1.75rem;
    border-top: 1px solid var(--line);
}
.trust-item { display: flex; gap: .85rem; }
.trust-item svg { flex: none; width: 24px; height: 24px; color: var(--primary); margin-top: .1rem; }
.trust-item b { display: block; margin-bottom: .2rem; }
.trust-item p { margin: 0; color: var(--muted); font-size: .92rem; line-height: 1.45; }

/* ── Forms ──────────────────────────────────────────────── */
label { display: block; margin: .9rem 0 .3rem; font-weight: 600; font-size: .9rem; }
input, select {
    padding: .6rem .7rem;
    width: 100%;
    max-width: 360px;
    box-sizing: border-box;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    transition: border-color .15s, box-shadow .15s;
}
input:focus-visible, select:focus-visible {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(13, 71, 161, .15);
}
.field-hint { margin: .35rem 0 0; color: var(--muted); font-size: .85rem; }
form .help-text, .form-text { color: var(--muted); font-size: .85rem; }

/* Quick-amount chips (donation form) */
.amount-chips { display: flex; flex-wrap: wrap; gap: .5rem; margin: .3rem 0 .2rem; }
.chip {
    appearance: none;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: .45rem .9rem;
    font: inherit;
    font-weight: 600;
    color: var(--ink);
    cursor: pointer;
    font-variant-numeric: tabular-nums;
    transition: border-color .15s, background .15s, color .15s;
}
.chip:hover { border-color: #b9c4d6; }
.chip[aria-pressed="true"], .chip[aria-current="true"] { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ── Filter bar ─────────────────────────────────────────── */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.25rem; margin: 0 0 1.5rem; }
.filter-group { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.filter-label { font-size: .85rem; font-weight: 600; color: var(--muted); margin-right: .15rem; }
.filters a.chip { text-decoration: none; }
.filter-clear { font-weight: 600; font-size: .9rem; color: var(--muted); text-decoration: none; }
.filter-clear:hover { color: var(--primary); text-decoration: underline; }

/* ── Tags (non-interactive badges) ──────────────────────── */
.tags { display: flex; flex-wrap: wrap; gap: .35rem; margin: 0 0 .75rem; }
.tag { display: inline-block; background: var(--track); color: var(--muted); border-radius: 999px; padding: .2rem .6rem; font-size: .78rem; font-weight: 600; line-height: 1.4; }
.deadline { display: inline-flex; align-items: center; gap: .3rem; margin: 0 0 .6rem; color: var(--muted); font-size: .8rem; font-weight: 600; }
.deadline svg { width: 14px; height: 14px; }

/* ── Panels / auth card / detail layout ─────────────────── */
.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 1.5rem;
    box-shadow: var(--shadow-rest);
}
.auth { max-width: 440px; margin: 1.5rem auto; }
.auth h1 { margin-top: 0; font-size: 1.5rem; }
.auth input, .auth select { max-width: 100%; }
.auth .btn { width: 100%; margin-top: 1.25rem; }
.auth-alt { margin: 1.1rem 0 0; color: var(--muted); font-size: .92rem; text-align: center; }

.detail { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 2rem; align-items: start; }
.detail-aside { position: sticky; top: 1.5rem; }
@media (max-width: 860px) { .detail { grid-template-columns: 1fr; } .detail-aside { position: static; } }
.lede { font-size: 1.05rem; line-height: 1.7; color: #2b3440; white-space: pre-line; }
.raised-figure { font-size: clamp(1.6rem, 4vw, 2.1rem); font-weight: 700; color: var(--green); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.raised-sub { color: var(--muted); font-size: .95rem; margin-top: .1rem; font-variant-numeric: tabular-nums; }

/* ── Donation ledger list ───────────────────────────────── */
.donations { list-style: none; padding: 0; margin: .5rem 0 0; }
.donations li { display: flex; align-items: baseline; gap: .6rem; padding: .7rem 0; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.donations li:first-child { border-top: 0; }
.donations .amt { font-weight: 700; color: var(--ink); }
.donations .who { color: var(--muted); }
.donations time { color: var(--muted); font-size: .85rem; margin-left: auto; }

/* ── Table (Moje wsparcia) ──────────────────────────────── */
.ledger-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.ledger-table th { text-align: left; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: .6rem .75rem; border-bottom: 1px solid var(--line); }
.ledger-table td { padding: .75rem; border-bottom: 1px solid var(--line); }
.ledger-table tr:last-child td { border-bottom: 0; }
.ledger-table td.num { text-align: right; font-weight: 600; }
.ledger-table a { text-decoration: none; }
.ledger-table a:hover { text-decoration: underline; }

/* ── Status pills ───────────────────────────────────────── */
.status { display: inline-flex; align-items: center; gap: .35rem; padding: .22rem .6rem; border-radius: 999px; font-size: .82rem; font-weight: 600; white-space: nowrap; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .9; }
.status-confirmed { background: var(--success-bg); color: var(--success-ink); }
.status-new { background: #eef2fb; color: var(--primary-deep); }
.status-rejected { background: var(--error-bg); color: var(--error-ink); }

/* ── Carousel (more fundraisers) ────────────────────────── */
.carousel { margin-top: 2.75rem; }
.carousel-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.1rem; }
.carousel-head h2 { margin: 0; }
.carousel-nav { margin-left: auto; display: flex; gap: .5rem; }
.carousel-btn {
    width: 40px; height: 40px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--line); border-radius: 999px;
    background: var(--surface); color: var(--primary);
    cursor: pointer;
    transition: border-color .15s, background .15s, color .15s;
}
.carousel-btn .icon { width: 20px; height: 20px; }
.carousel-btn:hover:not(:disabled) { border-color: #b9c4d6; background: #f4f7fc; }
.carousel-btn:disabled { color: var(--placeholder); opacity: .55; cursor: default; }
.carousel-track {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 270px;
    gap: 1.25rem;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding-bottom: .6rem;
    margin: 0 -1.5rem;
    padding-left: 1.5rem;
    padding-right: 1.5rem;
}
.carousel-track > .card { margin-bottom: 0; scroll-snap-align: start; }
@media (max-width: 480px) { .carousel-track { grid-auto-columns: 82%; } }

/* ── Empty states ───────────────────────────────────────── */
.empty { text-align: center; padding: 3rem 1.5rem; color: var(--muted); }
.empty svg { width: 40px; height: 40px; color: #b9c4d6; margin-bottom: .75rem; }
.empty p { margin: 0 0 1.1rem; }

/* ── Flashes ────────────────────────────────────────────── */
.flash { padding: .8rem 1rem; border-radius: 8px; margin-bottom: 1rem; display: flex; gap: .6rem; align-items: center; }
.flash svg { width: 18px; height: 18px; flex: none; }
.flash-success { background: var(--success-bg); color: var(--success-ink); }
.flash-error { background: var(--error-bg); color: var(--error-ink); }

/* ── Pagination ─────────────────────────────────────────── */
.pagination { display: flex; gap: 1rem; align-items: center; margin-top: 1.75rem; color: var(--muted); font-size: .95rem; }
.pagination a { font-weight: 600; text-decoration: none; }
.pagination a:hover { text-decoration: underline; }

/* ── Footer ─────────────────────────────────────────────── */
.site-footer { border-top: 1px solid var(--line); margin-top: 3rem; padding: 2rem 1.5rem; color: var(--muted); font-size: .9rem; }
.site-footer .inner { max-width: 1060px; margin: 0 auto; display: flex; flex-wrap: wrap; gap: .75rem 1.5rem; align-items: center; }
.site-footer .brand { color: var(--ink); }
.site-footer .demo-note { margin-left: auto; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
    .progress > span { transform: none; }
}
