:root {
    --primary: #003087;
    /* Professional Dark Blue */
    --primary-light: #e5edff;
    --primary-dark: #002266;
    --bg-main: #f8fafc;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --white: #ffffff;
    --up: #22c55e;
    --down: #ef4444;
}

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

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

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 1rem;
    gap: 0.75rem;
    overflow: hidden;
}

.main-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 0.75rem;
    min-height: 0;
}

/* Header Section */
.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--white);
    padding: 0.5rem 1.25rem;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-logos {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding-right: 1.5rem;
    border-right: 2px solid var(--primary-light);
    perspective: 1000px;
    /* Base for 3D */
}

.partner-logo {
    width: auto;
    object-fit: contain;
    /* 3D Base State */
    transform: rotateX(5deg) rotateY(-5deg);
    /* Remove white first, THEN apply shadow to the shape */
    filter: url(#remove-white) drop-shadow(5px 5px 10px rgba(0, 0, 0, 0.15)) contrast(1.1);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform-style: preserve-3d;
}

.logo-roca {
    height: 75px;
}

.logo-vendedor {
    height: 110px;
}

.partner-logo:hover {
    transform: rotateX(0deg) rotateY(0deg) scale(1.1) translateZ(30px);
    filter: url(#remove-white) drop-shadow(15px 15px 25px rgba(0, 0, 0, 0.2)) contrast(1.1);
}

/* Header Section Integrated Layout */
.header-left h1 {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--primary);
    margin-left: 1rem;
    white-space: nowrap;
    letter-spacing: -0.03em;
    display: flex;
    flex-direction: column;
    justify-content: center;
    line-height: 1.1;
    position: relative;
}

.header-left h1::before {
    content: 'BI PERFORMANCE';
    font-size: 0.65rem;
    letter-spacing: 0.25em;
    color: var(--text-muted);
    font-weight: 700;
    margin-bottom: 2px;
    opacity: 0.8;
}

.header-left h1 span {
    background: linear-gradient(135deg, var(--primary) 0%, #1e40af 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: inline-block;
}

.network-badge {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    background: rgba(0, 48, 135, 0.05);
    padding: 0.6rem 1.75rem;
    border-radius: 50px;
    border: 1px solid rgba(0, 48, 135, 0.1);
    color: var(--primary);
    font-weight: 700;
    font-size: 1.1rem;
    margin-right: 1.5rem;
    transition: all 0.3s ease;
}

.network-badge:hover {
    background: rgba(0, 48, 135, 0.08);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.network-logo {
    height: 42px;
    width: auto;
    object-fit: contain;
    filter: url(#remove-white) drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.header-right {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 1.5rem;
}

.trend-summary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-right: 1px solid var(--border);
    padding-right: 1.5rem;
}

.summary-item {
    padding: 0.25rem 0.6rem;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
    border: 2px solid transparent;
}

.summary-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.summary-item.active {
    border-color: currentColor;
    box-shadow: 0 0 0 2px var(--white), 0 0 0 4px currentColor;
    transform: scale(1.05);
}

.counts-group {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.filter-summary {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding-left: 0.5rem;
}

.summary-counts {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    min-width: 120px;
}

.counts-row {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    white-space: nowrap;
}

.record-count {
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 500;
}

.product-count {
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 600;
    opacity: 0.8;
}

/* Filter Bar */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--white);
    padding: 0.4rem 1rem;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    position: relative;
    z-index: 1001;
    /* Higher than sticky table header (100) */
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-right: 1rem;
    border-right: 1px solid var(--border);
    color: var(--text-muted);
}

.custom-select {
    position: relative;
    width: 280px;
    z-index: 100;
}

.select-trigger {
    background: #fff;
    border: 1px solid var(--border);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    transition: all 0.2s;
    min-height: 40px;
}

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

.select-trigger.disabled {
    background: #f1f5f9;
    cursor: not-allowed;
    opacity: 0.6;
}

.select-dropdown {
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    width: auto;
    min-width: 400px;
    /* wider for long store names */
    max-width: 600px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    display: none;
    overflow: hidden;
    z-index: 1000;
}

.select-dropdown.show {
    display: block;
    animation: slideDown 0.2s ease-out;
}

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

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

.select-search-container {
    padding: 10px;
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
}

.select-search-container input {
    width: 100%;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
    outline: none;
    transition: all 0.2s;
}

.select-search-container input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.select-options {
    max-height: 250px;
    overflow-y: auto;
}

.select-option {
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s;
    color: var(--text-dark);
}

.select-option:hover {
    background: #f1f5f9;
    color: var(--primary);
}

.select-option.selected {
    background: #eef2ff;
    color: var(--primary);
    font-weight: 600;
}

.select-option.no-results {
    color: var(--text-muted);
    text-align: center;
    padding: 2rem 1rem;
    cursor: default;
}

select,
.search-input {
    border: 1px solid var(--border);
    padding: 0.4rem 0.75rem;
    border-radius: 8px;
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s;
}

select:focus,
.search-input:focus {
    border-color: var(--primary);
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.45rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: opacity 0.2s;
}

.btn-primary:active {
    transform: translateY(1px);
}

.divider {
    color: var(--border);
}

.search-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    position: relative;
}

.search-input-wrapper {
    position: relative;
    width: 100%;
}

.search-input-wrapper .select-dropdown {
    width: 100%;
    min-width: 300px;
    max-height: 300px;
    top: calc(100% + 2px);
}

.filter-modes {
    display: flex;
    gap: 0.5rem;
}

.mode-btn {
    background: #f1f5f9;
    border: 1px solid var(--border);
    padding: 0.2rem 0.6rem;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.mode-btn:hover {
    background: #e2e8f0;
}

.mode-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Table View */
.table-container {
    flex: 1;
    background: var(--white);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.table-wrapper {
    flex: 1;
    overflow: auto;
    width: 100%;
}

.trend-header {
    background: #fdfdfd;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-muted);
}

.data-table {
    width: 100%;
    min-width: 1400px;
    border-collapse: separate;
    border-spacing: 0;
}

.data-table thead {
    position: sticky;
    top: 0;
    background: #f1f5f9;
    z-index: 100;
}

.data-table th {
    text-align: left;
    padding: 0.75rem 1rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    transition: background 0.2s, color 0.2s;
    user-select: none;
    position: relative;
    white-space: nowrap;
}

.data-table th[data-sort]:hover {
    background: var(--primary-light) !important;
    color: var(--primary);
}

.data-table th i {
    font-size: 0.8rem;
    margin-left: 0.25rem;
    transition: opacity 0.2s;
}

.data-table th.sorted {
    background: var(--primary-light) !important;
    color: var(--primary);
}

.data-table th.sorted i {
    opacity: 1 !important;
}

/* ph-caret-down */

.data-table tbody {
    width: 100%;
}

.data-table tr {
    width: 100%;
}

.data-table td {
    padding: 0.5rem 0.8rem;
    font-size: 0.8rem;
    border-bottom: 1px solid var(--border);
    word-break: break-word;
}

.data-table tbody tr {
    border-bottom: 1px solid var(--border);
    /* Changed from --border-color to --border to match existing variables */
    transition: background-color 0.2s;
    cursor: pointer;
}

.data-table tbody tr:hover {
    background-color: #fbfcfe;
    /* Kept original hover color, or use var(--bg-color) if defined */
}

.data-table tbody tr.selected-row {
    background-color: #e3f2fd !important;
    /* Soft blue */
    border-left: 4px solid var(--primary) !important;
    /* Changed from --primary-color to --primary to match existing variables */
}

/* Badges */
.trend-badge {
    padding: 0.2rem 0.6rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.trend-up {
    background: #dcfce7;
    color: #166534;
}

.trend-down {
    background: #fee2e2;
    color: #991b1b;
}

.trend-stable {
    background: #f1f5f9;
    color: #475569;
}

/* Loading State */
.loading-state {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--white);
    padding: 1rem 2rem;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 1rem;
    z-index: 100;
}

.loading-state i {
    color: var(--primary);
    font-size: 1.5rem;
}

.hidden {
    display: none;
}

/* Navigation Tabs - Integrated into Header */
.nav-tabs.mini-nav {
    display: flex;
    gap: 0.25rem;
    background: #f1f5f9;
    padding: 3px;
    border-radius: 10px;
}

.nav-tabs.mini-nav .nav-tab {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.8rem;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 7px;
    cursor: pointer;
    transition: all 0.2s;
}

.nav-tabs.mini-nav .nav-tab i {
    font-size: 1rem;
}

.nav-tabs.mini-nav .nav-tab:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--primary);
}

.nav-tabs.mini-nav .nav-tab.active {
    background: var(--white);
    color: var(--primary);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Ranking Section */
.ranking-container {
    padding: 1rem;
    background: var(--white);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    overflow-y: auto !important;
}

.ranking-header {
    margin-bottom: 2rem;
}

.ranking-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
}

.ranking-header p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.ranking-grid {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-width: 1000px;
    /* Centered narrow stack for better readability */
    margin: 0 auto;
}

.ranking-card {
    background: #fdfdfe;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.ranking-card h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px dashed var(--border);
}

.ranking-card h3 i {
    color: var(--down);
}

.ranking-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.ranking-item {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.ranking-item-info {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    font-size: 0.9rem;
    font-weight: 500;
    gap: 1rem;
}

.ranking-item-name {
    color: var(--text-main);
    white-space: normal;
    /* Allow text wrapping */
    overflow: visible;
    text-overflow: clip;
    flex: 1;
    line-height: 1.4;
}

.ranking-item.selected {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid var(--down);
    border-radius: 8px;
    padding: 0.6rem;
    margin: -0.2rem -0.4rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.ranking-item.selected .ranking-item-name {
    font-weight: 700;
}

.ranking-item-count {
    color: var(--down);
    font-weight: 700;
    margin-left: 0.5rem;
}

.ranking-bar-container {
    height: 6px;
    background: #f1f5f9;
    border-radius: 3px;
    overflow: hidden;
}

.ranking-bar-fill {
    height: 100%;
    background: var(--down);
    border-radius: 3px;
    transition: width 0.6s ease-out;
}

.loading-ranking {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem;
    color: var(--text-muted);
    gap: 1rem;
}

/* Nested Detail Table */
.detail-row {
    background: #f8fafc;
}

.detail-row td {
    padding: 0 !important;
}

.detail-container {
    padding: 1rem 2rem 1.5rem 4rem;
    border-left: 4px solid var(--primary);
    background: white;
    margin: 0.5rem 1rem 1rem 1rem;
    border-radius: 8px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
}

.detail-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nested-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.nested-table th {
    text-align: left;
    padding: 0.5rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
    font-weight: 500;
}

.nested-table td {
    padding: 0.6rem 0.5rem;
    border-bottom: 1px solid #f1f5f9;
}

.nested-table tr:last-child td {
    border-bottom: none;
}

.nested-trend-badge {
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
}

.row-expanded {
    background: #f1f5f9 !important;
    border-bottom: none !important;
}

.row-expanded td {
    font-weight: 600;
}