:root {
    --bg: #0f1520;
    --bg-elev: #172033;
    --bg-elev-2: #1f2a40;
    --border: #2a3650;
    --text: #eef2f8;
    --muted: #9aa7bd;
    --accent: #ffcb05;
    --accent-ink: #1b1400;
    --blue: #3b82f6;
    --danger: #ef4444;
    --ok: #22c55e;
    --warn: #f59e0b;
    --radius: 14px;
    --nav-h: 64px;
    --shadow: 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.45;
    min-height: 100dvh;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: .2rem 0 .8rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 1.4rem 0 .6rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
p { margin: .35rem 0; }
code { background: var(--bg-elev-2); padding: .1em .35em; border-radius: 6px; font-size: .9em; }
img { max-width: 100%; }
[hidden] { display: none !important; }
h1:focus { outline: none; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.up { color: var(--ok); }
.down { color: var(--danger); }

/* ---- shell ---- */
.topbar {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; gap: 1rem;
    padding: .6rem 1rem;
    padding-top: calc(.6rem + env(safe-area-inset-top));
    background: rgba(15, 21, 32, .92);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.topnav { display: none; gap: .25rem; margin-left: 1rem; }
.topnav a { padding: .4rem .8rem; border-radius: 999px; color: var(--muted); font-weight: 500; }
.topnav a.active { background: var(--bg-elev-2); color: var(--text); }
.topnav a:hover { text-decoration: none; color: var(--text); }
.account { margin-left: auto; }
.avatar {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--accent); color: var(--accent-ink); font-weight: 700;
}
.content { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 1rem); }
.page { max-width: 1100px; margin: 0 auto; padding: 1rem; }
.page.narrow { max-width: 720px; }

.bottomnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    display: grid; grid-template-columns: repeat(3, 1fr);
    height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(23, 32, 51, .96);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
}
.bottomnav a {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--muted); font-size: .72rem; font-weight: 600;
}
.bottomnav a:hover { text-decoration: none; }
.bottomnav a.active { color: var(--accent); }
.bottomnav svg { width: 26px; height: 26px; fill: currentColor; }
.bottomnav .scan-link svg { width: 30px; height: 30px; }

@media (min-width: 768px) {
    .topnav { display: flex; }
    .bottomnav { display: none; }
    .content { padding-bottom: 2rem; }
    h1 { font-size: 2rem; }
}

/* ---- buttons & forms ---- */
.button {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    min-height: 44px; padding: .6rem 1.1rem;
    border-radius: 12px; border: 1px solid transparent;
    font: inherit; font-weight: 600; cursor: pointer; color: var(--text);
    background: var(--bg-elev-2); text-decoration: none;
    transition: transform .05s ease, filter .15s ease;
}
.button:hover { text-decoration: none; filter: brightness(1.1); }
.button:active { transform: translateY(1px); }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button.primary { background: var(--accent); color: var(--accent-ink); }
.button.secondary { background: var(--bg-elev-2); border-color: var(--border); }
.button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.button.large { width: 100%; min-height: 54px; font-size: 1.05rem; }
.button.google { background: #fff; color: #1f2937; width: 100%; min-height: 52px; font-size: 1.02rem; }

label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; color: var(--muted); flex: 1; }
label.choice { flex-direction: row; align-items: center; gap: .5rem; color: var(--text); }
input[type=text], input[type=search], input[type=number], input[type=email], select {
    width: 100%; min-height: 44px; padding: .5rem .75rem;
    border-radius: 10px; border: 1px solid var(--border);
    background: var(--bg-elev); color: var(--text); font: inherit; font-size: 16px;
}
input:focus, select:focus { outline: 2px solid var(--blue); outline-offset: 1px; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.row { display: flex; gap: .6rem; align-items: flex-end; flex-wrap: wrap; }
.row.compact { align-items: center; }
.row > .button { flex: 0 0 auto; }
.qty-input { width: 5.5rem; flex: 0 0 auto; }

.alert { padding: .7rem .9rem; border-radius: 10px; border: 1px solid; margin: .6rem 0; }
.alert.ok { border-color: var(--ok); background: rgba(34, 197, 94, .12); }
.alert.error { border-color: var(--danger); background: rgba(239, 68, 68, .12); }
.alert.warn { border-color: var(--warn); background: rgba(245, 158, 11, .12); }

.panel { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.panel h2 { margin-top: 0; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0 0 1rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

/* ---- login ---- */
.auth-shell { min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem; }
.welcome { max-width: 420px; width: 100%; text-align: center; display: flex; flex-direction: column; gap: .8rem; align-items: center; }
.welcome h1 { font-size: 2.1rem; line-height: 1.1; margin: 0; }
.welcome .lead { color: var(--muted); }
.eyebrow { font-size: .75rem; letter-spacing: .2em; color: var(--accent); font-weight: 700; margin: 0; }
.hero-icon { filter: drop-shadow(0 10px 20px rgba(255, 203, 5, .25)); }
.dev-login { width: 100%; display: flex; flex-direction: column; gap: .6rem; margin-top: 1rem; padding-top: 1rem; border-top: 1px dashed var(--border); }
.welcome .alert { width: 100%; }

/* ---- collection ---- */
.summary {
    display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap;
    background: linear-gradient(135deg, var(--bg-elev), var(--bg-elev-2));
    border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1rem;
}
.summary .label { margin: 0; color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; }
.summary .total { margin: 0; font-size: 2.2rem; font-weight: 800; letter-spacing: -.02em; }
.summary-side { display: flex; flex-direction: column; align-items: flex-end; gap: .5rem; }
.toolbar { display: flex; gap: .5rem; margin-bottom: 1rem; }
.toolbar input[type=search] { flex: 1; }
.toolbar select { width: auto; flex: 0 0 auto; }

.card-grid {
    list-style: none; padding: 0; margin: 0;
    display: grid; gap: .8rem;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.card-tile {
    display: flex; flex-direction: column; height: 100%;
    background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
    overflow: hidden; color: var(--text);
    transition: transform .12s ease, box-shadow .12s ease;
}
.card-tile:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow); }
.card-image { position: relative; aspect-ratio: 63 / 88; background: var(--bg-elev-2); }
.card-image img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-placeholder { display: grid; place-items: center; height: 100%; padding: 1rem; color: var(--muted); text-align: center; }
.qty {
    position: absolute; top: .4rem; right: .4rem;
    background: rgba(0, 0, 0, .7); color: #fff; font-weight: 700; font-size: .8rem;
    padding: .15rem .45rem; border-radius: 999px;
}
.card-meta { display: flex; flex-direction: column; gap: .15rem; padding: .6rem .7rem .7rem; }
.card-meta strong { font-size: .95rem; line-height: 1.2; }
.price { color: var(--accent); font-weight: 700; }
.tag { align-self: flex-start; font-size: .7rem; padding: .1rem .45rem; border-radius: 999px; background: var(--bg-elev-2); color: var(--muted); }
.empty { text-align: center; padding: 3rem 1rem; border: 1px dashed var(--border); border-radius: var(--radius); }
.empty h2 { color: var(--text); text-transform: none; letter-spacing: 0; font-size: 1.3rem; }
.empty .button { margin-top: 1rem; }

/* ---- scan ---- */
.scan-form { display: flex; flex-direction: column; gap: .9rem; }
.photo-drop {
    display: block; position: relative; cursor: pointer;
    border: 2px dashed var(--border); border-radius: var(--radius);
    background: var(--bg-elev); min-height: 260px; overflow: hidden;
}
.photo-drop:hover { border-color: var(--accent); }
.photo-drop img { display: block; width: 100%; max-height: 60dvh; object-fit: contain; background: #000; }
.photo-prompt {
    position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .4rem;
    color: var(--text); text-align: center; padding: 1rem;
}
.photo-prompt.has-photo { inset: auto 0 0 0; background: rgba(0, 0, 0, .6); padding: .5rem; flex-direction: row; gap: .6rem; }
.photo-prompt.has-photo svg { width: 22px; height: 22px; }
.photo-prompt.has-photo .small { display: none; }
.manual-search { margin-top: 2rem; }
.reading { display: flex; gap: 1rem; align-items: flex-start; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem; }
.reading-photo { width: 96px; flex: 0 0 auto; border-radius: 8px; object-fit: cover; aspect-ratio: 63 / 88; background: #000; }

.candidates { list-style: none; padding: 0; margin: 1rem 0; display: flex; flex-direction: column; gap: .8rem; }
.candidate {
    display: flex; gap: .8rem;
    background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: .7rem;
}
.candidate-image { flex: 0 0 96px; }
.candidate-image img { width: 96px; border-radius: 6px; aspect-ratio: 63 / 88; object-fit: cover; }
.candidate-body { flex: 1; display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.candidate-body select { flex: 1 1 10rem; min-width: 0; }

/* ---- detail ---- */
.detail { display: flex; flex-direction: column; gap: 1rem; }
.detail-image img { width: 100%; max-width: 360px; margin: 0 auto; display: block; border-radius: 12px; box-shadow: var(--shadow); }
.big-price { font-size: 2rem; font-weight: 800; color: var(--accent); margin: .4rem 0 0; display: flex; flex-direction: column; line-height: 1.1; }
.big-price small { font-size: .85rem; font-weight: 500; }
.prices { width: 100%; border-collapse: collapse; margin-top: 1rem; font-size: .92rem; }
.prices th, .prices td { text-align: left; padding: .45rem .3rem; border-bottom: 1px solid var(--border); }
.prices th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }
.chart { margin: 0; }
.chart svg { width: 100%; height: 100px; color: var(--accent); background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px; }
.edit form + form { margin-top: 1rem; }

@media (min-width: 640px) {
    .detail { flex-direction: row; }
    .detail-image { flex: 0 0 300px; }
    .detail-body { flex: 1; }
}

/* ---- busy overlay ---- */
.busy { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: rgba(15, 21, 32, .82); backdrop-filter: blur(4px); }
.busy[hidden] { display: none; }
.busy-card { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 1rem; padding: 2rem; }
.spinner { width: 48px; height: 48px; border-radius: 50%; border: 4px solid var(--border); border-top-color: var(--accent); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
