* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --color-primary: #0A4A90;
    --color-primary-dark: #073760;
    --color-primary-light: #1a5fad;
    --color-accent: #f5820a;
    --color-green: #27ae60;
    --color-green-dark: #1e8449;
    --color-red: #e74c3c;
    --color-blue-text: #0066CC;
    --color-bg: #eef2f5;
    --color-border: #d7dee3;
    --color-text: #2c3e50;
    --header-height: 52px;
    --footer-height: 38px;
}

html, body {
    height: 100%;
}

body {
    font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 14px;
    overflow: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ===================== HEADER BAR ===================== */
.pos-header {
    height: var(--header-height);
    flex: 0 0 auto;
    background: linear-gradient(180deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    color: #fff;
    display: flex;
    align-items: center;
    padding: 0 10px;
    gap: 10px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    z-index: 40;
}

.header-search {
    flex: 0 0 27%;
    display: flex;
    gap: 6px;
    align-items: center;
}

.search-box {
    position: relative;
    flex: 1;
    min-width: 0;
}

.search-box input {
    width: 100%;
    padding: 9px 12px;
    border-radius: 4px;
    border: none;
    outline: none;
    font-size: 14px;
}

.barcode-btn {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border: 1px solid rgba(255,255,255,0.4);
    background: rgba(255,255,255,0.12);
    color: #fff;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
}

.barcode-btn:hover {
    background: rgba(255,255,255,0.25);
}

.search-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: #fff;
    color: var(--color-text);
    border-radius: 4px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.25);
    max-height: 320px;
    overflow-y: auto;
    display: none;
    z-index: 50;
}

.search-dropdown.show {
    display: block;
}

.search-dropdown .item {
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    gap: 8px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
}

.search-dropdown .item:hover,
.search-dropdown .item.active {
    background: #eaf3ff;
}

.search-dropdown .item .name {
    font-weight: 600;
}

.search-dropdown .item .meta {
    font-size: 12px;
    color: #888;
}

.search-dropdown .item .price {
    color: var(--color-primary);
    font-weight: 600;
    white-space: nowrap;
}

.search-dropdown .empty {
    padding: 10px 12px;
    color: #999;
    font-style: italic;
}

/* ===================== HEADER: TABS ===================== */
.header-tabs {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    height: 100%;
    min-width: 0;
}

.header-tabs::-webkit-scrollbar {
    height: 4px;
}

.order-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.3);
    padding: 6px 8px 6px 12px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 600;
    color: rgba(255,255,255,0.85);
    white-space: nowrap;
    flex-shrink: 0;
    font-size: 13px;
}

.order-tab::before {
    content: '⇄';
    margin-right: 2px;
    opacity: 0.7;
}

.order-tab.active {
    background: #fff;
    color: var(--color-primary);
    border-color: #fff;
}

.order-tab.return-mode.active {
    color: var(--color-red);
}

.order-tab .close-tab {
    border: none;
    background: transparent;
    color: inherit;
    opacity: 0.6;
    font-size: 13px;
    cursor: pointer;
    line-height: 1;
    padding: 2px 4px;
    border-radius: 50%;
}

.order-tab .close-tab:hover {
    opacity: 1;
    background: rgba(0,0,0,0.08);
    color: var(--color-red);
}

.tab-add {
    border: 1px dashed rgba(255,255,255,0.5);
    background: transparent;
    color: #fff;
    width: 30px;
    height: 30px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 700;
    flex-shrink: 0;
}

.tab-add:hover {
    background: rgba(255,255,255,0.15);
    border-style: solid;
}

/* ===================== HEADER: UTILITY ICONS ===================== */
.header-utils {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
}

.util-wrap {
    position: relative;
    display: flex;
}

.util-icon {
    position: relative;
    width: 34px;
    height: 34px;
    border-radius: 4px;
    border: none;
    background: rgba(255,255,255,0.12);
    color: #fff;
    font-size: 16px;
    cursor: pointer;
}

.util-icon:hover {
    background: rgba(255,255,255,0.25);
}

.util-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--color-accent);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    border-radius: 8px;
    min-width: 16px;
    height: 16px;
    line-height: 16px;
    text-align: center;
    padding: 0 3px;
}

.cashier-account {
    background: rgba(0,0,0,0.18);
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12.5px;
    font-weight: 600;
}

.util-popover {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: #fff;
    color: var(--color-text);
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.25);
    min-width: 220px;
    padding: 8px;
    z-index: 60;
}

.util-popover.show {
    display: block;
}

.popover-title {
    font-size: 12px;
    font-weight: 700;
    color: #789;
    padding: 4px 8px;
}

.util-popover label {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 8px;
    cursor: pointer;
    border-radius: 4px;
    font-size: 13px;
}

.util-popover label:hover {
    background: #f0f5fb;
}

.popover-link {
    display: block;
    padding: 8px 10px;
    border-radius: 4px;
    font-size: 13px;
    color: var(--color-text);
    cursor: pointer;
}

.popover-link:hover {
    background: #f0f5fb;
}

.popover-link.branch-item.active {
    color: var(--color-primary);
    font-weight: 700;
    background: #eaf3ff;
}

.popover-tab-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}

.popover-tab-item:hover {
    background: #f0f5fb;
}

.popover-empty {
    padding: 10px;
    color: #999;
    font-size: 13px;
    text-align: center;
}

/* ===================== MAIN LAYOUT: 3 COT ===================== */
.pos-main {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* ---- COT TRAI: GIO HANG (45%) ---- */
.col-cart {
    flex: 0 0 45%;
    max-width: 45%;
    background: #fff;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-right: 1px solid var(--color-border);
}

.cart-table {
    width: 100%;
    border-collapse: collapse;
    flex-shrink: 0;
}

.cart-table thead th {
    position: sticky;
    top: 0;
    background: var(--color-primary);
    color: #fff;
    padding: 9px 8px;
    font-size: 12.5px;
    text-align: left;
    z-index: 5;
}

.cart-table .col-stt { width: 40px; text-align: center; }
.cart-table .col-unit { width: 60px; text-align: center; }
.cart-table .col-qty { width: 120px; text-align: center; }
.cart-table .col-price { width: 100px; text-align: right; }
.cart-table .col-total { width: 110px; text-align: right; }
.cart-table .col-action { width: 36px; }

.cart-table tbody tr {
    border-bottom: 1px solid #eef1f4;
}

.cart-table tbody tr:hover {
    background: #f7fbff;
}

.cart-table tbody tr.return-row {
    background: #fff5f5;
}

.cart-table td {
    padding: 7px 8px;
    vertical-align: middle;
    font-size: 13px;
}

.cart-table .col-stt { text-align: center; color: #999; }

.product-name {
    font-weight: 600;
    color: var(--color-text);
}

.product-barcode {
    font-size: 11px;
    color: #999;
}

.qty-control {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
}

.qty-control button {
    width: 22px;
    height: 22px;
    border: 1px solid var(--color-border);
    background: #f5f7f9;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 700;
    color: var(--color-primary);
}

.qty-control button:hover {
    background: #eaf3ff;
}

.qty-control input {
    width: 42px;
    text-align: center;
    padding: 4px 2px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
}

.col-price, .col-total {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.col-total {
    font-weight: 700;
    color: var(--color-primary);
}

.return-row .col-total {
    color: var(--color-red);
}

.remove-item-btn {
    border: none;
    background: transparent;
    color: #bbb;
    cursor: pointer;
    font-size: 15px;
}

.remove-item-btn:hover {
    color: var(--color-red);
}

.cart-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #aaa;
    font-size: 14px;
    padding: 30px;
    text-align: center;
    overflow-y: auto;
}

.cart-footer {
    flex-shrink: 0;
    border-top: 1px solid var(--color-border);
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #fafcfe;
}

.cart-footer-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13.5px;
}

.discount-code-row input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-size: 13px;
}

.cart-final-row {
    font-size: 19px;
    font-weight: 800;
    color: var(--color-blue-text);
    border-top: 1px dashed var(--color-border);
    padding-top: 8px;
}

/* ---- COT GIUA: KHACH HANG (30%) ---- */
.col-customer {
    flex: 0 0 30%;
    max-width: 30%;
    background: #f7f9fb;
    display: flex;
    flex-direction: column;
    padding: 12px;
    gap: 12px;
    overflow-y: auto;
    border-right: 1px solid var(--color-border);
}

.mid-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    padding: 8px 10px;
}

.mid-header select {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    font-weight: 600;
    color: var(--color-primary);
    background: transparent;
    font-size: 13px;
}

.clock-mid {
    font-variant-numeric: tabular-nums;
    font-size: 12.5px;
    color: #789;
    white-space: nowrap;
}

.customer-box {
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    padding: 10px;
    position: relative;
}

.customer-box label {
    font-size: 12px;
    color: #789;
    font-weight: 600;
    display: block;
    margin-bottom: 6px;
}

.customer-search-row {
    display: flex;
    gap: 6px;
}

.customer-search-row input {
    flex: 1;
    padding: 8px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
}

.customer-search-row button {
    width: 36px;
    border: none;
    background: var(--color-primary);
    color: #fff;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 700;
    font-size: 16px;
}

.customer-info {
    margin-top: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #eaf7ee;
    border-radius: 4px;
    padding: 8px;
    font-size: 13px;
}

.customer-info #customerPoints {
    color: var(--color-green-dark);
    font-weight: 600;
}

.customer-info button {
    border: none;
    background: transparent;
    color: #999;
    cursor: pointer;
    font-size: 14px;
}

.empty-cart-illustration {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #aab4bd;
    font-size: 13px;
    text-align: center;
    gap: 8px;
    min-height: 100px;
}

.illustration-icon {
    font-size: 46px;
    opacity: 0.5;
}

.order-note-box {
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    padding: 10px;
}

.order-note-box label {
    font-size: 12px;
    color: #789;
    font-weight: 600;
    display: block;
    margin-bottom: 6px;
}

.order-note-box textarea {
    width: 100%;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 8px;
    resize: none;
    font-family: inherit;
    font-size: 13px;
}

.cod-switch-box {
    margin-top: auto;
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 600;
    color: #567;
}

.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch .slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: #ccd3d9;
    border-radius: 22px;
    transition: 0.15s;
}

.switch .slider::before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    border-radius: 50%;
    transition: 0.15s;
}

.switch input:checked + .slider {
    background-color: var(--color-green);
}

.switch input:checked + .slider::before {
    transform: translateX(18px);
}

/* ---- COT PHAI: THANH TOAN (25%) ---- */
.col-payment {
    flex: 0 0 25%;
    max-width: 25%;
    background: #f7f9fb;
    display: flex;
    flex-direction: column;
    padding: 12px;
    gap: 10px;
    overflow-y: auto;
}

.calc-box {
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.calc-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
}

.calc-row input[type="number"] {
    width: 130px;
    padding: 6px 8px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    text-align: right;
}

.discount-inputs {
    display: flex;
    align-items: center;
    gap: 4px;
}

.discount-inputs input {
    width: 62px;
    padding: 6px 6px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    text-align: right;
}

.discount-inputs span {
    color: #999;
    font-size: 12px;
}

.quick-cash {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.quick-cash button {
    padding: 8px 4px;
    border: 1px solid var(--color-border);
    background: #f5f7f9;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--color-primary);
}

.quick-cash button:hover {
    background: #eaf3ff;
}

#exactAmountBtn {
    grid-column: span 3;
    background: #fff3e0;
    color: var(--color-accent);
    border-color: #ffd699;
}

#changeAmount {
    font-weight: 700;
    color: var(--color-green-dark);
    font-size: 16px;
}

#changeAmount.negative {
    color: var(--color-red);
}

.cod-note-box {
    background: #fff8e6;
    border: 1px solid #ffe1a3;
    border-radius: 6px;
    padding: 10px;
    font-size: 12.5px;
    color: #8a6d1f;
    line-height: 1.5;
}

.payment-methods {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

.method-btn {
    padding: 10px 4px;
    border: 1px solid var(--color-border);
    background: #fff;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12.5px;
    font-weight: 600;
    color: #567;
}

.method-btn.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}

.action-buttons {
    display: flex;
    gap: 8px;
}

.action-buttons button {
    flex: 1;
    padding: 11px 4px;
    border: none;
    border-radius: 6px;
    font-size: 13.5px;
    font-weight: 700;
    cursor: pointer;
    color: #fff;
}

.btn-save {
    background: var(--color-accent);
}

.btn-save:hover {
    background: #d96f00;
}

.btn-checkout-full {
    width: 100%;
    padding: 16px 4px;
    border: none;
    border-radius: 6px;
    font-size: 17px;
    font-weight: 800;
    letter-spacing: 0.5px;
    cursor: pointer;
    color: #fff;
    background: var(--color-primary);
    margin-top: auto;
}

.btn-checkout-full:hover {
    background: var(--color-primary-light);
}

/* ===================== FOOTER BAR ===================== */
.pos-footer {
    height: var(--footer-height);
    flex: 0 0 auto;
    background: #fff;
    border-top: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    font-size: 12px;
    color: #567;
}

.footer-left {
    display: flex;
    gap: 4px;
}

.sale-mode-btn {
    border: 1px solid var(--color-border);
    background: #f5f7f9;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: #567;
}

.sale-mode-btn.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}

.footer-right {
    display: flex;
    align-items: center;
    gap: 18px;
}

.branch-select {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: #567;
}

.hotline strong {
    color: var(--color-primary);
}

.footer-icon {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: #567;
}

.footer-icon:hover, .branch-select:hover {
    color: var(--color-primary);
}

.pos-footer .util-popover {
    top: auto;
    bottom: calc(100% + 8px);
    right: 0;
}

/* ===================== MODALS ===================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-box {
    background: #fff;
    border-radius: 8px;
    padding: 22px;
    width: 360px;
    max-width: 90vw;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}

.modal-box h3 {
    margin-bottom: 14px;
    color: var(--color-primary-dark);
}

.modal-box label {
    display: block;
    font-size: 12px;
    color: #789;
    margin: 10px 0 4px;
    font-weight: 600;
}

.modal-box input {
    width: 100%;
    padding: 9px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 18px;
}

.modal-actions button {
    padding: 9px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
}

.modal-actions button:first-child {
    background: #eee;
    color: #555;
}

.modal-actions button:last-child {
    background: var(--color-primary);
    color: #fff;
}

.qr-box {
    text-align: center;
}

.qr-box img {
    width: 240px;
    height: 240px;
    object-fit: contain;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    margin: 10px 0;
}

/* ===================== TOAST ===================== */
.toast-container {
    position: fixed;
    top: 64px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 200;
}

.toast {
    background: #333;
    color: #fff;
    padding: 12px 18px;
    border-radius: 6px;
    font-size: 13px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.25);
    animation: toast-in 0.2s ease-out;
    max-width: 320px;
}

.toast.success { background: var(--color-green-dark); }
.toast.error { background: var(--color-red); }

@keyframes toast-in {
    from { transform: translateX(30px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ===================== PRINT AREA ===================== */
#printArea {
    display: none;
}

.bill-k80, .bill-k58 {
    font-family: 'Consolas', 'Courier New', monospace;
    color: #000;
    padding: 6px;
}

.bill-k80 { width: 80mm; font-size: 12px; }
.bill-k58 { width: 58mm; font-size: 10px; }

.bill-center { text-align: center; }
.bill-line { border-top: 1px dashed #000; margin: 6px 0; }
.bill-row { display: flex; justify-content: space-between; gap: 6px; }
.bill-item-name { font-weight: 700; }
.bill-total-row { display: flex; justify-content: space-between; font-weight: 700; font-size: 1.1em; margin-top: 4px; }

/* =========================================================
   RESPONSIVE CHO MOBILE & TABLET (CHUẨN KIOTVIET APP MOBILE)
   ========================================================= */

@media (max-width: 992px) {
    body, #app {
        height: auto;
        min-height: 100vh;
        overflow-y: auto;
    }

    .pos-header {
        flex-wrap: wrap;
        height: auto;
        padding: 8px 10px;
        gap: 8px;
    }

    .header-search {
        flex: 1 1 100%;
        max-width: 100%;
        order: 1;
    }

    .header-tabs {
        flex: 1 1 auto;
        order: 2;
        overflow-x: auto;
    }

    .header-utils {
        order: 3;
        margin-left: auto;
    }

    .cashier-account {
        display: none;
    }

    .pos-main {
        flex-direction: column;
        height: auto;
        overflow: visible;
        padding-bottom: 60px;
    }

    .col-cart, .col-customer, .col-payment {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 100% !important;
        flex: 1 1 100% !important;
        height: auto !important;
        border-right: none;
        border-bottom: 1px solid #d9d9d9;
    }

    .pos-footer {
        flex-direction: column;
        height: auto;
        padding: 8px 10px;
        gap: 8px;
    }

    .footer-left, .footer-right {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 6px;
    }

    .col-cart {
        order: 1;
    }

    .cart-table-wrap {
        max-height: 300px;
        overflow-x: auto;
    }

    .col-customer {
        order: 2;
        padding: 12px;
    }

    .empty-cart-illustration {
        display: none !important;
    }

    .quick-cash {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
    }

    .quick-cash button {
        padding: 8px 4px;
        font-size: 13px;
    }

    .action-buttons {
        margin-bottom: 8px;
    }

    .btn-save, .btn-checkout-full {
        width: 100%;
        height: 48px;
        font-size: 16px;
        border-radius: 6px;
    }

    .col-payment {
        order: 3;
        padding: 12px;
    }

    .pos-footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 100;
        background: #fff;
    }

    .pos-footer .footer-right .hotline {
        display: none;
    }
}

@media print {
    @page {
        margin: 0;
    body * {
        visibility: hidden;
    }
    #printArea, #printArea * {
        visibility: visible;
    }
    #printArea {
        display: block;
        position: absolute;
        left: 0;
        top: 0;
        width: auto;
    }
}
