/* ============================================================
   WeRescue /match — "the matchmaker's dossier"
   Extends the WeRescue design system (--wr-* tokens in base.html).
   Plus Jakarta Sans throughout; the Match Spec card is the artifact.
   ============================================================ */

.match-page {
    --match-font: 'Plus Jakarta Sans', 'Segoe UI', sans-serif;
    --match-ink: var(--wr-text, #1F2937);
    --match-muted: var(--wr-text-muted, #6B7280);
    --match-paper: #FFFDFA;
    --match-amber: #D97706;
    --match-amber-soft: #FEF3C7;
    --match-line: rgba(224, 122, 95, 0.18);

    font-family: var(--match-font);
    background:
        radial-gradient(1200px 500px at 85% -10%, var(--wr-warm-peach, #FFF0E6) 0%, transparent 60%),
        var(--wr-warm-cream, #FFF9F5);
    color: var(--match-ink);
    display: grid;
    grid-template-columns: minmax(340px, 420px) 1fr;
    gap: 28px;
    padding: 24px clamp(16px, 4vw, 48px) 64px;
    min-height: calc(100vh - 80px);
    align-items: start;
}

/* ---------------- Chat column ---------------- */

.match-chat {
    position: sticky;
    top: 16px;
    display: flex;
    flex-direction: column;
    /* Conservative fallback; match.js fits this to the space actually
       available from the column's current position. A fixed
       100vh-derived height pushed the input below the fold on laptop
       screens before the header scrolled away. */
    height: calc(100vh - 230px);
    min-height: 420px;
    background: var(--match-paper);
    border-radius: var(--wr-radius-lg, 28px);
    box-shadow: var(--wr-shadow-lg, 0 8px 40px rgba(0,0,0,0.12));
    overflow: hidden;
}

.match-chat__header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 20px 14px;
    border-bottom: 1px solid var(--match-line);
}

.match-chat__avatar {
    width: 44px; height: 44px;
    display: grid; place-items: center;
    font-size: 22px;
    background: linear-gradient(135deg, var(--wr-coral, #E07A5F), var(--wr-coral-light, #F4A393));
    border-radius: 14px;
    box-shadow: 0 4px 12px rgba(224, 122, 95, 0.35);
}

.match-chat__title {
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: -0.01em;
    margin: 0;
}

.match-chat__subtitle {
    margin: 2px 0 0;
    font-size: 0.78rem;
    color: var(--match-muted);
}

.match-chat__restart {
    margin-left: auto;
    border: none;
    background: none;
    color: var(--match-muted);
    font: 600 0.72rem var(--match-font);
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 8px;
}
.match-chat__restart:hover { color: var(--wr-coral); background: var(--wr-warm-peach); }

.match-chat__scroll {
    flex: 1;
    overflow-y: auto;
    padding: 20px 18px 8px;
    scroll-behavior: smooth;
}

.match-msg {
    max-width: 85%;
    padding: 11px 15px;
    margin-bottom: 10px;
    font-size: 0.92rem;
    line-height: 1.5;
    border-radius: 18px;
    animation: msg-in 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.match-msg--assistant {
    background: var(--wr-warm-peach, #FFF0E6);
    border-bottom-left-radius: 6px;
}

.match-msg--user {
    background: var(--wr-coral, #E07A5F);
    color: #fff;
    margin-left: auto;
    border-bottom-right-radius: 6px;
}

.match-msg--system {
    background: none;
    color: var(--match-muted);
    font-size: 0.78rem;
    text-align: center;
    max-width: 100%;
    padding: 4px;
}

@keyframes msg-in {
    from { opacity: 0; transform: translateY(8px) scale(0.97); }
    to   { opacity: 1; transform: none; }
}

.match-typing {
    display: inline-flex;
    gap: 5px;
    padding: 12px 16px;
    background: var(--wr-warm-peach);
    border-radius: 18px 18px 18px 6px;
    margin-bottom: 10px;
}
.match-typing span {
    width: 7px; height: 7px;
    background: var(--wr-coral);
    border-radius: 50%;
    animation: typing-bounce 1.2s infinite;
}
.match-typing span:nth-child(2) { animation-delay: 0.15s; }
.match-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-bounce {
    0%, 60%, 100% { transform: none; opacity: 0.4; }
    30% { transform: translateY(-5px); opacity: 1; }
}

.match-chat__composer {
    display: flex;
    gap: 10px;
    padding: 12px 14px 14px;
    border-top: 1px solid var(--match-line);
    background: var(--match-paper);
}

.match-chat__composer textarea {
    flex: 1;
    resize: none;
    border: 1.5px solid var(--match-line);
    border-radius: 14px;
    padding: 10px 14px;
    font: 400 0.92rem/1.4 var(--match-font);
    color: var(--match-ink);
    background: var(--wr-warm-cream);
    max-height: 110px;
    outline: none;
    transition: border-color 0.15s;
}
.match-chat__composer textarea:focus { border-color: var(--wr-coral); }

.match-chat__composer button {
    align-self: flex-end;
    width: 42px; height: 42px;
    border: none;
    border-radius: 13px;
    display: grid; place-items: center;
    background: var(--wr-coral);
    color: #fff;
    cursor: pointer;
    transition: transform 0.12s, box-shadow 0.12s;
}
.match-chat__composer button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(224, 122, 95, 0.4);
}
.match-chat__composer button:disabled { opacity: 0.5; cursor: default; transform: none; }

/* ---------------- Match Spec card ---------------- */

.match-side {
    display: flex;
    flex-direction: column;
    gap: 18px;
    min-width: 0;
}

.match-spec {
    position: sticky;
    top: 16px;
    z-index: 5;
    padding: 20px 22px 16px;
    background: var(--match-paper);
    /* stitched dossier edge */
    background-image: repeating-linear-gradient(90deg,
        var(--match-line) 0 8px, transparent 8px 16px);
    background-size: 100% 2px;
    background-repeat: no-repeat;
    background-position: 0 0;
}

.match-spec__head {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 6px;
}
.match-spec__paw { font-size: 1.1rem; }
.match-spec__title {
    font-size: 1.12rem;
    font-weight: 800;
    letter-spacing: -0.015em;
    margin: 0;
}
.match-spec__counts {
    margin-left: auto;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--match-muted);
}

.match-spec__empty {
    font-size: 0.85rem;
    color: var(--match-muted);
    font-style: italic;
    padding: 10px 0 6px;
}

.match-spec__group { margin-top: 12px; }
.match-spec__group h3 {
    font-size: 0.66rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--match-muted);
    margin: 0 0 7px;
}

.match-spec__chips { display: flex; flex-wrap: wrap; gap: 7px; }

.match-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1.3;
    border: 1.5px solid transparent;
}
.match-chip--must {
    background: var(--wr-coral);
    color: #fff;
}
.match-chip--nice {
    background: transparent;
    border-color: var(--wr-coral-light);
    color: var(--wr-coral);
}
.match-chip--deal {
    background: #475569;
    color: #fff;
}
.match-chip--deal::before { content: "🚫"; font-size: 0.7rem; }
/* Collapsed negation prefs ("No kittens") — muted, clearly exclusionary */
.match-chip--not {
    border-color: #94A3B8;
    color: #64748B;
}
.match-chip--not::before { content: "🚫"; font-size: 0.7rem; }
.match-chip__reason {
    font-weight: 500;
    opacity: 0.75;
    font-size: 0.72rem;
}

.match-chip--changed {
    animation: chip-glow 1.6s ease-out both;
}
@keyframes chip-glow {
    0%   { transform: scale(0.85); box-shadow: 0 0 0 0 rgba(224,122,95,0.55); }
    35%  { transform: scale(1.06); box-shadow: 0 0 0 9px rgba(224,122,95,0); }
    100% { transform: none; box-shadow: none; }
}

.match-spec__ledger {
    margin-top: 14px;
    padding: 9px 12px;
    border-radius: 12px;
    background: var(--match-amber-soft);
    color: #92400E;
    font-size: 0.78rem;
    font-weight: 600;
    animation: msg-in 0.3s ease-out both;
}
.match-spec__ledger::before { content: "✦ "; }

.match-spec__foot {
    margin-top: 16px;
    padding-top: 13px;
    border-top: 1px dashed var(--match-line);
}

.match-spec__save-btn {
    width: 100%;
    border: none;
    border-radius: 14px;
    padding: 12px;
    font: 700 0.92rem var(--match-font);
    background: linear-gradient(135deg, var(--wr-coral), #D26449);
    color: #fff;
    cursor: pointer;
    transition: transform 0.12s, box-shadow 0.12s;
}
.match-spec__save-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(224,122,95,0.4);
}

.match-spec__save-copy {
    font-size: 0.78rem;
    color: var(--match-muted);
    margin: 0 0 9px;
}
.match-spec__save-row { display: flex; gap: 8px; }
.match-spec__save-row input {
    flex: 1;
    border: 1.5px solid var(--match-line);
    border-radius: 12px;
    padding: 9px 13px;
    font: 500 0.88rem var(--match-font);
    background: var(--wr-warm-cream);
    outline: none;
}
.match-spec__save-row input:focus { border-color: var(--wr-coral); }
.match-spec__save-row button {
    border: none;
    border-radius: 12px;
    padding: 9px 16px;
    font: 700 0.85rem var(--match-font);
    background: var(--wr-coral);
    color: #fff;
    cursor: pointer;
    white-space: nowrap;
}
.match-spec__save-error {
    color: #B91C1C;
    font-size: 0.78rem;
    margin: 8px 0 0;
}

.match-spec__active {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    font-size: 0.83rem;
    line-height: 1.5;
}
.match-spec__active a {
    display: block;
    color: var(--wr-coral);
    font-weight: 700;
    text-decoration: none;
}
.match-spec__active a:hover { text-decoration: underline; }

.match-spec__brand {
    margin-top: 12px;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--match-muted);
    opacity: 0.7;
    text-align: right;
}

/* ---------------- Trust strip ---------------- */

.match-trust {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--match-muted);
    padding: 0 6px;
}

.match-live-dot {
    width: 9px; height: 9px;
    flex: none;
    margin-top: 2px;
    border-radius: 50%;
    background: var(--wr-success, #22C55E);
    box-shadow: 0 0 0 0 rgba(34,197,94,0.5);
    animation: live-pulse 2.4s infinite;
}
@keyframes live-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(34,197,94,0.5); }
    70%  { box-shadow: 0 0 0 7px rgba(34,197,94,0); }
    100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}

/* ---------------- Results ---------------- */

.match-results__bar {
    display: flex;
    align-items: center;
    gap: 12px;
}
.match-results__bar h2 {
    font-size: 1.02rem;
    font-weight: 800;
    letter-spacing: -0.01em;
    margin: 0;
}
.match-results__refresh {
    border: 1.5px solid var(--wr-coral-light);
    background: var(--match-paper);
    color: var(--wr-coral);
    border-radius: 999px;
    padding: 5px 13px;
    font: 700 0.76rem var(--match-font);
    cursor: pointer;
    animation: msg-in 0.25s ease-out both;
}
.match-results__hint {
    font-size: 0.8rem;
    color: var(--match-muted);
    margin: 4px 0 0;
}

.match-results__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
    gap: 16px;
    margin-top: 14px;
}

.match-pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-top: 16px;
}
.match-pager__btn {
    border: 1.5px solid var(--wr-coral-light);
    background: var(--match-paper);
    color: var(--wr-coral);
    border-radius: 999px;
    padding: 6px 15px;
    font: 700 0.8rem var(--match-font);
    cursor: pointer;
}
.match-pager__btn:disabled {
    opacity: 0.4;
    cursor: default;
}
.match-pager__label {
    font: 600 0.8rem var(--match-font);
    color: var(--match-muted);
}

.match-pet {
    overflow: hidden;
    padding: 0;
    display: flex;
    flex-direction: column;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    animation: card-in 0.4s ease-out both;
}
.match-pet:hover {
    transform: translateY(-3px);
    box-shadow: var(--wr-shadow-lg, 0 8px 40px rgba(0,0,0,0.12));
}
@keyframes card-in {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: none; }
}
/* staggered entrance */
.match-pet:nth-child(2) { animation-delay: 0.05s; }
.match-pet:nth-child(3) { animation-delay: 0.1s; }
.match-pet:nth-child(4) { animation-delay: 0.15s; }
.match-pet:nth-child(5) { animation-delay: 0.2s; }
.match-pet:nth-child(6) { animation-delay: 0.25s; }

.match-pet__photo-link {
    position: relative;
    display: block;
    aspect-ratio: 1 / 0.92;
    background: var(--wr-warm-peach);
}
.match-pet__photo {
    width: 100%; height: 100%;
    object-fit: cover;
}
.match-pet__distance {
    position: absolute;
    bottom: 8px; left: 8px;
    background: rgba(31, 41, 55, 0.72);
    color: #fff;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 999px;
    backdrop-filter: blur(4px);
}

.match-pet__body { padding: 12px 14px 14px; }
.match-pet__name {
    font-size: 0.98rem;
    font-weight: 800;
    margin: 0;
    text-transform: capitalize;
}
.match-pet__breed {
    font-size: 0.76rem;
    color: var(--match-muted);
    margin: 2px 0 0;
}
.match-pet__meta {
    font-size: 0.76rem;
    color: var(--match-muted);
    margin: 0 0 8px;
}
.match-pet__known {
    font-size: 0.74rem;
    color: #15803D;
    margin: 0 0 3px;
    line-height: 1.45;
}
.match-pet__known::before { content: "✓ "; font-weight: 800; }
.match-pet__unknown {
    font-size: 0.74rem;
    color: var(--match-muted);
    margin: 0;
    line-height: 1.45;
}
.match-pet__unknown::before { content: "? "; font-weight: 800; }

/* Worth-a-look + advocate treatments */
.match-worth { margin-top: 26px; }
.match-worth h3 {
    font-size: 0.92rem;
    font-weight: 800;
    margin: 0;
    color: var(--match-amber);
}
.match-worth__why {
    font-size: 0.78rem;
    color: var(--match-muted);
    margin: 3px 0 0;
}
.match-worth .match-pet { border-left: 4px solid var(--match-amber); }

.match-pet--advocate {
    border-left: 4px solid var(--match-amber);
    position: relative;
}
.match-pet--advocate::after {
    content: "🧡 Advocate pick";
    position: absolute;
    top: 10px; right: 10px;
    background: var(--match-amber-soft);
    color: #92400E;
    font-size: 0.66rem;
    font-weight: 800;
    padding: 4px 10px;
    border-radius: 999px;
}

/* ---------------- Mobile ---------------- */

.match-mobilebar { display: none; }
.match-sheet { display: none; }

@media (max-width: 991px) {
    .match-page {
        grid-template-columns: 1fr;
        padding: 10px 12px 90px;
    }
    .match-chat {
        position: static;
        height: calc(100vh - 210px);
        min-height: 400px;
    }
    .match-spec { position: static; }
    .match-side { order: -1; }
    .match-side .match-results { display: none; }   /* results live in the sheet */
    .match-spec__groups, .match-spec__empty { max-height: 130px; overflow-y: auto; }

    .match-mobilebar {
        display: flex;
        position: fixed;
        bottom: 14px; left: 14px; right: 14px;
        z-index: 60;
        align-items: center;
        justify-content: center;
        gap: 10px;
        padding: 14px;
        border: none;
        border-radius: 18px;
        background: var(--wr-text, #1F2937);
        color: #fff;
        font: 700 0.92rem var(--match-font);
        box-shadow: 0 10px 30px rgba(0,0,0,0.3);
        cursor: pointer;
    }
    .match-mobilebar__new {
        background: var(--wr-coral);
        border-radius: 999px;
        padding: 2px 10px;
        font-size: 0.72rem;
    }

    .match-sheet {
        display: block;
        position: fixed;
        left: 0; right: 0; bottom: 0;
        height: 86vh;
        z-index: 70;
        background: var(--wr-warm-cream, #FFF9F5);
        border-radius: 24px 24px 0 0;
        box-shadow: 0 -12px 50px rgba(0,0,0,0.25);
        transform: translateY(102%);
        transition: transform 0.32s cubic-bezier(0.3, 0.9, 0.3, 1);
    }
    .match-sheet.is-open { transform: none; }
    .match-sheet__grab {
        padding: 12px 0 6px;
        cursor: pointer;
        display: grid;
        place-items: center;
    }
    .match-sheet__grab span {
        width: 44px; height: 5px;
        border-radius: 999px;
        background: rgba(107, 114, 128, 0.4);
    }
    .match-sheet__body {
        height: calc(86vh - 30px);
        overflow-y: auto;
        padding: 6px 16px 40px;
    }
}

/* ---------------- Dark mode ---------------- */

@media (prefers-color-scheme: dark) {
    .match-page {
        --match-paper: #1E2430;
        --match-ink: #F3F4F6;
        --match-muted: #9CA3AF;
        --match-line: rgba(244, 163, 147, 0.16);
        --match-amber-soft: rgba(217, 119, 6, 0.18);
        background:
            radial-gradient(1200px 500px at 85% -10%, rgba(224,122,95,0.08) 0%, transparent 60%),
            #161B24;
        color: var(--match-ink);
    }
    .match-page .wr-card { background: var(--match-paper); }
    .match-msg--assistant { background: #2A3142; }
    .match-chat__composer { background: var(--match-paper); }
    .match-chat__composer textarea,
    .match-spec__save-row input {
        background: #161B24;
        color: var(--match-ink);
    }
    .match-chat__restart:hover { background: #2A3142; }
    .match-pet__photo-link { background: #2A3142; }
    .match-pet__known { color: #4ADE80; }
    .match-spec__ledger { color: #FCD34D; }
    .match-chip--not { border-color: #475569; color: #94A3B8; }
    .match-sheet { background: #161B24; }
    .match-results__refresh { background: var(--match-paper); }
    .match-pager__btn { background: var(--match-paper); }
}

@media (prefers-reduced-motion: reduce) {
    .match-msg, .match-pet, .match-chip--changed,
    .match-spec__ledger, .match-live-dot { animation: none !important; }
    .match-sheet { transition: none; }
}

/* ---------------- Intent panels: related reading + nearby shelters ---------------- */
.match-reading { margin: 4px 0 18px; }
.match-reading h3, .match-shelters h3 {
    font-size: 0.95rem; font-weight: 800; color: var(--match-ink);
    margin: 0 0 8px; letter-spacing: 0.01em;
}
.match-reading__row { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.match-read {
    display: flex; gap: 10px; align-items: flex-start; text-decoration: none;
    background: var(--wr-card-bg, #fff); border: 1px solid rgba(224, 122, 95, 0.18);
    border-radius: var(--wr-radius, 14px); padding: 10px;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.match-read:hover { transform: translateY(-2px); box-shadow: 0 8px 22px -14px rgba(31,41,55,0.4); }
.match-read__thumb {
    width: 56px; height: 56px; border-radius: 10px; object-fit: cover; flex: none;
    background: var(--wr-warm-peach, #FFF0E6);
}
.match-read__title {
    font-size: 0.84rem; font-weight: 700; color: var(--match-ink); line-height: 1.25;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.match-read__preview {
    font-size: 0.74rem; color: var(--match-muted); margin-top: 3px; line-height: 1.3;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.match-shelters { margin: 18px 0 6px; }
.match-shelters__why { font-size: 0.8rem; color: var(--match-muted); margin: 0 0 10px; }
.match-shelters__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.match-shelter {
    background: var(--wr-card-bg, #fff); border-radius: var(--wr-radius, 14px);
    border: 1px solid rgba(224, 122, 95, 0.16); border-left: 4px solid var(--wr-coral, #E07A5F);
    padding: 12px 14px;
}
.match-shelter__head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.match-shelter__name { font-weight: 800; font-size: 0.92rem; color: var(--match-ink); line-height: 1.25; }
.match-shelter__distance {
    flex: none; font-size: 0.72rem; font-weight: 700; color: var(--wr-coral, #E07A5F);
    background: var(--wr-warm-peach, #FFF0E6); border-radius: 999px; padding: 2px 8px;
}
.match-shelter__meta { font-size: 0.76rem; color: var(--match-muted); margin-top: 4px; }
.match-shelter__actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.match-shelter__action {
    font-size: 0.76rem; font-weight: 700; text-decoration: none;
    border-radius: 999px; padding: 5px 12px;
    color: var(--wr-coral, #E07A5F); border: 1.5px solid rgba(224, 122, 95, 0.45);
    transition: background 0.15s ease, color 0.15s ease;
}
.match-shelter__action:hover { background: var(--wr-warm-peach, #FFF0E6); }
.match-shelter__action.is-primary {
    color: #fff; background: var(--wr-coral, #E07A5F); border-color: var(--wr-coral, #E07A5F);
}
.match-shelter__action.is-primary:hover { background: var(--wr-coral-light, #F4A393); }

@media (prefers-color-scheme: dark) {
    .match-read, .match-shelter { background: var(--wr-card-bg, #1E293B); border-color: rgba(244, 163, 147, 0.22); }
    .match-shelter { border-left-color: var(--wr-coral-light, #F4A393); }
    .match-shelter__distance { background: rgba(244, 163, 147, 0.14); color: var(--wr-coral-light, #F4A393); }
    .match-shelter__action { color: var(--wr-coral-light, #F4A393); border-color: rgba(244, 163, 147, 0.45); }
    .match-shelter__action:hover { background: rgba(244, 163, 147, 0.12); }
}
