/* Modern Mobile-First Responsive Design */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #366092;
    --primary-dark: #2a4a73;
    --secondary-color: #00c300;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --success-color: #28a745;
    --bg-color: #f8f9fa;
    --text-color: #212529;
    --border-color: #dee2e6;
    --card-shadow: 0 2px 4px rgba(0,0,0,0.1);
    --card-shadow-hover: 0 4px 8px rgba(0,0,0,0.15);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    font-size: 16px;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 1.5rem 1rem;
    box-shadow: var(--card-shadow);
    margin-bottom: 2rem;
}

.header h1 {
    font-size: 1.75rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.header p {
    opacity: 0.9;
    font-size: 0.95rem;
}

/* Navigation */
.nav {
    background: white;
    padding: 1rem;
    border-radius: 8px;
    box-shadow: var(--card-shadow);
    margin-bottom: 2rem;
}

.nav-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    list-style: none;
}

.nav-tab {
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 500;
    border: 2px solid transparent;
}

.nav-tab:hover {
    background-color: var(--bg-color);
}

.nav-tab.active {
    background-color: var(--primary-color);
    color: white;
}

/* Cards */
.card {
    background: white;
    border-radius: 8px;
    box-shadow: var(--card-shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    transition: box-shadow 0.3s;
}

.card:hover {
    box-shadow: var(--card-shadow-hover);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
}

.card-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary-color);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
    text-decoration: none;
    text-align: center;
}

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

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-dark);
    transform: translateY(-1px);
}

.btn-success {
    background-color: var(--success-color);
    color: white;
}

.btn-success:hover:not(:disabled) {
    background-color: #218838;
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background-color: #c82333;
}

.btn-secondary {
    background-color: #6c757d;
    color: white;
}

.btn-warning {
    background-color: var(--warning-color);
    color: #000;
}

.btn-warning:hover:not(:disabled) {
    background-color: #e0a800;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-color);
}

.form-control {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.3s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(54, 96, 146, 0.1);
}

textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

/* Tables */
.table-container {
    overflow-x: auto;
    margin: 1rem 0;
}

.table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--card-shadow);
}

.table th,
.table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.table th {
    background-color: var(--primary-color);
    color: white;
    font-weight: 600;
}

.table tbody tr:hover {
    background-color: var(--bg-color);
}

.table tbody tr:last-child td {
    border-bottom: none;
}

/* Over-limit section tweaks */
#over-limit-section .form-group {
    margin-bottom: 1rem;
}

#over-limit-section .table td,
#over-limit-section .table th {
    vertical-align: top;
}

@media (max-width: 768px) {
    #over-limit-section .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.375rem 0.75rem;
    border-radius: 12px;
    font-size: 0.875rem;
    font-weight: 500;
}

/* Status badges - lowercase */
.badge-pending {
    background-color: #ffc107;
    color: #000;
    font-weight: 500;
}

.badge-sent {
    background-color: #28a745;
    color: white;
    font-weight: 500;
}

.badge-failed {
    background-color: #dc3545;
    color: white;
    font-weight: 500;
}

.badge-complete {
    background-color: #17a2b8;
    color: white;
    font-weight: 500;
}

/* Status badges - uppercase (for API responses) */
.badge-PENDING {
    background-color: #ffc107;
    color: #000;
    font-weight: 500;
}

.badge-SENT {
    background-color: #28a745;
    color: white;
    font-weight: 500;
}

.badge-FAILED {
    background-color: #dc3545;
    color: white;
    font-weight: 500;
}

.badge-COMPLETE {
    background-color: #20c997;
    color: white;
    font-weight: 500;
}

.badge-cancel {
    background-color: #6c757d;
    color: white;
    font-weight: 500;
}

.badge-CANCEL {
    background-color: #6c757d;
    color: white;
    font-weight: 500;
}

/* Status Summary */
.status-summary {
    display: flex;
    gap: 0.5rem;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: stretch;
    margin-bottom: 2rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.5rem 0;
}

.status-summary::-webkit-scrollbar {
    height: 4px;
}

.status-summary::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.status-summary::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 4px;
}

.status-card {
    background: white;
    padding: 0.75rem 0.5rem;
    border-radius: 6px;
    box-shadow: var(--card-shadow);
    text-align: center;
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: all 0.3s ease;
}

.status-card[onclick]:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    background-color: #f0f4f9;
    border: 2px solid var(--primary-color);
}

.status-card h3 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    color: var(--primary-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

.status-card p {
    color: #6c757d;
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    margin: 0;
}

/* Status Tabs */
.status-tabs-container {
    background: white;
    padding: 0.75rem;
    border-radius: 8px;
    box-shadow: var(--card-shadow);
    margin-bottom: 1.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

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

.status-tabs-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.status-tabs-container::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 4px;
}

.status-tabs {
    display: flex;
    gap: 0.4rem;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: center;
    min-width: 100%;
}

.status-tab {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    background: white;
    color: var(--text-color);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    flex: 1;
    min-width: 0;
    justify-content: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-tab:hover {
    border-color: var(--primary-color);
    background-color: #f0f4f9;
    transform: translateY(-2px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.status-tab.active {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
    box-shadow: 0 4px 8px rgba(54, 96, 146, 0.3);
}

.status-tab.active:hover {
    background-color: var(--primary-dark);
    border-color: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(54, 96, 146, 0.4);
}

.status-tab-label {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 1;
}

.status-tab-count {
    background-color: rgba(255, 255, 255, 0.2);
    color: inherit;
    padding: 0.2rem 0.4rem;
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: 600;
    min-width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.status-tab.active .status-tab-count {
    background-color: rgba(255, 255, 255, 0.3);
}

.status-tab:not(.active) .status-tab-count {
    background-color: var(--bg-color);
    color: var(--text-color);
}

/* Alerts */
.alert {
    padding: 1rem 1.5rem;
    padding-right: 2.5rem; /* Space for close button */
    border-radius: 6px;
    margin-bottom: 1rem;
    border-left: 4px solid;
    position: relative;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.alert-success {
    background-color: #d4edda;
    border-color: var(--success-color);
    color: #155724;
}

.alert-danger {
    background-color: #f8d7da;
    border-color: var(--danger-color);
    color: #721c24;
}

.alert-info {
    background-color: #d1ecf1;
    border-color: #17a2b8;
    color: #0c5460;
}

.alert-warning {
    background-color: #fff3cd;
    border-color: var(--warning-color);
    color: #856404;
}

/* Loading Spinner */
.spinner {
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 2rem auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin-top: 2rem;
    flex-wrap: wrap;
    padding: 1rem;
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.pagination-btn {
    padding: 0.6rem 1.2rem;
    border: 2px solid #366092;
    background: #ffffff;
    color: #366092;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
    font-size: 0.95rem;
    min-width: 44px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.pagination-btn:hover:not(:disabled) {
    background-color: #366092;
    color: #ffffff;
    border-color: #366092;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(54, 96, 146, 0.3);
}

.pagination-btn.active {
    background-color: #366092;
    color: #ffffff;
    border-color: #366092;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(54, 96, 146, 0.4);
}

.pagination-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background-color: #f5f5f5;
    border-color: #dee2e6;
    color: #6c757d;
}

.pagination-btn-last {
    background-color: #28a745;
    border-color: #28a745;
    color: #ffffff;
    font-weight: 600;
}

.pagination-btn-last:hover:not(:disabled) {
    background-color: #218838;
    border-color: #218838;
    box-shadow: 0 4px 8px rgba(40, 167, 69, 0.3);
}

.pagination-btn-go {
    background-color: #17a2b8;
    border-color: #17a2b8;
    color: #ffffff;
    padding: 0.6rem 1.5rem;
}

.pagination-btn-go:hover:not(:disabled) {
    background-color: #138496;
    border-color: #138496;
    box-shadow: 0 4px 8px rgba(23, 162, 184, 0.3);
}

.pagination-ellipsis {
    padding: 0.6rem 0.5rem;
    color: #6c757d;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    height: 40px;
}

.pagination-input-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: 1rem;
    padding-left: 1rem;
    border-left: 2px solid #dee2e6;
}

.pagination-input-label {
    color: #495057;
    font-weight: 500;
    font-size: 0.9rem;
    white-space: nowrap;
}

.pagination-input {
    width: 70px;
    padding: 0.5rem;
    border: 2px solid #366092;
    border-radius: 6px;
    text-align: center;
    font-size: 0.95rem;
    font-weight: 500;
    color: #366092;
    transition: all 0.3s ease;
}

.pagination-input:focus {
    outline: none;
    border-color: #366092;
    box-shadow: 0 0 0 3px rgba(54, 96, 146, 0.1);
    background-color: #f8f9ff;
}

.pagination-total {
    color: #6c757d;
    font-size: 0.85rem;
    white-space: nowrap;
}

/* Responsive Pagination */
@media (max-width: 768px) {
    .pagination {
        flex-direction: column;
        gap: 0.75rem;
        padding: 1rem 0.5rem;
    }
    
    .pagination-input-group {
        margin-left: 0;
        padding-left: 0;
        border-left: none;
        border-top: 2px solid #dee2e6;
        padding-top: 0.75rem;
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .pagination-btn {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
        min-width: 40px;
        height: 38px;
    }
    
    .pagination-btn-last {
        width: 100%;
        margin-top: 0.5rem;
    }
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #6c757d;
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* Hidden */
.hidden {
    display: none !important;
}

/* Danger Button Styles */
.btn-danger {
    background-color: #dc3545;
    color: white;
    border: none;
}

.btn-danger:hover:not(:disabled) {
    background-color: #c82333;
}

.btn-danger:disabled {
    background-color: #6c757d;
    opacity: 0.6;
    cursor: not-allowed;
}

/* Product Checkbox Styles */
.product-checkbox-label {
    user-select: none;
    display: flex;
    align-items: flex-start;
    width: 100%;
    min-height: 44px; /* Minimum touch target size */
}

.product-checkbox-label:hover {
    background-color: #e9ecef !important;
}

.product-checkbox-label input[type="checkbox"] {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    margin-top: 0.125rem;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.product-checkbox-label input[type="checkbox"]:checked {
    accent-color: var(--primary-color);
}

.product-checkbox-label input[type="checkbox"]:checked ~ span {
    font-weight: 600;
    color: var(--primary-color);
}

.product-checkbox-label span {
    flex: 1;
    word-break: break-word;
    overflow-wrap: break-word;
    white-space: normal;
    line-height: 1.5;
    display: block;
}

/* Selected state */
.product-checkbox-label input[type="checkbox"]:checked ~ span::before {
    content: '';
    display: inline-block;
    margin-right: 0.25rem;
}

/* Pre-order styles */
.preorder-checkbox {
    accent-color: #ffc107;
}

.preorder-date-input {
    font-family: inherit;
}

.preorder-date-input:focus {
    outline: none;
    border-color: #ffc107;
    box-shadow: 0 0 0 0.2rem rgba(255, 193, 7, 0.25);
}

/* Flatpickr Thai calendar styles */
.flatpickr-calendar {
    font-family: inherit;
}

.flatpickr-months .flatpickr-month {
    background: #ffc107;
    color: #000;
    font-weight: 600;
}

.flatpickr-weekdays {
    background: #ffc107;
}

.flatpickr-weekday {
    color: #000;
    font-weight: 600;
}

.flatpickr-day.selected,
.flatpickr-day.startRange,
.flatpickr-day.endRange {
    background: #ffc107;
    border-color: #ffc107;
    color: #000;
}

.flatpickr-day.selected:hover,
.flatpickr-day.startRange:hover,
.flatpickr-day.endRange:hover {
    background: #ffb300;
    border-color: #ffb300;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .container {
        padding: 0.5rem;
    }
    
    .header h1 {
        font-size: 1.5rem;
    }
    
    .card {
        padding: 1rem;
    }
    
    /* Product checkbox responsive */
    .product-checkbox-label {
        flex-wrap: wrap;
    }
    
    .product-checkbox-label > div:last-child {
        width: 100%;
        margin-top: 0.5rem;
        margin-left: 0 !important;
        align-items: flex-start !important;
    }
    
    .preorder-date-input {
        min-width: 100% !important;
    }
    
    .card-title {
        font-size: 1.25rem;
    }
    
    .btn-group {
        flex-direction: column;
    }
    
    .btn-group .btn {
        width: 100%;
    }
    
    .table {
        font-size: 0.875rem;
    }
    
    .table th,
    .table td {
        padding: 0.5rem;
    }
    
    .status-summary {
        flex-direction: row;
        gap: 0.3rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 0.5rem 0;
    }
    
    .status-card {
        flex: 0 0 auto;
        min-width: 90px;
        padding: 0.5rem 0.3rem;
    }
    
    .status-card h3 {
        font-size: 0.95rem;
    }
    
    .status-card p {
        font-size: 0.7rem;
    }
    
    .nav-tabs {
        flex-direction: column;
    }
    
    .nav-tab {
        width: 100%;
    }
    
    .status-tabs {
        flex-direction: row;
        gap: 0.3rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .status-tab {
        flex: 0 0 auto;
        min-width: 100px;
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
    }
    
    .status-tab-label {
        font-size: 0.75rem;
    }
    
    .status-tab-count {
        font-size: 0.75rem;
        padding: 0.15rem 0.3rem;
        min-width: 20px;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 1.25rem;
    }
    
    .btn {
        padding: 0.625rem 1rem;
        font-size: 0.875rem;
    }
}

/* Utility Classes */
.text-center {
    text-align: center;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

