/* StockMaster storefront (index.html) and product page (product_detail.html). Tokens in theme.css. */

/* ---------- kraft header ---------- */
.store-header { background: var(--kraft); color: var(--kraft-ink); }
.store-header-inner {
    max-width: 1240px; margin: 0 auto; padding: .7rem 1.5rem;
    display: grid; grid-template-columns: auto minmax(180px, 1fr) auto; align-items: center; gap: .75rem 1.25rem;
}
.brand { display: flex; align-items: center; text-decoration: none; }
.brand-logo {
    display: block; width: auto; height: 52px; max-width: none;
    border-radius: 7px; box-shadow: 0 1px 2px rgba(42, 32, 20, .2), 0 3px 8px rgba(42, 32, 20, .12);
}
.store-search { position: relative; width: 100%; max-width: 520px; }
.store-search i { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.search-input {
    width: 100%; min-height: 42px; padding: .5rem .9rem .5rem 2.35rem;
    border: 1px solid transparent; border-radius: var(--r); background: var(--surface);
    font-size: .95rem; box-shadow: inset 0 1px 2px rgba(42, 32, 20, .08);
}
.search-input:hover { border-color: var(--kraft-deep); }
.header-right { display: flex; align-items: center; justify-content: flex-end; gap: .5rem; flex-wrap: wrap; }
#userLabel { font-weight: 600; font-size: .86rem; color: var(--kraft-ink); max-width: 18rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.store-header .sm-account-open { border-color: transparent; }

/* ---------- buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
    min-height: 40px; padding: .5rem 1rem;
    border: 1px solid var(--rule-strong); border-radius: var(--r);
    background: var(--surface); color: var(--ink);
    font-weight: 600; font-size: .9rem; line-height: 1.2; cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: background-color .15s ease, border-color .15s ease;
}
.btn-primary, .btn-success { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover, .btn-success:hover { background: var(--ink-hover); border-color: var(--ink-hover); }
.btn-outline:hover { border-color: var(--ink); background: var(--surface-sunk); }
.store-header .btn-outline { border-color: transparent; }
.store-header .btn-outline:hover { border-color: var(--ink); background: var(--surface); }
.btn-danger-text { color: var(--bad); }
.btn-danger-text:hover { border-color: var(--bad); background: var(--bad-soft); }
.btn:disabled, .btn-primary:disabled { background: var(--surface-sunk); border-color: var(--rule); color: var(--ink-3); cursor: not-allowed; }
.cart-badge {
    min-width: 1.45rem; padding: 0 .4rem; margin-left: .1rem;
    border-radius: 999px; background: var(--kraft); color: var(--kraft-ink);
    font-size: .76rem; font-weight: 700; line-height: 1.45rem; text-align: center; font-variant-numeric: tabular-nums;
}

/* ---------- catalogue ---------- */
main { max-width: 1240px; margin: 0 auto; padding: 1.5rem; }
.page-title { margin: 0 0 1rem; font-size: 1.35rem; }
.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1.1rem; }
.product-card {
    display: flex; flex-direction: column; overflow: hidden;
    background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; box-shadow: var(--shadow);
    transition: box-shadow .2s ease, border-color .2s ease;
}
.product-card:hover { border-color: var(--rule-strong); box-shadow: 0 2px 4px rgba(42, 32, 20, .07), 0 8px 20px rgba(42, 32, 20, .08); }
.product-image-link { display: block; background: var(--surface-sunk); }
.product-card img { display: block; width: 100%; aspect-ratio: 1 / 1; object-fit: cover; background: var(--surface-sunk); }
.product-info { display: flex; flex-direction: column; gap: .2rem; flex-grow: 1; padding: .85rem .95rem 1rem; }
.product-info h3 { margin: 0; font-size: 1rem; font-weight: 600; line-height: 1.45; }
.card-cat { align-self: flex-start; margin: .2rem 0 .6rem; padding: .1rem .45rem; border: 1px solid var(--rule); border-radius: var(--r-sm); background: var(--surface-sunk); color: var(--ink-2); font-size: .76rem; font-weight: 600; }
.product-name-link { color: inherit; text-decoration: none; }
.product-name-link:hover { text-decoration: underline; }
.price-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; margin-bottom: .55rem; }
.price-tag { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.in-cart { min-height: 1.2em; margin-bottom: .45rem; font-size: .8rem; font-weight: 600; color: var(--ok); }
.btn-add-cart { width: 100%; margin-top: auto; }
.store-pager { grid-column: 1 / -1; display: flex; justify-content: center; align-items: center; gap: .4rem; flex-wrap: wrap; margin-top: .75rem; }
.store-pager .btn { min-width: 42px; }
.empty { grid-column: 1 / -1; width: 100%; padding: 3rem 1rem; text-align: center; color: var(--ink-2); }
.pending-banner {
    display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap;
    margin-bottom: 1.1rem; padding: .75rem 1rem;
    background: var(--low-soft); border: 1px solid var(--low-fill); border-radius: 8px; color: var(--kraft-ink);
}
.pending-banner i { color: var(--low); margin-right: .2rem; }

/* ---------- cart / quotation modal ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 1rem; overflow-y: auto; background: rgba(29, 27, 24, .52); }
.modal {
    width: 100%; max-width: 860px; margin: auto; display: flex; flex-direction: column;
    background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-pop);
    animation: modal-in .3s var(--ease-out);
}
@keyframes modal-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--rule); }
.modal-head h2 { margin: 0; font-size: 1.15rem; }
.modal-head small { color: var(--ink-2); font-size: .82rem; }
.modal-body { padding: 1.25rem; }
.modal-foot { display: flex; justify-content: flex-end; gap: .6rem; flex-wrap: wrap; padding: 1rem 1.25rem; border-top: 1px solid var(--rule); background: var(--surface-sunk); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.modal-msg { margin: 1rem 1.25rem 0; padding: .7rem 1rem; border-radius: var(--r); background: var(--bad-soft); color: var(--bad); font-size: .9rem; font-weight: 600; }
.tbl-wrap { overflow-x: auto; }
table.items { width: 100%; border-collapse: collapse; font-size: .92rem; font-variant-numeric: tabular-nums; }
table.items th, table.items td { padding: .6rem .5rem; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: middle; }
table.items th { border-bottom: 2px solid var(--ink); color: var(--ink-2); font-size: .78rem; font-weight: 700; white-space: nowrap; }
table.items .num { text-align: right; white-space: nowrap; }
table.items img { display: block; max-width: none; width: 48px; height: 48px; object-fit: cover; border-radius: var(--r); background: var(--surface-sunk); border: 1px solid var(--rule); }
.muted { color: var(--ink-2); }
.qty-box { display: inline-flex; align-items: stretch; border: 1px solid var(--rule-strong); border-radius: var(--r); overflow: hidden; }
.qty-box button { width: 36px; min-height: 36px; border: 0; background: var(--surface-sunk); cursor: pointer; font-weight: 700; font-size: 1rem; }
.qty-box button:hover { background: var(--kraft-soft); }
.qty-box input { width: 56px; border: 0; border-inline: 1px solid var(--rule-strong); text-align: center; font-size: .95rem; font-variant-numeric: tabular-nums; -moz-appearance: textfield; }
.qty-box input::-webkit-inner-spin-button, .qty-box input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.link-btn { background: none; border: 0; color: var(--bad); cursor: pointer; font-size: .85rem; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.total-row { display: flex; justify-content: flex-end; gap: 1rem; padding: .9rem .5rem 0; font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.check-row { display: flex; gap: .65rem; align-items: flex-start; margin-top: 1rem; padding: .8rem 1rem; background: var(--surface-sunk); border: 1px solid var(--rule); border-radius: 8px; cursor: pointer; line-height: 1.5; }
.check-row input { width: 20px; height: 20px; margin-top: .1rem; flex: none; accent-color: var(--ink); }
.field { margin-bottom: .9rem; }
.field-last { margin-bottom: 0; }
.field label { display: block; margin: .6rem 0 .3rem; font-size: .88rem; font-weight: 600; }
.field label:first-child { margin-top: 0; }
.field input, .field textarea {
    width: 100%; min-height: 44px; padding: .6rem .75rem;
    border: 1px solid var(--rule-strong); border-radius: var(--r); background: var(--surface); font-size: 1rem;
}
.field input:hover, .field textarea:hover { border-color: var(--ink-3); }
.field input[type="file"] { padding: .45rem; background: var(--surface-sunk); }
.field textarea { min-height: 90px; resize: vertical; }
.hint { padding: .75rem 1rem; background: var(--low-soft); border: 1px solid var(--low-fill); border-radius: 8px; color: var(--kraft-ink); font-size: .9rem; line-height: 1.6; }
.hint-gap { margin-bottom: 1rem; }
.status-bar { display: flex; justify-content: flex-start; align-items: center; gap: .65rem; flex-wrap: wrap; margin-bottom: 1rem; padding: .8rem 1rem; border-radius: 8px; font-weight: 600; line-height: 1.5; }
.status-bar > span:first-of-type { flex: 1 1 260px; }
.status-pending { background: var(--low-soft); color: var(--kraft-ink); border: 1px solid var(--low-fill); }
.status-bar > i { align-self: flex-start; margin-top: .3rem; }
.status-pending > i { color: var(--low); }
.status-confirmed { background: var(--ok-soft); color: var(--ok); border: 1px solid #b7dcc5; }
.status-expired, .status-cancelled { background: var(--bad-soft); color: var(--bad); border: 1px solid #f0c2bf; }
.countdown { margin-left: auto; padding: .15rem .6rem; border-radius: var(--r-sm); background: var(--ink); color: #fff; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.pay-box { margin-top: 1rem; padding: 1rem; border: 2px solid var(--ink); border-radius: 8px; }
.pay-box h3 { margin: 0 0 .6rem; font-size: 1rem; }
.pay-info { margin: 0 0 .9rem; padding: .7rem .9rem; white-space: pre-wrap; background: var(--surface-sunk); border-radius: var(--r); line-height: 1.65; }
.sheet { padding: 1.25rem; background: #fff; color: var(--ink); border: 1px solid var(--rule); border-radius: 8px; }
.sheet h2 { margin: 0 0 .35rem; font-size: 1.35rem; }
.sheet .sheet-top { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; padding-bottom: .9rem; border-bottom: 2px solid var(--ink); }
.sheet .muted { font-size: .88rem; line-height: 1.6; white-space: pre-wrap; }
.sheet .cust { margin-bottom: 1rem; padding: .75rem 1rem; background: var(--surface-sunk); border-radius: var(--r); line-height: 1.6; }
.toast { position: fixed; left: 50%; bottom: 1.5rem; z-index: 80; transform: translateX(-50%); max-width: 90vw; padding: .7rem 1.1rem; border-radius: 8px; background: var(--ink); color: #fff; font-weight: 600; box-shadow: var(--shadow-pop); }
#printArea { display: none; }

/* ---------- product page ---------- */
.back-link { display: inline-flex; align-items: center; gap: .45rem; color: var(--kraft-ink); font-weight: 700; text-decoration: none; }
.back-link:hover { text-decoration: underline; }
.user-label { color: var(--kraft-ink); font-size: .86rem; font-weight: 600; }
.detail-header-inner { grid-template-columns: auto minmax(0, 1fr) auto; }
.detail-header-inner .back-link { justify-self: start; }
.product-details { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(300px, .9fr); gap: 1.25rem 1.5rem; align-items: start; }
.product-heading-block { grid-column: 1 / -1; }
.product-heading { margin: 0; font-size: clamp(1.4rem, 2.6vw, 1.9rem); }
.product-meta { margin: .35rem 0 0; color: var(--ink-2); font-family: var(--font-code); font-size: .88rem; }
.image-gallery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
.image-gallery > :first-child { grid-column: 1 / -1; }
.image-gallery[data-count="1"] { grid-template-columns: minmax(0, 1fr); }
.gallery-item { margin: 0; overflow: hidden; background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; }
.gallery-item img, .empty-image { display: block; width: 100%; aspect-ratio: 1 / 1; object-fit: contain; background: var(--surface-sunk); }
.empty-image { display: grid; place-items: center; padding: 1rem; color: var(--ink-2); text-align: center; }
.gallery-item figcaption { padding: .55rem .85rem; color: var(--ink-2); font-size: .82rem; border-top: 1px solid var(--rule); }
.info-panel { padding: 1.25rem; background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; box-shadow: var(--shadow); position: sticky; top: 1rem; }
.spec-grid { display: grid; grid-template-columns: minmax(0, 1fr); margin: 0; }
.spec-item { display: flex; justify-content: space-between; gap: 1rem; padding: .6rem 0; border-bottom: 1px solid var(--rule); min-width: 0; }
.spec-item dt { color: var(--ink-2); font-size: .9rem; }
.spec-item dd { margin: 0; font-weight: 600; text-align: right; overflow-wrap: anywhere; }
.spec-item.price { order: -2; display: block; padding: 0 0 .9rem; }
.spec-item.price dt { font-size: .82rem; }
.spec-item.price dd { text-align: left; font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.spec-item.stock-row { order: -1; padding: .2rem 0 .9rem; align-items: center; }
.avail-lg { font-size: .92rem; }
.avail-lg > span, .avail-lg > b { padding: .32rem .7rem; }
.description-heading { margin: 1.2rem 0 .45rem; font-size: 1rem; }
.description { margin: 0; color: var(--ink); line-height: 1.75; white-space: pre-wrap; overflow-wrap: anywhere; }
.page-state { padding: 2rem; text-align: center; color: var(--ink-2); background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; }

/* ---------- responsive ---------- */
@media (max-width: 1024px) {
    .store-header-inner { padding: .65rem 1rem; }
    main { padding: 1rem; }
    .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
}
@media (max-width: 900px) {
    .search-input, .field input, .field textarea, .qty-box input { font-size: 16px; }
    .store-header-inner { grid-template-columns: auto minmax(0, 1fr); }
    .store-search { grid-column: 1 / -1; grid-row: 2; max-width: none; }
    .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .product-details { grid-template-columns: minmax(0, 1fr); }
    .info-panel { position: static; }
    .detail-header-inner { grid-template-columns: minmax(0, 1fr) auto; }
}
@media (max-width: 760px) {
    .brand-logo { height: 42px; }
    .btn { min-height: 44px; }
    #userLabel { display: none; }
    .header-right { gap: .4rem; }
    .header-right .sm-account-open, .header-right .btn { padding-inline: .7rem; font-size: .84rem; }
    .page-title { font-size: 1.15rem; margin-bottom: .75rem; }
    .product-info { padding: .75rem .8rem .85rem; }
    main { padding: .8rem; }
}
@media (max-width: 600px) {
    .modal-backdrop { padding: 0; }
    .modal { min-height: 100vh; min-height: 100dvh; border-radius: 0; }
    .modal-foot { border-radius: 0; position: sticky; bottom: 0; }
    .modal-foot .btn { flex: 1 1 auto; }
    .modal-body { padding: 1rem; }
    /* cart lines become stacked rows */
    .modal-body > .tbl-wrap table.items, .modal-body > .tbl-wrap table.items tbody { display: block; }
    .modal-body > .tbl-wrap table.items thead, .modal .sheet table.items thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    .modal-body > .tbl-wrap table.items tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .5rem .75rem; align-items: center; padding: .8rem 0; border-bottom: 1px solid var(--rule); }
    .modal-body > .tbl-wrap table.items td { display: block; padding: 0; border: 0; }
    .modal-body > .tbl-wrap table.items td:nth-child(1) { display: none; }
    .modal-body > .tbl-wrap table.items td:nth-child(2) { grid-column: 1 / -1; }
    .modal-body > .tbl-wrap table.items td:nth-child(4) { grid-column: 1; grid-row: 2; }
    .modal-body > .tbl-wrap table.items td:nth-child(5) { grid-column: 2; grid-row: 2; font-weight: 700; font-size: 1rem; }
    .modal-body > .tbl-wrap table.items td:nth-child(3) { grid-column: 1; grid-row: 3; text-align: left; color: var(--ink-2); font-size: .85rem; }
    .modal-body > .tbl-wrap table.items td:nth-child(3)::after { content: " / ชิ้น"; }
    .modal-body > .tbl-wrap table.items td:nth-child(6) { grid-column: 2; grid-row: 3; justify-self: end; }
    .qty-box button { width: 44px; min-height: 44px; }
    /* quotation items become stacked rows */
    .modal .sheet { padding: 1rem; }
    .modal .sheet table.items, .modal .sheet table.items tbody { display: block; }
    .modal .sheet table.items tr { display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; gap: .2rem .9rem; padding: .7rem 0; border-bottom: 1px solid var(--rule); }
    .modal .sheet table.items td { display: block; padding: 0; border: 0; text-align: left; }
    .modal .sheet table.items td:nth-child(1) { display: none; }
    .modal .sheet table.items td:nth-child(3) { grid-column: 1 / -1; grid-row: 1; font-weight: 600; }
    .modal .sheet table.items td:nth-child(2) { grid-column: 1; grid-row: 2; color: var(--ink-2); font-family: var(--font-code); font-size: .82rem; }
    .modal .sheet table.items td:nth-child(4) { grid-column: 2; grid-row: 2; color: var(--ink-2); }
    .modal .sheet table.items td:nth-child(5) { grid-column: 3; grid-row: 2; color: var(--ink-2); }
    .modal .sheet table.items td:nth-child(5)::before { content: "× "; }
    .modal .sheet table.items td:nth-child(6) { grid-column: 4; grid-row: 2; font-weight: 700; text-align: right; }
    .modal .sheet .muted[style] { text-align: left !important; }
}
@media (max-width: 480px) {
    .store-header-inner { gap: .55rem; padding: .55rem .75rem; }
    .header-right .sm-account-open { display: none; }
    .header-right { flex-wrap: nowrap; }
    .header-right .btn-label { display: none; }
    .header-right .btn { padding-inline: .75rem; }
    .grid { grid-template-columns: minmax(0, 1fr); gap: .75rem; }
    .product-card { display: grid; grid-template-columns: 116px minmax(0, 1fr); }
    .product-image-link { height: 100%; }
    .product-card img { height: 100%; min-height: 150px; aspect-ratio: auto; }
    .product-info { padding: .7rem .8rem .8rem; }
    .price-tag { font-size: 1.15rem; }
    .product-info h3 { font-size: .95rem; }
    .image-gallery { grid-template-columns: minmax(0, 1fr); }
    .page-state { padding: 1.25rem; }
}
@media print {
    body > *:not(#printArea) { display: none !important; }
    #printArea { display: block; }
    #printArea .sheet { border: 0; padding: 0; }
}
