:root {
    /* V4 Company Colors */
    --v4-red: #E60000;
    --v4-red-hover: #CC0000;
    --v4-red-glow: rgba(230, 0, 0, 0.4);

    --bg-dark: #050505;
    /* Almost true black */
    --bg-panel: #111111;
    /* Dark gray for cards */
    --bg-panel-hover: #1a1a1a;
    --border-color: #222222;
    --border-highlight: #333333;

    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --text-muted: #666666;

    /* System Accents for statuses (adapted to fit with red) */
    --accent-red: var(--v4-red);
    --accent-green: #00E676;
    /* Bright neon green for contrast */
    --accent-green-glow: rgba(0, 230, 118, 0.3);
    --accent-blue: #2979FF;
    /* Keeping a blue for some specific badges if needed */
    --accent-orange: #FF9100;
    --accent-purple: #D500F9;

    --font-heading: 'Montserrat', sans-serif;
    --font-body: 'Inter', sans-serif;

    --transition: all 0.2s ease-in-out;
}

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

body {
    font-family: var(--font-body);
    background-color: var(--bg-dark);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    /* High contrast dark background with very subtle red glow in the center */
    background-image: radial-gradient(circle at 50% -20%, rgba(230, 0, 0, 0.05) 0%, transparent 60%);
    display: flex;
    flex-direction: column;
}

/* Utilities */
.glass {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    /* Sharper corners for V4 */
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.flex-1 {
    flex: 1;
}

.flex-2 {
    flex: 2;
}

.mt-4 {
    margin-top: 1.5rem;
}

/* Top Navigation */
.top-nav {
    height: 70px;
    background: #0A0A0A;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 3rem;
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 32px;
    height: 32px;
    background: var(--v4-red);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 10px var(--v4-red-glow);
}

.logo-icon::after {
    content: "V4";
    color: white;
    font-family: var(--font-heading);
    font-weight: 800;
    font-style: italic;
    font-size: 14px;
    letter-spacing: -1px;
}

.logo h2 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    text-transform: uppercase;
}

.logo span {
    color: var(--v4-red);
}

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

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 4px;
    background: #1A1A1A;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-family: var(--font-heading);
    color: white;
    border: 1px solid var(--border-highlight);
}

.user-info h4 {
    font-size: 0.95rem;
    font-weight: 600;
}

/* Layout */
.app-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 2rem 3rem;
    overflow: hidden;
}

/* Header */
.top-header {
    margin-bottom: 1.5rem;
    animation: fadeInDown 0.6s ease forwards;
}

.header-title h1 {
    font-family: var(--font-heading);
    font-size: 2.2rem;
    font-weight: 800;
    letter-spacing: -1px;
    margin-bottom: 4px;
    text-transform: uppercase;
}

.header-title p {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Analytics Row */
.analytics-row {
    display: flex;
    gap: 1.5rem;
    animation: fadeInUp 0.6s ease backwards;
    animation-delay: 0.1s;
}

/* KPI Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
    flex: 2;
}

.kpi-card {
    padding: 1.5rem;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    transition: var(--transition);
    border-left: 3px solid transparent;
}

.kpi-card:hover {
    transform: translateY(-3px);
    background: var(--bg-panel-hover);
    border-left-color: var(--v4-red);
}

.kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
    background: #1A1A1A;
}

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

.highlight-green {
    color: var(--accent-green);
}

.highlight-purple {
    color: var(--accent-purple);
}

.highlight-orange {
    color: var(--accent-orange);
}

.kpi-info h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 4px;
}

.kpi-value {
    font-family: var(--font-heading);
    font-size: 2.2rem;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 8px;
}

.trend {
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: 500;
}

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

.trend.neutral {
    color: var(--text-muted);
}

/* Distribution Insight Card */
.insight-card {
    padding: 1.5rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.section-header-small h3 {
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-family: var(--font-heading);
    margin-bottom: 1.5rem;
    font-weight: 700;
}

.distribution-bars {
    display: flex;
    flex-direction: column;
    gap: 14px;
    flex: 1;
    justify-content: flex-start;
    overflow-y: auto;
    /* max-height: 250px; */
    padding-right: 8px;
}

.distribution-bars::-webkit-scrollbar {
    width: 4px;
}

.distribution-bars::-webkit-scrollbar-track {
    background: #111;
}

.distribution-bars::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 4px;
}

.dist-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.dist-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.dist-label span:last-child {
    font-weight: 700;
    color: var(--text-primary);
}

.progress-bar {
    width: 100%;
    height: 4px;
    background: #222;
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 1s ease-out;
}

/* Header Actions / Filters */
.header-actions-table {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
    width: 100%;
}

.search-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #0A0A0A;
    border: 1px solid var(--border-color);
    padding: 10px 16px;
    border-radius: 6px;
    min-width: 300px;
    height: 55px;
    transition: var(--transition);
}

.search-bar:focus-within {
    border-color: var(--v4-red);
}

.search-bar i {
    color: var(--text-secondary);
}

.search-bar input {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-body);
    width: 100%;
    outline: none;
    height: 55px;
}

.search-bar input::placeholder {
    color: var(--text-muted);
}

.filter-group {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.checkbox-filter {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #0A0A0A;
    border: 1px solid var(--border-color);
    padding: 10px 16px;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
    height: 55px;
}

.checkbox-filter:hover {
    border-color: var(--text-secondary);
}

.checkbox-filter label {
    font-size: 0.9rem;
    color: var(--text-primary);
    cursor: pointer;
    font-weight: 500;
}

.checkbox-filter input[type="checkbox"] {
    accent-color: var(--v4-red);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.glass-select {
    background: #0A0A0A;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 10px 16px;
    border-radius: 6px;
    font-family: var(--font-body);
    font-weight: 500;
    font-size: 16px;
    /* Fix for iOS/Safari tiny text and auto-zoom */
    outline: none;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%239494a0%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 12px top 50%;
    background-size: 10px auto;
    padding-right: 32px;
    height: 55px;
    transition: var(--transition);
}

.glass-select:focus,
.glass-select:hover {
    border-color: var(--text-secondary);
}

.glass-select option {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-size: 16px;
    padding: 12px;
}

.kpi-mini {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    margin-left: auto;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.kpi-mini span {
    color: white;
    font-weight: 800;
    font-size: 1.1rem;
}

/* Dashboard Body */
.dashboard-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    animation: fadeInUp 0.6s ease backwards;
    animation-delay: 0.3s;
}

.section-header {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 1rem;
}

/* Table */
.data-section {
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.table-container {
    overflow-y: auto;
    flex: 1;
    padding-right: 8px;
}

.table-container::-webkit-scrollbar {
    width: 6px;
}

.table-container::-webkit-scrollbar-track {
    background: #111;
    border-radius: 10px;
}

.table-container::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 10px;
}

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

th {
    text-align: left;
    padding: 12px 16px;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    position: sticky;
    top: 0;
    background: var(--bg-panel);
    z-index: 2;
    border-bottom: 1px solid var(--border-color);
}

td {
    padding: 16px;
    background: transparent;
    font-size: 0.9rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

tbody tr {
    transition: var(--transition);
}

tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.badge {
    min-width: 180px;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
    display: inline-block;
}

.badge.cat-Indústria {
    background: rgba(230, 0, 0, 0.1);
    color: var(--v4-red);
    border: 1px solid rgba(230, 0, 0, 0.3);
}

.badge.cat-Tecnologia {
    background: rgba(255, 145, 0, 0.1);
    color: var(--accent-orange);
    border: 1px solid rgba(255, 145, 0, 0.3);
}

.badge.cat-Agro {
    background: rgba(0, 230, 118, 0.1);
    color: var(--accent-green);
    border: 1px solid rgba(0, 230, 118, 0.3);
}

.badge.cat-Concessionárias {
    background: rgba(41, 121, 255, 0.1);
    color: var(--accent-blue);
    border: 1px solid rgba(41, 121, 255, 0.3);
}

.badge.cat-Outros {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.badge.cat-Varejo {
    background: #1A1A1A;
    color: #555;
    border: 1px solid #333;
}

/* Score Bar */
.score-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.score-value {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1.1rem;
    width: 35px;
}

.score-bar-bg {
    width: 100px;
    height: 4px;
    background: #222;
    border-radius: 2px;
    overflow: hidden;
}

.score-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 1s ease-out;
}

.score-high {
    color: var(--accent-green);
}

.score-high .score-fill {
    background: var(--accent-green);
    box-shadow: 0 0 8px var(--accent-green-glow);
}

.score-medium {
    color: var(--accent-orange);
}

.score-medium .score-fill {
    background: var(--accent-orange);
}

.score-low {
    color: var(--text-muted);
}

.score-low .score-fill {
    background: #444;
}

.action-btn {
    background: #1A1A1A;
    color: var(--text-secondary);
    border: 1px solid #333;
    cursor: pointer;
    font-size: 1.1rem;
    border-radius: 4px;
    padding: 6px;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-btn:hover {
    color: white;
    background: var(--v4-red);
    border-color: var(--v4-red);
}

a.site-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 4px;
}

a.site-link:hover {
    color: var(--v4-red);
}

/* Animations */
@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

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

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

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

/* Sidebar Styles */
.sidebar {
    position: fixed;
    top: 0;
    right: -500px;
    width: 500px;
    height: 100vh;
    background: var(--bg-panel);
    border-left: 1px solid var(--border-color);
    box-shadow: -5px 0 25px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    transition: right 0.3s ease-in-out;
    display: flex;
    flex-direction: column;
}

.sidebar.open {
    right: 0;
}

.sidebar-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    font-family: var(--font-heading);
    font-size: 1rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 80%;
}

.sidebar-content {
    padding: 24px;
    flex: 1;
    overflow-y: auto;
}

.form-group {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.checkbox-group {
    flex-direction: row;
    align-items: center;
    gap: 12px;
}

.checkbox-group input[type="checkbox"] {
    accent-color: var(--v4-red);
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.checkbox-group label {
    color: var(--text-primary);
    margin: 0;
    cursor: pointer;
}

.full-width {
    width: 100%;
}

.glass-input {
    background: #0A0A0A;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 12px;
    border-radius: 6px;
    font-family: var(--font-body);
    outline: none;
    resize: vertical;
    transition: var(--transition);
}

.glass-input:focus {
    border-color: var(--text-secondary);
}

.save-btn {
    width: 100%;
    background: var(--v4-red);
    color: white;
    border: none;
    padding: 14px;
    border-radius: 6px;
    font-weight: 700;
    font-family: var(--font-heading);
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
    transition: var(--transition);
    margin-top: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.save-btn:hover {
    background: var(--v4-red-hover);
    box-shadow: 0 0 15px var(--v4-red-glow);
}

.save-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* Mobile Responsive Adjustments */
@media (max-width: 768px) {
    body {
        overflow: auto;
    }

    #clearFiltersBtn {
        width: 100%;
        margin-bottom: 20px;
    }

    .app-container {
        overflow: visible;
        flex-direction: column;
    }

    .main-content {
        padding: 1rem;
        overflow: visible;
    }

    .top-nav {
        padding: 1rem;
    }

    .top-header h1 {
        font-size: 1.5rem;
    }

    .analytics-row {
        flex-direction: column;
    }

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

    .header-actions-table {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-group {
        width: 100%;
        display: flex;
        flex-direction: column;
    }

    .search-bar,
    .glass-select,
    .checkbox-filter {
        width: 100%;
        min-width: 100%;
    }

    .table-container {
        overflow: visible;
    }

    /* Convert Table to Cards */
    table,
    thead,
    tbody,
    th,
    td,
    tr {
        display: block;
    }

    thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    tbody tr {
        /* background: var(--bg-panel); */
        background: #202020;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        margin-bottom: 1.5rem;
        padding: 0.5rem;
    }

    td {
        display: flex;
        justify-content: flex-end;
        align-items: center;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        padding: 10px 8px 10px 45%;
        text-align: right;
        position: relative;
        min-height: 44px;
        word-break: break-word;
    }

    td::before {
        content: attr(data-label);
        position: absolute;
        left: 8px;
        top: 50%;
        transform: translateY(-50%);
        width: 40%;
        font-size: 0.75rem;
        text-transform: uppercase;
        font-weight: 700;
        color: var(--text-secondary);
        text-align: left;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    td:last-child {
        border-bottom: none;
    }

    /* Stack Empresa info */
    td[data-label="Empresa"] {
        flex-direction: column;
        align-items: flex-start;
        text-align: left;
        padding: 12px 8px;
    }

    td[data-label="Empresa"]::before {
        position: static;
        transform: none;
        width: 100%;
        margin-bottom: 6px;
    }

    td[data-label="Categoria"] {
        flex-direction: column;
        align-items: flex-start;
        text-align: left;
        padding: 12px 8px;
    }

    td[data-label="Categoria"]::before {
        position: static;
        transform: none;
        width: 100%;
        margin-bottom: 6px;
    }

    td[data-label="Localização"] {
        flex-direction: column;
        align-items: flex-start;
        text-align: left;
        padding: 12px 8px;
    }

    td[data-label="Localização"]::before {
        position: static;
        transform: none;
        width: 100%;
        margin-bottom: 6px;
    }

    td[data-label="Owner"] {
        flex-direction: column;
        align-items: flex-start;
        text-align: left;
        padding: 12px 8px;
    }

    td[data-label="Owner"]::before {
        position: static;
        transform: none;
        width: 100%;
        margin-bottom: 6px;
    }

    .score-container {
        justify-content: flex-end;
        width: 150px;
    }

    .sidebar {
        width: 100%;
        right: -100%;
    }
}

/* Clear Filters Button */
.clear-filters-btn {
    background: rgba(220, 38, 38, 0.1);
    color: var(--v4-red);
    border: 1px solid rgba(220, 38, 38, 0.2);
    padding: 10px 16px;
    height: 55px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: var(--transition);
}

.clear-filters-btn:hover {
    background: var(--v4-red);
    color: white;
    transform: translateY(-2px);
}

/* Back To Top Button */
.back-to-top-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--v4-red);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
}

.back-to-top-btn.show {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.back-to-top-btn:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 16px rgba(220, 38, 38, 0.4);
    background: #ef4444;
}

/* Accordion Toggle */
.accordion-header {
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
}
.accordion-icon {
    font-size: 1.2rem;
    color: var(--text-secondary);
    transition: transform 0.3s ease;
}
.accordion-card.collapsed .accordion-icon {
    transform: rotate(180deg);
}
.accordion-content {
    transition: max-height 0.4s ease, opacity 0.4s ease, margin-top 0.4s ease;
    max-height: 800px;
    opacity: 1;
    overflow: hidden;
    margin-top: 16px;
}
.accordion-card.collapsed .accordion-content {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
    pointer-events: none;
}


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