/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-main);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    /* Matches theme */
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Toggle Switch - Styled like iOS/Modern */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--surface-hover);
    border: 1px solid var(--border-color);
    -webkit-transition: .4s;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: var(--text-secondary);
    -webkit-transition: .4s;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
}

input:checked+.slider:before {
    -webkit-transform: translateX(26px);
    -ms-transform: translateX(26px);
    transform: translateX(26px);
    background-color: #0b0d12;
    /* Contrast dot */
}

/* CostIA Admin Theme Palette - Dark "LidIA" Style */
:root {
    --bg-color: #05050f;
    /* Deep dark blue/black */
    --sidebar-bg: #05050f;

    --surface-color: #0f1522;
    /* Slightly lighter for cards */
    --surface-hover: #1a2233;

    --text-primary: #ffffff;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    /* Accents */
    --accent-color: #22d3ee;
    /* Cyan */
    --accent-secondary: #c084fc;
    /* Purple/Pink */
    --accent-glow: rgba(34, 211, 238, 0.15);

    /* Status Colors */
    --success-color: #22c55e;
    --success-text: #4ade80;
    --error-color: #ef4444;
    --warning-text: #f59e0b;

    /* Borders */
    --border-color: #1e293b;
    --sidebar-border: transparent;
    /* Cleaner look */

    /* Spacing & Radius */
    --radius-lg: 16px;
    /* Larger radius as per modern design */
    --radius-md: 8px;
    --radius-sm: 4px;

    /* Shadows */
    --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.3),
        0 2px 4px -1px rgba(0, 0, 0, 0.15);
    --shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.4),
        0 4px 6px -2px rgba(0, 0, 0, 0.2);
}

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

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

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

/* SIDEBAR */
/* Neon Icons */
.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0.5rem;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.icon-edit {
    color: #facc15;
    /* Yellow */
    text-shadow: 0 0 5px rgba(250, 204, 21, 0.4), 0 0 10px rgba(250, 204, 21, 0.2);
}

.icon-edit:hover {
    color: #fde047;
    text-shadow: 0 0 8px rgba(250, 204, 21, 0.6), 0 0 16px rgba(250, 204, 21, 0.4);
    transform: scale(1.1);
}

.icon-delete {
    color: #ef4444;
    /* Red */
    text-shadow: 0 0 5px rgba(239, 68, 68, 0.4), 0 0 10px rgba(239, 68, 68, 0.2);
}

.icon-delete:hover {
    color: #f87171;
    text-shadow: 0 0 8px rgba(239, 68, 68, 0.6), 0 0 16px rgba(239, 68, 68, 0.4);
    transform: scale(1.1);
}

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

.brand {
    margin-bottom: 3rem;
    padding: 1rem 0.5rem;
    text-align: center;
}

.brand-text {
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    display: flex;
    justify-content: center;
    gap: 4px;
}

.brand-name {
    background: linear-gradient(to right, #22d3ee, #3b82f6);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.brand-suffix {
    background: linear-gradient(to right, #a855f7, #ec4899);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.nav-menu {
    list-style: none;
    flex: 1;
}

.nav-item {
    margin-bottom: 0.25rem;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
    font-size: 0.9rem;
    font-weight: 500;
}

.nav-link:hover {
    background-color: rgba(110, 118, 129, 0.1);
    color: var(--text-primary);
}

.nav-link.active {
    background-color: rgba(34, 211, 238, 0.05);
    /* Slight cyan tint */
    color: var(--accent-color);
    font-weight: 600;
    border: 1px solid rgba(34, 211, 238, 0.3);
    box-shadow: 0 0 15px rgba(34, 211, 238, 0.1);
}

.nav-icon {
    margin-right: 12px;
    opacity: 0.8;
}

/* MAIN CONTENT */
.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 2rem 3rem;
    min-width: 0;
}

/* TOPBAR */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.page-title {
    font-size: 1.5rem;
    font-weight: 600;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* PROJECTS VIEW */
.view-header {
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
}

.search-container {
    width: 100%;
    max-width: 400px;
}

.search-input {
    width: 100%;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent-color);
}

.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.project-card {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 180px;
}

.project-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
    border-color: var(--text-muted);
}

.project-card-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 1rem;
}

.project-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #1e293b, #0f1522);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.project-status {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 12px;
    background: rgba(35, 134, 54, 0.2);
    color: var(--success-text);
    border: 1px solid rgba(35, 134, 54, 0.3);
}

.project-name {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #fff;
}

.project-id {
    font-family: monospace;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* DETAILS VIEW */
.details-header {
    margin-bottom: 2rem;
}

.btn-text {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 0;
    font-size: 0.9rem;
    cursor: pointer;
    margin-bottom: 1rem;
    display: inline-flex;
    align-items: center;
}

.btn-text:hover {
    color: var(--accent-color);
}

.project-id-badge {
    display: inline-block;
    background: rgba(110, 118, 129, 0.1);
    color: var(--text-secondary);
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius-sm);
    font-family: monospace;
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

/* Filters Toolbar */
.filters-toolbar {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    margin-bottom: 2rem;
    display: flex;
    align-items: flex-end;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.quick-filters {
    display: flex;
    gap: 0.5rem;
}

.quick-filter-btn.active {
    background: rgba(34, 211, 238, 0.1);
    color: var(--accent-color);
    border-color: var(--accent-color);
}

/* Call Analysis Specific Buttons */
.call-filter-btn {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
    font-size: 0.85rem;
}

.call-filter-btn:hover {
    border-color: var(--text-primary);
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.call-filter-btn.active {
    background: rgba(34, 211, 238, 0.15);
    color: var(--accent-color);
    border-color: var(--accent-color);
    box-shadow: 0 0 10px rgba(34, 211, 238, 0.1);
}

.filter-wrapper {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    align-items: flex-end;
    flex: 1;
}

.filter-actions {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.filter-group label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.date-inputs {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.input-date,
.input-text,
.input-select {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
}

.input-date {
    min-width: 140px;
}

.btn-primary {
    background: var(--accent-color);
    color: #0b0d12;
    border: none;
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}


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

.btn-brand {
    background: linear-gradient(to right, #22d3ee, #3b82f6);
    color: #fff;
    border: none;
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 4px 6px rgba(34, 211, 238, 0.2);
}

.btn-brand:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 12px rgba(34, 211, 238, 0.3);
    opacity: 0.95;
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--text-secondary);
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-outline:hover {
    border-color: var(--text-primary);
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
}

/* STATS */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
}

.stat-card {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
}

.highlight-card {
    border-color: rgba(34, 211, 238, 0.3);
    background: linear-gradient(180deg, rgba(34, 211, 238, 0.05), var(--surface-color));
}

.stat-header {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    margin-bottom: 0.75rem;
}

.stat-main-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.stat-subtext {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* CHARTS */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
    margin-bottom: 2rem;
}

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

.chart-card {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    min-height: 300px;
}

.chart-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1.5rem;

    /* SELECT STYLING */
    select.form-control {
        appearance: none;
        -webkit-appearance: none;
        background-color: var(--surface-color);
        color: var(--text-primary);
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 1rem center;
        background-size: 1rem;
        padding-right: 2.5rem;
    }

    select.form-control option {
        background-color: #0f172a;
        /* Dark background for options */
        color: var(--text-primary);
    }

    border-bottom: 1px solid var(--border-color);
}

/* Chart Bars */
.chart-item {
    margin-bottom: 1rem;
}

.chart-wrapper {
    margin-bottom: 0.25rem;
}

.chart-label {
    font-size: 0.85rem;
    margin-bottom: 0.25rem;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
}

.chart-bar-bg {
    height: 8px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    overflow: hidden;
}

.chart-bar-fill {
    height: 100%;
    background: var(--accent-color);
    width: 0%;
    transition: width 0.6s cubic-bezier(0.25, 1, 0.5, 1);
}

.chart-value-text {
    text-align: right;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Loading */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(13, 17, 23, 0.9);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 999;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(34, 211, 238, 0.3);
    border-radius: 50%;
    border-top-color: var(--accent-color);
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 1024px) {
    .sidebar {
        width: 0;
        padding: 0;
        overflow: hidden;
    }

    .main-content {
        margin-left: 0;
        padding: 1rem;
    }

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

/* Custom Multiselect */
.custom-select-container {
    position: relative;
    width: 250px;
    font-size: 0.9rem;
}

.select-trigger {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    user-select: none;
}

.select-trigger::after {
    content: '▼';
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-left: 0.5rem;
}

.select-trigger:hover {
    border-color: var(--text-secondary);
}

.select-options {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-top: 4px;
    z-index: 200;
    max-height: 250px;
    overflow-y: auto;
    display: none;
    box-shadow: var(--shadow-hover);
}

.select-options.open {
    display: block;
}

.option-item {
    padding: 0.6rem 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    color: var(--text-secondary);
    transition: background 0.1s;
}

.option-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.option-item.selected {
    background: rgba(34, 211, 238, 0.1);
    color: var(--accent-color);
}

.option-item input[type="checkbox"] {
    margin-right: 10px;
    pointer-events: none;
    /* Let the div handle click */
    accent-color: var(--accent-color);
}

/* Disabled State for Date Inputs */
.input-date:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: rgba(255, 255, 255, 0.05);
    /* Slightly darker/different */
    color: var(--text-muted);
}

/* --- Global Dashboard Improvements --- */
.gradient-text {
    background: linear-gradient(90deg, #60a5fa, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 700;
}

.global-header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.global-header h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.global-subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
}

.premium-card {
    background: linear-gradient(145deg, rgba(30, 30, 30, 0.6), rgba(20, 20, 20, 0.8));
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.premium-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
    border-color: rgba(96, 165, 250, 0.2);
}

.premium-chart {
    background: rgba(20, 20, 20, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
}

.global-toolbar {
    background: rgba(30, 30, 30, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 1rem;
    border-radius: 12px;
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Ensure stats grid looks good */
.stats-grid.global-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-main-value.gradient-text {
    font-size: 2.5rem;
    /* Larger for impact */
}

/* Enhancements for Charts Grid */
.charts-grid {
    grid-template-columns: repeat(2, 1fr);
}

.full-width {
    grid-column: 1 / -1;
}

.custom-tooltip {
    position: fixed;
    background: rgba(15, 21, 34, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    color: #fff;
    padding: 0.75rem;
    border-radius: 8px;
    font-size: 0.85rem;
    z-index: 9999;
    pointer-events: none;
    display: none;
    min-width: 150px;
}

.tooltip-title {
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--accent-color);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 4px;
    font-size: 0.9rem;
}

/* Tooltip Container */
.tooltip-container {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 6px;
    cursor: help;
    vertical-align: middle;
}

/* The Icon itself */
.tooltip-icon {
    color: var(--accent-color);
    width: 16px;
    height: 16px;
    opacity: 0.7;
    transition: opacity 0.2s, color 0.2s;
}

.tooltip-container:hover .tooltip-icon {
    opacity: 1;
    color: var(--accent-hover);
}

/* The Popover (Tooltip text) */
.tooltip-popover {
    visibility: hidden;
    width: 200px;
    background-color: #1e1e1e;
    /* Darker than var(--bg-card) */
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 8px 12px;
    position: absolute;
    z-index: 9999;

    /* Position above */
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);

    /* Fade in */
    opacity: 0;
    transition: opacity 0.2s;

    /* Border/Shadow */
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    font-size: 0.75rem;
    font-weight: normal;
    line-height: 1.4;
    white-space: normal;
}

/* Arrow */
.tooltip-popover::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: #1e1e1e transparent transparent transparent;
}

/* Show on hover */
.tooltip-container:hover .tooltip-popover {
    visibility: visible;
    opacity: 1;
}



.tooltip-value {
    color: #fff;
    font-weight: 600;
}

/* Table Styles */
.table-container {
    overflow-x: auto;
    width: 100%;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.data-table th,
.data-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

/* Default center alignment for data columns (all except first) */
.data-table th:not(:first-child),
.data-table td:not(:first-child) {
    text-align: center;
}

/* Modal Fixes */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    /* Ensure on top */
}

.modal {
    background: var(--surface-color);
    padding: 2rem;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-hover);
    max-height: 90vh;
    /* Prevent overflow */
    display: flex;
    flex-direction: column;
}

.modal-content-scroll {
    overflow-y: auto;
    flex: 1;
    margin-bottom: 1rem;
    padding-right: 0.5rem;
    /* Space for scrollbar */
}

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

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.form-control {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
}

.form-control:focus {
    outline: none;
    border-color: var(--accent-color);
}

.data-table .text-right {
    text-align: right !important;
}

.data-table tr:hover {
    background-color: rgba(255, 255, 255, 0.02);
}

.data-table td.mono {
    font-family: monospace;
    color: var(--text-muted);
}

/* User Profile Dropdown */
.user-profile {
    position: relative;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: var(--radius-md);
    z-index: 100;
}

.user-profile:hover {
    background: rgba(255, 255, 255, 0.05);
}

.user-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.5rem;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.5rem;
    min-width: 180px;
    box-shadow: var(--shadow-hover);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.user-dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.8rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
}

.dropdown-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.dropdown-item.danger {
    color: var(--error-color);
}

.dropdown-item.danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

.dropdown-divider {
    height: 1px;
    background: var(--border-color);
    margin: 0.25rem 0;
}

/* =========================================
   MOBILE / RESPONSIVE STYLES (iPhone/App)
   ========================================= */

/* Bottom Navigation Bar (Hidden on Desktop) */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(15, 21, 34, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 1000;
    padding: 0.5rem 1rem calc(0.5rem + env(safe-area-inset-bottom));
    /* flex styling in media query */
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--text-secondary);
    padding: 0.5rem;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.bottom-nav-item .nav-icon {
    font-size: 1.4rem;
    margin-bottom: 2px;
}

.bottom-nav-item .nav-label {
    font-size: 0.7rem;
    font-weight: 500;
}

.bottom-nav-item.active {
    color: var(--accent-color);
}

.bottom-nav-item.active .nav-icon {
    transform: translateY(-2px);
    text-shadow: 0 0 10px var(--accent-glow);
}

/* Mobile Adjustments */
@media (max-width: 768px) {

    /* Layout Reset */
    .app-wrapper {
        flex-direction: column;
    }

    .sidebar {
        display: none !important;
        /* Hide Sidebar completely */
    }

    .main-content {
        margin-left: 0 !important;
        padding: 1rem 1rem 6rem 1rem !important;
        /* Bottom padding for nav */
        width: 100%;
    }

    /* Topbar Refresh */
    .topbar {
        border-bottom: none;
        margin-bottom: 1rem;
        padding-bottom: 0;
        background: transparent;
    }

    .page-title {
        font-size: 1.3rem;
        background: linear-gradient(to right, #fff, #cbd5e1);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
    }

    .user-profile {
        /* Hide user email/text on mobile, just avatar */
        padding: 0;
    }

    .user-email {
        display: none;
    }

    .user-avatar {
        font-size: 1.5rem;
        background: var(--surface-hover);
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        border: 1px solid var(--border-color);
    }

    /* Show Bottom Nav */
    .bottom-nav {
        display: flex;
        justify-content: space-around;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
    }

    /* Cards & Grids */
    .stats-grid {
        grid-template-columns: 1fr;
        /* Stack cards */
        gap: 1rem;
    }

    .stat-card {
        padding: 1.25rem;
        border: 1px solid rgba(255, 255, 255, 0.05);
        background: linear-gradient(145deg, var(--surface-color), rgba(15, 21, 34, 0.9));
    }

    .stat-main-value {
        font-size: 2rem;
    }

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

    .chart-card {
        padding: 1rem;
        overflow-x: hidden;
        /* Prevent horizontal break */
    }

    /* Projects Grid */
    .projects-grid {
        grid-template-columns: 1fr;
        /* Full width cards */
    }

    .project-card {
        height: auto;
        min-height: 160px;
    }

    /* Filters Toolbar Stack */
    .filters-toolbar {
        flex-direction: column;
        align-items: stretch;
        padding: 1rem;
        gap: 1rem;
    }

    .filter-group {
        width: 100%;
    }

    .filter-actions {
        width: 100%;
        justify-content: space-between;
    }

    .filter-actions button {
        flex: 1;
        justify-content: center;
    }

    .input-date,
    .input-select,
    .custom-select-container {
        width: 100% !important;
        font-size: 1rem;
        /* Better for touch */
    }

    /* Ensure inputs don't zoom on focus */
    input,
    select,
    textarea {
        font-size: 16px !important;
    }

    /* Tables - Scrollable Card */
    .table-container {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 8px;
        border: 1px solid var(--border-color);
    }

    th,
    td {
        white-space: nowrap;
        padding: 1rem 0.75rem;
    }

    /* Details View Header & Back Button */
    .details-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    /* Hide some brand elements or adjust sizes */
    .brand {
        display: none;
        /* Sidebar handles branding usually */
    }

    /* Adjust buttons for touch */
    .btn-brand,
    .btn-primary,
    .btn-outline {
        min-height: 44px;
        /* Apple Human Interface Guidelines */
    }

    .quick-filters {
        overflow-x: auto;
        padding-bottom: 5px;
        -ms-overflow-style: none;
        /* IE */
        scrollbar-width: none;
        /* Firefox */
    }

    .quick-filters::-webkit-scrollbar {
        display: none;
    }

    .quick-filter-btn {
        flex: 0 0 auto;
        /* Don't shrink */
    }
}

/* Refinements for Mobile Nav & Grid */

/* Collapsible Nav Wrapper */
.bottom-nav-wrapper {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    /* Toggle button on right ? or center? User said "flecha en la propia barra". */
    /* Let's put the button centered above or attached to the bar. */
    align-items: center;
    pointer-events: none;
    /* Let clicks pass through empty space */
}

/* The actual bar */
.bottom-nav {
    /* Override previous fixed positioning since wrapper handles it */
    position: static;
    width: 100%;
    pointer-events: auto;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateY(0);
}

.bottom-nav.collapsed {
    transform: translateY(100%);
}

/* Toggle Button */
.nav-toggle-btn {
    pointer-events: auto;
    background: rgba(15, 21, 34, 0.9);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    width: 48px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    cursor: pointer;
    margin-bottom: -1px;
    /* Align perfectly with bar */
    transition: all 0.3s ease;
}

.nav-toggle-btn:hover {
    color: var(--accent-color);
}

.nav-toggle-btn.collapsed-state {
    transform: translateY(100%);
    /* Move down with the bar? No, it should stay visible above bottom */
    /* Wait, if bar goes down 100%, toggle should follow or stay? */
    /* User wants to hide the bar. The toggle must remain visible to open it back. */
    /* If wrapper is bottom 0, bar is inside. */
    /* If bar translates Y 100%, it goes off screen. Toggle is above it. */
    /* Iterate: Toggle needs to be visible always. */

    /* Let's adjust wrapper logic */
}

/* New Logic for Toggle Positioning */
/* We want the toggle to "ride" the bar or stay fixed */
/* Simplest: Toggle is always fully visible at bottom if collapsed, or above bar if expanded. */
/* Actually, let's keep toggle attached to the top of the bar. */

.bottom-nav-wrapper {
    /* Reset pointer events to auto for children container */
    pointer-events: none;
}

.nav-toggle-btn {
    pointer-events: auto;
    /* If bar is collapsed, we want button to be at bottom of screen */
    /* If bar is expanded, button is above bar */
    /* So transform should match bar but offset? */

    /* Let's try simpler: Wrapper contains button then nav. */
    /* If nav is collapsed (transform Y 100%), button moves down? */
    /* We want button to stay at bottom of screen when collapsed? */

    /* Better UX: Button stays at same place relative to bar top. */
    transform: translateY(0);
}

.bottom-nav.collapsed {
    /* If we just hide nav, button hangs in air? */
    /* Let's translate the whole wrapper? */
    /* No, wrapper is bottom:0. */
}

/* Let's try this: */
.bottom-nav-wrapper {
    transition: transform 0.3s ease;
}

/* When collapsed, we move the wrapper down by the height of nav? */
/* JS handles class on nav. Let's handle class on wrapper for easier CSS */
/* We will update JS to put class on wrapper if we change strategy, but provided JS puts class on NAV and BUTTON. */

/* Logic: Button is ABOVE nav. */
/* Default: Nav is visible. Button is above it. */
/* Collapsed: Nav is translated down. Button follows? */
/* If Nav is transform Y 100%, it goes down. Button is in normal flow above it. It will NOT move down automatically unless container shrinks or we transform button too. */

/* Styling update for Mobile Layout Grid */
@media (max-width: 768px) {

    /* 2 Column Grid for Projects */
    .projects-grid {
        grid-template-columns: 1fr 1fr !important;
        /* Force 2 columns */
        gap: 0.75rem;
    }

    .project-card {
        min-height: 140px;
        padding: 1rem;
    }

    .project-name {
        font-size: 1rem;
        line-height: 1.3;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .project-icon {
        width: 32px;
        height: 32px;
        font-size: 1rem;
    }

    /* Adjust stats grid to be tighter if needed, but stacked is fine */
}

/* Refined Mobile Drawer Animation & Layout */

/* Wrapper fixed at bottom */
.bottom-nav-wrapper {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
    /* Allow clicks through transparent areas */

    /* Animation base */
    transform: translateY(0);
    transition: transform 0.4s cubic-bezier(0.33, 1, 0.68, 1);
    /* Quick elastic feel */
}

/* Logic: Button Height = 32px. We want to hide everything except button when collapsed. */
.bottom-nav-wrapper.collapsed {
    /* Translate down by 100% of height minus the button height */
    transform: translateY(calc(100% - 32px));
}

/* Button Styling */
.nav-toggle-btn {
    pointer-events: auto;
    width: 60px;
    /* Wider touch target */
    height: 32px;
    background: rgba(15, 21, 34, 0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-bottom: none;
    border-radius: 12px 12px 0 0;
    /* Smooth rounded top */
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-color);
    cursor: pointer;
    box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.2);
    z-index: 2;
    /* Content above bar */
}

/* Nav Bar Styling */
.bottom-nav {
    pointer-events: auto;
    width: 100%;
    background: rgba(15, 21, 34, 0.95);
    /* Match button */
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    padding: 0.75rem 1rem calc(1rem + env(safe-area-inset-bottom));
    display: flex;
    justify-content: space-around;
    position: relative;
    /* Contain layout */
    z-index: 1;
}

/* Ensure dropdown is visible on mobile when toggled via Profile */
@media (max-width: 768px) {
    .user-dropdown {
        position: fixed;
        top: 90%;
        /* Above nav bar */
        right: 1rem;
        left: auto;
        width: auto;
        min-width: 200px;
        transform-origin: bottom right;
        max-width: calc(100% - 2rem);
        z-index: 2000;
        /* Above everything */
        border: 1px solid var(--accent-glow);
        box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.5);
    }

    /* Animation for dropdown bottom up */
    .user-dropdown.show {
        animation: slideUpFade 0.2s ease-out forwards;
    }
}

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

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

/* FINAL MOBILE FIXES */

/* 1. Ensure Fixed Positioning strictly for Nav Wrapper */
.bottom-nav-wrapper {
    position: fixed !important;
    /* Force viewport fixing */
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    z-index: 9999 !important;
    /* Highest priority */
    /* Remove any potential relative positioning or flow affecting properties */
    transform: translateY(0);
    will-change: transform;
    /* Optimize animation */
}

/* Collapsed state: Move down but keep button visible */
/* Button height is 32px + border = approx 33px. */
.bottom-nav-wrapper.collapsed {
    transform: translateY(calc(100% - 34px)) !important;
    /* Slightly more to be safe */
}

/* 2. Proportional Project Grid */
@media (max-width: 768px) {
    .projects-grid {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        /* Strict 2 columns */
        gap: 12px !important;
        /* Smaller gap for mobile */
        width: 100% !important;
        padding-bottom: 80px;
        /* Space for nav */
    }

    .project-card {
        width: 100% !important;
        /* Fill column */
        min-height: 140px;
        /* Reasonable height */
        height: auto;
        /* Allow growth */
        padding: 12px 10px !important;
        /* Reduce padding slightly */
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2) !important;
    }

    .project-name {
        font-size: 0.95rem !important;
        /* Slightly smaller */
        font-weight: 600;
        margin-bottom: 4px;
        /* Line clamping for safety */
        display: -webkit-box;
        -webkit-line-clamp: 3;
        /* Allow 3 lines */
        -webkit-box-orient: vertical;
        overflow: hidden;
        word-break: break-word;
        /* Prevent overflow */
    }

    .project-id {
        font-size: 0.75rem !important;
        opacity: 0.8;
    }

    .project-icon {
        width: 36px;
        height: 36px;
        font-size: 1.1rem;
        margin-bottom: 12px;
    }

    /* 3. Ensure Header Profile is visible/usable */
    .topbar {
        position: sticky;
        top: 0;
        z-index: 100;
        background: rgba(5, 5, 15, 0.95);
        /* Backdrop for sticky header */
        backdrop-filter: blur(10px);
        margin: -1rem -1rem 1rem -1rem !important;
        /* Counteract padding */
        padding: 0.75rem 1rem !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
    }
}

/* FIX v4: Grid & Toggle Sticking */

@media (max-width: 768px) {

    /* 1. Project Grid Fixes */
    .projects-grid {
        display: grid !important;
        /* strict 2 columns, prevent overflow */
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 12px !important;
        width: 100% !important;
        padding: 0 !important;
        /* Remove grid padding, let main-content handle edge */
    }

    .main-content {
        padding: 1rem 1rem 80px 1rem !important;
        /* Ensure side padding matches design */
        overflow-x: hidden;
        /* Prevent horizontal scroll */
    }

    .project-card {
        width: 100% !important;
        margin: 0 !important;
        box-sizing: border-box !important;
        /* Ensure consistent height */
        display: flex;
        flex-direction: column;
        justify-content: space-between;
    }

    /* Fix weird width issues */
    .projects-grid>* {
        max-width: 100%;
    }

    /* 2. Toggle Sticking Fix */
    /* Ensure wrapper handles layout context */
    .bottom-nav-wrapper {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: auto !important;
        /* Don't force height */
        transform: translateY(0);
        z-index: 10000 !important;
        transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    }

    .bottom-nav-wrapper.collapsed {
        /* Move down but leave 32px (button) visible + safe area if needed */
        /* Note: Button is 32px. Safe area might be below. */
        /* If we just use translateY(100%), it hides completely. */
        /* We want to show the button. The button is the first child (visually top). */
        /* Actually, in DOM: button is top, nav is bottom. */
        /* So translateY: 100% of nav height? */
        /* Wrapper height = Button + Nav. */
        /* Collapsed should show only Button. */
        /* So transform Y = Nav Height. */
        /* But Nav Height is variable. */
        /* Alternative: transform: translateY(calc(100% - 32px)); */
        /* 100% is the full wrapper height. */
        /* Leaving 32px (button height) visible. */
        transform: translateY(calc(100% - 32px)) !important;
    }

    .nav-toggle-btn {
        width: 100px !important;
        /* Wider for easier tap */
        border-radius: 12px 12px 0 0 !important;
        background: rgba(15, 21, 34, 0.98) !important;
        /* Ensure button height is fixed for calculation */
        height: 32px !important;
        flex-shrink: 0;
    }

    .bottom-nav {
        background: rgba(15, 21, 34, 0.98) !important;
        padding-bottom: max(1rem, env(safe-area-inset-bottom)) !important;
    }

    /* 3. Sticky Header safety */
    .topbar {
        position: sticky;
        top: 0;
        margin-top: -1rem !important;
        /* Pull back to edge */
        padding-top: max(0.75rem, env(safe-area-inset-top)) !important;
    }
}

/* FINAL FIX v5: Absolute Toggle & Ellipsis */

@media (max-width: 768px) {

    /* 1. Project Grid & Text Overflow */
    .projects-grid {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 12px !important;
        width: 100% !important;
        padding: 0 !important;
    }

    .project-card {
        width: 100% !important;
        margin: 0 !important;
        min-height: 140px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        background: var(--surface-color) !important;
    }

    .project-name {
        /* "overflow ellipsis y listo" usually implies single line, but 2 lines is better for mobile. */
        /* Let's try 2 lines with strict overflow hidden */
        display: -webkit-box !important;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        /* Ensure it respects width */
        width: 100%;
        max-width: 100%;
        word-break: break-word;
        /* handle long words */
        font-size: 0.95rem !important;
        line-height: 1.3;
    }

    /* 2. Absolute Toggle Logic (Robust Docking) */
    .bottom-nav-wrapper {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        width: 100% !important;
        z-index: 10000 !important;
        /* Wrapper only contributes height of its static content (the NAV) */
        background: transparent !important;
        pointer-events: none;
        /* Let clicks pass through if wrapper has gaps? No, nav has pointer-events: auto */

        transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
        transform: translateY(0);

        /* Remove flex */
        display: block !important;
    }

    .bottom-nav-wrapper.collapsed {
        /* Move the entire wrapper (Nav) down out of view */
        transform: translateY(100%) !important;
    }

    .nav-toggle-btn {
        /* Absolute position ABOVE the wrapper's content box (the nav) */
        position: absolute !important;
        top: -34px !important;
        /* Height 32px + 2px border overlap allowance */
        left: 50% !important;
        transform: translateX(-50%) !important;

        width: 80px !important;
        height: 34px !important;

        background: rgba(15, 21, 34, 0.98) !important;
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);

        border: 1px solid rgba(255, 255, 255, 0.15);
        border-bottom: none !important;
        /* Visual merge */
        border-radius: 12px 12px 0 0 !important;

        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        pointer-events: auto !important;
        z-index: 10001 !important;

        color: var(--accent-color);
        box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.1);
    }

    .bottom-nav {
        /* Nav sits in normal flow inside wrapper, defining wrapper height */
        position: relative !important;
        pointer-events: auto !important;
        background: rgba(15, 21, 34, 0.98) !important;
        border-top: 1px solid rgba(255, 255, 255, 0.15);
        padding-bottom: max(1rem, env(safe-area-inset-bottom)) !important;
        z-index: 10000 !important;
    }
}

/* FINAL CONSOLIDATED MOBILE FIXES v6 */

/* Force hide deskop/other elements first to be sure */
.bottom-nav-wrapper {
    display: none;
    /* Hidden by default on desktop */
}

@media (max-width: 768px) {

    /* --- 1. Mobile Visibility --- */
    .bottom-nav-wrapper {
        display: block !important;
    }

    /* --- 2. Project Grid & Overflow --- */
    .projects-grid {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 12px !important;
        width: 100% !important;
        padding: 0 !important;
    }

    .project-card {
        width: 100% !important;
        min-height: 140px;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        /* Align top */
        overflow: hidden;
        /* Contain overflow */
    }

    /* Project Name */
    .project-name {
        display: -webkit-box !important;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        width: 100%;
        margin-bottom: 8px;
        font-size: 0.95rem !important;
        line-height: 1.3;
    }

    /* Project ID - This was missing! */
    .project-id {
        display: block !important;
        width: 100%;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
        /* Force single line */
        font-size: 0.75rem !important;
        opacity: 0.7;
    }

    /* --- 3. Robust Toggle Logic --- */
    /* 
       Problem: Button floats.
       Cause: translateY(100%) moves wrapper down properly, but maybe wrapper height is weird.
       Solution: Use strict fixed positioning for BOTH states.
    */

    .bottom-nav-wrapper {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        width: 100% !important;
        z-index: 99999 !important;
        transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
        transform: translateY(0);

        /* Ensure wrapper has height of content */
        height: auto !important;
        pointer-events: none;
        /* Let clicks pass beside toggle */
    }

    .bottom-nav-wrapper.collapsed {
        /* Move completely off screen */
        transform: translateY(100%) !important;
    }

    /* The Button - Anchored to the wrapper top */
    .nav-toggle-btn {
        position: absolute !important;
        /* Position it sticking out of the top of the wrapper */
        top: -34px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;

        /* Dimensions */
        width: 60px !important;
        height: 34px !important;

        /* Styles */
        background: rgba(15, 21, 34, 0.95) !important;
        border: 1px solid rgba(255, 255, 255, 0.15);
        border-bottom: none !important;
        border-radius: 12px 12px 0 0 !important;

        pointer-events: auto !important;
        cursor: pointer;
        z-index: 100000 !important;
    }

    /* When collapsed, since wrapper is down 100%, the top edge of wrapper is at viewport bottom.
       The button is at top: -34px (34px ABOVE viewport bottom). Perfect. 
       If it was floating, maybe previous styles interfered. 
       We use !important to override everything.
    */

    .bottom-nav {
        pointer-events: auto !important;
        position: relative !important;
        background: rgba(15, 21, 34, 0.95) !important;
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
        border-top: 1px solid rgba(255, 255, 255, 0.15);
    }
}

/* FINAL MOBILE FIXES v7 - Flex Drawer & Strict Overflow */

@media (max-width: 768px) {
    /* --- 1. Robust Toggle Logic (Flexbox Approach) --- */
    /* 
       Architecture: 
       Wrapper (Fixed Bottom)
       Pro: Button (32px)
       Pro: Nav (Auto)
       
       State Open: translateY(0)
       State Closed: translateY(calc(100% - 32px)) -> Leaves only button visible.
    */

    .bottom-nav-wrapper {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;

        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        width: 100% !important;
        z-index: 10000 !important;

        /* Reset any height/bg constraints */
        height: auto !important;
        background: transparent !important;
        pointer-events: none;
        /* Let clicks pass outside */

        transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
        transform: translateY(0);

        /* Ensure it sits on top of everything */
        will-change: transform;
    }

    .bottom-nav-wrapper.collapsed {
        /* Move down, leaving only the top 34px (button + border) visible */
        transform: translateY(calc(100% - 34px)) !important;
    }

    .nav-toggle-btn {
        /* Static positioning within flex column - NO absolute */
        position: relative !important;
        top: auto !important;
        left: auto !important;
        transform: none !important;
        display: flex !important;

        width: 80px !important;
        height: 34px !important;
        /* Fixed height for calculation */
        flex-shrink: 0 !important;

        background: rgba(15, 21, 34, 0.95) !important;
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);

        border: 1px solid rgba(255, 255, 255, 0.15);
        border-bottom: none !important;
        /* Merges with nav below */
        border-radius: 12px 12px 0 0 !important;

        align-items: center;
        justify-content: center;
        cursor: pointer;
        pointer-events: auto !important;
        z-index: 2;

        margin-bottom: -1px !important;
        /* Overlap border */
        color: var(--accent-color);
    }

    .bottom-nav {
        /* Static positioning within flex column */
        position: relative !important;
        width: 100% !important;
        flex-shrink: 0 !important;

        background: rgba(15, 21, 34, 0.95) !important;
        border-top: 1px solid rgba(255, 255, 255, 0.15);
        padding-bottom: max(1rem, env(safe-area-inset-bottom)) !important;

        pointer-events: auto !important;
        z-index: 1;
    }

    /* --- 2. Project Grid & Overflow Fix --- */
    .projects-grid {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        /* Strict 2 columns */
        gap: 12px !important;
        width: 100% !important;
        padding: 0 !important;
    }

    .project-card {
        width: 100% !important;
        overflow: hidden !important;
        /* Crucial for text-overflow to work */
        min-height: 140px;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        background: var(--surface-color) !important;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06) !important;
    }

    .project-card>* {
        min-width: 0;
        /* Flexbox child overflow fix */
    }

    .project-name {
        display: -webkit-box !important;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        width: 100%;
        font-size: 0.9rem !important;
        line-height: 1.3;
        margin-bottom: auto;
        /* Push ID to bottom? No, let spacing handle it */
    }

    .project-id-wrapper {
        /* Optional wrapper if structure allows, otherwise target ID directly */
    }

    .project-id {
        display: block !important;
        width: 100% !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        font-size: 0.75rem !important;
        opacity: 0.7;
        margin-top: 8px;
    }
}

/* FINAL FIX v8 - User Override for Toggle */

@media (max-width: 768px) {

    /* 1. Toggle Button Logic - User Suggested */
    /* 1. Toggle Button Logic - User Suggested */
    /* The button needs to move down significantly when collapsed */
    .nav-toggle-btn.collapsed-state {
        transform: translateY(250%) !important;
    }

    /* Ensure basic toggle styling is correct */
    .nav-toggle-btn {
        transition: transform 0.3s ease;
        /* Keep other styles safe */
    }

    /* 2. Project Grid & Overflow (Re-applying for safety) */
    .projects-grid {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 12px !important;
        width: 100% !important;
        padding: 0 !important;
    }

    .project-card {
        width: 100% !important;
        min-height: 140px;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        overflow: hidden !important;
    }

    .project-card>* {
        min-width: 0;
    }

    .project-name {
        display: -webkit-box !important;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        width: 100%;
        font-size: 0.95rem !important;
    }

    .project-id {
        display: block !important;
        width: 100% !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        font-size: 0.75rem !important;
        opacity: 0.7;
    }
}

/* FILTERS BAR (NEW RESPONSIVE) */
.filters-bar {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    padding: 1rem;
    border-radius: var(--radius-lg);
    margin-bottom: 2rem;
}

.filters-mobile-header {
    display: none;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}

.filters-mobile-header span {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
}

.filters-content {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
    width: 100%;
}

.filter-dates-row {
    display: flex;
    gap: 1rem;
}

.filter-label {
    font-size: 0.8rem;
    margin-bottom: 0.25rem;
    display: block;
    color: var(--text-secondary);
}

.mb-0 {
    margin-bottom: 0 !important;
}

.filters-bar .period-selector {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
    margin-left: 0.5rem;
}

.filter-actions-row {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex: 1;
}

.api-selector-group {
    margin-left: auto;
    min-width: 200px;
}

@media (max-width: 768px) {
    .filters-bar {
        padding: 1rem;
    }

    .filters-mobile-header {
        display: flex;
    }

    .filters-content {
        display: none;
        /* Collapsed by default */
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
        margin-top: 0;
    }

    .filters-content.show {
        display: flex;
        margin-top: 1rem;
        padding-top: 1rem;
        border-top: 1px solid var(--border-color);
        animation: slideDown 0.3s ease-out;
    }

    .filter-dates-row {
        gap: 0.5rem;
    }

    .filter-dates-row .form-group {
        flex: 1;
    }

    .filters-bar .period-selector {
        margin-left: 0;
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        /* 3 buttons per row */
        gap: 0.5rem;
        margin-bottom: 0;
    }

    .call-filter-btn.period-btn {
        width: 100%;
        text-align: center;
        padding: 0.6rem 0.2rem;
        font-size: 0.75rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .filter-actions-row {
        flex-direction: column;
        /* Stack apply and api select */
        align-items: stretch;
        gap: 1rem;
    }

    .api-selector-group {
        width: 100%;
        margin-left: 0;
    }

    .api-selector-group select {
        width: 100%;
    }

    .btn-apply {
        width: 100%;
    }

    /* Chevron rotation */
    .filters-mobile-header .btn-icon svg {
        transition: transform 0.3s;
    }

    .filters-mobile-header.open .btn-icon svg {
        transform: rotate(180deg);
    }
}

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

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