/* Import Plus Jakarta Sans and Sarabun (for Thai text) fonts */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=Sarabun:wght@300;400;500;600;700&display=swap');

:root {
    /* HSL Color System - Premium Light Theme */
    --bg-base: 220 33% 97%;      /* Light blue-gray #f1f5f9 */
    --bg-surface: 0 0% 100%;     /* Pure White for sidebar/headers #ffffff */
    --bg-card: 0 0% 100%;        /* Pure White for panels/cards #ffffff */
    --border-color: 220 20% 88%; /* Soft slate gray border #e2e8f0 */
    
    --primary: 250 85% 55%;      /* Vibrant Royal Purple/Indigo */
    --primary-glow: 250 85% 55% / 0.08;
    --secondary: 190 90% 40%;    /* Vibrant Teal/Cyan */
    
    --success: 142 72% 29%;      /* Clean Green */
    --warning: 38 92% 38%;       /* Clean Amber/Orange */
    --danger: 0 84% 50%;         /* Coral/Red */
    --info: 214 90% 45%;         /* Soft Corporate Blue */
    
    --txt-main: 222 47% 11%;     /* Deep Slate for high legibility #0f172a */
    --txt-muted: 215 16% 47%;    /* Neutral Slate for secondary text #64748b */
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 1px 2px 0 rgba(0, 0, 0, 0.03);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.04), 0 4px 6px -2px rgba(0, 0, 0, 0.02);
    
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: hsl(var(--bg-base));
    color: hsl(var(--txt-main));
    font-family: 'Plus Jakarta Sans', 'Sarabun', -apple-system, sans-serif;
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
}

/* App Layout */
.app-container {
    display: flex;
    width: 100%;
    min-height: 100vh;
}

/* Sidebar Navigation */
.sidebar {
    width: 280px;
    background-color: hsl(var(--bg-surface));
    border-right: 1px solid hsl(var(--border-color));
    display: flex;
    flex-direction: column;
    padding: 2rem 1.5rem;
    position: fixed;
    height: 100vh;
    z-index: 100;
    transition: var(--transition);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 3rem;
    padding: 0 0.5rem;
}

.brand-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, hsl(var(--primary)), hsl(var(--secondary)));
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: hsl(var(--bg-base));
    font-weight: 800;
    box-shadow: 0 0 20px hsl(var(--primary) / 0.4);
}

.brand-name {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(to right, hsl(var(--txt-main)), hsl(var(--txt-muted)));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-menu {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
}

.nav-item a {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1rem;
    color: hsl(var(--txt-muted));
    text-decoration: none;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 0.95rem;
    transition: var(--transition);
}

.nav-item a:hover,
.nav-item.active a {
    color: hsl(var(--txt-main));
    background-color: hsl(var(--bg-card));
    box-shadow: inset 0 0 0 1px hsl(var(--border-color));
}

.nav-item.active a {
    background: linear-gradient(135deg, hsl(var(--bg-card)), hsl(var(--primary-glow)));
    box-shadow: inset 0 0 0 1px hsl(var(--primary) / 0.3);
    border-left: 3px solid hsl(var(--primary));
}

.nav-item a i {
    font-size: 1.2rem;
    color: hsl(var(--txt-muted));
    transition: var(--transition);
}

.nav-item a:hover i,
.nav-item.active a i {
    color: hsl(var(--primary));
    transform: scale(1.05);
}

.sidebar-footer {
    padding-top: 1rem;
    border-top: 1px solid hsl(var(--border-color));
    font-size: 0.8rem;
    color: hsl(var(--txt-muted));
    text-align: center;
}

/* Main Content Area */
.main-content {
    margin-left: 280px;
    flex: 1;
    padding: 2rem 3rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header & Breadcrumb */
.header-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
}

.page-title h1 {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    margin-bottom: 0.25rem;
}

.page-title p {
    color: hsl(var(--txt-muted));
    font-size: 0.9rem;
}

/* Stats Cards Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.stat-card {
    background-color: hsl(var(--bg-card));
    border: 1px solid hsl(var(--border-color));
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background-color: var(--card-accent, hsl(var(--primary)));
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
    border-color: hsl(var(--primary) / 0.3);
}

.stat-icon {
    width: 48px;
    height: 48px;
    background-color: hsl(var(--bg-surface));
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--card-accent, hsl(var(--primary)));
    box-shadow: inset 0 0 0 1px hsl(var(--border-color));
}

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

.stat-value {
    font-size: 1.75rem;
    font-weight: 800;
    line-height: 1.1;
    margin-bottom: 0.15rem;
}

.stat-label {
    font-size: 0.85rem;
    color: hsl(var(--txt-muted));
    font-weight: 500;
}

/* Glassmorphic Panel Layouts */
.panel {
    background-color: hsl(var(--bg-card) / 0.7);
    backdrop-filter: blur(12px);
    border: 1px solid hsl(var(--border-color));
    border-radius: var(--radius-lg);
    padding: 1.75rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-md);
}

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

.panel-title {
    font-size: 1.15rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Charts Panel Grid */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

@media (max-width: 992px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
}

.chart-container {
    position: relative;
    height: 280px;
    width: 100%;
}

/* Action Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.65rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: var(--transition);
}

.btn-primary {
    background: linear-gradient(135deg, hsl(var(--primary)), hsl(var(--secondary)));
    color: hsl(var(--bg-base));
    box-shadow: 0 4px 12px hsl(var(--primary) / 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px hsl(var(--primary) / 0.45);
}

.btn-secondary {
    background-color: hsl(var(--bg-surface));
    color: hsl(var(--txt-main));
    box-shadow: inset 0 0 0 1px hsl(var(--border-color));
}

.btn-secondary:hover {
    background-color: hsl(var(--bg-card));
    box-shadow: inset 0 0 0 1px hsl(var(--txt-muted) / 0.5);
}

.btn-success {
    background-color: hsl(var(--success));
    color: #fff;
    box-shadow: 0 4px 12px hsl(var(--success) / 0.2);
}

.btn-success:hover {
    opacity: 0.95;
    transform: translateY(-1px);
}

.btn-danger {
    background-color: hsl(var(--danger));
    color: #fff;
}

.btn-danger:hover {
    opacity: 0.95;
}

.btn-sm {
    padding: 0.4rem 0.85rem;
    font-size: 0.8rem;
    border-radius: var(--radius-sm);
}

.btn-icon-only {
    padding: 0.5rem;
    border-radius: var(--radius-sm);
}

/* Custom Table Design */
.table-responsive {
    overflow-x: auto;
    width: 100%;
}

.custom-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.9rem;
}

.custom-table th {
    padding: 1rem 1.25rem;
    background-color: hsl(var(--bg-surface) / 0.6);
    color: hsl(var(--txt-muted));
    font-weight: 600;
    border-bottom: 1px solid hsl(var(--border-color));
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
}

.custom-table td {
    padding: 1.15rem 1.25rem;
    border-bottom: 1px solid hsl(var(--border-color));
    color: hsl(var(--txt-main));
    vertical-align: middle;
}

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

.custom-table tr {
    transition: var(--transition);
}

.custom-table tbody tr:hover {
    background-color: hsl(var(--bg-surface) / 0.3);
}

/* Status & Priority Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.65rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 50px;
    text-transform: uppercase;
}

/* Task Status Badges */
.badge-pending {
    background-color: hsl(var(--info) / 0.15);
    color: hsl(var(--info));
    border: 1px solid hsl(var(--info) / 0.3);
}
.badge-in_progress {
    background-color: hsl(var(--warning) / 0.15);
    color: hsl(var(--warning));
    border: 1px solid hsl(var(--warning) / 0.3);
}
.badge-completed {
    background-color: hsl(var(--success) / 0.15);
    color: hsl(var(--success));
    border: 1px solid hsl(var(--success) / 0.3);
}
.badge-cancelled {
    background-color: hsl(var(--txt-muted) / 0.15);
    color: hsl(var(--txt-muted));
    border: 1px solid hsl(var(--txt-muted) / 0.3);
}

/* Priority & Severity Badges */
.badge-low {
    background-color: hsl(var(--info) / 0.15);
    color: hsl(var(--info));
}
.badge-medium {
    background-color: hsl(var(--success) / 0.15);
    color: hsl(var(--success));
}
.badge-high {
    background-color: hsl(var(--warning) / 0.15);
    color: hsl(var(--warning));
    box-shadow: 0 0 10px hsl(var(--warning) / 0.1);
}
.badge-critical,
.badge-urgent {
    background-color: hsl(var(--danger) / 0.15);
    color: hsl(var(--danger));
    box-shadow: 0 0 12px hsl(var(--danger) / 0.25);
    animation: pulse 2s infinite;
}

/* Animations */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.02); }
    100% { transform: scale(1); }
}

/* Filter Controls */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    margin-bottom: 2rem;
    background-color: hsl(var(--bg-card));
    padding: 1.25rem;
    border-radius: var(--radius-md);
    border: 1px solid hsl(var(--border-color));
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    flex: 1;
    min-width: 150px;
}

.filter-group label {
    font-size: 0.75rem;
    color: hsl(var(--txt-muted));
    font-weight: 600;
    text-transform: uppercase;
}

/* Premium Form Elements */
.form-control,
.form-select {
    width: 100%;
    padding: 0.65rem 0.85rem;
    background-color: hsl(var(--bg-surface));
    border: 1px solid hsl(var(--border-color));
    border-radius: var(--radius-md);
    color: hsl(var(--txt-main));
    font-size: 0.9rem;
    font-family: inherit;
    transition: var(--transition);
}

.form-control:focus,
.form-select:focus {
    outline: none;
    border-color: hsl(var(--primary));
    box-shadow: 0 0 0 3px hsl(var(--primary-glow));
}

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

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 2rem;
    padding-top: 1.25rem;
    border-top: 1px solid hsl(var(--border-color));
}

/* Alert Notification Banner */
.alert {
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-left: 4px solid;
    animation: slideDown 0.3s ease-out;
}

.alert-success {
    background-color: hsl(var(--success) / 0.1);
    border-color: hsl(var(--success));
    color: hsl(var(--success));
}

.alert-danger, .alert-error {
    background-color: hsl(var(--danger) / 0.1);
    border-color: hsl(var(--danger));
    color: hsl(var(--danger));
}

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

/* Error Incident Cards (Alternative to table) */
.incident-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.5rem;
}

.incident-card {
    background-color: hsl(var(--bg-card));
    border: 1px solid hsl(var(--border-color));
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    position: relative;
}

.incident-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: hsl(var(--primary) / 0.25);
}

.incident-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
}

.incident-title {
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.4;
}

.incident-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    font-size: 0.8rem;
    color: hsl(var(--txt-muted));
    border-bottom: 1px dashed hsl(var(--border-color));
    padding-bottom: 0.75rem;
}

.incident-body {
    font-size: 0.85rem;
    color: hsl(var(--txt-main) / 0.9);
    line-height: 1.5;
}

.incident-rca {
    background-color: hsl(var(--bg-surface) / 0.4);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    font-size: 0.8rem;
    border-left: 3px solid hsl(var(--warning));
}

.incident-ca {
    background-color: hsl(var(--bg-surface) / 0.4);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    font-size: 0.8rem;
    border-left: 3px solid hsl(var(--success));
    margin-top: 0.5rem;
}

.section-label {
    font-weight: 700;
    color: hsl(var(--txt-main));
    display: block;
    margin-bottom: 0.2rem;
}

.incident-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: auto;
    padding-top: 0.75rem;
    border-top: 1px solid hsl(var(--border-color) / 0.5);
}

/* Responsive Mobile Rules */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 250px;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
        padding: 1.5rem 1.5rem;
    }
    
    .header-wrapper {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }
}

/* Premium Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(15, 23, 42, 0.45); /* Slate 900 with transparency */
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-card {
    background-color: hsl(var(--bg-card));
    border: 1px solid hsl(var(--border-color));
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 550px;
    padding: 2rem;
    box-shadow: var(--shadow-lg);
    transform: scale(0.92) translateY(20px);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.open .modal-card {
    transform: scale(1) translateY(0);
}

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

.modal-title {
    font-size: 1.2rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: hsl(var(--primary));
}

.modal-close {
    background: none;
    border: none;
    cursor: pointer;
    color: hsl(var(--txt-muted));
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.modal-close:hover {
    background-color: hsl(var(--bg-base));
    color: hsl(var(--danger));
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.75rem;
    padding-top: 1rem;
    border-top: 1px solid hsl(var(--border-color));
}
