:root {
    /* Light Corporate Glassmorphism Theme Colors */
    --bg-primary: #F8FAFC;
    /* Clean platinum */
    --bg-secondary: rgba(255, 255, 255, 0.7);
    /* Light Glass layer */
    --bg-tertiary: rgba(241, 245, 249, 0.8);
    /* Light Highlights */

    --glass-border: rgba(0, 0, 0, 0.08);
    --glass-shadow: 0 10px 30px 0 rgba(0, 0, 0, 0.05);

    --text-main: #0F172A;
    --text-muted: #64748B;

    /* Accents */
    --accent-emerald: #10B981;
    --accent-crimson: #EF4444;
    --accent-blue: #2563EB;
    --accent-gold: #D97706;

    /* Grid settings */
    --gap: 12px;
    --radius: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-primary);
    background-image: url('assets/app_bg.png');
    background-size: cover;
    background-position: center;
    background-blend-mode: overlay; /* Allows the image texture to blend flawlessly with the new light background color */
    background-attachment: fixed;
    background-repeat: no-repeat;
    color: var(--text-main);
    overflow-x: hidden;
    overflow-y: auto;
    min-height: 100vh;
    width: 100vw;
}

.dashboard-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 100vh;
    padding: var(--gap);
    background: rgba(248, 250, 252, 0.92);
}

/* Header */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-secondary);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    padding: 15px 30px;
    border-radius: var(--radius);
    margin-bottom: var(--gap);
    box-shadow: var(--glass-shadow);
}

.header-title h1 {
    font-size: 32px;
    font-weight: 800;
    letter-spacing: 1px;
}

.header-metrics {
    text-align: center;
}

.metric-label {
    display: block;
    font-size: 14px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 4px;
}

.metric-value {
    font-size: 36px;
    font-weight: 800;
}

.gold-accent {
    color: var(--accent-gold);
}

.header-time-export {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
}

.header-time {
    text-align: right;
}

.export-btn {
    background-color: var(--accent-blue);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.export-btn:hover {
    background-color: #2563EB;
}

.export-btn:disabled {
    background-color: var(--bg-tertiary);
    color: var(--text-muted);
    cursor: not-allowed;
}

.time-display {
    font-size: 28px;
    font-weight: 600;
    color: var(--accent-blue);
}

.refresh-status {
    font-size: 14px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Main Content Wrapper */
.dashboard-content {
    display: flex;
    flex-direction: column;
    gap: var(--gap);
    flex: 1;
    overflow-y: auto;
    padding-right: 10px;
    /* Space for scrollbar */
}

/* Base Panel Styles */
.panel {
    background: var(--bg-secondary);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 12px 15px;
    display: flex;
    flex-direction: column;
    box-shadow: var(--glass-shadow);
}

.panel h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.panel-group {
    display: flex;
    gap: var(--gap);
}

.panel-group.vertical {
    flex-direction: column;
}

.panel-group>.panel {
    flex: 1;
}

/* Specific Section Sizing */
.section-overview {
    grid-column: span 4;
}

.section-company-revenue {
    grid-column: span 1;
}

.section-revenue-trend {
    grid-column: span 2;
}

/* Top Clients & Projects in a column */
.dashboard-grid>.panel-group:nth-of-type(1) {
    grid-column: span 1;
}

.section-receivable-risk {
    grid-column: span 1;
}

/* Collections & Profitability in a column */
.dashboard-grid>.panel-group:nth-of-type(2) {
    grid-column: span 1;
}

.section-expenses {
    grid-column: span 1;
}

.section-ai-insights {
    grid-column: span 1;
    border-left: 4px solid var(--accent-blue);
}

/* KPI Cards */
.kpi-grid {
    display: flex;
    justify-content: space-between;
    gap: 16px;
}

.kpi-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 12px 18px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.kpi-label {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.kpi-value {
    font-size: 28px;
    font-weight: 800;
    margin-bottom: 4px;
}

.kpi-trend {
    font-size: 14px;
    font-weight: 600;
}

.positive {
    color: var(--accent-emerald);
}

.negative {
    color: var(--accent-crimson);
}

.text-crimson {
    color: var(--accent-crimson) !important;
}

.text-emerald {
    color: var(--accent-emerald) !important;
}

.text-blue {
    color: var(--accent-blue) !important;
}

/* Charts */
.chart-container {
    flex: 1;
    position: relative;
    min-height: 0;
    width: 100%;
}

.chart-container.donut {
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Tables */
.table-container {
    flex: 1;
    overflow-y: auto;
}

/* Custom scrollbar for tables if they overflow slightly */
.table-container::-webkit-scrollbar {
    width: 6px;
}

.table-container::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

.table-container::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 3px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 12px 8px;
    text-align: left;
    border-bottom: 1px solid var(--bg-tertiary);
}

.data-table th {
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
}

.data-table td {
    font-size: 14px;
    font-weight: 600;
}

/* Lists */
.metrics-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    flex: 1;
    justify-content: center;
}

.list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-tertiary);
    padding: 16px;
    border-radius: 8px;
}

.list-item span:first-child {
    color: var(--text-muted);
    font-size: 14px;
}

.list-item span:last-child {
    font-size: 20px;
    font-weight: 800;
}

/* AI Insights */
.section-ai-insights h2 {
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-icon {
    color: var(--accent-blue);
}

.insight-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.insight-list li {
    background: linear-gradient(145deg, var(--bg-tertiary) 0%, rgba(59, 130, 246, 0.1) 100%);
    padding: 16px;
    border-radius: 8px;
    font-size: 16px;
    line-height: 1.5;
    border-left: 3px solid var(--accent-blue);
    animation: fadeIn 1s ease-in-out;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =========================================
   PDF Template Styles (Hidden & Print Only)
   ========================================= */
.pdf-report {
    width: 100%;
    /* Let html2pdf canvas determine A4 width */
    padding: 0;
    /* Margins are now handled by html2pdf opt array */
    background-color: white;
    color: #111827;
    /* Dark text for white paper */
    font-family: sans-serif;
    line-height: 1.6;
}

.pdf-section {
    margin-bottom: 20px;
    page-break-inside: auto;
}

/* Cover Page */
.pdf-cover {
    min-height: 800px;
    /* Push elements down to fill cover visually on canvas without overflowing */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    border: 4px solid #111827;
    padding: 60px 40px;
}

.pdf-logo {
    font-size: 24px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 20px;
    color: #3B82F6;
}

.pdf-title {
    font-size: 42px;
    font-weight: 800;
    margin-bottom: 40px;
    line-height: 1.2;
}

.pdf-meta {
    font-size: 16px;
    color: #4B5563;
    width: 100%;
    text-align: left;
    margin-top: auto;
    border-top: 2px solid #E5E7EB;
    padding-top: 20px;
}

/* Internal Pages */
.pdf-h2 {
    font-size: 24px;
    font-weight: 800;
    color: #1F2937;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid #E5E7EB;
}

.pdf-narrative {
    font-size: 14px;
    color: #374151;
    margin-bottom: 24px;
}

.pdf-narrative ul {
    margin-left: 20px;
    margin-top: 10px;
}

.pdf-narrative li {
    margin-bottom: 8px;
}

/* Data Tables */
.pdf-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 24px;
    font-size: 12px;
}

.pdf-table th {
    background-color: #F3F4F6;
    color: #1F2937;
    font-weight: 600;
    text-align: left;
    padding: 10px 12px;
    border-bottom: 2px solid #D1D5DB;
}

.pdf-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #E5E7EB;
    color: #374151;
}

/* Utilities */
.html2pdf__page-break {
    page-break-before: always;
}

.pdf-chart-container {
    page-break-inside: avoid;
}

/* Responsive Grid System */
.companies-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    margin-bottom: 15px;
}

@media (max-width: 1440px) {
    .dashboard-header {
        padding: 12px 20px;
    }

    .header-title h1 {
        font-size: 24px;
    }

    .metric-value {
        font-size: 28px;
    }
}

@media (max-width: 1200px) {
    .companies-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .header-title h1 {
        font-size: 20px;
    }
}

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

    .dashboard-header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }

    .header-title {
        flex-direction: column;
        gap: 10px !important;
    }

    .header-metrics {
        margin-top: 10px;
    }

    .kpi-grid {
        flex-direction: column;
    }
}

/* =========================================
   Cinematic Tech Loading Screen
   ========================================= */
.tech-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(3, 7, 18, 0.8);
    backdrop-filter: blur(5px);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.8s ease-out, visibility 0.8s ease-out;
}

.loader-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
}

.loader-logo {
    height: 80px;
    object-fit: contain;
    animation: pulseLogo 2s infinite ease-in-out;
}

@keyframes pulseLogo {
    0% {
        transform: scale(0.95);
        opacity: 0.8;
    }

    50% {
        transform: scale(1.05);
        opacity: 1;
    }

    100% {
        transform: scale(0.95);
        opacity: 0.8;
    }
}

.loader-title {
    color: #F9FAFB;
    font-size: 32px;
    font-weight: 800;
    letter-spacing: 2px;
    text-transform: uppercase;
    text-align: center;
    text-shadow: 0 0 20px rgba(59, 130, 246, 0.5);
}

.loader-text {
    color: #10B981;
    font-size: 14px;
    letter-spacing: 4px;
    font-family: monospace;
    animation: blinkText 1s infinite;
}

@keyframes blinkText {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.3;
    }
}

/* 3D Tech Spinner */
.tech-spinner {
    position: relative;
    width: 120px;
    height: 120px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.tech-spinner .ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid transparent;
}

.tech-spinner .ring:nth-child(1) {
    border-top: 2px solid #3B82F6;
    /* Blue */
    animation: rotateSpin 1.5s linear infinite;
}

.tech-spinner .ring:nth-child(2) {
    width: 80%;
    height: 80%;
    border-right: 2px solid #10B981;
    /* Emerald */
    animation: rotateSpinReverse 2s linear infinite;
}

.tech-spinner .ring:nth-child(3) {
    width: 60%;
    height: 60%;
    border-bottom: 2px solid #F59E0B;
    /* Gold */
    animation: rotateSpin 2.5s linear infinite;
}

.tech-spinner .core {
    width: 20%;
    height: 20%;
    background-color: #3B82F6;
    border-radius: 50%;
    box-shadow: 0 0 15px #3B82F6;
    animation: pulseLogo 1s infinite alternate;
}

@keyframes rotateSpin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

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

    100% {
        transform: rotate(0deg);
    }
}

.tech-loader.fade-out {
    opacity: 0;
    visibility: hidden;
}

/* Premium Auth Styles */
.login-view {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(11, 15, 25, 0.6);
    backdrop-filter: blur(15px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    overflow: hidden;
}

.login-bg-shape {
    position: absolute;
    filter: blur(80px);
    z-index: 0;
    opacity: 0.5;
    animation: floatShape 10s infinite ease-in-out alternate;
}

.shape-1 {
    width: 400px;
    height: 400px;
    background: rgba(59, 130, 246, 0.4);
    top: -100px;
    left: -100px;
    border-radius: 50%;
}

.shape-2 {
    width: 500px;
    height: 500px;
    background: rgba(16, 185, 129, 0.3);
    bottom: -150px;
    right: -100px;
    border-radius: 50%;
    animation-delay: -5s;
}

.shape-3 {
    width: 300px;
    height: 300px;
    background: rgba(245, 158, 11, 0.2);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    animation-delay: -2s;
}

@keyframes floatShape {
    0% {
        transform: translate(0, 0) scale(1);
    }

    100% {
        transform: translate(30px, -40px) scale(1.1);
    }
}

.premium-glass {
    position: relative;
    z-index: 10;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.5);
    padding: 50px 40px;
    border-radius: 20px;
    width: 100%;
    max-width: 440px;
    text-align: center;
}

.login-logo-container {
    margin-bottom: 24px;
}

.login-logo {
    height: 70px;
    object-fit: contain;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.3));
}

.login-title {
    color: #0F172A;
    font-size: 28px;
    font-weight: 800;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.login-subtitle {
    color: #64748B;
    font-size: 14px;
    margin-bottom: 32px;
}

.premium-input-group {
    margin-bottom: 20px;
}

.premium-input-group label {
    font-size: 12px;
    font-weight: 600;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    display: block;
    text-align: left;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 14px;
    font-size: 16px;
    color: #94A3B8;
    pointer-events: none;
}

.premium-input-group input,
.premium-input-group select {
    width: 100%;
    padding: 14px 14px 14px 40px;
    background: rgba(241, 245, 249, 0.8);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    color: #0F172A;
    font-size: 15px;
    transition: all 0.3s ease;
    box-sizing: border-box;
}

.premium-input-group input:focus,
.premium-input-group select:focus {
    background: rgba(255, 255, 255, 0.9);
    border-color: #3B82F6;
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.premium-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    width: 100%;
    background: linear-gradient(135deg, #2563EB 0%, #1D4ED8 100%);
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
    border-radius: 10px;
    border: none;
    color: white;
    padding: 16px;
    font-size: 16px;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.premium-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.6);
    background: linear-gradient(135deg, #3B82F6 0%, #2563EB 100%);
}

.login-error {
    color: #EF4444;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    padding: 10px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 20px;
    text-align: left;
}

/* Categorized Report Grid */
.report-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-top: 20px;
}

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

.report-column {
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid var(--bg-tertiary);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.mini-dropzone {
    border: 2px dashed #4B5563;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    background: rgba(30, 41, 59, 0.3);
    transition: all 0.2s;
    margin-bottom: 20px;
    flex-shrink: 0;
}

.mini-dropzone:hover {
    border-color: #3B82F6;
    background: rgba(59, 130, 246, 0.1);
}

.mini-dropzone-icon {
    font-size: 24px;
    margin-bottom: 10px;
}

.mini-dropzone-txt {
    font-size: 13px;
    color: #D1D5DB;
    font-weight: 600;
}