/* Microsegment Analysis Styles */

.microsegment-container {
    padding: 20px;
    background: #f8f9fa;
    min-height: calc(100vh - 60px);
}

/* Page Header */
.page-header {
    background: white;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
}

.page-title {
    font-size: 28px;
    font-weight: 600;
    color: #1a1a1a;
    margin: 0;
}

.page-subtitle {
    color: #6c757d;
    margin: 8px 0 0 0;
    font-size: 14px;
}

/* Stats Cards */
.stats-cards {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.stat-card {
    background: white;
    border-radius: 8px;
    padding: 14px 20px;
    min-width: 110px;
    text-align: center;
    border: 2px solid transparent;
    transition: all 0.3s ease;
}

.stat-card.chargeoff-stat {
    border-color: #ef4444;
    background: linear-gradient(135deg, #ef444410 0%, #ef444405 100%);
}

.stat-card.rollrate-stat {
    border-color: #f59e0b;
    background: linear-gradient(135deg, #f59e0b10 0%, #f59e0b05 100%);
}

.stat-card.yield-stat {
    border-color: #10b981;
    background: linear-gradient(135deg, #10b98110 0%, #10b98105 100%);
}

.stat-card.winrate-stat {
    border-color: #3b82f6;
    background: linear-gradient(135deg, #3b82f610 0%, #3b82f605 100%);
}

.stat-card.segments-count {
    border-color: #445082;
    background: linear-gradient(135deg, #44508210 0%, #44508205 100%);
}

.stat-card.at-risk-stat {
    border-color: #6b7280;
    background: linear-gradient(135deg, #6b728010 0%, #6b728005 100%);
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 4px;
}

.chargeoff-stat .stat-value {
    color: #ef4444;
}

.rollrate-stat .stat-value {
    color: #f59e0b;
}

.yield-stat .stat-value {
    color: #10b981;
}

.winrate-stat .stat-value {
    color: #3b82f6;
}

.segments-count .stat-value {
    color: #445082;
}

.at-risk-stat .stat-value {
    color: #6b7280;
}

.stat-label {
    font-size: 11px;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

/* Stat Tooltip Icon */
.stat-tooltip-icon {
    font-size: 10px;
    color: #9ca3af;
    cursor: help;
    transition: color 0.2s ease;
}

.stat-tooltip-icon:hover {
    color: #6b7280;
}

/* Custom tooltip styling */
.tooltip {
    font-size: 12px;
}

.tooltip-inner {
    max-width: 280px;
    text-align: left;
    padding: 10px 12px;
    background: #1f2937;
    border-radius: 8px;
}

.tooltip-inner strong {
    display: block;
    margin-bottom: 4px;
    color: #f3f4f6;
}

.tooltip-inner em {
    color: #a5b4fc;
    font-style: normal;
    font-weight: 500;
}

/* Table Header Tooltip Icons */
.th-content {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.th-tooltip-icon {
    font-size: 9px;
    color: #c9cdd4;
    cursor: help;
    transition: color 0.2s ease;
    opacity: 0.7;
}

.th-tooltip-icon:hover {
    color: #6b7280;
    opacity: 1;
}

/* Prevent tooltip icon from triggering sort */
.microsegment-table th .th-tooltip-icon {
    pointer-events: auto;
}

/* Filter Tooltip Icon */
.filter-tooltip-icon {
    font-size: 10px;
    color: #9ca3af;
    cursor: help;
    transition: color 0.2s ease;
    margin-left: 4px;
}

.filter-tooltip-icon:hover {
    color: #6b7280;
}

/* Filter Section */
.filter-section {
    background: white;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 24px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
}

/* Search Input */
.search-wrapper {
    position: relative;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #6c757d;
    font-size: 14px;
}

.search-input {
    padding-left: 36px;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    transition: all 0.3s ease;
}

.search-input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.search-input::placeholder {
    color: #6b7280;
    font-size: 14px;
}

/* Filter Dropdowns */
.form-select {
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    transition: all 0.3s ease;
    color: #6b7280;
    font-size: 14px;
}

.form-select:has(option:checked[value=""]) {
    color: #6b7280;
}

.form-select option:not([value=""]) {
    color: #212529;
}

.form-select:has(option:checked:not([value=""])) {
    color: #212529;
}

.form-select:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* At Risk Filter Checkbox */
#atRiskFilter {
    cursor: pointer;
}

#atRiskFilter:checked {
    background-color: #ef4444;
    border-color: #ef4444;
}

.form-check-label[for="atRiskFilter"] {
    cursor: pointer;
    user-select: none;
    font-weight: 500;
    font-size: 13px;
}

/* Advanced Filters Toggle */
.advanced-filter-toggle {
    color: #445082;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: color 0.3s ease;
}

.advanced-filter-toggle:hover {
    color: #354066;
}

.advanced-filter-toggle i {
    transition: transform 0.3s ease;
}

.advanced-filter-toggle[aria-expanded="true"] i.fa-chevron-down {
    transform: rotate(180deg);
}

/* Table Section */
.table-section {
    background: white;
    border-radius: 12px;
    padding: 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
    /* Use clip instead of hidden to maintain rounded corners while allowing sticky */
    overflow: clip;
}

/* Override Bootstrap's table-responsive to not break sticky header */
.table-section .table-responsive {
    overflow: visible;
}

/* Table Styles */
.microsegment-table {
    margin: 0;
    table-layout: fixed;
    width: 100%;
}

/* Sticky table header - stays visible while scrolling */
.microsegment-table thead {
    position: sticky;
    top: 0;
    z-index: 100;
    background: #f8f9fa;
    border-bottom: 2px solid #e5e7eb;
    /* Add subtle shadow when sticky to show depth */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.microsegment-table th {
    font-weight: 600;
    color: #374151;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 14px 10px;
    white-space: nowrap;
    vertical-align: middle;
    /* Solid background required for sticky header */
    background: #f8f9fa;
}

/* Column Width Distribution */
.microsegment-table .segment-col { width: 26%; }
.microsegment-table .metric-col { width: 8%; text-align: right; }
.microsegment-table .change-col { width: 6%; text-align: right; }

/* Column Grouping with Borders */
.microsegment-table th:nth-child(1) {
    background: linear-gradient(to bottom, #f8f9fa, #f3f4f6);
    border-right: 2px solid #e5e7eb;
}

.microsegment-table td:nth-child(1) {
    border-right: 2px solid #e5e7eb;
}

/* Chargeoff group */
.microsegment-table th:nth-child(3),
.microsegment-table td:nth-child(3) {
    border-right: 1px solid #e5e7eb;
}

/* Yield group */
.microsegment-table th:nth-child(5),
.microsegment-table td:nth-child(5) {
    border-right: 1px solid #e5e7eb;
}

/* Roll Rate group */
.microsegment-table th:nth-child(7),
.microsegment-table td:nth-child(7) {
    border-right: 1px solid #e5e7eb;
}

/* Win Rate group */
.microsegment-table th:nth-child(9),
.microsegment-table td:nth-child(9) {
    border-right: 1px solid #e5e7eb;
}

.microsegment-table th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background-color 0.3s ease;
}

.microsegment-table th.sortable:hover {
    background-color: #e5e7eb;
}

.sort-icon {
    margin-left: 4px;
    font-size: 10px;
    color: #9ca3af;
}

.microsegment-table th.sort-asc .sort-icon::before {
    content: "\f0de";
    color: #3b82f6;
}

.microsegment-table th.sort-desc .sort-icon::before {
    content: "\f0dd";
    color: #3b82f6;
}

.microsegment-table tbody tr {
    border-bottom: 1px solid #f3f4f6;
    transition: background-color 0.2s ease;
    cursor: pointer;
}

.microsegment-table tbody tr:hover {
    background-color: #f9fafb;
}

.microsegment-table td {
    padding: 12px 10px;
    color: #1f2937;
    font-size: 13px;
    vertical-align: middle;
}

/* At-Risk Row Indicator */
.microsegment-table tbody tr.at-risk-row {
    border-left: 3px solid #ef4444;
}

.microsegment-table tbody tr.at-risk-row td:first-child {
    padding-left: 7px;
}

/* Segment Tags */
.segment-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.segment-tag {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    font-size: 11px;
    color: #374151;
    font-weight: 500;
    white-space: nowrap;
}

.segment-tag .tag-label {
    color: #6b7280;
    margin-right: 3px;
}

.segment-tag .tag-value {
    color: #1f2937;
    font-weight: 600;
}

/* Metric Values */
.metric-value {
    font-weight: 600;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', monospace;
    font-size: 13px;
    text-align: right;
}

.metric-na {
    color: #9ca3af;
    font-style: italic;
    font-weight: 400;
}

/* Change Indicators */
.change-value {
    font-weight: 500;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', monospace;
    font-size: 12px;
    text-align: right;
}

.change-positive {
    color: #10b981;
}

.change-negative {
    color: #ef4444;
}

.change-neutral {
    color: #6b7280;
}

.change-na {
    color: #9ca3af;
    font-style: italic;
    font-weight: 400;
}

/* Pagination Section */
.pagination-section {
    padding: 20px;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
    border-radius: 0 0 12px 12px;
}

.pagination-info {
    color: #6b7280;
    font-size: 14px;
}

.pagination {
    margin: 0;
}

.pagination .page-link {
    color: #445082;
    border: 1px solid #e5e7eb;
    margin: 0 2px;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 14px;
}

.pagination .page-item.active .page-link {
    background-color: #445082;
    border-color: #445082;
}

.pagination .page-link:hover {
    background-color: #f0f2f7;
    border-color: #445082;
}

/* Export Button */
#exportBtn {
    background: #10b981;
    border: none;
    color: white;
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.3s ease;
}

#exportBtn:hover {
    background: #059669;
    transform: translateY(-1px);
}

/* Clear Filters Button */
#clearFiltersBtn {
    border-color: #d1d5db;
    color: #6b7280;
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.3s ease;
}

#clearFiltersBtn:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
    color: #374151;
}

/* Empty State */
#emptyState {
    padding: 60px 20px;
}

#emptyState i {
    opacity: 0.3;
}

#emptyState h5 {
    color: #374151;
    margin-bottom: 8px;
}

/* Loading State */
#tableLoading {
    padding: 60px 20px;
}

/* Toast */
.toast {
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Animations */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.microsegment-table tbody tr {
    animation: slideIn 0.3s ease;
}

/* Responsive Design */
@media (max-width: 768px) {
    .stats-cards {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .stat-card {
        min-width: auto;
    }

    .page-title {
        font-size: 24px;
    }

    .microsegment-table {
        font-size: 12px;
    }

    .microsegment-table th,
    .microsegment-table td {
        padding: 8px 6px;
    }

    /* Hide columns on mobile - show only Segment, Chargeoff, Originations, Yield */
    .microsegment-table th:nth-child(5), /* Yield Change */
    .microsegment-table td:nth-child(5),
    .microsegment-table th:nth-child(6), /* Roll Rate */
    .microsegment-table td:nth-child(6),
    .microsegment-table th:nth-child(7), /* Roll Change */
    .microsegment-table td:nth-child(7),
    .microsegment-table th:nth-child(8), /* Win Rate */
    .microsegment-table td:nth-child(8),
    .microsegment-table th:nth-child(9), /* Win Change */
    .microsegment-table td:nth-child(9),
    .microsegment-table th:nth-child(11), /* Orig Change */
    .microsegment-table td:nth-child(11) {
        display: none;
    }

    /* Adjust column widths for mobile */
    .microsegment-table .segment-col { width: 40%; }
    .microsegment-table .metric-col { width: 15%; }
    .microsegment-table .change-col { width: 12%; }

    .pagination-section {
        padding: 16px;
    }

    .pagination-info {
        text-align: center;
        margin-bottom: 12px;
    }

    .pagination-section .row > .col-md-4:last-child {
        text-align: center !important;
        margin-top: 12px;
    }

    /* Segment tags wrap */
    .segment-tags {
        flex-direction: column;
        gap: 2px;
    }

    .segment-tag {
        font-size: 10px;
        padding: 2px 6px;
    }
}

@media (max-width: 576px) {
    .microsegment-container {
        padding: 12px;
    }

    .page-header {
        padding: 16px;
    }

    .filter-section {
        padding: 16px;
    }

    .stat-value {
        font-size: 24px;
    }

    /* Hide even more columns on very small screens */
    .microsegment-table th:nth-child(3), /* Chargeoff Change */
    .microsegment-table td:nth-child(3),
    .microsegment-table th:nth-child(4), /* Yield */
    .microsegment-table td:nth-child(4) {
        display: none;
    }
}

/* Dimension Filter Multi-select Styling */
.dimension-filter-wrapper {
    position: relative;
}

/* Hide native multi-select by default */
#dimensionFilter {
    display: none !important;
}

.custom-dimension-select {
    position: relative;
}

.dimension-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    background: white;
    min-height: 38px;
}

.dimension-select-trigger:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.dimension-select-trigger .trigger-text {
    color: #6b7280;
    font-size: 14px;
}

.dimension-select-trigger i {
    color: #9ca3af;
    font-size: 12px;
    transition: transform 0.2s;
}

.dimension-dropdown.show + .dimension-select-trigger i,
.custom-dimension-select:focus-within .dimension-select-trigger i {
    transform: rotate(180deg);
}

/* Dimension Dropdown Styles */
.dimension-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    z-index: 1000;
    display: none;
    overflow: hidden;
}

.dimension-dropdown.show {
    display: block;
}

/* Search Input in Dropdown */
.dimension-search-wrapper {
    position: relative;
    padding: 10px;
    border-bottom: 1px solid #e5e7eb;
    background: #f9fafb;
}

.dimension-search-icon {
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    color: #9ca3af;
    font-size: 12px;
}

.dimension-search-input {
    width: 100%;
    padding: 8px 12px 8px 32px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.dimension-search-input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.dimension-search-input::placeholder {
    color: #9ca3af;
}

/* Options Container */
.dimension-options-container {
    max-height: 280px;
    overflow-y: auto;
}

/* Loading State */
.dimension-loading {
    padding: 20px;
    text-align: center;
    color: #6b7280;
    font-size: 13px;
}

/* Empty State */
.dimension-empty,
.dimension-no-results {
    padding: 20px;
    text-align: center;
    color: #9ca3af;
    font-size: 13px;
}

/* Group Headers */
.dimension-group-header {
    padding: 8px 12px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #6b7280;
    background: #f3f4f6;
    border-top: 1px solid #e5e7eb;
    position: sticky;
    top: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    z-index: 1;
}

.dimension-group-header:hover {
    background: #e5e7eb;
}

.dimension-group-header:first-child {
    border-top: none;
}

.dimension-group-header .group-select-all {
    margin: 0;
    cursor: pointer;
    flex-shrink: 0;
}

.dimension-group-header .group-select-all:checked {
    background-color: #3b82f6;
    border-color: #3b82f6;
}

/* Disabled state for large groups (100+ options) */
.dimension-group-header.large-group {
    cursor: default;
}

.dimension-group-header.large-group:hover {
    background: #f3f4f6;
}

.dimension-group-header .group-select-all:disabled {
    cursor: not-allowed;
    opacity: 0.4;
}

.dimension-group-header .large-group-warning {
    color: #f59e0b;
    font-size: 11px;
    margin-left: 4px;
    cursor: help;
}

.dimension-group-header .large-group-warning i {
    font-size: 10px;
}

.dimension-group-header .group-header-label {
    flex-grow: 1;
}

.dimension-group-header .group-count {
    font-size: 9px;
    font-weight: 600;
    color: #9ca3af;
    margin-left: auto;
}

.dimension-group-header .group-count.has-selections {
    color: #3b82f6;
    font-weight: 700;
}

/* Option Items */
.dimension-option {
    padding: 10px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.15s;
    border-bottom: 1px solid #f3f4f6;
}

.dimension-option:hover {
    background: #f9fafb;
}

.dimension-option.selected {
    background: #eff6ff;
}

.dimension-option .form-check-input {
    margin: 0;
    flex-shrink: 0;
}

.dimension-option .form-check-input:checked {
    background-color: #3b82f6;
    border-color: #3b82f6;
}

.dimension-option-label {
    color: #6b7280;
    font-size: 12px;
    font-weight: 500;
}

.dimension-option-value {
    color: #1f2937;
    font-size: 13px;
    font-weight: 600;
}

/* Selected dimensions pills */
.selected-dimensions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.selected-dimension-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 16px;
    font-size: 12px;
    color: #1d4ed8;
    font-weight: 500;
}

.selected-dimension-pill .remove-btn,
.selected-dimension-pill .remove-group-btn {
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    opacity: 0.6;
    transition: opacity 0.2s;
    line-height: 1;
}

.selected-dimension-pill .remove-btn:hover,
.selected-dimension-pill .remove-group-btn:hover {
    opacity: 1;
}

/* Grouped pills (multiple selections in one dimension) */
.selected-dimension-pill.grouped-pill {
    background: linear-gradient(135deg, #dbeafe 0%, #eff6ff 100%);
    border-color: #93c5fd;
    cursor: help;
}

.selected-dimension-pill.grouped-pill:hover {
    background: linear-gradient(135deg, #bfdbfe 0%, #dbeafe 100%);
}
