:root {
    /* Base Color Tokens */
    --bg-main: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-alt: #f1f5f9;
    --border-color: #e2e8f0;

    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-inverse: #ffffff;

    /* Default Brand Colors (Theme: Flame Orange) */
    --brand-primary: #ea580c;
    --brand-primary-hover: #c2410c;
    --brand-primary-light: #ffedd5;
    --brand-accent: #0284c7;

    /* Status Colors */
    --color-success: #16a34a;
    --color-success-light: #dcfce7;
    --color-warning: #d97706;
    --color-warning-light: #fef3c7;
    --color-danger: #dc2626;
    --color-danger-light: #fee2e2;

    /* Geometry Tokens */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-full: 9999px;
    --shadow-card: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-elevated: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --tap-min: 44px;
}

/* ==========================================================================
   Merchant Custom Themes (สามารถเลือกธีมร้านตามสีแบรนด์ได้ง่ายๆ ด้วย data-theme)
   ========================================================================== */
[data-theme="green"] { /* ร้านชาเขียว, สลัด, อาหารคลีน, มังสวิรัติ */
    --brand-primary: #15803d;
    --brand-primary-hover: #166534;
    --brand-primary-light: #dcfce7;
}
[data-theme="red"] { /* ร้านสุกี้, หม่าล่า, ก๋วยเตี๋ยวต้มยำแดง */
    --brand-primary: #dc2626;
    --brand-primary-hover: #b91c1c;
    --brand-primary-light: #fee2e2;
}
[data-theme="blue"] { /* ร้านน้ำชง, ซีฟู้ด, คาเฟ่โทนเย็น */
    --brand-primary: #0284c7;
    --brand-primary-hover: #0369a1;
    --brand-primary-light: #e0f2fe;
}
[data-theme="yellow"] { /* ร้านข้าวมันไก่, ข้าวหมูแดง, คาเฟ่มินิมอล */
    --brand-primary: #d97706;
    --brand-primary-hover: #b45309;
    --brand-primary-light: #fef3c7;
}
[data-theme="purple"] { /* ร้านขนมหวาน, เบเกอรี่, ชานมไข่มุกพรีเมียม */
    --brand-primary: #7c3aed;
    --brand-primary-hover: #6d28d9;
    --brand-primary-light: #ede9fe;
}
[data-theme="dark"], body.kds-body {
    --bg-main: #090d16;
    --bg-surface: #111827;
    --bg-surface-alt: #1f2937;
    --border-color: #374151;

    --text-main: #f9fafb;
    --text-muted: #9ca3af;
    --text-inverse: #030712;

    --brand-primary: #f97316;
    --brand-primary-hover: #ea580c;
    --brand-primary-light: #7c2d12;
}

/* ==========================================================================
   Core Reset & Base Typography
   - Headings/Titles: 'Prompt' (Google Fonts)
   - Body/Controls/Options/Paragraphs: 'Noto Sans Thai' เป็นหลัก (Google Fonts - อ่านง่าย สบายตา คมชัด)
   ========================================================================== */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
    margin: 0;
    font-family: 'Noto Sans Thai', 'Open Sans', system-ui, -apple-system, sans-serif;
    font-size: 15px;
    background: var(--bg-main);
    color: var(--text-main);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* Headings & Brand Titles use 'Prompt' */
h1, h2, h3, h4, h5, h6,
.merchant-title,
.category-title,
.kds-card-title,
.standee-table-num,
.option-group-title,
.merchant-badge,
.cart-total,
.btn-primary,
.btn-secondary,
.btn-checkout,
.btn-add {
    font-family: 'Prompt', 'Noto Sans Thai', sans-serif;
}

/* Modal Option labels, text & Form controls use 'Noto Sans Thai' เป็นหลัก */
.option-label,
.form-control,
.form-label,
.menu-name,
.menu-price,
.kds-item-row,
.stamp-dot,
p, span, label,
input, button, select, textarea {
    font-family: 'Noto Sans Thai', 'Open Sans', system-ui, sans-serif;
}

/* ==========================================================================
   Utility Classes (ขจัด Inline Style ทั้งหมด)
   ========================================================================== */
.container-narrow { max-width: 520px; margin: 0 auto; padding: 24px 16px; }
.container-medium { max-width: 640px; margin: 0 auto; padding: 24px 16px; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-primary { color: var(--brand-primary); }
.text-success { color: var(--color-success); }
.text-danger { color: var(--color-danger); }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.emoji-hero { font-size: 3rem; line-height: 1; margin-bottom: 8px; }
.flex-column { display: flex; flex-direction: column; gap: 10px; }
.d-none { display: none !important; }

/* Form Controls */
.form-group { margin-bottom: 14px; }
.form-label { font-size: 0.9rem; font-weight: 600; display: block; margin-bottom: 4px; }
.form-control {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-main);
    font-family: inherit;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.15s ease;
}
.form-control:focus {
    border-color: var(--brand-primary);
}
.input-prefix-box {
    display: flex;
    align-items: center;
    background: var(--bg-surface-alt);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding-left: 12px;
}
.input-prefix-box .form-control {
    border: none;
    background: transparent;
}

/* ==========================================================================
   Badges, Cards & Buttons
   ========================================================================== */
.merchant-badge {
    display: inline-block;
    background: var(--brand-primary-light);
    color: var(--brand-primary);
    font-size: 0.8rem;
    font-weight: 600;
    padding: 3px 12px;
    border-radius: var(--radius-full);
    margin-bottom: 6px;
}
.badge-success {
    background: var(--color-success-light);
    color: var(--color-success);
}

.card-box {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 18px;
    box-shadow: var(--shadow-card);
}

.btn-primary {
    background: var(--brand-primary);
    color: var(--text-inverse);
    border: none;
    border-radius: var(--radius-md);
    padding: 14px 24px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    min-height: var(--tap-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
    transition: background 0.15s ease, transform 0.1s ease;
}
.btn-primary:active { transform: scale(0.98); }
.btn-secondary {
    background: var(--bg-surface-alt);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 14px 24px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    min-height: var(--tap-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}
.btn-block { width: 100%; }

/* ==========================================================================
   Customer Ordering Layout
   ========================================================================== */
.customer-header {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    padding: 16px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.merchant-title {
    font-size: 1.3rem;
    font-weight: 700;
    margin: 0;
    color: var(--text-main);
}
.merchant-meta {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.menu-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 16px 16px 110px 16px;
}
.category-section {
    margin-bottom: 24px;
}
.category-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 16px 0 10px 0;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}
.menu-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 14px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-card);
    transition: transform 0.1s ease;
}
.menu-card:active {
    transform: scale(0.99);
}
.menu-info { flex: 1; padding-right: 12px; }
.menu-name { font-weight: 600; font-size: 1rem; margin-bottom: 4px; }
.menu-price { color: var(--brand-primary); font-weight: 700; font-size: 1.05rem; }
.btn-add {
    background: var(--brand-primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    min-height: var(--tap-min);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Floating Bottom Bar (Cart) */
.cart-floating-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    padding: 12px 16px;
    box-shadow: var(--shadow-elevated);
    z-index: 100;
}
.cart-floating-content {
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.cart-summary {
    display: flex;
    flex-direction: column;
}
.cart-qty { font-size: 0.85rem; color: var(--text-muted); }
.cart-total { font-size: 1.25rem; font-weight: 700; color: var(--brand-primary); }
.btn-checkout {
    background: var(--brand-primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    padding: 12px 24px;
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    min-height: var(--tap-min);
}

/* Modal for Options */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    place-content: flex-end;
    z-index: 200;
}
.modal-overlay.active { display: flex; }
.modal-box {
    background: var(--bg-surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
    max-height: 80vh;
    overflow-y: auto;
    animation: slideUp 0.25s ease-out;
}
@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}
.option-group-title {
    font-family: 'Prompt', 'Noto Sans Thai', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-muted);
    margin: 14px 0 8px 0;
}
.option-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 13px 16px;
    background: var(--bg-surface-alt);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    cursor: pointer;
    min-height: var(--tap-min);
    font-size: 0.95rem;
    color: var(--text-main);
    transition: all 0.15s ease;
}
.option-label:hover {
    border-color: var(--brand-primary);
}
.option-label input[type="checkbox"],
.option-label input[type="radio"] {
    width: 18px;
    height: 18px;
    accent-color: var(--brand-primary);
    margin-right: 10px;
    cursor: pointer;
    vertical-align: middle;
}
.option-label span:first-child {
    display: inline-flex;
    align-items: center;
}

/* Payment & QR Presentation */
.pay-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    text-align: center;
    margin: 0 auto 20px auto;
    box-shadow: var(--shadow-card);
}
.qr-wrapper {
    background: #fff;
    padding: 16px;
    display: inline-block;
    border-radius: var(--radius-md);
    margin: 16px 0;
    box-shadow: var(--shadow-card);
}
.copy-btn {
    background: var(--bg-surface-alt);
    border: 1px solid var(--border-color);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    min-height: var(--tap-min);
    margin: 4px;
}
.url-preview-link {
    color: var(--brand-primary);
    font-weight: 600;
    text-decoration: none;
    word-break: break-all;
}

/* ==========================================================================
   KDS Kitchen Display Styles
   ========================================================================== */
.kds-header {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.kds-board {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
    padding: 16px;
}
.kds-card {
    background: var(--bg-surface);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-card);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
.kds-card.cooking { border-color: var(--brand-primary); }
.kds-card.ready { border-color: var(--color-success); }
.kds-card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
    margin-bottom: 10px;
}
.kds-card-title { font-size: 1.2rem; font-weight: 700; color: #fff; }
.kds-card-badge {
    background: var(--brand-primary);
    color: #fff;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
}
.kds-item-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px dashed var(--border-color);
    font-size: 1.05rem;
}
.kds-item-opt { font-size: 0.85rem; color: var(--text-muted); display: block; }
.kds-actions { display: flex; gap: 8px; margin-top: 16px; }
.kds-btn {
    flex: 1;
    min-height: 48px;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
}
.kds-btn-ready { background: var(--color-success); color: #fff; }
.kds-btn-done { background: var(--brand-accent); color: #fff; }

/* ==========================================================================
   Table Standee Print Styles (4x6 & A4 Grid)
   ========================================================================== */
.table-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.table-standee-card {
    background: #ffffff;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    text-align: center;
    box-shadow: var(--shadow-card);
    position: relative;
    page-break-inside: avoid;
    break-inside: avoid;
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #0f172a;
}

.standee-header {
    width: 100%;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 12px;
    margin-bottom: 16px;
}
.standee-brand {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--brand-primary);
    text-transform: uppercase;
    letter-spacing: 1px;
}
.standee-shop-name {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 4px 0 0 0;
    color: #0f172a;
}

.standee-table-pill {
    background: #0f172a;
    color: #ffffff;
    display: inline-block;
    padding: 6px 24px;
    border-radius: var(--radius-full);
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    margin-bottom: 14px;
}

.standee-qr-frame {
    background: #ffffff;
    padding: 14px;
    border: 3px solid var(--brand-primary);
    border-radius: var(--radius-md);
    display: inline-block;
    margin-bottom: 14px;
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.05);
}

.standee-steps {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-md);
    padding: 12px 16px;
    width: 100%;
    margin-bottom: 14px;
    text-align: left;
}
.standee-step-item {
    font-size: 0.85rem;
    font-weight: 600;
    color: #334155;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.standee-step-item:last-child { margin-bottom: 0; }
.standee-step-num {
    background: var(--brand-primary);
    color: #ffffff;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    flex-shrink: 0;
}

.standee-footer-url {
    font-size: 0.8rem;
    color: #64748b;
    word-break: break-all;
}

/* Print Toolbar (Controls) */
.print-toolbar {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 24px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-card);
}

/* @media print Rules: 4 Cards Exactly Per A4 Page (2x2 Grid) */
@page {
    size: A4 portrait;
    margin: 8mm 6mm;
}

@media print {
    html, body {
        background: #ffffff !important;
        color: #000000 !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        height: auto !important;
    }

    .print-hide, .customer-header, .print-toolbar, .no-print {
        display: none !important;
    }

    main {
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .table-preview-grid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        column-gap: 6mm !important;
        row-gap: 6mm !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .table-standee-card {
        border: 1.5px solid #0f172a !important;
        border-radius: 10px !important;
        box-shadow: none !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
        padding: 10px 12px !important;
        height: 133mm !important;
        max-height: 135mm !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: space-between !important;
        align-items: center !important;
        box-sizing: border-box !important;
    }

    /* บังคับตัดหน้าทุกๆ 4 โต๊ะ (โต๊ะที่ 4, 8, 12, 16...) */
    .table-standee-card:nth-child(4n) {
        page-break-after: always !important;
        break-after: page !important;
    }

    .standee-header {
        border-bottom: 1.5px solid #e2e8f0 !important;
        padding-bottom: 6px !important;
        margin-bottom: 8px !important;
    }
    .standee-brand {
        font-size: 0.75rem !important;
    }
    .standee-shop-name {
        font-size: 1.05rem !important;
        margin: 2px 0 0 0 !important;
    }

    .standee-table-pill {
        background: #0f172a !important;
        color: #ffffff !important;
        font-size: 1.15rem !important;
        padding: 4px 18px !important;
        margin-bottom: 8px !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .standee-qr-frame {
        border: 2px solid var(--brand-primary) !important;
        border-radius: 8px !important;
        padding: 8px !important;
        margin-bottom: 8px !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .standee-qr-frame canvas {
        width: 140px !important;
        height: 140px !important;
    }

    .standee-steps {
        background: #f8fafc !important;
        border: 1px solid #cbd5e1 !important;
        border-radius: 6px !important;
        padding: 6px 10px !important;
        margin-bottom: 6px !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .standee-step-item {
        font-size: 0.72rem !important;
        margin-bottom: 2px !important;
        color: #1e293b !important;
    }
    .standee-step-num {
        background: var(--brand-primary) !important;
        color: #ffffff !important;
        width: 16px !important;
        height: 16px !important;
        font-size: 0.65rem !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .standee-footer-url {
        font-size: 0.72rem !important;
        color: #475569 !important;
    }
}

