/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #1565c0;
    --primary-dark: #0d47a1;
    --success: #2e7d32;
    --danger: #c62828;
    --warning: #f57f17;
    --bg: #f5f5f5;
    --surface: #ffffff;
    --text: #212121;
    --text-secondary: #616161;
    --border: #e0e0e0;
    --focus: #1565c0;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,.1);
}

html { font-size: 16px; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Thai", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

/* ===== Focus ===== */
:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

/* ===== Skip link ===== */
.skip-link {
    position: absolute;
    top: -100%;
    left: 1rem;
    background: var(--primary);
    color: #fff;
    padding: .5rem 1rem;
    border-radius: var(--radius);
    z-index: 9999;
    text-decoration: none;
    font-weight: 600;
}
.skip-link:focus { top: 1rem; }

/* ===== Nav ===== */
header {
    background: var(--primary);
    color: #fff;
    padding: 0 1rem;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}
nav {
    display: flex;
    align-items: center;
    gap: 1rem;
    max-width: 1400px;
    margin: 0 auto;
    height: 56px;
}
.nav-brand { font-weight: 700; font-size: 1.1rem; white-space: nowrap; }
.nav-links {
    list-style: none;
    display: flex;
    gap: .25rem;
    margin-left: 1rem;
}
.nav-links a {
    color: rgba(255,255,255,.85);
    text-decoration: none;
    padding: .5rem .75rem;
    border-radius: var(--radius);
    transition: background .15s;
}
.nav-links a:hover,
.nav-links a[aria-current="page"] {
    background: rgba(255,255,255,.2);
    color: #fff;
}
.nav-user {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .9rem;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .6rem 1.2rem;
    border: none;
    border-radius: var(--radius);
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, transform .1s;
    white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b71c1c; }
.btn-sm { padding: .35rem .75rem; font-size: .85rem; }
.btn-full { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #000; }

/* ===== Forms ===== */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: .3rem;
    font-size: .95rem;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: .6rem .75rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    transition: border-color .15s;
    font-family: inherit;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--focus);
    outline: none;
    box-shadow: 0 0 0 3px rgba(21,101,192,.2);
}
.form-row { display: flex; gap: 1rem; }
.form-row .form-group { flex: 1; }
.form-inline { display: inline-flex; align-items: center; gap: .5rem; }
.form-inline label { margin-bottom: 0; }

/* ===== Alerts ===== */
.alert {
    padding: .75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-weight: 500;
}
.alert-error { background: #ffcdd2; color: var(--danger); border: 1px solid #ef9a9a; }
.alert-success { background: #c8e6c9; color: var(--success); border: 1px solid #a5d6a7; }

/* ===== Login ===== */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}
.login-container {
    background: var(--surface);
    padding: 2.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 400px;
}
.login-container h1 {
    text-align: center;
    color: var(--primary);
    margin-bottom: .25rem;
}
.login-container h2 {
    text-align: center;
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
}

/* ===== POS Layout ===== */
.pos-layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 1rem;
    max-width: 1400px;
    margin: 1rem auto;
    padding: 0 1rem;
    min-height: calc(100vh - 72px);
}
.pos-products {
    background: var(--surface);
    padding: 1.25rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-y: auto;
    max-height: calc(100vh - 88px);
}
.pos-products h1 { font-size: 1.3rem; margin-bottom: 1rem; }
.pos-products h2 {
    font-size: 1.1rem;
    color: var(--primary);
    border-bottom: 2px solid var(--primary);
    padding-bottom: .3rem;
    margin: 1.25rem 0 .75rem;
}
.pos-products h2:first-of-type { margin-top: 0; }
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: .75rem;
}
.product-btn {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: .75rem;
    text-align: center;
    cursor: pointer;
    transition: border-color .15s, box-shadow .15s;
    font-family: inherit;
}
.product-btn:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.product-btn:focus-visible { border-color: var(--focus); }
.product-btn .product-name { font-weight: 600; font-size: .95rem; display: block; }
.product-btn .product-price { color: var(--primary); font-weight: 700; font-size: 1rem; display: block; margin-top: .25rem; }
.product-btn .product-stock { color: var(--text-secondary); font-size: .8rem; display: block; }
.product-btn.out-of-stock {
    opacity: .5;
    cursor: not-allowed;
    border-color: var(--border);
}

/* ===== Cart ===== */
.pos-cart {
    background: var(--surface);
    padding: 1.25rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 88px);
}
.pos-cart h1 { font-size: 1.3rem; margin-bottom: 1rem; }
#cart-items {
    flex: 1;
    overflow-y: auto;
    min-height: 100px;
}
.empty-cart { color: var(--text-secondary); text-align: center; padding: 2rem; }
.cart-item {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem 0;
    border-bottom: 1px solid var(--border);
}
.cart-item-name { flex: 1; font-weight: 500; }
.cart-item-qty {
    display: flex;
    align-items: center;
    gap: .25rem;
}
.cart-item-qty button {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}
.cart-item-qty span { min-width: 28px; text-align: center; font-weight: 600; }
.cart-item-subtotal { font-weight: 700; min-width: 80px; text-align: right; }
.cart-item-remove {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 1.2rem;
    padding: .25rem;
}
.cart-summary {
    border-top: 2px solid var(--text);
    padding-top: 1rem;
    margin-top: .5rem;
}
.cart-total {
    display: flex;
    justify-content: space-between;
    font-size: 1.2rem;
    margin-bottom: 1rem;
}
.cart-actions { display: flex; gap: .5rem; }
.cart-actions .btn { flex: 1; }

/* ===== Modal ===== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal[hidden] { display: none; }
.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.5);
}
.modal-content {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0,0,0,.2);
    max-height: 90vh;
    overflow-y: auto;
}
.modal-actions { display: flex; gap: .75rem; margin-top: 1.5rem; justify-content: flex-end; }
.modal-success { text-align: center; }
.modal-success h2 { color: var(--success); margin-bottom: .5rem; }

/* ===== Payment ===== */
.payment-total {
    display: flex;
    justify-content: space-between;
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 1.25rem;
    padding: .75rem;
    background: var(--bg);
    border-radius: var(--radius);
}
.payment-methods {
    border: none;
    margin-bottom: 1.25rem;
}
.payment-methods legend { font-weight: 600; margin-bottom: .5rem; }
.radio-card {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .6rem 1.2rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    margin-right: .5rem;
    transition: border-color .15s;
}
.radio-card:has(input:checked) { border-color: var(--primary); background: #e3f2fd; }
.change-display {
    font-size: 1.3rem;
    padding: .75rem;
    background: #e8f5e9;
    border-radius: var(--radius);
    text-align: center;
    margin-top: .5rem;
}
.qr-image-container {
    text-align: center;
    padding: 1rem;
}
.qr-image-container img {
    max-width: 280px;
    width: 100%;
    border: 2px solid var(--border);
    border-radius: var(--radius);
}

/* ===== Tabs ===== */
.tabs {
    display: flex;
    gap: .25rem;
    border-bottom: 2px solid var(--border);
    margin: 1rem 1rem 0;
    max-width: 1400px;
}
.tab {
    padding: .75rem 1.5rem;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color .15s, border-color .15s;
    margin-bottom: -2px;
    font-family: inherit;
}
.tab:hover { color: var(--text); }
.tab.active,
.tab[aria-selected="true"] {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
.tab-panel {
    padding: 1.5rem 1rem;
    max-width: 1400px;
    margin: 0 auto;
}
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}
.panel-header h2 { font-size: 1.2rem; }

/* ===== Tables ===== */
.table-responsive { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
th, td {
    padding: .75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
th {
    background: var(--bg);
    font-weight: 700;
    font-size: .9rem;
    color: var(--text-secondary);
    text-transform: none;
}
tr:hover td { background: #f8f9fa; }
.badge {
    display: inline-block;
    padding: .15rem .6rem;
    border-radius: 12px;
    font-size: .8rem;
    font-weight: 600;
}
.badge-active { background: #c8e6c9; color: var(--success); }
.badge-inactive { background: #ffcdd2; color: var(--danger); }
.badge-completed { background: #c8e6c9; color: var(--success); }
.badge-cancelled { background: #ffcdd2; color: var(--danger); }
.badge-cash { background: #fff9c4; color: #f57f17; }
.badge-qr { background: #e3f2fd; color: var(--primary); }

/* ===== Dashboard ===== */
.dashboard-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    max-width: 1400px;
    margin: 0 auto;
}
.filter-presets { display: flex; gap: .25rem; }
.filter-btn.active { background: var(--primary); color: #fff; }
.filter-custom { display: flex; align-items: flex-end; gap: .5rem; }
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    padding: 0 1rem 1rem;
    max-width: 1400px;
    margin: 0 auto;
}
.card {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
}
.card h2 { font-size: .95rem; color: var(--text-secondary); margin-bottom: .5rem; }
.card-value { font-size: 1.8rem; font-weight: 700; color: var(--text); }
.card-profit { color: var(--success); }

main > section {
    padding: 0 1rem 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
}
main > section h2 {
    font-size: 1.15rem;
    margin-bottom: .75rem;
    padding-top: .5rem;
}

/* ===== QR Upload ===== */
.qr-upload {
    padding: 1.5rem 1rem;
    max-width: 1400px;
    margin: 0 auto;
}

/* ===== Success details ===== */
.success-details {
    text-align: left;
    background: var(--bg);
    padding: 1rem;
    border-radius: var(--radius);
    margin: 1rem 0;
    font-size: .95rem;
}
.success-details p { margin-bottom: .3rem; }

/* ===== Combo buttons (POS) ===== */
.product-btn.combo-btn {
    background: #fff8e1;
    border-color: var(--warning);
}
.product-btn.combo-btn:hover {
    border-color: #e65100;
    box-shadow: var(--shadow);
}
.combo-detail {
    display: block;
    font-size: .75rem;
    color: var(--text-secondary);
    margin-top: .2rem;
    line-height: 1.3;
}

/* ===== Combo badge in cart ===== */
.cart-item-combo-badge {
    display: inline-block;
    background: #fff8e1;
    color: #e65100;
    font-size: .7rem;
    font-weight: 700;
    padding: .1rem .4rem;
    border-radius: 4px;
    margin-right: .25rem;
    vertical-align: middle;
}

/* ===== Combo item rows (Admin modal) ===== */
.combo-item-row {
    display: flex;
    gap: .5rem;
    align-items: center;
    margin-bottom: .5rem;
}
.combo-item-row select {
    flex: 1;
    padding: .5rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: .9rem;
    font-family: inherit;
}
.combo-item-row input[type="number"] {
    width: 80px;
    padding: .5rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: .9rem;
    font-family: inherit;
}
.combo-item-row select:focus,
.combo-item-row input:focus {
    border-color: var(--focus);
    outline: none;
    box-shadow: 0 0 0 3px rgba(21,101,192,.2);
}
.combo-item-remove {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 1.1rem;
    padding: .25rem .5rem;
}

/* ===== Discount section (Payment modal) ===== */
.discount-section {
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1.25rem;
}
.discount-section legend {
    font-weight: 600;
    padding: 0 .5rem;
}
.discount-section select,
.discount-section input[type="number"] {
    width: 100%;
    padding: .5rem .75rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: inherit;
}
.discount-section select:focus,
.discount-section input:focus {
    border-color: var(--focus);
    outline: none;
    box-shadow: 0 0 0 3px rgba(21,101,192,.2);
}
.discount-preview {
    display: flex;
    justify-content: space-between;
    background: #fff3e0;
    padding: .6rem .75rem;
    border-radius: var(--radius);
    margin-top: .75rem;
    font-size: .95rem;
    font-weight: 500;
}

/* ===== Dashboard discount card ===== */
.card-discount { color: #e65100; }

/* ===== Order detail modal ===== */
#order-detail-info {
    background: var(--bg);
    padding: .75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: .95rem;
}
#order-detail-info p { margin-bottom: .25rem; }
.order-items-table {
    box-shadow: none;
    font-size: .9rem;
}
.order-items-table th {
    font-size: .8rem;
    padding: .4rem .75rem;
}
.order-items-table td {
    padding: .4rem .75rem;
}
.order-detail-discount {
    margin-top: .5rem;
    font-weight: 600;
    color: #e65100;
    font-size: .9rem;
}
.daily-order-item {
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}
.daily-order-item:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}
.daily-order-item h3 {
    font-size: 1rem;
    margin-bottom: .5rem;
    color: var(--primary);
}
.daily-order-item > p {
    font-size: .9rem;
    margin-bottom: .5rem;
    line-height: 1.6;
}
#order-detail-body {
    max-height: 70vh;
    overflow-y: auto;
}
.daily-summary-section {
    background: var(--bg);
    padding: 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
}
.daily-summary-section h3 {
    margin-bottom: .5rem;
    color: var(--success);
}
.table-total-row {
    border-top: 2px solid var(--text);
    background: var(--bg);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .pos-layout { grid-template-columns: 1fr; }
    .pos-products, .pos-cart { max-height: none; }
    .product-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
    nav { flex-wrap: wrap; height: auto; padding: .5rem 0; }
    .nav-links { margin-left: 0; }
    .summary-cards { grid-template-columns: repeat(2, 1fr); }
    .form-row { flex-direction: column; gap: 0; }
    .filter-custom { flex-wrap: wrap; }
}
