:root {
    color-scheme: dark;
    --bg: #0b1015;
    --panel: #121a22;
    --panel-2: #17232d;
    --line: #2b3a46;
    --text: #edf5f7;
    --muted: #99abb6;
    --accent: #4fd1c5;
    --accent-strong: #2eb8ac;
    --danger: #ff6b6b;
    --warning: #ffc857;
    --success: #6ee7a8;
    --radius: 18px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at top right, rgba(79, 209, 197, .09), transparent 26rem),
        var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: inherit; }
button, input { font: inherit; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .85rem max(1rem, calc((100vw - 1100px) / 2));
    background: rgba(11, 16, 21, .92);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(16px);
}

.brand {
    font-weight: 900;
    letter-spacing: -.04em;
    text-decoration: none;
    font-size: 1.25rem;
}

.topbar nav { display: flex; align-items: center; gap: .9rem; }
.topbar nav > a, .link-button {
    color: var(--muted);
    background: none;
    border: 0;
    text-decoration: none;
    padding: 0;
    cursor: pointer;
}
.topbar nav > a:hover, .link-button:hover { color: var(--text); }
.inline-form { display: inline; margin: 0; }

.page-shell { width: min(1100px, calc(100% - 2rem)); margin: 0 auto; padding: 2rem 0 5rem; }
.narrow { max-width: 520px; margin-inline: auto; }

h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(2rem, 7vw, 3.7rem); line-height: .98; letter-spacing: -.055em; margin-bottom: .8rem; }
h2 { font-size: 1.6rem; letter-spacing: -.035em; }
p { color: var(--muted); line-height: 1.55; }

.eyebrow { display: inline-block; margin-bottom: .7rem; color: var(--accent); font-size: .74rem; font-weight: 800; letter-spacing: .16em; }
.muted { color: var(--muted); }

.card {
    background: linear-gradient(180deg, rgba(23, 35, 45, .95), rgba(18, 26, 34, .95));
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 18px 60px rgba(0,0,0,.14);
}

.alert { margin-bottom: 1rem; padding: .9rem 1rem; border-radius: 12px; border: 1px solid; }
.alert.success { color: var(--success); border-color: rgba(110,231,168,.35); background: rgba(110,231,168,.08); }
.alert.error { color: #ffaaaa; border-color: rgba(255,107,107,.35); background: rgba(255,107,107,.08); }

.page-heading { margin: 1.5rem 0 1.6rem; }
.page-heading p { max-width: 700px; }
.page-heading.split, .section-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; }
.section-heading { margin: 2.4rem 0 1rem; }
.section-heading h2 { margin-bottom: 0; }
.section-heading > span { color: var(--muted); }

.button {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    gap: .45rem;
    border: 1px solid transparent;
    border-radius: 12px;
    padding: .7rem 1rem;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
    transition: transform .12s ease, background .12s ease, border-color .12s ease;
}
.button:active { transform: translateY(1px); }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button.primary { background: var(--accent); color: #061212; }
.button.primary:hover { background: #6ae1d6; }
.button.secondary { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.button.consume { background: #eef7f8; color: #0a1319; min-width: 112px; }
.button.danger { background: var(--danger); color: #1a0808; }
.button.danger.ghost { color: #ff9797; background: transparent; border-color: rgba(255,107,107,.35); }
.button.large { min-height: 52px; padding-inline: 1.25rem; }
.button-row, .form-actions, .batch-actions, .scanner-actions { display: flex; flex-wrap: wrap; gap: .65rem; }

.stack { display: grid; gap: 1rem; }
.form-card, .auth-card { padding: clamp(1rem, 4vw, 1.6rem); }
.form-grid { display: grid; gap: 1rem; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
label { display: grid; gap: .45rem; font-weight: 750; }
label small { color: var(--muted); font-weight: 500; }
input {
    width: 100%;
    min-height: 48px;
    padding: .78rem .9rem;
    color: var(--text);
    background: #0d151b;
    border: 1px solid var(--line);
    border-radius: 11px;
    outline: none;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,209,197,.12); }
input[type="file"] { padding: .7rem; }
input[type="checkbox"] { width: auto; min-height: 0; accent-color: var(--accent); }
.check-row { display: flex; align-items: center; gap: .55rem; font-weight: 600; }
.validation { color: #ff9b9b; font-size: .88rem; }
.validation:empty { display: none; }
.photo-picker { padding: 1rem; border: 1px dashed #49606f; border-radius: 14px; background: rgba(79,209,197,.03); }
.existing-photo { display: flex; align-items: center; gap: 1rem; }
.existing-photo img { width: 110px; height: 110px; object-fit: cover; border-radius: 14px; }

.scanner-page { max-width: 760px; margin: 0 auto; }
.scanner-card { overflow: hidden; padding: .8rem; }
.reader { overflow: hidden; border-radius: 14px; min-height: 220px; background: #06090c; }
.reader video { border-radius: 14px !important; object-fit: cover !important; }
.scanner-status { color: var(--muted); text-align: center; padding: .85rem .5rem .4rem; }
.scanner-actions { justify-content: center; padding: .5rem; }
.divider { display: grid; grid-template-columns: 1fr auto 1fr; gap: .8rem; align-items: center; margin: 1.2rem 0; color: var(--muted); }
.divider::before, .divider::after { content: ""; height: 1px; background: var(--line); }
.manual-entry { padding: 1rem; }
.input-action-row, .search-row { display: flex; gap: .65rem; }
.input-action-row input, .search-row input { flex: 1; }
.search-row { margin-bottom: 1rem; }

.product-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.product-card { overflow: hidden; text-decoration: none; transition: transform .14s ease, border-color .14s ease; }
.product-card:hover { transform: translateY(-2px); border-color: #48606f; }
.product-thumb { aspect-ratio: 4 / 3; display: grid; place-items: center; background: #0a1015; color: #5e707b; font-size: .75rem; font-weight: 800; letter-spacing: .13em; }
.product-thumb img { width: 100%; height: 100%; object-fit: cover; }
.product-card-body { display: grid; gap: .25rem; padding: 1rem; }
.product-card-body strong { font-size: 1.1rem; }
.product-card-body > span { color: var(--muted); }
.stock-pill { justify-self: start; margin-top: .55rem; padding: .35rem .55rem; background: rgba(79,209,197,.1); color: var(--accent) !important; border-radius: 99px; font-size: .82rem; font-weight: 800; }
.barcode-text { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: #b8c8d0 !important; overflow-wrap: anywhere; }

.product-hero { display: grid; grid-template-columns: minmax(220px, 38%) 1fr; overflow: hidden; }
.hero-image { min-height: 330px; display: grid; place-items: center; background: #080d11; color: #5e707b; font-size: .75rem; font-weight: 800; letter-spacing: .13em; }
.hero-image img { width: 100%; height: 100%; max-height: 440px; object-fit: cover; }
.hero-copy { padding: clamp(1.25rem, 5vw, 2.3rem); align-self: center; }
.hero-copy h1 { font-size: clamp(2rem, 7vw, 4.3rem); }
.product-size { font-size: 1.2rem; color: var(--text); }
.stock-total { display: flex; align-items: baseline; gap: .55rem; margin: 1.4rem 0; }
.stock-total strong { font-size: 3rem; line-height: 1; color: var(--accent); }
.stock-total span { color: var(--muted); }

.batch-list { display: grid; gap: .8rem; }
.batch-card { padding: 1rem; border-left: 4px solid transparent; }
.batch-card.soon { border-left-color: var(--warning); }
.batch-card.urgent, .batch-card.expired { border-left-color: var(--danger); }
.batch-main { display: flex; justify-content: space-between; gap: 1rem; align-items: start; }
.batch-source { font-size: 1.1rem; font-weight: 800; }
.batch-source a { text-decoration: none; }
.batch-meta { display: flex; flex-wrap: wrap; gap: .35rem 1rem; color: var(--muted); margin-top: .35rem; font-size: .9rem; }
.quantity-badge { min-width: 54px; min-height: 54px; display: grid; place-items: center; background: #0d151b; border: 1px solid var(--line); border-radius: 14px; font-size: 1.55rem; font-weight: 900; }
.expiry-warning { margin-top: .75rem; color: var(--warning); font-size: .88rem; font-weight: 800; }
.batch-card.expired .expiry-warning, .batch-card.urgent .expiry-warning { color: #ff9999; }
.batch-actions { margin-top: 1rem; }
.add-batch-card { margin-top: 2.2rem; }
.danger-zone { margin-top: 3rem; padding: 1rem; border-color: rgba(255,107,107,.28); }
.danger-zone h3 { margin-bottom: .25rem; }
.danger-zone p { margin-bottom: .8rem; }
.empty-state { text-align: center; padding: 2.5rem 1rem; }
.empty-state.compact { padding: 1.25rem; }
.empty-state p:last-child { margin-bottom: 0; }

@media (max-width: 760px) {
    .page-shell { width: min(100% - 1rem, 1100px); padding-top: 1rem; }
    .topbar { padding: .8rem; }
    .topbar nav { gap: .7rem; font-size: .9rem; }
    .product-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
    .product-card-body { padding: .8rem; }
    .product-card-body > span:not(.stock-pill) { font-size: .85rem; }
    .form-grid.two { grid-template-columns: 1fr; }
    .product-hero { grid-template-columns: 1fr; }
    .hero-image { min-height: 240px; max-height: 360px; }
    .hero-copy { padding: 1.2rem; }
    .batch-actions .button, .batch-actions form { flex: 1 1 auto; }
    .batch-actions form .button { width: 100%; }
}

@media (max-width: 430px) {
    .product-grid { grid-template-columns: 1fr; }
    .page-heading.split { align-items: center; }
    .input-action-row, .search-row { flex-direction: column; }
    .scanner-actions .button, .form-actions .button { flex: 1 1 100%; }
    .batch-main { align-items: center; }
}
