/* =============================================
   Order Line Man — Main Stylesheet
   ============================================= */

/* ---- Variables ---- */
:root {
    --red:        #e60026;
    --red-dark:   #cc001e;
    --dark:       #1a1a1a;
    --bg:         #f4f6f9;
    --card:       #ffffff;
    --border:     #e0e0e0;
    --text:       #1a1a1a;
    --muted:      #888;
    --success:    #27ae60;
    --danger:     #e74c3c;
    --warning:    #f39c12;
    --radius:     12px;
    --shadow:     0 2px 12px rgba(0,0,0,.08);
    --font:       Tahoma, Arial, 'Sarabun', sans-serif;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; }
body   { margin: 0; font-family: var(--font); background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.5; }
a      { color: inherit; text-decoration: none; }
img    { max-width: 100%; display: block; }
input, button, select, textarea { font-family: inherit; }
button { cursor: pointer; }

/* ======================================
   NAVBAR
   ====================================== */
.navbar {
    background: var(--dark);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 8px;
}
.navbar-brand { display: flex; align-items: center; gap: 8px; }
.navbar-brand img { height: 34px; }
.navbar-brand span { font-size: 17px; font-weight: bold; }
.navbar-links { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.navbar-links a,
.navbar-links button {
    color: #fff;
    padding: 5px 11px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.3);
    background: transparent;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}
.navbar-links a:hover,
.navbar-links button:hover { background: rgba(255,255,255,0.15); }
.navbar-links .btn-admin  { background: var(--red); border-color: var(--red); }

/* ======================================
   LOGIN PAGE
   ====================================== */
.login-wrap {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--dark);
}
.login-card {
    background: var(--card);
    border-radius: 20px;
    padding: 36px 28px;
    width: 100%;
    max-width: 340px;
    text-align: center;
    box-shadow: 0 8px 40px rgba(0,0,0,0.4);
}
.login-logo { margin-bottom: 20px; }
.login-logo img { height: 56px; margin: 0 auto; }
.login-title    { font-size: 20px; font-weight: bold; margin: 0 0 4px; }
.login-subtitle { font-size: 13px; color: var(--muted); margin: 0 0 24px; }

/* PIN dots */
.pin-display {
    display: flex;
    justify-content: center;
    gap: 14px;
    margin-bottom: 24px;
    min-height: 20px;
}
.pin-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--border);
    transition: background 0.15s, transform 0.1s;
}
.pin-dot.filled { background: var(--red); transform: scale(1.15); }

/* Numpad */
.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.numpad-btn {
    background: #f4f6f9;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 24px;
    font-weight: bold;
    padding: 16px 8px;
    transition: all 0.1s;
    user-select: none;
    line-height: 1;
}
.numpad-btn:active { transform: scale(0.93); background: var(--border); }
.numpad-btn.btn-back  { font-size: 18px; color: var(--muted); }
.numpad-btn.btn-enter { background: var(--red); color: #fff; border-color: var(--red); }
.numpad-btn.btn-enter:active { background: var(--red-dark); }
.login-error { color: var(--danger); font-size: 13px; margin-top: 14px; min-height: 20px; }

/* ======================================
   DASHBOARD
   ====================================== */
.page-content { max-width: 900px; margin: 0 auto; padding: 20px 16px; }

.btn-new-order {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: var(--red);
    color: #fff;
    padding: 18px 24px;
    border-radius: 14px;
    font-size: 20px;
    font-weight: bold;
    border: none;
    width: 100%;
    margin-bottom: 28px;
    transition: background 0.2s, transform 0.1s;
    text-decoration: none;
}
.btn-new-order:hover  { background: var(--red-dark); }
.btn-new-order:active { transform: scale(0.98); }

.section-title { font-size: 18px; font-weight: bold; margin: 0 0 14px; color: var(--text); }

.orders-table-wrap { overflow-x: auto; border-radius: var(--radius); box-shadow: var(--shadow); }
.orders-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card);
    font-size: 15px;
}
.orders-table th,
.orders-table td {
    padding: 11px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.orders-table th { background: #f8f9fa; font-weight: bold; font-size: 13px; color: var(--muted); }
.orders-table tr:last-child td { border-bottom: none; }
.orders-table tbody tr:hover td { background: #fafafa; }

.btn-reprint {
    background: #f0f0f0;
    border: none;
    padding: 5px 12px;
    border-radius: 8px;
    font-size: 13px;
    transition: background 0.2s;
}
.btn-reprint:hover { background: var(--border); }

.orders-empty {
    text-align: center;
    padding: 48px 20px;
    color: var(--muted);
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.orders-empty .icon { font-size: 48px; margin-bottom: 12px; }

/* ======================================
   ORDER CREATE PAGE
   ====================================== */
.order-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    position: sticky;
    top: 57px;
    z-index: 90;
}
.order-no-label { font-size: 16px; font-weight: bold; white-space: nowrap; }
.order-no-input {
    font-size: 28px;
    font-weight: bold;
    padding: 6px 10px;
    border: 2px solid var(--border);
    border-radius: 10px;
    width: 130px;
    text-align: center;
    transition: border-color 0.2s;
}
.order-no-input:focus { border-color: var(--red); outline: none; }

/* Category filters */
.cat-filters {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 12px 16px 4px;
    scrollbar-width: none;
    background: var(--bg);
}
.cat-filters::-webkit-scrollbar { display: none; }
.cat-btn {
    background: var(--card);
    border: 2px solid var(--border);
    border-radius: 20px;
    padding: 6px 16px;
    font-size: 14px;
    font-weight: bold;
    white-space: nowrap;
    transition: all 0.2s;
}
.cat-btn:hover  { border-color: var(--red); color: var(--red); }
.cat-btn.active { background: var(--red); border-color: var(--red); color: #fff; }

/* ==============================================
   MENU SECTIONS — Column layout
   แต่ละหมวดหมู่ = 1 คอลัมน์
   ============================================== */
.menu-sections {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    padding: 16px 16px 150px;
    align-items: start;
}

/* แต่ละ section = 1 คอลัมน์ */
.menu-section {
    background: var(--card);
    border-radius: 14px;
    box-shadow: var(--shadow);
    overflow: hidden;
    scroll-margin-top: 120px;
    transition: box-shadow 0.2s;
}
.menu-section:hover {
    box-shadow: 0 4px 20px rgba(0,0,0,.12);
}

/* หัวหมวด */
.section-header {
    background: var(--dark);
    color: #fff;
    font-size: 16px;
    font-weight: bold;
    padding: 10px 14px;
    letter-spacing: 0.3px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.section-header::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 16px;
    background: var(--red);
    border-radius: 2px;
    flex-shrink: 0;
}

/* Grid ภายใน section = stack แนวตั้ง */
.menu-grid {
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 8px;
}

/* ---- Card — แนวนอน (image ซ้าย, text ขวา) ---- */
.menu-card {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #fafafa;
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
    position: relative;
    border: 2px solid transparent;
    user-select: none;
    padding: 6px 10px 6px 6px;
}
.menu-card:hover:not(.out-of-stock) {
    background: #fff;
    box-shadow: 0 2px 10px rgba(0,0,0,.10);
    transform: translateX(2px);
}
.menu-card.in-cart  { border-color: var(--red); background: #fff5f5; }
.menu-card.out-of-stock { cursor: not-allowed; opacity: 0.6; }

/* ภาพเมนู — สี่เหลี่ยมเล็กซ้ายมือ */
.menu-card-img {
    width: 62px;
    height: 62px;
    border-radius: 8px;
    object-fit: cover;
    background: #ede9fe;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    color: #a78bfa;
    flex-shrink: 0;
    overflow: hidden;
}
.menu-card-img img {
    width: 62px;
    height: 62px;
    object-fit: cover;
    display: block;
    border-radius: 8px;
}

/* ข้อมูลเมนู */
.menu-card-body {
    flex: 1;
    min-width: 0;
}
.menu-card-name {
    font-size: 14px;
    font-weight: bold;
    line-height: 1.35;
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.menu-card-price {
    font-size: 13px;
    color: var(--red);
    font-weight: bold;
}


/* Out-of-stock overlay */
.oos-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.48);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
}
.oos-label {
    background: #fff;
    color: var(--text);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: bold;
    transform: rotate(-15deg);
}

/* Cart badge on card */
.card-qty-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--red);
    color: #fff;
    border-radius: 50%;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}

/* ======================================
   CART BAR (sticky bottom)
   ====================================== */
.cart-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #1a1a1a;
    color: #fff;
    z-index: 200;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,.3);
}
.cart-bar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    cursor: pointer;
    user-select: none;
}
.cart-header-left  { display: flex; align-items: center; gap: 10px; }
.cart-summary-text { font-size: 16px; font-weight: bold; }
.cart-count-badge  { background: var(--red); color: #fff; border-radius: 12px; padding: 2px 10px; font-size: 13px; font-weight: bold; }
.cart-toggle-icon  { font-size: 18px; transition: transform 0.25s; }
.cart-toggle-icon.open { transform: rotate(180deg); }

.cart-items-list { display: none; max-height: 260px; overflow-y: auto; padding: 0 14px 4px; }
.cart-items-list.show { display: block; }

.cart-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    font-size: 15px;
}
.cart-item:last-child { border-bottom: none; }
.cart-item-name  { flex: 1; min-width: 0; }
.cart-item-comment { color: #aaa; font-size: 13px; font-style: italic; }
.cart-qty-group  { display: flex; align-items: center; gap: 6px; }

.qty-c-btn {
    background: rgba(255,255,255,0.18);
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background 0.15s;
}
.qty-c-btn:hover { background: rgba(255,255,255,0.3); }
.qty-c-val { min-width: 24px; text-align: center; font-weight: bold; }

.cart-del-btn {
    background: rgba(231,76,60,0.7);
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    flex-shrink: 0;
    transition: background 0.15s;
}
.cart-del-btn:hover { background: rgba(231,76,60,1); }

.cart-bar-footer { padding: 10px 14px 14px; }
.btn-print-order {
    background: var(--red);
    color: #fff;
    border: none;
    padding: 14px;
    border-radius: 12px;
    font-size: 18px;
    font-weight: bold;
    width: 100%;
    transition: background 0.2s, transform 0.1s;
}
.btn-print-order:hover  { background: var(--red-dark); }
.btn-print-order:active { transform: scale(0.98); }

/* ======================================
   MODAL (quantity selector / comment)
   ====================================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 300;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}
.modal-overlay.hidden { display: none !important; }

.modal-box {
    background: var(--card);
    border-radius: 20px 20px 0 0;
    width: 100%;
    max-width: 480px;
    padding: 24px;
    animation: slideUp 0.22s ease;
}
@keyframes slideUp {
    from { transform: translateY(60px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}
.modal-drag  { width: 40px; height: 4px; background: #ddd; border-radius: 2px; margin: 0 auto 20px; }
.modal-title { font-size: 20px; font-weight: bold; margin-bottom: 4px; }
.modal-price { font-size: 17px; color: var(--red); font-weight: bold; margin-bottom: 20px; }

/* Qty selector */
.qty-selector { display: flex; align-items: center; justify-content: center; gap: 16px; margin-bottom: 14px; }
.qty-main-btn {
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 50%;
    width: 48px;
    height: 48px;
    font-size: 26px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: all 0.15s;
}
.qty-main-btn:hover { border-color: var(--red); color: var(--red); }
.qty-display { font-size: 42px; font-weight: bold; min-width: 72px; text-align: center; }

/* Editable qty input */
.qty-display-input {
    font-size: 40px;
    font-weight: bold;
    width: 90px;
    text-align: center;
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 4px 6px;
    line-height: 1;
    transition: border-color 0.2s;
    -moz-appearance: textfield;
}
.qty-display-input:focus { border-color: var(--red); outline: none; }
.qty-display-input::-webkit-inner-spin-button,
.qty-display-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.qty-quick-row { display: flex; gap: 8px; justify-content: center; margin-bottom: 4px; }
.qty-quick {
    border: none;
    border-radius: 20px;
    padding: 7px 16px;
    font-size: 15px;
    font-weight: bold;
    transition: background 0.15s;
}
.qty-plus  { background: #e8f5e9; color: #1b5e20; }
.qty-plus:hover  { background: #c8e6c9; }
.qty-minus { background: #fde8e8; color: #b71c1c; }
.qty-minus:hover { background: #ffcdd2; }

.modal-actions { display: flex; gap: 10px; }
.btn-modal-cancel {
    flex: 1;
    background: #f0f0f0;
    border: none;
    padding: 14px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: bold;
    transition: background 0.15s;
}
.btn-modal-cancel:hover { background: var(--border); }
.btn-modal-add {
    flex: 2;
    background: var(--red);
    color: #fff;
    border: none;
    padding: 14px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: bold;
    transition: background 0.15s;
}
.btn-modal-add:hover { background: var(--red-dark); }

/* Comment modal */
.comment-textarea {
    width: 100%;
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 16px;
    resize: none;
    margin-bottom: 16px;
    transition: border-color 0.2s;
}
.comment-textarea:focus { border-color: var(--red); outline: none; }

.btn-comment-trigger {
    background: var(--card);
    border: 2px solid var(--border);
    border-radius: 20px;
    padding: 6px 16px;
    font-size: 14px;
    font-weight: bold;
    white-space: nowrap;
    transition: all 0.2s;
    margin-left: auto;
    flex-shrink: 0;
}
.btn-comment-trigger:hover { border-color: var(--red); color: var(--red); }

/* ======================================
   ADMIN PAGES
   ====================================== */
.admin-wrap { max-width: 960px; margin: 0 auto; padding: 20px 16px; }
.admin-section-title { font-size: 22px; font-weight: bold; margin: 0 0 20px; }

.admin-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}
.admin-card-title { font-size: 17px; font-weight: bold; margin: 0 0 16px; }

.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 14px; font-weight: bold; margin-bottom: 6px; }
.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    transition: border-color 0.2s;
    background: #fff;
}
.form-control:focus { border-color: var(--red); outline: none; }
.form-row  { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 160px; }
.form-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* Data table */
.data-table-wrap { overflow-x: auto; border-radius: var(--radius); }
.data-table { width: 100%; border-collapse: collapse; background: var(--card); font-size: 15px; }
.data-table th,
.data-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { background: #f8f9fa; font-weight: bold; font-size: 13px; color: var(--muted); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: #fafafa; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: bold;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    white-space: nowrap;
}
.btn-sm  { padding: 5px 10px; font-size: 13px; border-radius: 6px; }
.btn-primary   { background: var(--red);     color: #fff; }
.btn-primary:hover   { background: var(--red-dark); }
.btn-secondary { background: #f0f0f0;        color: var(--text); }
.btn-secondary:hover { background: var(--border); }
.btn-danger    { background: var(--danger);  color: #fff; }
.btn-danger:hover    { background: #c0392b; }
.btn-success   { background: var(--success); color: #fff; }
.btn-success:hover   { background: #229954; }

/* Availability toggle badge */
.avail-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    border: none;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.15s;
}
.avail-badge.yes { background: #d5f5e3; color: #1e8449; }
.avail-badge.no  { background: #fde8e8; color: var(--danger); }

/* Alerts */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 15px; }
.alert-success { background: #d5f5e3; color: #1e8449; }
.alert-danger   { background: #fde8e8; color: var(--danger); }
.alert-info     { background: #d6eaf8; color: #1a5276; }

/* Thumb image */
.img-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); }
.img-thumb-placeholder { width: 56px; height: 56px; border-radius: 8px; border: 1px dashed var(--border); background: var(--bg); display: flex; align-items: center; justify-content: center; font-size: 24px; color: #ccc; }

/* ======================================
   PRINT STYLES — EXACT 55mm thermal
   ====================================== */
.print-only { display: none; }

@media print {
    @page {
        size: 55mm auto;
        margin: 0;
        padding-left: 3px;
    }

    * { margin: 0; padding: 0; }

    body {
        background: #fff;
        margin: 0;
        padding: 0;
    }

    .no-print { display: none !important; }

    .print-only {
        display: block !important;
        width: 52mm;
        padding: 3mm;
        font-size: 16px;
        line-height: 1.4;
        color: #000;
        background: #fff;
        font-family: Tahoma, Arial, sans-serif;
    }

    .print-logo {
        text-align: center;
        margin-top: 50px;
        margin-bottom: 8px;
        font-weight: bold;
        font-size: 20px;
    }

    .print-center { text-align: center; font-weight: bold; }
    .print-time   { font-size: 12px; margin-top: 3px; font-weight: normal; }

    .print-line { border-top: 1px dashed #000; margin: 8px 0; }

    .print-item {
        display: flex;
        justify-content: space-between;
        margin-bottom: 4px;
        font-size: 13px;
    }
    .print-item span:first-child { font-weight: normal; }
    .print-item span:last-child  { font-weight: bold; }

    .print-comment {
        font-size: 12px;
        padding: 2px 0;
        font-style: italic;
    }

    .print-footer { margin-top: 10px; text-align: center; font-size: 13px; }

    .fontbig  { font-size: 22px; }
    .fontlist { font-size: 16px; }
}

/* ======================================
   RESPONSIVE
   ====================================== */
@media (max-width: 480px) {
    .menu-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .order-no-input { width: 110px; font-size: 22px; }
    .menu-card-img { height: 100px; }
    .menu-card-img img { height: 100px; }
    .navbar-links a,
    .navbar-links button { font-size: 12px; padding: 4px 8px; }
}
