/* Visibrick: purple claymorphism (soft, puffy surfaces, bright rims, soft purple shadows).
   The palette matches the app's Resources/Styles/Colors.xaml. Dark mode follows the device setting. */

@font-face {
    font-family: "Open Sans";
    src: url("../fonts/OpenSans-Regular.ttf") format("truetype");
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: "Open Sans";
    src: url("../fonts/OpenSans-Semibold.ttf") format("truetype");
    font-weight: 600;
    font-display: swap;
}

:root {
    --primary: #512BD4;
    --primary-light: #8B6CF5;
    --primary-text: #512BD4;
    --bg: #EEE9FB;
    --surface: #FBF9FF;
    --surface-shade: #E9E0FF;
    --well: #FFFFFF;
    --text: #2B1A4A;
    --muted: #7D6E9C;
    --chip: #E2D7FF;
    --chip-text: #4B23B8;
    --error: #C62F35;
    --shadow: rgba(74, 43, 168, 0.22);
    --rim-light: rgba(255, 255, 255, 0.95);
    --rim-dark: rgba(74, 43, 168, 0.12);
    --nav-bg: rgba(251, 249, 255, 0.85);
    --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --primary-text: #AC99EA;
        --bg: #191226;
        --surface: #2E2347;
        --surface-shade: #241B3A;
        --well: #F1ECFF;
        --text: #F2EDFF;
        --muted: #B5A7D6;
        --chip: #3A2C62;
        --chip-text: #D9CCFF;
        --error: #FF8A8F;
        --shadow: rgba(10, 4, 30, 0.55);
        --rim-light: rgba(255, 255, 255, 0.14);
        --rim-dark: rgba(0, 0, 0, 0.3);
        --nav-bg: rgba(36, 27, 58, 0.85);
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Open Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary-text); text-decoration: none; }
img { max-width: 100%; }
h1, h2, h3 { font-weight: 600; margin: 0; }
h1 { font-size: 32px; }
h2 { font-size: 18px; }
p { margin: 0; }
:focus-visible { outline: 3px solid var(--primary-light); outline-offset: 3px; border-radius: 12px; }

/* Blazor moves focus to each page's heading after navigating (for screen readers); that shouldn't draw a ring */
h1:focus, h1:focus-visible { outline: none; }

.muted { color: var(--muted); }
.caption { color: var(--muted); font-size: 12.5px; }
.error { color: var(--error); }
.center { text-align: center; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- Surfaces ---------- */

.clay-card {
    background: linear-gradient(135deg, var(--surface), var(--surface-shade));
    border-radius: 28px;
    padding: 24px;
    box-shadow: 0 12px 28px var(--shadow), inset 2px 2px 0 var(--rim-light), inset -2px -2px 6px var(--rim-dark);
}

.well {
    background: var(--well);
    border-radius: 22px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--chip);
    color: var(--chip-text);
    border-radius: 12px;
    padding: 4px 10px;
    font-size: 11.5px;
    font-weight: 600;
    white-space: nowrap;
}

/* ---------- Buttons (hover lifts, press squishes, release springs back) ---------- */

.btn, .link-btn, .chip-btn, .press {
    transition: transform 0.32s var(--spring), opacity 0.15s, box-shadow 0.2s;
}

.btn:hover, .chip-btn:hover, .press:hover { transform: translateY(-2px) scale(1.02); }
.btn:active, .chip-btn:active, .press:active, .link-btn:active { transform: scale(0.96); transition-duration: 0.09s; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 52px;
    padding: 0 22px;
    border: none;
    border-radius: 22px;
    font: 600 16px "Open Sans", sans-serif;
    cursor: pointer;
    width: 100%;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    color: white;
    box-shadow: 0 10px 22px rgba(81, 43, 212, 0.35);
}

.btn-apple { background: #000; color: #fff; }
.btn-google { background: #fff; color: #1F1F1F; border: 1px solid #DADCE0; }
.btn:disabled { opacity: 0.6; cursor: default; transform: none; }
.btn-small { height: 44px; width: auto; padding: 0 16px; font-size: 15px; }

.link-btn {
    background: none;
    border: none;
    padding: 4px 0;
    color: var(--primary-text);
    font: 600 15px "Open Sans", sans-serif;
    cursor: pointer;
}

.link-btn.danger { color: var(--error); }
.link-btn:hover { text-decoration: underline; }

.chip-btn {
    background: var(--chip);
    color: var(--chip-text);
    border: none;
    border-radius: 17px;
    height: 34px;
    padding: 0 14px;
    font: 600 13px "Open Sans", sans-serif;
    cursor: pointer;
}

.chip-btn.selected { background: var(--primary); color: white; }

/* ---------- Inputs ---------- */

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-weight: 600; font-size: 14px; }

.input {
    display: flex;
    align-items: center;
    background: linear-gradient(135deg, var(--surface), var(--surface-shade));
    border-radius: 24px;
    padding: 0 8px 0 20px;
    box-shadow: 0 12px 28px var(--shadow), inset 2px 2px 0 var(--rim-light), inset -2px -2px 6px var(--rim-dark);
}

.input input {
    flex: 1;
    min-width: 0;
    height: 50px;
    border: none;
    background: transparent;
    color: var(--text);
    font: 15px "Open Sans", sans-serif;
    outline: none;
}

.input input::placeholder { color: var(--muted); }
.input .link-btn { padding: 0 12px; }

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

.page {
    max-width: 1400px;
    margin: 0 auto;
    padding: 28px 24px 48px;
}

.page.narrow { max-width: 720px; }
.page.form { max-width: 560px; }

.page-header { display: flex; flex-direction: column; gap: 2px; margin-bottom: 20px; }
.page-header .back { align-self: flex-start; margin-bottom: 8px; }

.toolbar { display: flex; flex-direction: column; gap: 14px; margin-bottom: 24px; }

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 20px;
}

.load-more { display: flex; justify-content: center; margin-top: 28px; }
.load-more .btn { width: auto; min-width: 220px; }

.spinner {
    width: 22px;
    height: 22px;
    border: 3px solid var(--chip);
    border-top-color: var(--primary-light);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Item card ---------- */

.item-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    color: var(--text);
    border-radius: 28px;
}

.item-card:hover { transform: translateY(-3px); }

.item-card .image {
    position: relative;
    height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
}

.item-card .image img { max-height: 100%; object-fit: contain; }
.item-card .image .placeholder { width: 56px; height: 56px; position: absolute; opacity: 0.9; }
.item-card .image img.photo { position: relative; }

.item-card .name {
    font-weight: 600;
    font-size: 14px;
    line-height: 1.4;
    height: 2.8em;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.item-card .footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.badge {
    position: absolute;
    top: 6px;
    right: 6px;
    min-width: 32px;
    height: 32px;
    border-radius: 16px;
    border: none;
    padding: 0 10px;
    font: 600 14px "Open Sans", sans-serif;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

.badge.add { background: var(--chip); color: var(--chip-text); font-size: 20px; padding: 0 0 2px; width: 32px; }
.badge.owned { background: var(--primary); color: white; }

/* ---------- Top navigation (desktop) and bottom tabs (phones) ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 28px;
    padding: 12px 24px;
    background: var(--nav-bg);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: 0 4px 20px var(--shadow);
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 600; font-size: 20px; }
.brand img { width: 34px; height: 34px; }

.nav-links { display: flex; gap: 6px; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 16px;
    color: var(--muted);
    font-weight: 600;
}

.nav-link:hover { color: var(--text); }
.nav-link.active { color: var(--primary-text); background: var(--chip); }
.nav-link svg { width: 20px; height: 20px; fill: currentColor; }

.tabbar { display: none; }

@media (max-width: 720px) {
    .nav-links { display: none; }
    .page { padding: 20px 16px 110px; }
    h1 { font-size: 28px; }
    .card-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
    .item-card .image { height: 120px; }

    .tabbar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 20;
        display: flex;
        justify-content: space-around;
        padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
        background: var(--nav-bg);
        backdrop-filter: blur(14px);
        -webkit-backdrop-filter: blur(14px);
        box-shadow: 0 -4px 20px var(--shadow);
    }

    .tabbar .nav-link { flex-direction: column; gap: 2px; font-size: 12px; padding: 6px 18px; }
}

/* ---------- Avatar and its menu ---------- */

.avatar {
    width: var(--size, 44px);
    height: var(--size, 44px);
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    color: white;
    font-weight: 600;
    font-size: calc(var(--size, 44px) * 0.38);
    border: 2px solid rgba(255, 255, 255, 0.25);
    flex-shrink: 0;
}

.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar svg { width: 60%; height: 60%; fill: white; }

.account { position: relative; }
.account > button { background: none; border: none; padding: 0; cursor: pointer; border-radius: 50%; }

.menu-backdrop { position: fixed; inset: 0; z-index: 30; }

.menu {
    position: absolute;
    right: 0;
    top: 56px;
    z-index: 31;
    width: 280px;
    padding: 8px;
    border-radius: 24px;
    animation: menu-in 0.16s ease-out;
    transform-origin: top right;
}

@keyframes menu-in { from { opacity: 0; transform: scale(0.94); } }

.menu .header { display: flex; align-items: center; gap: 12px; padding: 8px 10px; min-width: 0; }
.menu .header > div { min-width: 0; }
.menu .header .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu hr { border: none; height: 1px; background: rgba(139, 108, 245, 0.18); margin: 4px 8px; }

.menu-item {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 12px;
    border-radius: 14px;
    color: var(--text);
    font: 600 14px "Open Sans", sans-serif;
    cursor: pointer;
}

.menu-item:hover { background: var(--chip); }
.menu-item.danger { color: var(--error); }

/* ---------- Item page ---------- */

.item-hero { padding: 14px; }
.item-hero .well { height: 320px; display: flex; align-items: center; justify-content: center; padding: 16px; position: relative; }
.item-hero img.photo { max-height: 100%; object-fit: contain; position: relative; }
.item-hero .placeholder { width: 80px; height: 80px; position: absolute; }

.details { display: grid; grid-template-columns: auto 1fr; gap: 10px 20px; align-items: baseline; }
.details dt { color: var(--muted); font-size: 13px; }
.details dd { margin: 0; font-weight: 600; }

.stepper { display: flex; align-items: center; gap: 14px; }
.stepper .btn { width: 48px; height: 48px; padding: 0; font-size: 22px; }
.stepper .count { min-width: 40px; text-align: center; font-size: 28px; font-weight: 600; color: var(--primary-text); }

/* ---------- Catalog categories ---------- */

.category {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    color: var(--text);
}

.category .icon { width: 64px; height: 64px; display: flex; align-items: center; justify-content: center; }
.category .icon img { width: 36px; height: 36px; }
.category .chevron { margin-left: auto; font-size: 28px; color: var(--muted); }

.brand-mark { width: 72px; height: 72px; margin: 0 auto; display: block; }

/* ---------- Blazor's own loading and error UI ---------- */

.loading-screen { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; }
.loading-screen img { width: 88px; height: 88px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(0.92); opacity: 0.7; } }

#blazor-error-ui {
    background: #FFF4E5;
    color: #5B3A00;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }

/* ---------- Toast (short messages at the bottom) ---------- */

.toast {
    position: fixed;
    left: 50%;
    bottom: 28px;
    transform: translateX(-50%);
    z-index: 40;
    padding: 14px 22px;
    border-radius: 20px;
    max-width: min(520px, calc(100% - 32px));
    animation: toast-in 0.2s ease-out;
}

@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px); } }

@media (max-width: 720px) {
    .toast { bottom: calc(96px + env(safe-area-inset-bottom)); }
}

/* Grid cells otherwise refuse to shrink below their widest unbreakable content (the number chip and year),
   which pushes narrow screens wider than the phone */
.card-grid > * { min-width: 0; }
.item-card .footer .chip { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.topbar { min-width: 0; }
