/* ==================== VARIABLES ==================== */
:root {
    --bg-primary: #080f1d;
    --bg-secondary: #0e172a;
    --bg-card: rgba(15, 23, 42, 0.65);
    --bg-glass: rgba(255, 255, 255, 0.03);
    --border-glass: rgba(255, 255, 255, 0.07);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-blue: #3b82f6;
    --accent-emerald: #10b981;
    --accent-amber: #f59e0b;
    --accent-rose: #f43f5e;
    --accent-purple: #8b5cf6;
    --accent-cyan: #06b6d4;
    --sidebar-width: 260px;
    --navbar-height: 64px;
    --radius: 12px;
    --radius-sm: 8px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==================== RESET ==================== */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&family=Inter:wght@400;500;600&family=Sarabun:wght@300;400;500;600;700;800&display=swap');

*, *::before, *::after { box-sizing: border-box; }
body {
    font-family: 'Outfit', 'Inter', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    margin: 0;
    min-height: 100vh;
    overflow-x: hidden;
    letter-spacing: -0.01em;
    background-image: 
        radial-gradient(circle at 0% 0%, rgba(59, 130, 246, 0.05) 0%, transparent 40%),
        radial-gradient(circle at 100% 100%, rgba(139, 92, 246, 0.05) 0%, transparent 40%),
        radial-gradient(circle at 50% 50%, rgba(15, 23, 42, 1) 0%, rgba(8, 15, 29, 1) 100%);
    background-attachment: fixed;
}

/* ==================== SCROLLBAR ==================== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-glass); border-radius: 3px; }

/* ==================== NAVBAR ==================== */
.navbar-glass {
    background: rgba(10,22,40,0.85);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-glass);
    height: var(--navbar-height);
    z-index: 1040;
}
.brand-icon {
    width: 36px; height: 36px;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; color: #fff;
}
.brand-text { font-weight: 700; font-size: 1.1rem; color: var(--text-primary); }
.nav-icon-btn {
    width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%; color: var(--text-secondary);
    transition: var(--transition); text-decoration: none;
}
.nav-icon-btn:hover { background: var(--bg-glass); color: var(--accent-blue); }
.notif-badge {
    position: absolute; top: 2px; right: 2px;
    background: var(--accent-rose); color: #fff;
    font-size: 10px; font-weight: 700;
    min-width: 18px; height: 18px;
    border-radius: 9px; display: flex; align-items: center; justify-content: center;
    padding: 0 4px;
}
.user-avatar-btn {
    background: transparent !important; border: none !important;
    color: var(--text-primary) !important;
    display: flex; align-items: center; padding: 4px 8px;
}
.user-avatar-sm {
    width: 32px; height: 32px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700; color: #fff;
}
.dropdown-glass {
    background: rgba(17,29,53,0.95) !important;
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-glass) !important;
    border-radius: var(--radius) !important;
}
.dropdown-glass .dropdown-item { color: var(--text-secondary); transition: var(--transition); }
.dropdown-glass .dropdown-item:hover { background: var(--bg-glass); color: var(--text-primary); }

/* ==================== SIDEBAR ==================== */
.sidebar {
    position: fixed; top: var(--navbar-height); left: 0;
    width: var(--sidebar-width); height: calc(100vh - var(--navbar-height));
    background: rgba(10,22,40,0.6);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-glass);
    z-index: 1030; transition: var(--transition);
    overflow-y: auto;
}
.sidebar-inner { display: flex; flex-direction: column; height: 100%; padding: 16px 12px; }
.sidebar-menu { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.sidebar-link {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 16px; border-radius: var(--radius-sm);
    color: var(--text-secondary); text-decoration: none;
    font-size: 0.9rem; font-weight: 500;
    transition: var(--transition);
}
.sidebar-link i { width: 20px; text-align: center; font-size: 1rem; }
.sidebar-link:hover { background: var(--bg-glass); color: var(--text-primary); transform: translateX(4px); }
.sidebar-link.active {
    background: linear-gradient(135deg, rgba(59,130,246,0.15), rgba(139,92,246,0.1));
    color: var(--accent-blue); border-left: 3px solid var(--accent-blue);
}
.sidebar-footer { padding: 16px 0 8px; border-top: 1px solid var(--border-glass); margin-top: 16px; }

/* ==================== MAIN CONTENT ==================== */
.app-wrapper { display: flex; padding-top: var(--navbar-height); }
.main-content {
    flex: 1; margin-left: var(--sidebar-width);
    padding: 24px; min-height: calc(100vh - var(--navbar-height));
    transition: var(--transition);
    min-width: 0;
}

/* ==================== CARDS ==================== */
.card-glass {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    transition: var(--transition);
}
.card-glass:hover { border-color: rgba(255,255,255,0.12); transform: translateY(-2px); box-shadow: 0 8px 32px rgba(0,0,0,0.3); }

/* KPI Cards */
.kpi-card {
    padding: 24px; position: relative; overflow: hidden;
}
.kpi-card::before {
    content: ''; position: absolute; top: 0; right: 0;
    width: 100px; height: 100px;
    border-radius: 50%; opacity: 0.08;
    transform: translate(30%, -30%);
}
.kpi-card.blue::before { background: var(--accent-blue); }
.kpi-card.emerald::before { background: var(--accent-emerald); }
.kpi-card.amber::before { background: var(--accent-amber); }
.kpi-card.rose::before { background: var(--accent-rose); }
.kpi-card.purple::before { background: var(--accent-purple); }
.kpi-icon {
    width: 48px; height: 48px; border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; color: #fff; margin-bottom: 16px;
}
.kpi-icon.blue { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.kpi-icon.emerald { background: linear-gradient(135deg, #10b981, #059669); }
.kpi-icon.amber { background: linear-gradient(135deg, #f59e0b, #d97706); }
.kpi-icon.rose { background: linear-gradient(135deg, #ef4444, #dc2626); }
.kpi-icon.purple { background: linear-gradient(135deg, #8b5cf6, #7c3aed); }
.kpi-icon.cyan { background: linear-gradient(135deg, #06b6d4, #0891b2); }
.kpi-value { font-size: 2rem; font-weight: 800; line-height: 1; margin-bottom: 4px; }
.kpi-label { font-size: 0.85rem; color: var(--text-secondary); font-weight: 500; }

/* ==================== TABLE ==================== */
.table-glass {
    width: 100%; border-collapse: separate; border-spacing: 0;
    font-size: 0.875rem;
}
.table-glass thead th {
    background: rgba(255,255,255,0.03);
    border-bottom: 1px solid var(--border-glass);
    padding: 12px 16px; font-weight: 600;
    color: var(--text-secondary); font-size: 0.8rem;
    text-transform: uppercase; letter-spacing: 0.05em;
    white-space: nowrap;
}
.table-glass tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    vertical-align: middle;
}
.table-glass tbody tr { transition: var(--transition); }
.table-glass tbody tr:hover { background: rgba(59,130,246,0.08); }
.table-responsive { border-radius: var(--radius); overflow-x: auto; border: 1px solid var(--border-glass); }

/* ==================== DOCUMENT STYLE (SO DETAIL) ==================== */
.doc-paper {
    background: #ffffff !important;
    color: #1e293b !important;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3) !important;
    border: 1px solid #e2e8f0 !important;
    font-family: 'Inter', 'Outfit', sans-serif !important;
    position: relative;
    overflow: hidden;
}

.doc-paper::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 6px;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-purple));
}

.doc-table {
    border: none !important;
    margin-bottom: 0;
}

.doc-table thead th {
    background: #f1f5f9 !important;
    color: #475569 !important;
    text-transform: uppercase;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.05em;
    padding: 12px 8px !important;
    border: none !important;
    border-bottom: 2px solid #e2e8f0 !important;
}

.doc-table tbody td {
    padding: 10px 8px !important;
    border: none !important;
    border-bottom: 1px solid #f1f5f9 !important;
    color: #334155 !important;
    font-size: 12px;
}

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

.doc-header-title {
    color: #0f172a;
    font-weight: 800;
    font-size: 1.25rem;
    margin-bottom: 2px;
}

.doc-label {
    font-size: 10px;
    font-weight: 600;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.doc-value {
    font-size: 13px;
    font-weight: 500;
    color: #1e293b;
}

.doc-footer-label {
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
}

.doc-footer-value {
    font-size: 14px;
    font-weight: 700;
    color: #0f172a;
}

.doc-grand-total {
    background: #f8fafc;
    border-radius: 8px;
    padding: 12px;
    margin-top: 8px;
}

/* ==================== BADGES ==================== */
.badge { font-weight: 600; font-size: 0.75rem; padding: 4px 10px; border-radius: 6px; }
.bg-success-glass { background: rgba(16,185,129,0.15) !important; color: #34d399 !important; }
.bg-danger-glass { background: rgba(239,68,68,0.15) !important; color: #f87171 !important; }
.bg-warning-glass { background: rgba(245,158,11,0.15) !important; color: #fbbf24 !important; }
.bg-info-glass { background: rgba(6,182,212,0.15) !important; color: #22d3ee !important; }
.bg-primary-glass { background: rgba(59,130,246,0.15) !important; color: #60a5fa !important; }
.bg-secondary-glass { background: rgba(148,163,184,0.15) !important; color: #94a3b8 !important; }
.bg-purple-glass { background: rgba(139,92,246,0.15) !important; color: #a78bfa !important; }
.badge-critical { background: rgba(239,68,68,0.15); color: #f87171; }
.badge-warning { background: rgba(245,158,11,0.15); color: #fbbf24; }
.badge-info-custom { background: rgba(16,185,129,0.15); color: #34d399; }
.badge-success { background: rgba(59,130,246,0.15); color: #60a5fa; }

/* ==================== BUTTONS ==================== */
.btn-glass {
    background: var(--bg-glass); border: 1px solid var(--border-glass);
    color: var(--text-primary); border-radius: var(--radius-sm);
    transition: var(--transition);
}
.btn-glass:hover { background: rgba(255,255,255,0.08); color: #fff; }
.btn-glow {
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    border: none; color: #fff; border-radius: var(--radius-sm);
    font-weight: 600; transition: var(--transition);
    box-shadow: 0 4px 16px rgba(59,130,246,0.3);
}
.btn-glow:hover { transform: translateY(-1px); box-shadow: 0 6px 24px rgba(59,130,246,0.4); color: #fff; }

/* ==================== FORMS ==================== */
.form-control-glass, .form-select-glass {
    background: var(--bg-glass) !important;
    border: 1px solid var(--border-glass) !important;
    color: var(--text-primary) !important;
    border-radius: var(--radius-sm) !important;
    transition: var(--transition);
}
.form-control-glass:focus, .form-select-glass:focus {
    border-color: var(--accent-blue) !important;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15) !important;
}
.form-control-glass::placeholder { color: var(--text-muted) !important; }

/* ==================== MODALS ==================== */
.modal-glass .modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
}
.modal-glass .modal-header { border-bottom: 1px solid var(--border-glass); }
.modal-glass .modal-footer { border-top: 1px solid var(--border-glass); }

/* ==================== LOGIN PAGE ==================== */
.login-wrapper {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: var(--bg-primary);
    background-image: radial-gradient(ellipse at 30% 50%, rgba(59,130,246,0.12) 0%, transparent 50%),
                      radial-gradient(ellipse at 70% 30%, rgba(139,92,246,0.1) 0%, transparent 50%);
}
.login-card {
    width: 100%; max-width: 420px;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-glass);
    border-radius: 16px; padding: 40px; margin: 20px;
}
.login-logo {
    width: 64px; height: 64px; border-radius: 16px;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    display: flex; align-items: center; justify-content: center;
    font-size: 28px; color: #fff; margin: 0 auto 24px;
}

/* ==================== PAGE HEADER ==================== */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 24px; flex-wrap: wrap; gap: 16px;
}
.page-title { font-size: 1.5rem; font-weight: 700; margin: 0; }
.page-subtitle { color: var(--text-secondary); font-size: 0.875rem; margin-top: 4px; }

/* ==================== TABS ==================== */
.nav-tabs-glass {
    border-bottom: 1px solid var(--border-glass);
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
}
.nav-tabs-glass::-webkit-scrollbar { display: none; /* Chrome, Safari, Opera */ }
.nav-tabs-glass .nav-link {
    color: var(--text-secondary); border: none; padding: 12px 20px;
    font-weight: 500; transition: var(--transition);
    border-bottom: 2px solid transparent;
    white-space: nowrap;
}
.nav-tabs-glass .nav-link:hover { color: var(--text-primary); border-color: rgba(59,130,246,0.3); }
.nav-tabs-glass .nav-link.active {
    color: var(--accent-blue); background: transparent;
    border-color: var(--accent-blue);
}

/* ==================== NOTIFICATION ITEMS ==================== */
.notif-item {
    padding: 16px 20px; border-bottom: 1px solid var(--border-glass);
    display: flex; align-items: flex-start; gap: 12px; transition: var(--transition);
}
.notif-item:hover { background: var(--bg-glass); }
.notif-item.unread { border-left: 3px solid var(--accent-blue); }
.notif-icon {
    width: 40px; height: 40px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; flex-shrink: 0;
}
.notif-icon.critical { background: rgba(239,68,68,0.15); color: #f87171; }
.notif-icon.warning { background: rgba(245,158,11,0.15); color: #fbbf24; }
.notif-icon.info { background: rgba(16,185,129,0.15); color: #34d399; }

/* ==================== ANIMATIONS ==================== */
@keyframes fadeInUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.animate-in { animation: fadeInUp 0.5s ease forwards; }
.animate-delay-1 { animation-delay: 0.1s; opacity: 0; }
.animate-delay-2 { animation-delay: 0.2s; opacity: 0; }
.animate-delay-3 { animation-delay: 0.3s; opacity: 0; }
.animate-delay-4 { animation-delay: 0.4s; opacity: 0; }
@keyframes pulse-soft { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.6; transform: scale(1.2); } }
.animate-pulse { animation: pulse-soft 2s infinite ease-in-out; }

/* ==================== CUSTOMER DETAIL CARD ==================== */
.customer-info-card {
    background: linear-gradient(135deg, rgba(59,130,246,0.1), rgba(139,92,246,0.05));
    border: 1px solid var(--border-glass);
    border-radius: var(--radius); padding: 24px;
}
.customer-avatar {
    width: 56px; height: 56px; border-radius: var(--radius);
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; font-weight: 700; color: #fff;
}
.info-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 2px; }
.info-value { font-size: 0.9rem; font-weight: 500; }

/* ==================== CHART CONTAINERS ==================== */
.chart-container { position: relative; padding: 20px; }

/* ==================== SEARCH BAR ==================== */
.search-bar {
    position: relative; max-width: 360px;
}
.search-bar .form-control-glass { padding-left: 40px; }
.search-bar .search-icon {
    position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
    color: var(--text-muted); font-size: 14px;
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 991.98px) {
    :root {
        --sidebar-width: 280px;
        --navbar-height: 56px;
    }
    .sidebar { 
        transform: translateX(-100%); 
        box-shadow: 20px 0 50px rgba(0,0,0,0.4);
        border-right: none;
    }
    .sidebar.show { transform: translateX(0); }
    .main-content { margin-left: 0; padding: 12px; }
    .app-wrapper { padding-top: var(--navbar-height); }
    
    .sidebar-overlay {
        position: fixed; top: 0; left: 0; width: 100%; height: 100%;
        background: rgba(8, 15, 29, 0.7); backdrop-filter: blur(8px);
        z-index: 1025; display: none; opacity: 0; transition: opacity 0.3s ease;
    }
    .sidebar-overlay.show { display: block; opacity: 1; }
    
    .navbar-glass { 
        padding: 0 8px; 
        height: var(--navbar-height);
    }
    .brand-text { font-size: 0.95rem; }
    .brand-icon { width: 32px; height: 32px; font-size: 14px; }
    
    .user-avatar-sm { width: 28px; height: 28px; }
}

@media (max-width: 767.98px) {
    .kpi-card { padding: 16px; }
    .kpi-value { font-size: 1.25rem; }
    .kpi-icon { width: 36px; height: 36px; font-size: 16px; margin-bottom: 8px; }
    
    .page-header h1 {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px !important;
    }
    .page-header h1 .btn-glow {
        width: 100%;
        text-align: center;
    }
    
    /* Make tables scrollable and add a hint */
    .table-responsive {
        position: relative;
        border-radius: var(--radius-sm);
    }
    .table-responsive::after {
        content: '← Scroll →';
        position: absolute; bottom: 8px; right: 8px;
        background: rgba(0,0,0,0.5); color: #fff;
        padding: 2px 8px; border-radius: 10px; font-size: 10px;
        pointer-events: none; opacity: 0.6;
    }
}

@media (max-width: 575.98px) {
    .main-content { padding: 10px; }
    .page-title { font-size: 1.1rem; }
    .page-header { margin-bottom: 16px; }
    .card-glass { border-radius: var(--radius-sm); }
    
    /* Document Modal Adjustments */
    .modal-dialog.modal-xl { 
        margin: 0; 
        max-width: 100%; 
        height: 100%; 
    }
    .modal-content { 
        height: 100%; 
        border-radius: 0 !important; 
        border: none !important;
    }
    .modal-body { padding: 0 !important; }
    .doc-paper { 
        padding: 15px !important; 
        max-width: 100% !important; 
        margin: 0 !important;
        border: none !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        min-height: 100vh;
    }
    .doc-header-title { font-size: 1.1rem; }
    
    /* Mobile-First Tables */
    .table-glass thead th { 
        padding: 8px 12px; 
        font-size: 0.7rem; 
    }
    .table-glass tbody td { 
        padding: 8px 12px; 
        font-size: 0.8rem; 
    }
    
    /* Form Stacking */
    .card-glass .row.g-2 > div { 
        margin-bottom: 8px; 
    }
    
    /* Search Bar */
    .search-bar { max-width: 100%; }
}

/* ==================== SIDEBAR TOGGLE ==================== */
.sidebar-toggle {
    color: var(--text-secondary); font-size: 1.2rem;
    padding: 0; border: none;
}

/* ==================== TECHNICAL PROFILE ==================== */
.profile-section-card {
    background: rgba(255,255,255,0.02);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    padding: 20px;
    transition: var(--transition);
}
.profile-section-card:hover {
    background: rgba(255,255,255,0.04);
    border-color: rgba(255,255,255,0.15);
}
.profile-item {
    margin-bottom: 12px;
}
.profile-item:last-child { margin-bottom: 0; }
.profile-item .label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 2px;
}
.profile-item .value {
    display: block;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-primary);
}
.value-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
