:root {
    --bg: #f5fbf8;
    --surface: #ffffff;
    --surface-soft: #edf7f2;
    --surface-muted: #e4f2ec;
    --primary: #5fa38f;
    --primary-dark: #427a69;
    --primary-soft: #d8eee6;
    --accent: #7fc4ad;
    --text: #18322a;
    --text-soft: #56756b;
    --text-faint: #7f9a90;
    --border: #d7e7df;
    --danger: #cc5a5a;
    --warning: #d39b32;
    --shadow: 0 10px 30px rgba(41, 92, 75, 0.08);
    --radius: 18px;
    --radius-sm: 12px;
    --radius-xs: 10px;
    --bottom-nav-height: 78px;
    --top-safe: env(safe-area-inset-top, 0px);
    --bottom-safe: env(safe-area-inset-bottom, 0px);
    --font: "Noto Sans Thai", "Prompt", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    cursor: pointer;
    border: none;
    background: none;
}

img {
    max-width: 100%;
    display: block;
}

.hidden {
    display: none !important;
}

.app-shell {
    min-height: 100vh;
    padding-top: calc(12px + var(--top-safe));
    padding-bottom: calc(var(--bottom-nav-height) + 14px + var(--bottom-safe));
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    gap: 12px;
    align-items: flex-start;
    justify-content: space-between;
    padding: 14px 16px 12px;
    background: rgba(245, 251, 248, 0.92);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(215, 231, 223, 0.8);
}

.brand-title {
    margin: 0;
    font-size: 1.2rem;
    line-height: 1.3;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.brand-subtitle {
    margin: 4px 0 0;
    color: var(--text-soft);
    font-size: 0.88rem;
    line-height: 1.4;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

.icon {
    font-size: 1rem;
}

.badge-wrap {
    position: relative;
}

.badge {
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.76rem;
    font-weight: 700;
}

.badge-wrap .badge {
    position: absolute;
    top: -4px;
    right: -2px;
}

.inline-badge {
    margin-left: 6px;
}

.user-summary {
    margin: 14px 16px 0;
    background: linear-gradient(180deg, var(--surface), var(--surface-soft));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.user-name {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
}

.user-meta {
    margin: 6px 0 0;
    color: var(--text-soft);
    font-size: 0.9rem;
}

.user-summary-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.shortcut-row {
    display: flex;
    gap: 8px;
    padding: 14px 16px 0;
    overflow-x: auto;
    scrollbar-width: none;
}

.shortcut-row::-webkit-scrollbar {
    display: none;
}

.shortcut-btn {
    white-space: nowrap;
    padding: 11px 14px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-soft);
    font-weight: 600;
}

.shortcut-btn.active {
    background: var(--primary-soft);
    color: var(--primary-dark);
    border-color: transparent;
}

.main-content {
    padding: 14px 16px 0;
}

.view-section {
    animation: fadeIn 0.2s ease;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.section-heading h3 {
    margin: 0;
    font-size: 1.05rem;
}

.section-heading p {
    margin: 4px 0 0;
    color: var(--text-soft);
    font-size: 0.88rem;
}

.product-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.product-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    overflow: hidden;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    min-height: 100%;
}

.product-image-wrap {
    position: relative;
    aspect-ratio: 1 / 1;
    background: var(--surface-muted);
    overflow: hidden;
}

.product-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.product-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(24, 50, 42, 0.78);
    color: #fff;
    padding: 6px 9px;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 700;
}

.product-badge.soldout {
    background: rgba(204, 90, 90, 0.92);
}

.product-body {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

.product-name {
    margin: 0;
    font-size: 0.97rem;
    line-height: 1.35;
    font-weight: 700;
}

.product-desc {
    margin: 0;
    color: var(--text-soft);
    font-size: 0.84rem;
    line-height: 1.45;
    min-height: 2.5em;
}

.product-price {
    font-size: 1rem;
    font-weight: 800;
    color: var(--primary-dark);
}

.product-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    color: var(--text-soft);
    font-size: 0.79rem;
}

.countdown {
    color: var(--warning);
    font-weight: 700;
}

.soldout-text {
    color: var(--danger);
    font-weight: 700;
}

.primary-btn,
.secondary-btn,
.ghost-btn {
    min-height: 44px;
    padding: 11px 14px;
    border-radius: 14px;
    font-weight: 700;
    transition: 0.18s ease;
}

.primary-btn {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 8px 20px rgba(95, 163, 143, 0.28);
}

.primary-btn:active {
    transform: scale(0.985);
}

.secondary-btn {
    background: var(--surface-soft);
    color: var(--primary-dark);
    border: 1px solid var(--border);
}

.ghost-btn {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

.full-btn {
    width: 100%;
}

.small-btn {
    min-height: 38px;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 0.88rem;
}

.danger-text {
    color: var(--danger);
}

.card-actions,
.inline-actions {
    display: flex;
    gap: 8px;
}

.card-actions {
    margin-top: auto;
}

.card-actions>*,
.inline-actions>* {
    flex: 1;
}

.stack-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stack-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--shadow);
}

.stack-card h4 {
    margin: 0 0 8px;
    font-size: 0.98rem;
}

.stack-card p {
    margin: 4px 0;
    color: var(--text-soft);
    font-size: 0.88rem;
    line-height: 1.45;
}

.cart-summary {
    position: sticky;
    bottom: calc(var(--bottom-nav-height) + 10px + var(--bottom-safe));
    margin-top: 16px;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    border-radius: 18px;
    padding: 14px;
}

.summary-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    font-size: 1rem;
}

.empty-state {
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    text-align: center;
    padding: 28px 18px;
    color: var(--text-soft);
}

.empty-icon {
    font-size: 2rem;
    margin-bottom: 8px;
}

.bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    height: calc(var(--bottom-nav-height) + var(--bottom-safe));
    padding: 8px 12px calc(8px + var(--bottom-safe));
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(14px);
    border-top: 1px solid rgba(215, 231, 223, 0.9);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.bottom-nav-btn {
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    color: var(--text-soft);
    font-size: 0.76rem;
    font-weight: 700;
}

.bottom-nav-btn.active {
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(16, 33, 28, 0.38);
}

.modal-panel {
    position: absolute;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.sheet-panel {
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 88vh;
    overflow-y: auto;
    border-radius: 24px 24px 0 0;
    padding: 14px 16px 24px;
}

.large-panel {
    min-height: 45vh;
}

.centered-panel {
    left: 16px;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    border-radius: 20px;
    padding: 14px;
}

.modal-header {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 10px;
    margin-bottom: 12px;
}

.modal-header h3 {
    margin: 0;
    font-size: 1rem;
}

.auth-tab-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: var(--surface-soft);
    border-radius: 14px;
    padding: 4px;
    gap: 4px;
    margin-bottom: 14px;
}

.auth-tab {
    min-height: 42px;
    border-radius: 12px;
    color: var(--text-soft);
    font-weight: 700;
}

.auth-tab.active {
    background: var(--surface);
    color: var(--primary-dark);
    box-shadow: var(--shadow);
}

.form-block {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.option-editor-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.option-editor-row {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr 1fr auto;
    gap: 8px;
    align-items: end;
    padding: 12px;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.option-editor-heading {
    grid-column: 1 / -1;
    color: var(--primary-dark);
    font-size: 0.86rem;
    font-weight: 800;
}

.option-editor-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    color: var(--text-soft);
    font-size: 0.78rem;
    font-weight: 700;
}

.option-editor-field .text-input {
    min-width: 0;
    background: var(--surface);
}

.option-editor-remaining {
    color: var(--text-faint);
    font-size: 0.75rem;
    font-weight: 600;
}

.option-editor-empty {
    margin: 0;
    padding: 12px;
    color: var(--text-faint);
    background: var(--surface-soft);
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    text-align: center;
}

.add-option-btn {
    width: 100%;
}

.field-label {
    display: flex;
    flex-direction: column;
    gap: 7px;
    color: var(--text);
    font-size: 0.93rem;
    font-weight: 600;
}

.text-input,
.textarea-input,
.select-input {
    width: 100%;
    min-height: 46px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface);
    padding: 12px 14px;
    color: var(--text);
    outline: none;
}

.textarea-input {
    min-height: 100px;
    resize: vertical;
}

.text-input:focus,
.textarea-input:focus,
.select-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(95, 163, 143, 0.12);
}

.preview-body {
    padding-top: 6px;
}

.preview-image {
    width: 100%;
    border-radius: 16px;
    border: 1px solid var(--border);
}

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--bottom-nav-height) + 18px + var(--bottom-safe));
    transform: translateX(-50%);
    z-index: 120;
    background: rgba(24, 50, 42, 0.94);
    color: #fff;
    padding: 12px 16px;
    border-radius: 999px;
    font-size: 0.88rem;
    max-width: calc(100vw - 32px);
    text-align: center;
    box-shadow: var(--shadow);
}

.qty-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.qty-btn {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: var(--surface-soft);
    color: var(--primary-dark);
    font-weight: 800;
    border: 1px solid var(--border);
}

.qty-value {
    min-width: 36px;
    text-align: center;
    font-weight: 700;
}

.option-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.option-chip {
    padding: 10px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-soft);
    font-size: 0.88rem;
    font-weight: 700;
}

.option-chip.active {
    background: var(--primary-soft);
    color: var(--primary-dark);
    border-color: transparent;
}

.status-pill {
    display: inline-flex;
    width: fit-content;
    padding: 7px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    background: var(--surface-soft);
    color: var(--primary-dark);
}

.status-pill.warning {
    background: #fff5df;
    color: #9a6b10;
}

.status-pill.danger {
    background: #fdeaea;
    color: #b54c4c;
}

.status-pill.success {
    background: #e4f6ec;
    color: #2c7d57;
}

.upload-box {
    border: 1px dashed var(--border);
    border-radius: 16px;
    padding: 14px;
    background: var(--surface-soft);
}

.file-input {
    width: 100%;
}

.helper-text {
    margin: 6px 0 0;
    color: var(--text-faint);
    font-size: 0.8rem;
}

.muted-text {
    color: var(--text-soft);
}

.divider {
    height: 1px;
    background: var(--border);
    margin: 12px 0;
}

.skeleton {
    background: linear-gradient(90deg,
            #e8f3ee 25%,
            #f3faf7 37%,
            #e8f3ee 63%);
    background-size: 400% 100%;
    animation: shimmer 1.4s ease infinite;
    border-radius: 10px;
}

.skeleton-card {
    padding: 12px;
}

.skeleton-image {
    width: 100%;
    aspect-ratio: 1 / 1;
    margin-bottom: 12px;
}

.skeleton-line {
    width: 100%;
    height: 14px;
    margin-bottom: 10px;
}

.skeleton-line.short {
    width: 60%;
}

.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.one-line-clamp {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.two-line-clamp {
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
}

.three-line-clamp {
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
}

@keyframes shimmer {
    0% {
        background-position: 100% 0;
    }

    100% {
        background-position: 0 0;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (min-width: 768px) {
    body {
        display: flex;
        justify-content: center;
        background:
            linear-gradient(180deg, #eef8f4 0%, #f7fcf9 100%);
    }

    .app-shell {
        width: 100%;
        max-width: 480px;
        min-height: 100vh;
        background: var(--bg);
        box-shadow: 0 0 0 1px rgba(215, 231, 223, 0.8);
    }

    .centered-panel {
        left: 50%;
        right: auto;
        width: 420px;
        transform: translate(-50%, -50%);
    }

    .sheet-panel {
        left: 50%;
        right: auto;
        width: 480px;
        transform: translateX(-50%);
        border-radius: 24px 24px 0 0;
    }
}

@media (max-width: 520px) {
    .option-editor-row {
        grid-template-columns: 1fr 1fr;
    }

    .option-editor-field:first-of-type {
        grid-column: span 2;
    }

    .option-editor-row .remove-option-btn {
        grid-column: span 2;
        width: 100%;
    }
}