/* =============================================================
   POS SYSTEM — Responsive Stylesheet
   File  : css/responsive.css
   Import หลัง main.css เสมอ
   Breakpoints:
     Desktop  ≥ 1024px  (default — ไม่ต้องใส่ media query)
     Tablet   768–1023px
     Mobile   < 768px
   ============================================================= */


/* -------------------------------------------------------------
   1. GRID HELPERS — ปรับ columns ตามขนาดหน้าจอ
   ------------------------------------------------------------- */

/* Product grid หน้า POS */
.product-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);  /* desktop: 4 คอลัมน์ */
    gap: 12px;
}

/* Stat card row (dashboard/report) */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

/* Form grid 2 คอลัมน์ */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* Generic responsive grid */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }


/* -------------------------------------------------------------
   2. POS LAYOUT — หน้าขายหลัก
      Desktop : product panel (flex:1) | cart panel (fixed 340px)
      Tablet  : product panel | cart panel (280px)
      Mobile  : product panel เต็มจอ + cart เป็น bottom sheet
   ------------------------------------------------------------- */
.pos-layout {
    display: flex;
    height: calc(100dvh - var(--navbar-h));
    overflow: hidden;
}

.pos-products {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.pos-cart {
    width: 400px;
    flex-shrink: 0;
    background: var(--white);
    border-left: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.pos-cart__header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.pos-cart__items {
    flex: 1;
    overflow-y: auto;
    padding: 0 16px;
}

.pos-cart__footer {
    border-top: 1px solid var(--gray-200);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.pos-cart__summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: .88rem;
    color: var(--gray-600);
}
.pos-cart__summary-row.total {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--gray-900);
    padding-top: 6px;
    margin-top: 4px;
    border-top: 1.5px solid var(--gray-200);
}

/* ปุ่มชำระเงิน 2 ปุ่มเรียงแนวนอน */
.pos-pay-btns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 4px;
}

/* ปุ่มแถวล่าง (พัก/ล้าง/ยกเลิก) */
.pos-action-btns {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
}

/* Cart toggle button (mobile เท่านั้น — ซ่อนบน desktop/tablet) */
.cart-toggle-btn { display: none; }


/* -------------------------------------------------------------
   3. TABLET  768px – 1023px
   ------------------------------------------------------------- */
@media (max-width: 1023px) {

    /* Navbar */
    .navbar__nav { display: none; }   /* ซ่อน nav links → ใช้ sidebar แทน */
    .navbar__toggle { display: flex; }

    /* Sidebar เปิด/ปิด ด้วย class .open */
    .sidebar {
        position: fixed;
        top: var(--navbar-h);
        left: 0;
        bottom: 0;
        z-index: 150;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
        width: 240px;
    }
    .sidebar.open { transform: translateX(0); }

    /* Sidebar overlay */
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        top: var(--navbar-h);
        background: rgba(15,23,42,.35);
        z-index: 140;
    }
    .sidebar-overlay.open { display: block; }

    /* Grids */
    .stat-grid    { grid-template-columns: repeat(2, 1fr); }
    .product-grid { grid-template-columns: repeat(3, 1fr); }
    .grid-4       { grid-template-columns: repeat(2, 1fr); }
    .grid-3       { grid-template-columns: repeat(2, 1fr); }

    /* POS cart แคบลง */
    .pos-cart { width: 340px; }

    /* Content padding */
    .main-content { padding: 16px; }
}


/* -------------------------------------------------------------
   4. MOBILE  < 768px
   ------------------------------------------------------------- */
@media (max-width: 767px) {

    /* Base font */
    html { font-size: 14px; }

    /* Navbar */
    .navbar { padding: 0 12px; gap: 10px; }
    .navbar__brand span { display: none; }  /* ซ่อนชื่อ — เหลือแค่ icon */
    .navbar__time { display: none; }

    /* Grids */
    .stat-grid    { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .product-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .form-grid    { grid-template-columns: 1fr; }
    .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }

    /* Main content */
    .main-content { padding: 12px; }

    /* Page header */
    .page-header { flex-direction: column; align-items: flex-start; }

    /* ------------------------------------------------
       POS Layout บนมือถือ
       - Products เต็มจอ
       - Cart เป็น Bottom Sheet เลื่อนขึ้น-ลง
       ------------------------------------------------ */
    .pos-layout {
        flex-direction: column;
        height: calc(100dvh - var(--navbar-h));
        position: relative;
    }

    .pos-products {
        flex: 1;
        overflow-y: hidden;          /* ← เปลี่ยนจาก auto */
        padding: 16px;
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    /* Cart toggle floating button */
    .cart-toggle-btn {
        display: flex;
        position: fixed;
        bottom: 16px;
        left: 50%;
        transform: translateX(-50%);
        z-index: 120;
        background: var(--primary);
        color: var(--white);
        border: none;
        border-radius: 99px;
        padding: 10px 24px;
        font-size: .9rem;
        font-weight: 700;
        align-items: center;
        gap: 8px;
        box-shadow: var(--shadow-lg);
        cursor: pointer;
        white-space: nowrap;
        transition: background var(--transition);
    }
    .cart-toggle-btn:hover { background: var(--primary-dark); }

    /* Cart badge จำนวนสินค้า */
    .cart-badge {
        background: var(--danger);
        color: var(--white);
        font-size: .72rem;
        font-weight: 700;
        min-width: 20px;
        height: 20px;
        border-radius: 99px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 0 5px;
    }

    /* Cart panel เป็น bottom sheet */
    .pos-cart {
        position: fixed;
        inset: auto 0 0 0;
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--gray-200);
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        box-shadow: 0 -4px 24px rgba(0,0,0,.12);
        z-index: 130;
        max-height: 85dvh;
        transform: translateY(100%);
        transition: transform .28s cubic-bezier(.32,.72,0,1);
    }
    .pos-cart.open { transform: translateY(0); }

    /* Drag handle */
    .pos-cart::before {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        background: var(--gray-300);
        border-radius: 99px;
        margin: 10px auto 0;
    }

    /* Cart overlay */
    .cart-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(15,23,42,.4);
        z-index: 125;
    }
    .cart-overlay.open { display: block; }

    /* Product card เล็กลงบนมือถือ */
    .product-card { padding: 8px 6px; }
    .product-card__name  { font-size: .75rem; }
    .product-card__price { font-size: .85rem; }

    /* ปุ่มจ่ายเงินเต็มแถว */
    .pos-pay-btns   { grid-template-columns: 1fr 1fr; }
    .pos-action-btns { grid-template-columns: 1fr 1fr 1fr; }

    /* Table scroll */
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table { min-width: 560px; }

    /* Modal เต็มจอล่างบนมือถือ */
    .modal-overlay { align-items: flex-end; padding: 0; }
    .modal {
        max-width: 100%;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        max-height: 92dvh;
    }

    /* Stat card แนวนอนบนมือถือ */
    .stat-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat-card { padding: 12px 14px; gap: 10px; }
    .stat-card__icon  { width: 38px; height: 38px; font-size: 1.1rem; }
    .stat-card__value { font-size: 1.25rem; }
}


/* -------------------------------------------------------------
   5. EXTRA SMALL  < 400px  (มือถือขนาดเล็ก)
   ------------------------------------------------------------- */
@media (max-width: 399px) {
    .product-grid { grid-template-columns: repeat(2, 1fr); }
    .stat-grid    { grid-template-columns: 1fr; }
    .pos-pay-btns { grid-template-columns: 1fr; }
}


/* -------------------------------------------------------------
   6. PRINT  (ใบเสร็จ)
   ------------------------------------------------------------- */
@media print {
    .navbar, .sidebar, .pos-products,
    .pos-cart__header .btn,
    .pos-action-btns,
    .pos-pay-btns,
    .cart-toggle-btn { display: none !important; }

    body { background: white; font-size: 12px; }

    .receipt {
        width: 80mm;
        margin: 0 auto;
        font-family: 'Courier New', monospace;
    }
    .receipt__divider {
        border-top: 1px dashed #000;
        margin: 6px 0;
    }
}
/* sidebar เฉพาะหน้า POS */
.sidebar--pos {
    display: none;  /* ซ่อนบน desktop */
}

@media (max-width: 1023px) {
    .sidebar--pos {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: var(--navbar-h);
        left: 0;
        bottom: 0;
        z-index: 150;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
        width: 240px;
        transition: transform var(--transition);
    }
    .sidebar--pos.open {
        transform: translateX(0);
    }
}