:root {
    /* Premium Color Palette */
    --primary-color: #1e3a8a; /* Deep blue */
    --primary-hover: #1e40af;
    --accent-color: #2563eb;
    --bg-color: #f1f5f9; /* Slate background softer */
    --sidebar-bg: #0f172a; /* Very dark slate for sidebar */
    --card-bg: rgba(255, 255, 255, 0.85); /* For glassmorphism */
    --text-main: #334155;
    --text-muted: #64748b;
    --border-color: rgba(226, 232, 240, 0.8);
    
    /* Semantic Colors */
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --success: #10b981;
    --success-light: #ecfdf5;
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    --info: #3b82f6;
    --info-light: #eff6ff;
    
    /* Shadows & Transitions */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --transition-fast: 0.15s ease-in-out;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body, input, select, textarea, button {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: var(--bg-color);
    background-image: radial-gradient(circle at 85% 10%, #ffffff 0%, transparent 50%), radial-gradient(circle at 10% 90%, #f8fafc 0%, transparent 40%);
    background-attachment: fixed;
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    animation: fadeIn 0.5s ease-out;
}

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

/* Typography and Links */
a { color: var(--accent-color); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--primary-hover); text-decoration: none; }
h1, h2, h3, h4 { color: #0f172a; font-weight: 600; margin-bottom: 1rem; letter-spacing: -0.025em; }

/* ==========================================================================
   APP LAYOUT (SIDEBAR + MAIN)
   ========================================================================== */
.app-wrapper {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 76px;
    background-color: var(--sidebar-bg);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 50;
    box-shadow: var(--shadow-lg);
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-x: hidden;
    white-space: nowrap;
}

.sidebar:hover {
    width: 260px;
}

.sidebar-header {
    height: 70px;
    display: flex;
    align-items: center;
    padding: 0 20px;
    background-color: rgba(0,0,0,0.1);
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.logo-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--accent-color), var(--primary-color));
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 1.25rem;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    flex-shrink: 0;
}

.sidebar-header span {
    font-size: 1.125rem;
    font-weight: 700;
    color: white;
    letter-spacing: -0.025em;
    opacity: 0;
    transition: opacity 0.2s;
}

.sidebar:hover .sidebar-header span {
    opacity: 1;
}

.sidebar-nav {
    padding: 1.5rem 0.75rem;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.nav-section {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #64748b;
    margin: 1rem 0 0.5rem 0.5rem;
    font-weight: 600;
    opacity: 0;
    transition: opacity 0.2s;
}

.sidebar:hover .nav-section {
    opacity: 1;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    color: #94a3b8;
    border-radius: 8px;
    transition: all var(--transition-fast);
    font-size: 0.95rem;
    font-weight: 500;
}

.sidebar-nav a svg {
    width: 20px;
    height: 20px;
    margin-right: 1.25rem;
    color: #64748b;
    transition: color var(--transition-fast);
    flex-shrink: 0;
}

.sidebar-nav a span {
    opacity: 0;
    transition: opacity 0.2s;
}

.sidebar:hover .sidebar-nav a span {
    opacity: 1;
}

.sidebar-nav a:hover {
    background-color: rgba(255,255,255,0.05);
    color: white;
}

.sidebar-nav a:hover svg {
    color: white;
}

.sidebar-nav a.active {
    background-color: var(--accent-color);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.4);
}

.sidebar-nav a.active svg {
    color: white;
}

.sidebar-footer {
    padding: 1.5rem 20px;
    border-top: 1px solid rgba(255,255,255,0.05);
    background-color: rgba(0,0,0,0.15);
}

.user-info {
    display: flex;
    align-items: center;
}

.user-info .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: #334155;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 1.25rem;
    border: 2px solid #475569;
    flex-shrink: 0;
}

.user-info .details {
    display: flex;
    flex-direction: column;
    opacity: 0;
    transition: opacity 0.2s;
}

.sidebar:hover .user-info .details {
    opacity: 1;
}

.user-info .name {
    font-size: 0.875rem;
    font-weight: 600;
    color: white;
}

.user-info .role {
    font-size: 0.75rem;
    color: #94a3b8;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* .top-header removed */

.header-search {
    display: flex;
    align-items: center;
    background-color: var(--bg-color);
    border-radius: 20px;
    padding: 0.4rem 1rem;
    width: 300px;
    border: 1px solid var(--border-color);
    transition: all var(--transition-fast);
}

.header-search:focus-within {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    background-color: white;
}

.search-input {
    border: none;
    background: transparent;
    outline: none;
    padding-left: 0.5rem;
    font-size: 0.875rem;
    width: 100%;
}

.header-actions {
    display: flex;
    gap: 1rem;
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.btn-icon:hover {
    background-color: var(--bg-color);
    color: var(--primary-color);
}

.container {
    padding: 2.5rem;
    flex: 1;
    overflow-y: auto;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
}

/* ==========================================================================
   CARDS & CONTAINERS
   ========================================================================== */
.card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 16px;
    box-shadow: 0 4px 24px -4px rgba(0, 0, 0, 0.05);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid rgba(255, 255, 255, 0.6);
    transition: box-shadow var(--transition-fast);
}
.card:hover {
    box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.06);
}
.card-header { 
    display: flex; justify-content: space-between; align-items: center; 
    margin-bottom: 1.5rem; border-bottom: 1px solid var(--border-color); padding-bottom: 1rem; 
}
.card-header h2 { margin: 0; font-size: 1.25rem; }

/* ==========================================================================
   DASHBOARD METRICS & CHARTS
   ========================================================================== */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.metric-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
}

.metric-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.metric-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-muted);
}

.metric-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.metric-icon.blue { background-color: var(--info-light); color: var(--info); }
.metric-icon.purple { background-color: #f3e8ff; color: #9333ea; }

.metric-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1;
    margin-bottom: 1rem;
}

.metric-footer {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

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

/* ==========================================================================
   ALERTS
   ========================================================================== */
.alerts-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.alert {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-radius: 8px;
    font-size: 0.9rem;
    border-left: 4px solid;
}

.alert-warning {
    background-color: var(--warning-light);
    color: #92400e;
    border-color: var(--warning);
}

.alert-danger {
    background-color: var(--danger-light);
    color: #991b1b;
    border-color: var(--danger);
}

.alert-info {
    background-color: var(--info-light);
    color: #1e40af;
    border-color: var(--info);
}

.alert i { margin-top: 0.1rem; }

/* ==========================================================================
   BUTTONS
   ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    border: none;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    line-height: 1.5;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(0); }
.btn-primary { 
    background: linear-gradient(135deg, var(--accent-color), var(--primary-hover)); 
    color: white; 
    box-shadow: 0 2px 10px rgba(37, 99, 235, 0.2);
}
.btn-primary:hover { 
    background: linear-gradient(135deg, #1d4ed8, #1e3a8a); 
    color: white; 
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
}
.btn-secondary { background-color: white; color: var(--text-main); border: 1px solid var(--border-color); }
.btn-secondary:hover { background-color: var(--bg-color); color: var(--text-main); border-color: #cbd5e0; }
.btn-danger { background-color: var(--danger); color: white; }
.btn-danger:hover { background-color: #dc2626; color: white; }
.btn-success { background-color: var(--success); color: white; }
.btn-success:hover { background-color: #059669; color: white; }

/* ==========================================================================
   FORMS
   ========================================================================== */
.form-group { margin-bottom: 1.25rem; }
.form-label { display: block; margin-bottom: 0.5rem; font-weight: 500; font-size: 0.875rem; color: #475569; }
.form-control {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: #fff;
    transition: all var(--transition-fast);
    color: var(--text-main);
    font-family: inherit;
}
.form-control:focus { outline: none; border-color: var(--accent-color); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1); }
textarea.form-control { min-height: 100px; resize: vertical; }

.grid-cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }

/* ==========================================================================
   TABLES
   ========================================================================== */
.table-responsive { overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; text-align: left; font-size: 0.875rem; }
.table th, .table td { padding: 0.875rem 1rem; border-bottom: 1px solid var(--border-color); vertical-align: middle; }
.table th { 
    background-color: rgba(248, 250, 252, 0.8); 
    font-weight: 600; 
    color: var(--text-muted); 
    text-transform: uppercase; 
    font-size: 0.75rem; 
    letter-spacing: 0.05em; 
    border-top: 1px solid var(--border-color);
}
.truncate-cell {
    max-width: 250px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.table th:first-child { border-top-left-radius: 8px; border-left: 1px solid var(--border-color); }
.table th:last-child { border-top-right-radius: 8px; border-right: 1px solid var(--border-color); }
.table td:first-child { border-left: 1px solid transparent; }
.table td:last-child { border-right: 1px solid transparent; }
.table tr:hover td { background-color: #f8fafc; }
.table tr:last-child td { border-bottom: none; }
.table tr:last-child td:first-child { border-bottom-left-radius: 8px; }
.table tr:last-child td:last-child { border-bottom-right-radius: 8px; }

/* ==========================================================================
   BADGES
   ========================================================================== */
.badge { 
    padding: 0.25rem 0.6rem; 
    border-radius: 9999px; 
    font-size: 0.75rem; 
    font-weight: 600; 
    display: inline-flex; 
    align-items: center;
    border: 1px solid transparent;
}
.badge-blue { background-color: var(--info-light); color: var(--info); border-color: #bfdbfe; }
.badge-green { background-color: var(--success-light); color: var(--success); border-color: #a7f3d0; }
.badge-yellow { background-color: var(--warning-light); color: #d97706; border-color: #fde68a; }
.badge-red { background-color: var(--danger-light); color: var(--danger); border-color: #fecaca; }
.badge-gray { background-color: #f1f5f9; color: #475569; border-color: #e2e8f0; }

/* ==========================================================================
   TIMELINE / HISTORY
   ========================================================================== */
.history-list { display: flex; flex-direction: column; gap: 1rem; }
.history-item { 
    background: white; 
    padding: 1.25rem; 
    border-radius: 8px; 
    border-left: 4px solid var(--accent-color);
    box-shadow: var(--shadow-sm);
    border-top: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}
.history-meta { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.history-meta strong { color: var(--text-main); }
.history-text { font-size: 0.9rem; white-space: pre-line; color: #334155; }

/* ==========================================================================
   FILTERS BAR
   ========================================================================== */
.filters-bar { 
    display: flex; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; align-items: flex-end; 
    background: var(--card-bg); padding: 1rem; border-radius: 8px; border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}
.filters-bar .form-group { margin-bottom: 0; flex: 1; min-width: 150px; }
.filters-bar .form-label { font-size: 0.75rem; margin-bottom: 0.35rem; color: var(--text-muted); }
.filters-bar .form-control { padding: 0.4rem 0.5rem; font-size: 0.85rem; }
.filters-bar .btn { height: 34px; padding: 0 1rem; }

/* ==========================================================================
   DRAG AND DROP ZONE
   ========================================================================== */
.drag-drop-zone { 
    position: relative; overflow: hidden; transition: all var(--transition-fast); 
    background-color: var(--bg-color); border: 2px dashed #cbd5e0;
}
.drag-drop-zone:hover { border-color: #94a3b8; background-color: #f1f5f9; }
.drag-drop-zone.dragover { background-color: var(--info-light) !important; border-color: var(--info) !important; transform: scale(1.01); }

/* ==========================================================================
   PRINT STYLES
   ========================================================================== */
.print-header { display: none; }

@media print {
    .print-header { display: block !important; width: 100%; max-height: 150px; object-fit: contain; margin-bottom: 2rem; border-bottom: 2px solid var(--border-color); padding-bottom: 1rem; }
    .sidebar, .top-header, .btn, .filters-bar, .no-print { display: none !important; }
    .app-wrapper { height: auto; display: block; }
    .main-content { overflow: visible; }
    body { background-color: white; color: black; }
    .container { margin: 0; padding: 0; max-width: 100%; overflow: visible; }
    .card { box-shadow: none; border: 1px solid #ccc; padding: 1rem; margin-bottom: 2rem; break-inside: avoid; }
    .card-header { border-bottom: 2px solid black; }
    .table th { background-color: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .badge { border: 1px solid #ccc; background: transparent !important; color: black !important; }
}

/* ==========================================================================
   RESPONSIVE DESIGN (MOBILE & TABLET)
   ========================================================================== */
@media (max-width: 1024px) {
    .charts-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .app-wrapper { flex-direction: column; }
    
    /* Transform Sidebar into a Bottom/Top Navigation */
    .sidebar { 
        width: 100%; 
        height: auto; 
        flex-direction: row; 
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1); 
        order: 3; /* Move to bottom */
    }
    .sidebar:hover { width: 100%; }
    
    .sidebar-header { display: none; }
    .sidebar-footer { display: none; }
    .nav-section { display: none; }
    
    .sidebar-nav { 
        flex-direction: row; 
        padding: 0.5rem; 
        justify-content: space-around; 
        align-items: center; 
        width: 100%;
        overflow: hidden;
    }
    
    .sidebar-nav a { padding: 0.5rem; flex-direction: column; justify-content: center; gap: 0.25rem; font-size: 0.7rem; }
    .sidebar-nav a svg { margin-right: 0; width: 22px; height: 22px; }
    
    /* Always show text on mobile nav, but smaller */
    .sidebar-nav a span { opacity: 1; display: block; }
    .sidebar:hover .sidebar-nav a span { opacity: 1; }

    /* Main content adjustments */
    .top-header { padding: 0 1rem; height: 60px; }
    .header-search { width: 100%; margin-right: 0.5rem; }
    
    .container { padding: 1rem; }
    .grid-cols-2 { grid-template-columns: 1fr; }
    
    .filters-bar { flex-direction: column; align-items: stretch; gap: 0.75rem; }
    .filters-bar .form-group { width: 100%; }
    .filters-bar .btn { width: 100%; justify-content: center; }
    
    .card { padding: 1.25rem; }
    .metrics-grid { grid-template-columns: 1fr; }
}
