/* Optimized and consolidated CSS */
@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@400;700&display=swap');

/* === Base Styles === */
* {
    box-sizing: border-box;
}

body {
    font-family: 'Sarabun', sans-serif;
    font-size: 16px;
    background-color: #f4f7f6;
    color: #333;
    margin: 0;
    line-height: 1.5;
}

h1, h2, h3 {
    color: #004a99;
    margin-top: 0;
}

/* === Navigation === */
nav.main-nav {
    display: flex;
    background-color: #004a99;
    padding: 0 20px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

nav.main-nav a {
    color: white;
    padding: 14px 16px;
    text-decoration: none;
    font-weight: bold;
    font-size: 16px;
    border-bottom: 3px solid transparent;
    transition: background-color 0.2s, border-bottom 0.2s;
}

nav.main-nav a:hover {
    background-color: #0056b3;
}

nav.main-nav a.active {
    border-bottom: 3px solid #66bfff;
}

/* === Layout === */
.page-container {
    padding: 20px;
    max-width: 1200px;
    margin: 20px auto;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.content-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

@media (min-width: 1024px) {
    .content-grid {
        grid-template-columns: 2fr 1fr;
    }
}

/* === Cards === */
.card, .sidebar {
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.sidebar {
    background-color: #f8f9fa;
    align-self: start;
}

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

.stat-card {
    background-color: #fff;
    padding: 20px 20px 15px;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    border-left: 6px solid #007bff;
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
}

.stat-card.pending { border-left-color: #ffc107; }
.stat-card.confirmed { border-left-color: #28a745; }
.stat-card.total { border-left-color: #007bff; }
.stat-card.max-dose { border-left-color: #ffc107; }
.stat-card.avg-time { border-left-color: #dc3545; }

.stat-card h3 {
    margin: 0 0 10px;
    color: #777;
    font-size: 0.9rem;
    font-weight: 500;
}

.stat-card .value {
    font-size: 2.8rem;
    font-weight: 800;
    color: #004a99;
    line-height: 1.2;
    margin-bottom: 5px;
}

.stat-card.pending .value { color: #cc8400; }
.stat-card.confirmed .value { color: #218838; }

/* === Buttons === */
.btn, button[type="submit"], .controls-bar button {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-primary, .controls-bar button {
    background-color: #007bff;
    color: white;
}

.btn-primary:hover, .controls-bar button:hover {
    background-color: #0056b3;
}

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

.btn-secondary:hover {
    background-color: #5a6268;
}

.btn-success {
    background-color: #28a745;
    color: white;
}

.btn-success:hover {
    background-color: #218838;
}

.btn:disabled, button:disabled {
    background-color: #ccc;
    cursor: not-allowed;
    opacity: 0.6;
}

/* === Tables === */
.data-table, #cases-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    border-radius: 8px;
    overflow: hidden;
}

.data-table th, .data-table td,
#cases-table th, #cases-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid #dee2e6;
}

.data-table th, #cases-table th {
    background-color: #f1f3f5;
    font-weight: 600;
    white-space: nowrap;
    color: #333;
}

.data-table tbody tr:nth-of-type(even),
#cases-table tr:nth-child(even) {
    background-color: #f8f9fa;
}

.data-table tbody tr:hover,
#cases-table tr:hover {
    background-color: #e9ecef;
}

.data-table .hl {
    font-weight: 700;
    color: #d9534f;
}

.status {
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 12px;
}

.status.PENDING {
    background-color: #ffc107;
    color: #333;
}

.status.CONFIRMED {
    background-color: #28a745;
    color: white;
}

/* === Forms === */
.controls-bar, .filter-group {
    padding: 15px 0;
    margin-bottom: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: flex-end;
}

.filter-group {
    flex-direction: column;
    align-items: flex-start;
}

.filter-group label, .controls-bar label {
    font-size: 0.9em;
    font-weight: 600;
    margin-bottom: 5px;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="password"],
select {
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
    width: 100%;
}

/* === Pagination === */
.pagination-controls, #pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 20px;
    gap: 15px;
}

/* === Modals === */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.4);
    padding-top: 60px;
}

.modal-content {
    background-color: #fefefe;
    margin: 5% auto;
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
    max-width: 500px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    position: relative;
}

.modal-close-btn {
    color: #aaa;
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.modal-close-btn:hover {
    color: black;
}

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

.loading {
    color: #6c757d;
    font-style: italic;
    text-align: center;
}

.loading-placeholder {
    text-align: center;
    padding: 40px;
    font-size: 1.2rem;
    color: #777;
}

.highlight, .weight-input {
    font-weight: bold;
    color: #d9534f;
}

/* === Chart Containers === */
.chart-box {
    background-color: #fff;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.chart-box h2 {
    font-size: 1.5rem;
    font-weight: 700;
    border-bottom: 2px solid #007bff;
    padding-bottom: 10px;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.chart-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

@media (min-width: 1024px) {
    .chart-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* === Animations === */
@keyframes blink {
    0%, 100% { background-color: #ffc10740; }
    50% { background-color: #ffffff; }
}

.new-case-alert {
    animation: blink 2s linear 5;
}

/* === Loading States === */
.skeleton-loader {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.skeleton-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
}

.skeleton-item {
    height: 20px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 4px;
}

@keyframes loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.progress-container {
    padding: 20px;
    text-align: center;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background-color: #e0e0e0;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 10px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #0056b3);
    border-radius: 10px;
    transition: width 0.3s ease;
    width: 0%;
}

.progress-text {
    font-size: 0.9rem;
    color: #666;
    margin: 0;
}

.loading {
    opacity: 0.7;
    pointer-events: none;
}

/* === Smooth Transitions === */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.slide-in {
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateX(-20px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* === Print Styles === */
@media print {
    body {
        background-color: #fff;
        padding: 0;
        margin: 0;
    }

    .main-nav, .controls-bar, .btn, button,
    .page-container > h1:first-child {
        display: none !important;
    }

    .page-container {
        box-shadow: none;
        border-radius: 0;
        margin: 0;
        max-width: 100%;
        padding: 0;
    }
}
