*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 20px;
    background-color: #f4f7f6;
}

header {
    text-align: center;
    background: #2c3e50;
    color: white;
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.login-panel,
.owner-access,
.session-panel,
.sync-panel {
    margin-bottom: 20px;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.login-panel {
    max-width: 420px;
    margin-left: auto;
    margin-right: auto;
}

.owner-access {
    max-width: 100%;
    margin-bottom: 20px;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.login-panel h2 {
    margin-top: 0;
}

.owner-access h2 {
    margin-top: 0;
}

.login-panel label,
.customer-info label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
}

.login-panel select,
.login-panel input,
.customer-info input,
.customer-info select,
.checkout-form input,
.checkout-form select,
.danger-form input {
    width: 100%;
    padding: 10px;
    margin-bottom: 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-sizing: border-box;
}

.login-note {
    margin-bottom: 0;
    color: #666;
    font-size: 0.9em;
}

.session-panel {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.session-panel strong {
    display: block;
    font-size: 1.1em;
}

.session-panel span {
    color: #666;
}

.sync-status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.connection-badge {
    display: inline-flex;
    align-items: center;
    padding: 8px 12px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.9em;
}

.badge-online {
    background: #e0f5e5;
    color: #19692c;
}

.badge-offline {
    background: #fff1d6;
    color: #8a5a00;
}

.sync-note {
    margin: 6px 0;
    color: #4f5b66;
}

.offline-queue-list {
    list-style: none;
    padding: 0;
    margin: 12px 0 0;
}

.offline-queue-item {
    padding: 10px 12px;
    border: 1px dashed #d9e4ec;
    border-radius: 8px;
    background: #f9fcff;
    margin-bottom: 10px;
}

.offline-queue-meta {
    margin-top: 4px;
    color: #667;
    font-size: 0.9em;
}

.hidden {
    display: none;
}

.alert {
    padding: 14px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.alert-success {
    background: #e8f7ee;
    color: #1d6f42;
}

.alert-error {
    background: #fdecea;
    color: #9b2c2c;
}

.alert-info {
    background: #eaf4ff;
    color: #1e5e9f;
}

.pos-container {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
}

.product-grid, .cart-container, .history-container {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.product-grid {
    padding-top: 12px;
    padding-bottom: 12px;
}

.product-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 8px;
    border-bottom: 1px solid #eee;
}

.product-info {
    display: flex;
    flex-direction: column;
}

.product-info span {
    font-weight: bold;
}

.product-info small {
    color: #666;
}

.product-action {
    display: flex;
    align-items: center;
}

.product-action input,
.product-action-form input[type="number"] {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.product-action-form {
    display: flex;
    gap: 8px;
    align-items: center;
}

.product-action-form input[type="number"],
.product-action-form input[name="quantity"] {
    width: 90px;
    font-size: 16px;
    text-align: center;
}

.cart-items li {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px dashed #eee;
}

.btn-add {
    background: #27ae60;
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 5px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.1s;
}

.btn-add:hover { background: #219150; }
.btn-add:active { transform: scale(0.96); }

/* Tombol gambar keranjang pada daftar barang */
.btn-cart-action {
    min-width: 42px;
    height: 36px;
    padding: 0 10px;
    background: #27ae60;
    color: white;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-cart-action .icon-cart-svg {
    display: block;
    pointer-events: none;
}
.btn-cart-action:hover {
    background: #1e824c;
}

/* Header Keranjang Belanja & Tombol Navigasi Kembali ke Produk */
.cart-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    gap: 8px;
}
.cart-header-row h2 {
    margin: 0;
}

.btn-nav-products {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #2c3e50;
    color: #ffffff;
    padding: 6px 12px;
    border-radius: 6px;
    text-decoration: none;
    font-size: 0.84em;
    font-weight: 600;
    cursor: pointer;
    border: none;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
    transition: background 0.15s, transform 0.1s;
    white-space: nowrap;
}
.btn-nav-products:hover {
    background: #1a252f;
    color: #ffffff;
}
.btn-nav-products:active {
    transform: scale(0.96);
}
.cart-plus-symbol {
    font-size: 1.2em;
    font-weight: 900;
    color: #f1c40f;
    margin-left: -2px;
    line-height: 1;
}

/* Efek highlight halus saat mendarat di keranjang */
.cart-pulse-glow {
    animation: cartPulseGlow 0.8s ease-out;
}
@keyframes cartPulseGlow {
    0% { box-shadow: 0 0 0 0 rgba(39, 174, 96, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(39, 174, 96, 0); }
    100% { box-shadow: 0 0 0 0 rgba(39, 174, 96, 0); }
}

.cart-items { list-style: none; padding: 0; }

.print-help {
    margin-bottom: 12px;
    padding: 10px 12px;
    background: #eef6ff;
    color: #24527a;
    border-radius: 6px;
    font-size: 0.9em;
}

.print-box {
    margin-top: 16px;
    padding: 14px;
    background: #f7fbf7;
    border: 1px solid #d6ead6;
    border-radius: 8px;
}

.print-box strong {
    display: block;
    margin-bottom: 10px;
}

.btn-login,
.btn-logout,
.btn-owner-action,
.btn-owner-cancel,
.btn-print,
.btn-sync {
    border: none;
    border-radius: 5px;
    cursor: pointer;
    padding: 10px 16px;
    color: white;
}

.btn-login {
    width: 100%;
    background: #2980b9;
}

.btn-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    border-radius: 5px;
    background: #2c3e50;
    color: white;
    text-decoration: none;
}

.btn-logout {
    background: #7f8c8d;
}

.owner-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.btn-owner-action {
    background: #2c3e50;
}

.btn-owner-cancel {
    background: #c0392b;
}

.btn-print {
    background: #16a085;
}

.btn-sync {
    background: #8e44ad;
}

.btn-print:disabled {
    opacity: 0.7;
    cursor: wait;
}

.btn-sync:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.btn-print-small {
    margin-left: 6px;
    padding: 6px 10px;
    font-size: 0.85em;
}

.owner-mode-form {
    background: #f9fbfc;
    border: 1px solid #e5eef4;
    border-radius: 8px;
    padding: 14px;
}

.owner-mode-form small {
    display: block;
    margin-top: 8px;
    color: #666;
}

.session-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.checkout-actions {
    display: flex;
    gap: 12px;
    margin-top: 10px;
}

.btn-checkout {
    flex: 1;
    padding: 15px;
    background: #2980b9;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 1.1em;
    cursor: pointer;
}

.btn-cancel {
    flex: 1;
    padding: 15px;
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 1.1em;
    cursor: pointer;
}

.checkout-form label,
.danger-form label {
    display: block;
    margin-top: 14px;
    margin-bottom: 6px;
    font-weight: 600;
}

.checkout-form {
    margin-top: 16px;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

.history-table {
    table-layout: fixed;
}

th, td {
    text-align: left;
    padding: 10px;
    border-bottom: 1px solid #eee;
}

.history-items-cell {
    white-space: normal;
    word-break: break-word;
    line-height: 1.5;
}

.history-action-cell {
    white-space: nowrap;
}

.history-table tr.history-row-cashier1 {
    background-color: #fff8d6;
}

.history-table tr.history-row-cashier2 {
    background-color: #e8f8e8;
}

.history-table tr.history-row-cashier1 td:first-child,
.history-table tr.history-row-cashier2 td:first-child {
    border-left: 4px solid transparent;
}

.history-table tr.history-row-cashier1 td:first-child {
    border-left-color: #d4ac0d;
}

.history-table tr.history-row-cashier2 td:first-child {
    border-left-color: #27ae60;
}

.btn-clear {
    margin-top: 20px;
    background: #e74c3c;
    color: white;
    border: none;
    padding: 10px;
    border-radius: 5px;
    cursor: pointer;
}

.btn-close-shift {
    margin-top: 20px;
    background: #27ae60;
    color: white;
    border: none;
    padding: 10px;
    border-radius: 5px;
    cursor: pointer;
}

.history-total-row.shift-closure-total {
    background: #fff4e5;
    color: #8a5300;
}

.debt-section {
    margin-top: 20px;
}

.debt-section h3 {
    margin-bottom: 6px;
}

.debt-summary {
    font-size: 0.9em;
    color: #555;
    margin-bottom: 10px;
}

.debt-table .row-debt td {
    background: #fdecea;
}

.shift-closure-row td {
    background: #2c3e50;
    color: #fff;
    font-weight: bold;
    text-align: center;
    font-size: 0.85em;
    letter-spacing: 0.03em;
}

.status-badge {
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 0.85em;
    font-weight: bold;
}

.badge-paid {
    background-color: #d4edda;
    color: #155724;
}

.badge-debt {
    background-color: #f8d7da;
    color: #721c24;
}

.row-debt {
    background-color: #fff9f9;
}

.btn-pay {
    background-color: #f39c12;
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8em;
}

.btn-pay:hover {
    background-color: #e67e22;
}

.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.card {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    text-align: center;
}

.card h3 {
    margin-top: 0;
    color: #7f8c8d;
}

.summary-breakdown {
    margin-top: 12px;
    display: grid;
    gap: 8px;
}

.summary-breakdown-item {
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 0.92em;
    font-weight: 600;
}

.summary-breakdown-cashier1 {
    background: #fff4bf;
    color: #8a6d00;
}

.summary-breakdown-cashier2 {
    background: #def5df;
    color: #1f6b2a;
}

.value {
    font-size: 1.5em;
    font-weight: bold;
    color: #2c3e50;
}

.value-paid {
    color: #27ae60;
}

.value-debt {
    color: #e74c3c;
}

.danger-zone {
    margin-top: 30px;
    padding: 20px;
    background: #fff5f5;
    border: 1px solid #f5c6cb;
    border-radius: 8px;
}

.danger-zone h3 {
    margin-top: 0;
}

.danger-form {
    max-width: 420px;
}

.inline-form {
    display: inline-block;
}

.empty-state {
    color: #777;
    text-align: center;
    padding: 16px 0;
}

.reset-form {
    margin-top: 20px;
}

@media (max-width: 768px) and (orientation: portrait) {
    body {
        padding: 12px;
    }
    .pos-container { grid-template-columns: 1fr; }
    .session-panel {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    .session-actions {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }
    .sync-status-row {
        flex-direction: column;
        align-items: stretch;
    }
    .owner-actions {
        grid-template-columns: 1fr;
    }
    .product-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .product-action-form {
        width: 100%;
        display: flex;
        gap: 8px;
    }
    .product-action-form input[type="number"],
    .product-action-form input[name="quantity"],
    .product-action-form input[type="text"] {
        flex: 1;
        height: 38px;
    }
    .btn-cart-action {
        width: 48px;
        min-width: 48px;
        height: 38px;
        padding: 0;
    }
    .history-table,
    .history-table thead,
    .history-table tbody,
    .history-table tr,
    .history-table th,
    .history-table td {
        display: block;
        width: 100%;
    }
    .history-table thead {
        display: none;
    }
    .history-table tr {
        background: white;
        border: 1px solid #e9ecef;
        border-radius: 10px;
        margin-bottom: 12px;
        padding: 10px 12px;
        box-sizing: border-box;
    }
    .history-table tr.history-row-cashier1 {
        background: #fff8d6;
        border-color: #f1d76a;
    }
    .history-table tr.history-row-cashier2 {
        background: #e8f8e8;
        border-color: #9fd7aa;
    }
    .history-table td {
        border-bottom: none;
        padding: 6px 0;
    }
    .history-table td::before {
        content: attr(data-label);
        display: block;
        font-size: 0.82em;
        font-weight: 700;
        color: #666;
        margin-bottom: 2px;
    }
    .history-items-cell,
    .history-action-cell {
        white-space: normal;
    }
    .history-action-cell .inline-form {
        display: inline-block;
        margin-right: 6px;
        margin-bottom: 6px;
    }
    .history-table .empty-state {
        text-align: left;
        padding: 0;
    }
    .history-table .empty-state::before {
        content: none;
    }
}

/* ========================================================
   TATA LETAK KHUSUS HP POSISI LANDSCAPE (MENCEGAH BERANTAKAN)
   ======================================================== */
@media (orientation: landscape) and (max-height: 550px), (max-width: 950px) and (orientation: landscape) {
    body {
        padding: 6px 10px;
        font-size: 13px;
        overflow-x: hidden;
    }

    /* 1. Header & Panel Atas Kompak (Hemat Ruang Vertikal) */
    header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 6px 12px;
        margin-bottom: 6px;
        border-radius: 6px;
    }
    header h1 {
        font-size: 1.05em;
        margin: 0;
        text-align: left;
    }
    header p {
        display: none;
    }

    .session-panel {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        padding: 6px 12px;
        margin-bottom: 6px;
        border-radius: 6px;
        gap: 8px;
    }
    .session-panel strong {
        font-size: 0.9em;
        display: inline-block;
    }
    .session-panel span {
        font-size: 0.8em;
        color: #666;
        margin-left: 6px;
        display: inline-block;
    }
    .session-actions {
        display: flex;
        flex-direction: row;
        gap: 6px;
        align-items: center;
        width: auto;
    }
    .session-actions .btn-logout,
    .session-actions .btn-owner-action,
    .session-actions .btn-link {
        padding: 4px 10px;
        font-size: 0.8em;
        margin: 0;
        border-radius: 4px;
    }

    .sync-panel {
        padding: 5px 12px;
        margin-bottom: 6px;
        border-radius: 6px;
    }
    .sync-status-row {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 0;
        gap: 8px;
    }
    .sync-note {
        display: none;
    }
    .btn-sync {
        padding: 3px 8px;
        font-size: 0.75em;
    }

    /* 2. Container POS Kasir: 2 Kolom Seimbang (Produk Kiri, Keranjang Kanan) */
    .pos-container {
        display: grid;
        grid-template-columns: 57% 43%;
        gap: 8px;
        align-items: start;
        box-sizing: border-box;
        margin-bottom: 10px;
    }

    .product-grid,
    .cart-container {
        padding: 8px 10px;
        border-radius: 6px;
        box-sizing: border-box;
    }

    .product-grid h2,
    .cart-container h2 {
        font-size: 0.95em;
        margin: 0 0 6px 0;
        padding-bottom: 4px;
        border-bottom: 1px solid #eee;
    }

    /* Daftar produk: 1 kolom memanjang yang leluasa, tidak bertumpuk */
    #products {
        display: flex;
        flex-direction: column;
        gap: 5px;
        max-height: 56vh;
        overflow-y: auto;
        padding-right: 3px;
    }

    .product-item {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        padding: 6px 8px;
        border: 1px solid #e2e8f0;
        border-radius: 6px;
        background: #fff;
        gap: 8px;
        box-sizing: border-box;
    }

    .product-info {
        display: flex;
        flex-direction: column;
        min-width: 0;
        flex: 1;
    }
    .product-info span {
        font-size: 0.88em;
        font-weight: 700;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        color: #2c3e50;
        line-height: 1.2;
    }
    .product-info small {
        font-size: 0.76em;
        color: #666;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        margin-top: 2px;
    }

    .product-action-form {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 5px;
        flex: 0 0 auto;
        width: auto;
        margin: 0;
    }

    .product-action-form input[name="quantity"],
    .product-action-form input[type="text"],
    .product-action-form input[type="number"] {
        width: 60px;
        height: 32px;
        padding: 0 4px;
        font-size: 14px;
        text-align: center;
        border: 1px solid #cbd5e1;
        border-radius: 4px;
        box-sizing: border-box;
    }

    .btn-add {
        height: 32px;
        padding: 0 10px;
        font-size: 0.8em;
        font-weight: bold;
        border-radius: 4px;
        white-space: nowrap;
        flex: 0 0 auto;
    }

    .btn-cart-action {
        width: 36px;
        min-width: 36px;
        height: 32px;
        padding: 0;
    }

    .btn-nav-products {
        padding: 4px 8px;
        font-size: 0.78em;
    }

    /* 3. Keranjang & Form Checkout Sisi Kanan */
    .print-help {
        display: none;
    }

    .cart-items {
        max-height: 20vh;
        overflow-y: auto;
        margin-bottom: 6px;
        padding-right: 3px;
    }
    .cart-items li {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        padding: 3px 0;
        font-size: 0.8em;
        border-bottom: 1px dashed #e2e8f0;
    }
    .cart-items li span:first-child {
        font-weight: 600;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 65%;
    }
    .cart-items li span:last-child {
        font-weight: 700;
        color: #2c3e50;
    }

    .cart-total {
        margin-top: 3px;
        padding: 3px 0;
        font-size: 0.9em;
        border-top: 2px solid #e2e8f0;
    }

    .checkout-form {
        margin-top: 4px;
    }
    .checkout-form label {
        font-size: 0.76em;
        margin-bottom: 2px;
        display: block;
        font-weight: 600;
    }
    .checkout-form input,
    .checkout-form select {
        padding: 4px 6px;
        margin-bottom: 4px;
        font-size: 0.8em;
        height: 28px;
        box-sizing: border-box;
    }

    .checkout-actions {
        display: flex;
        flex-direction: row;
        gap: 6px;
        margin-top: 4px;
    }
    .btn-checkout,
    .btn-cancel {
        padding: 6px 8px;
        font-size: 0.82em;
        font-weight: 700;
        border-radius: 4px;
        flex: 1;
        text-align: center;
    }

    .print-box {
        margin-top: 5px;
        padding: 5px 8px;
        border-radius: 6px;
    }
    .print-box strong {
        font-size: 0.78em;
        display: block;
    }
    .btn-print {
        padding: 4px 8px;
        font-size: 0.78em;
        margin-top: 3px;
        border-radius: 4px;
    }

    /* 4. Riwayat Transaksi (Scrollable Horizontal Rapi, Tidak Merusak Halaman) */
    .history-container,
    .product-management {
        padding: 8px 10px;
        border-radius: 6px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        box-sizing: border-box;
    }
    .history-container h2 {
        font-size: 0.95em;
        margin: 0 0 6px 0;
    }
    .history-table {
        display: table !important;
        width: 100% !important;
        min-width: 600px;
        font-size: 0.8em;
    }
    .history-table thead {
        display: table-header-group !important;
    }
    .history-table tbody {
        display: table-row-group !important;
    }
    .history-table tr {
        display: table-row !important;
        background: transparent !important;
        border: none !important;
        padding: 0 !important;
    }
    .history-table th,
    .history-table td {
        display: table-cell !important;
        width: auto !important;
        padding: 6px 8px !important;
        border-bottom: 1px solid #e2e8f0 !important;
        white-space: nowrap;
    }
    .history-table td::before {
        display: none !important;
    }
    .history-items-cell {
        white-space: normal !important;
        max-width: 200px;
    }
    .btn-print-small {
        padding: 3px 6px;
        font-size: 0.75em;
    }
}

.product-out-of-stock {
    opacity: 0.75;
    background: #fff5f5 !important;
    border-left: 4px solid #e74c3c !important;
}
.product-out-of-stock .btn-add {
    background: #95a5a6 !important;
    cursor: not-allowed !important;
}

/* ===== Highlight Transaksi Baru di Riwayat ===== */
@keyframes highlightRow {
    0%   { background-color: #fff9c4; box-shadow: inset 0 0 0 3px #f1c40f; }
    60%  { background-color: #fffde7; box-shadow: inset 0 0 0 2px #f1c40f; }
    100% { background-color: transparent; box-shadow: none; }
}

.highlight-new-tx {
    animation: highlightRow 4s ease-out forwards;
    position: relative;
}

.highlight-badge-new {
    display: inline-block;
    background: #e74c3c;
    color: #fff;
    font-size: 0.65em;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 3px;
    margin-left: 6px;
    vertical-align: middle;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}
