:root {
    --bg: #f5f7fb;
    --card: #ffffff;
    --text: #111827;
    --muted: #6b7280;
    --border: #e5e7eb;
    --primary: #16a34a;
    --primary-dark: #15803d;
    --danger: #dc2626;
    --shadow: 0 10px 30px rgba(17, 24, 39, 0.08);
    --radius: 18px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    min-height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
}
a { color: inherit; text-decoration: none; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }

.container {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 50px;
}
.container.narrow { width: min(820px, calc(100% - 32px)); }
.home-container { width: min(900px, calc(100% - 28px)); }

.store-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 0 24px;
}
.store-logo {
    width: 58px;
    height: 58px;
    flex: 0 0 58px;
    display: grid;
    place-items: center;
    background: transparent;
}

.store-logo img {
    width: 58px;
    height: 58px;
    display: block;
    object-fit: contain;
}
.store-header h1 {
    margin: 0;
    font-size: 25px;
    line-height: 1.15;
}

.page-heading h1 {
    margin: 0;
    font-size: clamp(26px, 5vw, 36px);
}
.store-header p { margin: 4px 0 0; color: var(--muted); }
.admin-link { margin-left: auto; font-size: 21px; opacity: .75; }

.hero-actions { margin: 12px 0 18px; }
.scan-button {
    width: 100%;
    border: 0;
    border-radius: 22px;
    padding: 28px 20px 25px;
    background: linear-gradient(180deg, #16a34a 0%, #15803d 100%);
    color: white;
    box-shadow:
        0 12px 30px rgba(21, 128, 61, .22),
        inset 0 1px 0 rgba(255,255,255,.08);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    transition: transform .15s ease, box-shadow .15s ease;
}
.scan-button:hover {
    transform: translateY(-1px);
    box-shadow:
        0 15px 34px rgba(21, 128, 61, .26),
        inset 0 1px 0 rgba(255,255,255,.08);
}
.scan-button:active {
    transform: translateY(1px) scale(.995);
}
.scan-icon {
    width: 58px;
    height: 58px;
    margin-bottom: 3px;
}
.scan-button span {
    font-size: 21px;
    font-weight: 800;
    letter-spacing: .3px;
}
.scan-button small {
    font-size: 14px;
    opacity: .88;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 9px 8px 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 4px 16px rgba(17, 24, 39, .04);
}
.search-box input { flex: 1; min-width: 0; border: 0; outline: 0; font-size: 17px; background: transparent; }
.search-box button, .btn {
    border: 1px solid var(--border);
    background: white;
    color: var(--text);
    border-radius: 12px;
    padding: 10px 14px;
    font-weight: 650;
}
.search-box button { background: #111827; color: white; border-color: #111827; }

.section-heading, .page-heading {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 16px;
    margin: 28px 0 14px;
}
.section-heading h2, .form-card h2 { margin: 0; font-size: 20px; }

.product-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}
.product-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 6px 24px rgba(17,24,39,.05);
    transition: transform .15s ease, box-shadow .15s ease;
}
.product-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.product-card img, .product-card-placeholder { width: 100%; height: 180px; object-fit: contain; background: #f8fafc; }
.product-card-placeholder { display: grid; place-items: center; font-size: 52px; }
.product-card-body { padding: 14px; }
.product-card h3 { margin: 0 0 9px; font-size: 18px; line-height: 1.3; }
.main-price { font-size: 19px; font-weight: 800; }
.main-price span { font-size: 13px; color: var(--muted); font-weight: 500; }
.sub-price { margin-top: 5px; color: #374151; font-size: 14px; }

.empty-card, .not-found, .barcode-box, .form-card, .stat-card, .quick-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 6px 24px rgba(17,24,39,.04);
}
.empty-card { text-align: center; padding: 42px 20px; }
.empty-card div, .not-found-icon { font-size: 44px; margin-bottom: 10px; }

.back-link { display: inline-block; margin: 8px 0 18px; color: #374151; }
.product-detail {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
}
.product-detail > .detail-image-wrap,
.product-detail > .detail-info {
    width: 100%;
    min-width: 0;
    flex: 0 0 100%;
}

.detail-image-wrap { background: white; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.detail-image { width: 100%; height: 300px; object-fit: contain; background: #f8fafc; }
.detail-placeholder { height: 300px; display: grid; place-items: center; font-size: 82px; background: #f8fafc; }
.detail-info { background: white; border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; }
.eyebrow { font-size: 12px; font-weight: 800; color: var(--primary-dark); letter-spacing: 1px; }
.detail-info h1 { font-size: clamp(28px, 5vw, 40px); line-height: 1.15; margin: 6px 0 16px; }
.scan-result { display: inline-block; padding: 7px 10px; border-radius: 999px; background: #dcfce7; color: #166534; font-size: 13px; margin-bottom: 14px; }
.price-list { border-top: 1px solid var(--border); }
.price-row { display: flex; justify-content: space-between; gap: 16px; padding: 16px 0; border-bottom: 1px solid var(--border); }
.price-row strong { font-size: 22px; white-space: nowrap; }
.price-row.highlight { background: #f0fdf4; margin-inline: -10px; padding-inline: 10px; border-radius: 12px; }
.description { padding: 16px 0; color: #4b5563; line-height: 1.6; }
.barcode-box { margin-top: 18px; padding: 18px; }
.barcode-box h2 { font-size: 17px; margin: 0 0 10px; }
.barcode-item { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.barcode-item:last-child { border-bottom: 0; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.ghost { background: transparent; }
.btn.full { width: 100%; }
.small-btn { padding: 7px 10px; font-size: 13px; }

.admin-header { background: #111827; color: white; }
.admin-header-inner { width: min(1180px, calc(100% - 32px)); margin: 0 auto; min-height: 62px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.brand-small { font-weight: 800; }
.admin-header nav { display: flex; gap: 18px; font-size: 14px; }
.admin-header nav a { opacity: .9; }
.admin-header nav a:hover { opacity: 1; }

.stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.stat-card { padding: 20px; }
.stat-label { display: block; color: var(--muted); font-size: 14px; margin-bottom: 5px; }
.stat-card strong { font-size: 34px; }
.quick-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-top: 16px; }
.quick-card { padding: 18px; }
.quick-card span { font-size: 28px; display: block; margin-bottom: 8px; }
.quick-card strong { display: block; }
.quick-card small { display: block; margin-top: 5px; color: var(--muted); line-height: 1.45; }

.search-row { display: flex; gap: 10px; margin-bottom: 16px; }
.search-row input { flex: 1; min-width: 0; border: 1px solid var(--border); border-radius: 12px; padding: 11px 13px; background: white; outline: 0; }
.table-wrap { overflow-x: auto; background: white; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; min-width: 850px; }
th, td { text-align: left; padding: 13px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 13px; color: var(--muted); background: #f9fafb; }
tbody tr:last-child td { border-bottom: 0; }
.thumb { width: 58px; height: 58px; border-radius: 12px; object-fit: contain; background: #f8fafc; border: 1px solid var(--border); }
.thumb.placeholder { display: grid; place-items: center; font-size: 24px; }
.price-cell div { margin: 2px 0; font-size: 13px; }
.badge { display: inline-flex; padding: 6px 9px; border-radius: 999px; font-size: 12px; font-weight: 750; }
.badge.active { background: #dcfce7; color: #166534; }
.badge.inactive { background: #f3f4f6; color: #4b5563; }
.actions { white-space: nowrap; }

.form-card { padding: 22px; }
.form-card section { padding-bottom: 24px; margin-bottom: 24px; border-bottom: 1px solid var(--border); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 14px; }
label { display: flex; flex-direction: column; gap: 7px; font-weight: 650; font-size: 14px; }
input[type="text"], input[type="password"], input[type="number"], input[type="file"], textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 11px 12px;
    background: white;
    outline: 0;
    font-weight: 400;
}
textarea { resize: vertical; }
input:focus, textarea:focus { border-color: #94a3b8; box-shadow: 0 0 0 3px rgba(148,163,184,.15); }
.span-2 { grid-column: 1 / -1; }
.check { flex-direction: row; align-items: center; }
.check input { width: auto; }
.edit-image { width: 110px; height: 110px; border: 1px solid var(--border); border-radius: 12px; object-fit: contain; background: #f8fafc; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }

.alert { border-radius: 12px; padding: 12px 14px; margin-bottom: 15px; }
.alert.success { background: #dcfce7; color: #166534; }
.alert.error { background: #fee2e2; color: #991b1b; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 32px; }

.auth-page { display: grid; place-items: center; padding: 24px; background: linear-gradient(180deg, #f8fafc, #eef2f7); }
.auth-card { width: min(420px, 100%); padding: 28px; background: white; border: 1px solid var(--border); border-radius: 24px; box-shadow: var(--shadow); text-align: center; }
.auth-card h1 { margin: 10px 0 4px; }
.brand-icon { width: 70px; height: 70px; margin: 0 auto; border-radius: 22px; background: #111827; color: white; display: grid; place-items: center; font-size: 34px; }
.stack { display: grid; gap: 14px; margin-top: 20px; text-align: left; }
.back-link { color: #374151; }

.modal[hidden] { display: none; }
.modal { position: fixed; inset: 0; z-index: 100; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.65); }
.scanner-dialog { position: relative; width: min(560px, calc(100% - 24px)); margin: 5vh auto; background: #111827; color: white; border-radius: 22px; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 18px; }
.modal-header h2 { margin: 0 0 3px; }
.icon-button { width: 40px; height: 40px; border: 0; border-radius: 50%; background: rgba(255,255,255,.1); color: white; }
#reader {
    width: 100%;
    min-height: 340px;
    background: #000;
}
#reader video {
    width: 100% !important;
    height: 100% !important;
    min-height: 340px;
    object-fit: cover;
    display: block;
}
.scanner-view {
    position: relative;
    width: 100%;
    overflow: hidden;
    background: #000;
}
.scanner-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
.scanner-frame {
    position: relative;
    width: min(78%, 330px);
    aspect-ratio: 2.05 / 1;
}
.corner {
    position: absolute;
    width: 34px;
    height: 34px;
}
.corner::before,
.corner::after {
    content: "";
    position: absolute;
    background: #fff;
    border-radius: 3px;
}
.corner::before {
    width: 100%;
    height: 4px;
}
.corner::after {
    width: 4px;
    height: 100%;
}
.top-left { top: 0; left: 0; }
.top-left::before, .top-left::after { top: 0; left: 0; }
.top-right { top: 0; right: 0; }
.top-right::before { top: 0; right: 0; }
.top-right::after { top: 0; right: 0; }
.bottom-left { bottom: 0; left: 0; }
.bottom-left::before { bottom: 0; left: 0; }
.bottom-left::after { bottom: 0; left: 0; }
.bottom-right { bottom: 0; right: 0; }
.bottom-right::before { bottom: 0; right: 0; }
.bottom-right::after { bottom: 0; right: 0; }
.scan-line {
    position: absolute;
    left: 10%;
    right: 10%;
    top: 50%;
    height: 2px;
    background: rgba(255,255,255,.95);
    box-shadow: 0 0 10px rgba(255,255,255,.65);
    animation: scanLine 1.8s ease-in-out infinite;
}
@keyframes scanLine {
    0%, 100% {
        transform: translateY(-46px);
        opacity: .35;
    }
    50% {
        transform: translateY(46px);
        opacity: 1;
    }
}
.scanner-help {
    padding: 14px 18px 18px;
    color: #d1d5db;
    font-size: 14px;
    text-align: center;
}
\nbody.scanner-open { overflow: hidden; }\n
@media (max-width: 760px) {
    .container, .home-container, .container.narrow { width: min(100% - 20px, 900px); padding-top: 18px; }
    .product-grid { grid-template-columns: 1fr; }
    .product-card img, .product-card-placeholder { height: 210px; }
    .product-detail {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.detail-image {
    height: 300px;
    width: 100%;
}

.detail-info {
    width: 100%;
    padding: 18px;
}
    .quick-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .admin-header-inner { width: calc(100% - 20px); }
    .admin-header nav { gap: 10px; font-size: 12px; }
    .page-heading { align-items: flex-start; flex-direction: column; }
    .form-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .search-row { flex-wrap: wrap; }
    .search-row input { flex-basis: 100%; }
    .price-row strong { font-size: 19px; }
}
.login-icon {
    width: 28px;
    height: 28px;
    display: block;
}
.store-logo {
    display: flex;
    align-items: center;
    justify-content: center;
}

.store-logo svg {
    width: 50px;
    height: 50px;
    display: block;
}
.price-input {
    position: relative;
}

.price-input input {
    width: 100%;
    padding-right: 40px;
}

.price-input span {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: #6b7280;
    font-weight: 600;
    pointer-events: none;
}
.product-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 12px;
    width: 100%;
    margin-top: 18px;
}

.product-actions > a,
.product-actions > form {
    min-width: 0;
    width: 100%;
    margin: 0;
}

.product-actions .btn {
    width: 100%;
    min-width: 0;
    min-height: 52px;
    white-space: normal;
}

.stock-form {
    min-width: 0;
    width: 100%;
    margin: 0;
}

.product-actions > a,
.product-actions > form {
    width: 100%;
    min-width: 0;
    margin: 0;
}

.product-actions .btn {
    width: 100%;
    min-width: 0;
    min-height: 52px;
}

.stock-form {
    width: 100%;
    margin: 0;
}

.stock-form .btn {
    width: 100%;
}

.stock-out {
    background: #dc2626;
    border-color: #dc2626;
    color: #fff;
}

.stock-out:hover {
    background: #b91c1c;
    border-color: #b91c1c;
}

.stock-available {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.stock-available:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

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

.stock-confirm-modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: grid;
    place-items: center;
    padding: 20px;
}

.stock-confirm-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .55);
}

.stock-confirm-card {
    position: relative;
    width: min(420px, 100%);
    background: #fff;
    border-radius: 22px;
    padding: 28px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, .25);
    text-align: center;
}

.stock-confirm-icon {
    width: 52px;
    height: 52px;
    margin: 0 auto 14px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: #fee2e2;
    color: #dc2626;
    font-size: 26px;
    font-weight: 800;
}

.stock-confirm-card h3 {
    margin: 0 0 8px;
    font-size: 22px;
}

.stock-confirm-card p {
    margin: 0;
    color: var(--muted);
    line-height: 1.5;
}

.stock-confirm-actions {
    display: flex;
    gap: 10px;
    margin-top: 22px;
}

.stock-confirm-actions .btn {
    flex: 1;
    min-height: 48px;
}

@media (max-width: 600px) {
    .product-actions {
        grid-template-columns: 1fr;
    }
}
.edit-product-btn {
    background: #111827;
    border-color: #111827;
    color: #fff;
}

.edit-product-btn:hover {
    background: #1f2937;
    border-color: #1f2937;
}
.product-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
}

.product-title-row h1 {
    margin-bottom: 16px;
}

.edit-product-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 10px 16px;
    border-radius: 12px;
    background: #111827;
    color: #fff;
    font-weight: 700;
    text-decoration: none;
}

.edit-product-btn:hover {
    background: #1f2937;
}

@media (max-width: 600px) {
    .product-title-row {
        align-items: flex-start;
    }

    .edit-product-btn {
        font-size: 13px;
        padding: 9px 11px;
    }
}
.action-icon {
    width: 17px;
    height: 17px;
    flex: 0 0 auto;
    display: block;
}

.actions {
    white-space: nowrap;
}

.actions .btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.action-view {
    background: #eff6ff;
    border-color: #dbeafe;
    color: #1d4ed8;
}

.action-view:hover {
    background: #dbeafe;
    border-color: #bfdbfe;
}
.not-found-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.not-found-actions .btn {
    min-height: 48px;
}

.action-icon {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}