/* Wishlist — Pinterest-style dashboard */

:root {
    --bg: #f6f6f4;
    --surface: #ffffff;
    --surface-2: #efefec;
    --text: #1c1c1a;
    --text-muted: #6b6b66;
    --border: #e3e3df;
    --primary: #e60023;
    --primary-hover: #c8001f;
    --on-primary: #ffffff;
    --success: #16a34a;
    --shadow: 0 1px 3px rgba(0,0,0,.07), 0 8px 24px rgba(0,0,0,.06);
    --shadow-lg: 0 4px 12px rgba(0,0,0,.12), 0 16px 40px rgba(0,0,0,.14);
    --radius: 16px;
    /* z-index scale */
    --z-bar: 30;
    --z-fab: 40;
    --z-modal: 50;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #121212;
        --surface: #1e1e1e;
        --surface-2: #2a2a2a;
        --text: #f2f2f0;
        --text-muted: #a3a39e;
        --border: #333330;
        --shadow: 0 1px 3px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
        --shadow-lg: 0 4px 12px rgba(0,0,0,.5), 0 16px 40px rgba(0,0,0,.5);
    }
}

* { box-sizing: border-box; }

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

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

svg { width: 1.25em; height: 1.25em; flex: none; }

.sr-only {
    position: absolute; width: 1px; height: 1px;
    margin: -1px; padding: 0; border: 0;
    clip: rect(0 0 0 0); overflow: hidden;
}

/* ---------- top bar ---------- */

.topbar {
    position: sticky; top: 0; z-index: var(--z-bar);
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.topbar-inner {
    max-width: 1280px; margin: 0 auto;
    display: flex; align-items: center; gap: 12px;
    padding: 10px 16px;
}

.brand {
    display: flex; align-items: center; gap: 8px;
    color: var(--primary); text-decoration: none;
    font-weight: 700; font-size: 18px; white-space: nowrap;
}
.brand svg { fill: var(--primary); }
.brand span { color: var(--text); }

.search-wrap {
    flex: 1; display: flex; align-items: center; gap: 8px;
    background: var(--surface-2);
    border-radius: 999px; padding: 0 14px;
    min-width: 0;
}
.search-wrap svg { color: var(--text-muted); width: 18px; height: 18px; }
.search-wrap input {
    flex: 1; min-width: 0; border: 0; background: none; outline: none;
    color: var(--text); font-size: 16px; padding: 11px 0;
}
.search-wrap:focus-within { outline: 2px solid var(--primary); outline-offset: 1px; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- buttons ---------- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    border: 0; border-radius: 999px;
    padding: 11px 18px; min-height: 44px;
    font-size: 15px; font-weight: 600;
    cursor: pointer; text-decoration: none;
    transition: background-color .2s, color .2s, box-shadow .2s;
    color: var(--text);
}
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); }

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

.btn-block { width: 100%; }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; border-radius: 999px;
    border: 0; background: var(--surface-2); color: var(--text);
    cursor: pointer; transition: background-color .2s, color .2s;
}
.icon-btn:hover { background: var(--border); }
.icon-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- layout ---------- */

.container { max-width: 1280px; margin: 0 auto; padding: 16px; }

.totals-bar {
    display: grid; grid-template-columns: 1fr auto auto auto; gap: 12px;
    background: var(--surface-2); border-radius: var(--radius);
    padding: 14px 16px; margin-bottom: 16px;
    font-size: 14px;
}
@media (max-width: 639px) {
    .totals-bar { grid-template-columns: 1fr 1fr; }
}

.total-group {
    display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
}
.total-label { color: var(--text-muted); font-size: 12px; font-weight: 600; text-transform: uppercase; }
.total-amount { font-weight: 700; font-size: 15px; color: var(--text); }

.total-group.total-high .total-amount { color: #ef4444; }
.total-group.total-medium .total-amount { color: #f59e0b; }
.total-group.total-low .total-amount { color: #10b981; }

.filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }

.chip {
    display: inline-flex; align-items: center; gap: 6px;
    border: 1px solid var(--border); border-radius: 999px;
    background: var(--surface); color: var(--text);
    padding: 9px 16px; min-height: 40px;
    font-size: 14px; font-weight: 600; cursor: pointer;
    transition: background-color .2s, color .2s, border-color .2s;
}
.chip:hover { background: var(--surface-2); }
.chip:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip-count { opacity: .65; font-weight: 500; }

/* ---------- masonry grid ---------- */

.masonry { columns: 2 140px; column-gap: 12px; }
@media (min-width: 640px)  { .masonry { columns: 3 200px; column-gap: 16px; } }
@media (min-width: 1024px) { .masonry { columns: 4 220px; } }
@media (min-width: 1440px) { .masonry { columns: 5 230px; } }

.card {
    break-inside: avoid;
    margin: 0 0 12px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: box-shadow .2s;
}
@media (min-width: 640px) { .card { margin-bottom: 16px; } }
.card:hover { box-shadow: var(--shadow-lg); }

.card-media { position: relative; background: var(--surface-2); }
.card-media img { display: block; width: 100%; height: auto; }

.card-open {
    position: absolute; right: 8px; bottom: 8px;
    display: inline-flex; align-items: center; gap: 6px;
    background: rgba(0,0,0,.65); color: #fff;
    border-radius: 999px; padding: 7px 12px;
    font-size: 13px; font-weight: 600; text-decoration: none;
    opacity: 0; transition: opacity .2s;
}
.card-open svg { width: 14px; height: 14px; }
.card:hover .card-open, .card-open:focus-visible { opacity: 1; }
@media (hover: none) { .card-open { opacity: 1; } }

.badge-bought {
    position: absolute; left: 8px; top: 8px;
    display: inline-flex; align-items: center; gap: 5px;
    background: var(--success); color: #fff;
    border-radius: 999px; padding: 5px 10px;
    font-size: 12px; font-weight: 700;
}
.badge-bought svg { width: 12px; height: 12px; }

.badge-priority {
    display: inline-block; flex-shrink: 0;
    border-radius: 6px; padding: 4px 8px;
    font-size: 10px; font-weight: 700; text-transform: uppercase;
}
.card-media .badge-priority {
    position: absolute; right: 8px; top: 8px;
}
.badge-priority.priority-high { background: #ef4444; color: #fff; }
.badge-priority.priority-medium { background: #f59e0b; color: #fff; }
.badge-priority.priority-low { background: #10b981; color: #fff; }

.is-purchased .card-media img { filter: grayscale(.7); opacity: .75; }
.is-purchased .card-title { color: var(--text-muted); }

.card-body { padding: 12px 14px 10px; }

.card-header {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
    margin-bottom: 4px;
}

.card-price { font-weight: 700; font-size: 16px; margin-bottom: 2px; line-height: 1.3; }
.card-original { display: block; font-size: 13px; font-weight: 500; color: var(--text-muted); text-decoration: line-through; margin-bottom: 2px; }
.card-shipping { display: block; font-size: 13px; font-weight: 500; color: var(--text-muted); margin-top: 2px; }

.card-title {
    margin: 0 0 4px; font-size: 15px; font-weight: 600; line-height: 1.35;
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

.card-domain {
    display: flex; align-items: center; gap: 6px;
    color: var(--text-muted); font-size: 13px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card-domain img { border-radius: 3px; }

.card-actions {
    display: flex; gap: 6px; justify-content: flex-end;
    margin-top: 8px; padding-top: 8px;
    border-top: 1px solid var(--border);
}
.card-actions .icon-btn { width: 36px; height: 36px; background: transparent; }
.card-actions .icon-btn:hover { background: var(--surface-2); }
.card-actions .icon-btn svg { width: 16px; height: 16px; }
.act-toggle:hover { color: var(--success); }
.act-delete:hover { color: var(--primary); }
.is-purchased .act-toggle { color: var(--success); }

/* ---------- empty state ---------- */

.empty {
    text-align: center; padding: 64px 24px; color: var(--text-muted);
}
.empty svg { width: 56px; height: 56px; margin-bottom: 8px; color: var(--primary); }
.empty h2 { color: var(--text); margin: 0 0 6px; }
.empty p { max-width: 420px; margin: 0 auto 20px; }

/* ---------- FAB (mobile) ---------- */

.fab {
    position: fixed; right: 16px; bottom: 16px; z-index: var(--z-fab);
    width: 56px; height: 56px; border-radius: 999px; border: 0;
    background: var(--primary); color: var(--on-primary);
    display: none; align-items: center; justify-content: center;
    box-shadow: var(--shadow-lg); cursor: pointer;
    transition: background-color .2s;
}
.fab:hover { background: var(--primary-hover); }
.fab:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.fab svg { width: 24px; height: 24px; }

@media (max-width: 639px) {
    .fab { display: flex; }
    #add-btn-top span { display: none; }
    #add-btn-top { display: none; }
    .brand span { display: none; }
}

/* ---------- modal ---------- */

.modal-backdrop[hidden] { display: none; }

.modal-backdrop {
    position: fixed; inset: 0; z-index: var(--z-modal);
    background: rgba(0,0,0,.55);
    display: flex; align-items: flex-end; justify-content: center;
    padding: 0;
}
@media (min-width: 640px) {
    .modal-backdrop { align-items: center; padding: 24px; }
}

.modal {
    background: var(--surface);
    width: 100%; max-width: 520px;
    max-height: 92dvh; overflow-y: auto;
    border-radius: 20px 20px 0 0;
    padding: 20px;
    box-shadow: var(--shadow-lg);
}
@media (min-width: 640px) { .modal { border-radius: 20px; } }

.modal-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 14px;
}
.modal-head h2 { margin: 0; font-size: 20px; }

.fetch-row { display: flex; gap: 8px; }
.fetch-row input {
    flex: 1; min-width: 0;
    border: 1.5px solid var(--border); border-radius: 12px;
    background: var(--surface-2); color: var(--text);
    padding: 11px 14px; font-size: 16px; outline: none;
}
.fetch-row input:focus { border-color: var(--primary); }

.fetch-status { min-height: 1.3em; margin: 6px 2px 10px; font-size: 13px; color: var(--text-muted); }
.fetch-status.error { color: var(--primary); }

.spinner {
    width: 16px; height: 16px;
    border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
    .spinner { animation-duration: 1.6s; }
    * { transition-duration: .01ms !important; }
}

.img-preview {
    position: relative; margin-bottom: 14px;
    border-radius: 12px; overflow: hidden; background: var(--surface-2);
}
.img-preview img { display: block; width: 100%; max-height: 260px; object-fit: cover; }
.img-remove {
    position: absolute; top: 8px; right: 8px;
    background: rgba(0,0,0,.6); color: #fff;
}
.img-remove:hover { background: rgba(0,0,0,.8); }

.form-field { margin-bottom: 12px; }
.form-field label {
    display: block; font-size: 13px; font-weight: 600;
    color: var(--text-muted); margin-bottom: 5px;
}
.text-muted { opacity: 0.7; font-weight: 400; }
.form-field input[type="text"],
.form-field input[type="url"],
.form-field textarea,
.form-field select {
    width: 100%;
    border: 1.5px solid var(--border); border-radius: 12px;
    background: var(--surface-2); color: var(--text);
    padding: 11px 14px; font-size: 16px; font-family: inherit;
    outline: none; resize: vertical;
}
.form-field input:focus, .form-field textarea:focus, .form-field select:focus { border-color: var(--primary); }
.form-field select { cursor: pointer; appearance: none; padding-right: 36px; background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 12 15 18 9"/></svg>'); background-repeat: no-repeat; background-position: right 10px center; background-size: 18px; padding-right: 32px; }
@media (prefers-color-scheme: dark) {
    .form-field select { background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2"><polyline points="6 9 12 15 18 9"/></svg>'); }
}
.form-field input[type="file"] { font-size: 14px; color: var(--text-muted); }

.form-row { display: flex; gap: 10px; }
.form-row .form-field { flex: 1; }
.form-row .form-field-sm { flex: 0 0 100px; min-width: 100px; }

.modal-foot {
    display: flex; justify-content: flex-end; gap: 10px;
    margin-top: 16px;
}

/* ---------- login ---------- */

.login-body {
    min-height: 100dvh;
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
}

.login-card {
    background: var(--surface);
    border-radius: 20px; box-shadow: var(--shadow);
    padding: 36px 28px; width: 100%; max-width: 380px;
    text-align: center;
}
.login-logo svg { width: 44px; height: 44px; color: var(--primary); fill: var(--primary); }
.login-card h1 { margin: 10px 0 4px; font-size: 24px; }
.login-sub { color: var(--text-muted); margin: 0 0 20px; }
.login-card input[type="password"] {
    width: 100%;
    border: 1.5px solid var(--border); border-radius: 12px;
    background: var(--surface-2); color: var(--text);
    padding: 12px 14px; font-size: 16px; outline: none;
    margin-bottom: 12px;
}
.login-card input[type="password"]:focus { border-color: var(--primary); }
.login-error { color: var(--primary); font-size: 14px; }
.login-warn {
    background: #fff7e0; color: #7a5b00;
    border-radius: 10px; padding: 10px 12px; font-size: 13px;
}
@media (prefers-color-scheme: dark) {
    .login-warn { background: #3a3000; color: #ffd866; }
}
.login-warn code { font-family: ui-monospace, monospace; }
