@import url('https://fonts.googleapis.com/css2?family=Urbanist:wght@400;500;600;700&display=swap');

:root {
    /* Colors - Light Mode (Default) */
    --primary: #F8A540;
    --primary-hover: #e59330;
    --primary-light: rgba(248, 165, 64, 0.1);

    --bg-body: #F4F5F7;
    --bg-card: #FFFFFF;
    --bg-sidebar: #FFFFFF;

    --text-main: #111111;
    --text-secondary: #718EBF;
    --text-muted: #B1B1B1;

    --border: #E6EFF5;
    --shadow: 0px 4px 20px rgba(0, 0, 0, 0.02);

    --success: #16DBCC;
    --danger: #FF82AC;

    /* Dimensions & Spacing */
    --sidebar-width: 250px;
    --header-height: 80px;
    --border-radius: 20px;
    --padding-card: 25px;
}

[data-theme="dark"] {
    --bg-body: #18191B;
    /* Very dark grey, almost black */
    --bg-card: #25262C;
    /* Slightly lighter for cards */
    --bg-sidebar: #1E1F23;

    --text-main: #FFFFFF;
    --text-secondary: #8BA3CB;
    --text-muted: #5C6270;

    --border: #333333;
    --shadow: 0px 4px 20px rgba(0, 0, 0, 0.2);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Urbanist', sans-serif;
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

body {
    background-color: var(--bg-body);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

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

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 30px;
    z-index: 100;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 50px;
}

.logo-container img {
    height: 40px;
    /* Adjust based on asset */
}

.logo-text {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-main);
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px 20px;
    color: var(--text-muted);
    font-weight: 500;
    cursor: pointer;
    border-radius: 12px;
    text-decoration: none;
}

.nav-item:hover,
.nav-item.active {
    color: var(--primary);
    background-color: var(--primary-light);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    width: 4px;
    height: 30px;
    background: var(--primary);
    border-radius: 0 4px 4px 0;
    display: none;
    /* Removed the sidebar line style for simpler pill style */
}

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 30px;
}

/* Header */
.top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: var(--header-height);
    background: transparent;
}

.header-title h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-main);
}

.header-title span {
    font-size: 14px;
    color: var(--text-secondary);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 20px;
}

.period-select {
    padding: 10px 20px;
    border-radius: 50px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-family: 'Urbanist';
    outline: none;
    cursor: pointer;
}

.theme-toggle {
    background: var(--bg-card);
    border: 1px solid var(--border);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--primary);
    font-size: 1.2rem;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background-color: var(--primary-light);
    /* Placeholder */
    object-fit: cover;
}

/* --- Dashboard Grid --- */

/* Hero Section (Includes Balance & Actions) */
.hero-section {
    display: grid;
    grid-template-columns: 1fr 350px;
    /* Balance/Actions left, Recent/Other right if needed. For now 1fr */
    grid-template-columns: 1fr;
    gap: 20px;
}

.balance-card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: var(--padding-card);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.balance-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.balance-label {
    color: var(--text-secondary);
    font-size: 14px;
}

.balance-amount {
    font-size: 36px;
    font-weight: 700;
    color: var(--text-main);
    margin-top: 5px;
}

.action-buttons {
    display: flex;
    gap: 15px;
    margin-top: 10px;
}

.action-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px;
    border-radius: 50px;
    /* Pill shape */
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-main);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.action-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--bg-body);
}

.action-btn.active {
    /* Just in case we want a primary one */
    background: var(--text-main);
    /* Black in light */
    color: #fff;
    border: none;
}

[data-theme="dark"] .action-btn.active {
    background: #fff;
    color: #000;
}


/* KPI Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 25px;
}

.kpi-card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 15px;
    /* Reduced from 20px */
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 15px;
    /* Reduced from 20px */
    position: relative;
    /* For semaphore positioning */
    overflow: visible !important;
    /* Force visible for tooltips */
    transition: box-shadow 0.2s;
    /* Removed transform */
    z-index: 1;
}

.kpi-card:hover {
    z-index: 1000 !important;
    /* Float above everything */
    /* transform: translateY(-5px); Removed to avoid stacking context issues */
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

.kpi-icon {
    width: 50px;
    /* Reduced from 60px */
    height: 50px;
    min-width: 50px;
    /* Prevent shrinking */
    min-height: 50px;
    border-radius: 50%;
    background: var(--bg-body);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    /* Reduced font */
    color: var(--primary);
    flex-shrink: 0;
    /* Critical for keeping circle shape */
}

.kpi-content {
    display: flex;
    flex-direction: column;
    min-width: 0;
    /* Trigger flex text truncation */
    flex: 1;
    overflow: visible !important;
    /* Force visible */
}

.kpi-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 2px;
    /* Allow percentage to sit inline-flex */
    display: flex;
    align-items: center;
    white-space: nowrap;
    overflow: visible !important;
    /* Force visible */
    flex-wrap: nowrap;
    /* Keep on one line but truncate safely */
}

.kpi-value {
    font-size: 18px;
    /* Reduced from 20px */
    font-weight: 700;
    color: var(--text-main);
    display: block;
    /* flexible block */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    line-height: 1.2;
}

.kpi-value {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

/* Modern Semaphore (Bottom Bar - Inset to prevent overflow) */
.semaphore {
    position: absolute;
    bottom: 5px;
    left: 10px;
    width: calc(100% - 20px);
    height: 4px;
    border-radius: 4px;
    pointer-events: none;
}

.semaphore.green {
    background-color: #2ecc71;
    box-shadow: 0 -2px 10px rgba(46, 204, 113, 0.3);
}

.semaphore.yellow {
    background-color: #f1c40f;
    box-shadow: 0 -2px 10px rgba(241, 196, 15, 0.3);
}

.semaphore.red {
    background-color: #e74c3c;
    box-shadow: 0 -2px 10px rgba(231, 76, 60, 0.3);
}

/* Charts Section */
.charts-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 25px;
}

.chart-card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: var(--padding-card);
    box-shadow: var(--shadow);
}

.card-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 20px;
}

/* Advanced Indicators (Table Style) */
.advanced-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
}

.ratio-card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 15px;
    border: 1px solid var(--border);
    text-align: center;
    position: relative;
    overflow: visible !important;
    /* Force visible */
    transition: box-shadow 0.2s;
    /* Removed transform */
    z-index: 1;
}

.ratio-card:hover {
    z-index: 1000 !important;
    /* transform: translateY(-5px); Removed */
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

.ratio-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ratio-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    width: 100%;
    max-width: 450px;
    padding: 30px;
    border-radius: var(--border-radius);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
}

.modal-header h2 {
    font-size: 20px;
    color: var(--text-main);
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 14px;
}

.form-control {
    width: 100%;
    padding: 12px 15px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-body);
    color: var(--text-main);
    font-family: 'Urbanist';
    outline: none;
}

.form-control:focus {
    border-color: var(--primary);
}

.btn-primary {
    width: 100%;
    padding: 15px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    font-size: 16px;
    margin-top: 10px;
}

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

/* Mobile responsive */
@media (max-width: 768px) {
    .sidebar {
        display: none;
    }

    .main-content {
        margin-left: 0;
    }

    .hero-section {
        grid-template-columns: 1fr;
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }

    .action-buttons {
        flex-wrap: wrap;
    }
}

/* Progress Bar Overlay */
.progress-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    color: white;
}

.progress-container {
    width: 300px;
    height: 10px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    margin-top: 20px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.progress-bar {
    width: 0%;
    height: 100%;
    background: var(--primary);
    box-shadow: 0 0 15px var(--primary);
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 1px;
}

/* --- Educational Tooltips --- */
.tooltip-container {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: help;
    margin-left: 6px;
    overflow: visible;
}

.tooltip-icon {
    font-size: 14px;
    color: var(--text-secondary);
    transition: color 0.2s;
}

.tooltip-container:hover .tooltip-icon {
    color: var(--primary);
}

.tooltip-content {
    visibility: hidden;
    opacity: 0;
    width: 220px;
    background-color: var(--bg-card);
    /* Fallback */
    background: rgba(30, 30, 35, 0.95);
    /* Dark semi-transparent default */
    color: #fff;
    text-align: left;
    border-radius: 12px;
    padding: 12px;
    position: absolute;
    z-index: 9999 !important;
    /* Max z-index */
    /* Higher than sidebar/header */
    bottom: 150%;
    left: 50%;
    transform: translateX(-50%) translateY(10px);

    /* Glassmorphism Effect */
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);

    /* Animation */
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s;

    font-size: 13px;
    line-height: 1.4;
    font-weight: 500;
    white-space: normal;
    /* Fix for parents with nowrap */
}

[data-theme="light"] .tooltip-content {
    background: rgba(255, 255, 255, 0.95);
    color: #333;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.tooltip-container:hover .tooltip-content {
    visibility: visible;
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.tooltip-content::after {
    content: "";
    position: absolute;
    top: 100%;
    /* At bottom of tooltip */
    left: 50%;
    margin-left: -6px;
    border-width: 6px;
    border-style: solid;
    border-color: rgba(30, 30, 35, 0.95) transparent transparent transparent;
}

[data-theme="light"] .tooltip-content::after {
    border-color: rgba(255, 255, 255, 0.95) transparent transparent transparent;
}

/* --- Responsive Table Utilities --- */
.table-responsive {
    width: 100%;
    margin-bottom: 20px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-responsive .modern-table {
    min-width: 900px;
}

.table-responsive::-webkit-scrollbar {
    height: 6px;
}

.table-responsive::-webkit-scrollbar-track {
    background: transparent;
}

.table-responsive::-webkit-scrollbar-thumb {
    background-color: var(--text-muted);
    border-radius: 20px;
    border: 2px solid transparent;
    background-clip: content-box;
    opacity: 0.5;
}