/**
 * Drill-Down Component Styles
 * Complete UI styles for modals, panels, inline expansions
 */

/* ============================================================================
   VARIABLES
   ============================================================================ */

:root {
    /* Drill-down specific transitions */
    --drilldown-transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --drilldown-transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --drilldown-transition-slow: 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    /* Modal sizes */
    --modal-sm-width: 400px;
    --modal-md-width: 600px;
    --modal-lg-width: 900px;
    --modal-xl-width: 1200px;
    --modal-full-width: 95vw;

    /* Panel sizes */
    --panel-width: 480px;
    --panel-width-lg: 640px;
    --panel-width-xl: 800px;

    /* Z-index layers */
    --z-modal: 1000;
    --z-panel: 1000;
    --z-backdrop: 999;
}

/* ============================================================================
   MODAL COMPONENT
   ============================================================================ */

.drill-down-modal {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: var(--z-modal);
    display: none;
}

.drill-down-modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Modal Backdrop */
.drill-down-modal__backdrop {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.5);
    animation: fadeIn var(--drilldown-transition-normal);
    z-index: var(--z-backdrop);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Modal Content Container */
.drill-down-modal__content {
    position: relative;
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-xl);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    z-index: calc(var(--z-backdrop) + 1);
    animation: scaleIn var(--drilldown-transition-normal);
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Modal Size Variants */
.drill-down-modal--sm .drill-down-modal__content {
    width: var(--modal-sm-width);
    max-width: 90vw;
}

.drill-down-modal--md .drill-down-modal__content {
    width: var(--modal-md-width);
    max-width: 90vw;
}

.drill-down-modal--lg .drill-down-modal__content {
    width: var(--modal-lg-width);
    max-width: 90vw;
}

.drill-down-modal--xl .drill-down-modal__content {
    width: var(--modal-xl-width);
    max-width: 90vw;
}

.drill-down-modal--full .drill-down-modal__content {
    width: var(--modal-full-width);
    height: 90vh;
}

/* Modal Header */
.drill-down-modal__header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.drill-down-modal__title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.drill-down-modal__close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--border-radius-sm);
    transition: all var(--drilldown-transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.drill-down-modal__close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.drill-down-modal__close:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* Modal Body */
.drill-down-modal__body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

/* Custom scrollbar for modal */
.drill-down-modal__body::-webkit-scrollbar {
    width: 8px;
}

.drill-down-modal__body::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

.drill-down-modal__body::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.drill-down-modal__body::-webkit-scrollbar-thumb:hover {
    background: var(--border-color);
}

/* Modal Footer */
.drill-down-modal__footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    flex-shrink: 0;
}

/* ============================================================================
   PANEL COMPONENT (Slide-out)
   ============================================================================ */

.drill-down-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: var(--z-panel);
    display: none;
}

.drill-down-panel.active {
    display: block;
}

/* Panel Backdrop */
.drill-down-panel__backdrop {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.5);
    animation: fadeIn var(--drilldown-transition-normal);
    z-index: var(--z-backdrop);
}

/* Panel Content Container */
.drill-down-panel__content {
    position: absolute;
    top: 0;
    bottom: 0;
    width: var(--panel-width);
    max-width: 100%;
    background: var(--bg-secondary);
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    z-index: calc(var(--z-backdrop) + 1);
}

/* Panel Position: Right (default) */
.drill-down-panel--right .drill-down-panel__content {
    right: 0;
    animation: slideInRight var(--drilldown-transition-slow);
}

@keyframes slideInRight {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

/* Panel Position: Left */
.drill-down-panel--left .drill-down-panel__content {
    left: 0;
    animation: slideInLeft var(--drilldown-transition-slow);
}

@keyframes slideInLeft {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
}

/* Panel Header */
.drill-down-panel__header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.drill-down-panel__title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.drill-down-panel__close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--border-radius-sm);
    transition: all var(--drilldown-transition-fast);
}

.drill-down-panel__close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Panel Body */
.drill-down-panel__body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

/* Panel Footer */
.drill-down-panel__footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    flex-shrink: 0;
}

/* ============================================================================
   INLINE EXPANSION COMPONENT
   ============================================================================ */

.drill-down-inline {
    max-height: 0;
    overflow: hidden;
    transition: max-height var(--drilldown-transition-slow);
    background: var(--bg-tertiary);
    border-radius: var(--border-radius);
    margin-top: 0.5rem;
}

.drill-down-inline.active {
    border: 1px solid var(--border-color);
    padding: 1rem;
}

/* ============================================================================
   TABLE DRILL-DOWN ENHANCEMENTS
   ============================================================================ */

.drill-down-table-row {
    cursor: pointer;
    transition: all var(--drilldown-transition-fast);
}

.drill-down-table-row:hover {
    background: var(--bg-card-hover);
    border-left: 3px solid var(--accent-primary);
}

.drill-down-table-row:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* Expandable row indicator */
.drill-down-table-row__expand-icon {
    transition: transform var(--drilldown-transition-normal);
}

.drill-down-table-row.expanded .drill-down-table-row__expand-icon {
    transform: rotate(180deg);
}

/* ============================================================================
   CHART DRILL-DOWN ENHANCEMENTS
   ============================================================================ */

.drill-down-chart {
    cursor: pointer;
    position: relative;
}

.drill-down-chart canvas {
    cursor: pointer;
}

.drill-down-chart__loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    z-index: 10;
}

/* ============================================================================
   LOADING STATES
   ============================================================================ */

.drill-down-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    gap: 1rem;
}

.drill-down-loading__spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.drill-down-loading__text {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Skeleton loading */
.drill-down-skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-tertiary) 25%,
        var(--bg-card-hover) 50%,
        var(--bg-tertiary) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--border-radius-sm);
    height: 1rem;
    margin-bottom: 0.5rem;
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.drill-down-skeleton--short {
    width: 60%;
}

.drill-down-skeleton--long {
    width: 100%;
}

/* ============================================================================
   RESPONSIVE DESIGN
   ============================================================================ */

@media (max-width: 768px) {
    /* Modal becomes full-screen on mobile */
    .drill-down-modal__content {
        width: 100vw !important;
        height: 100vh !important;
        max-height: 100vh;
        border-radius: 0;
    }

    /* Panel becomes bottom sheet on mobile */
    .drill-down-panel__content {
        width: 100%;
        top: auto;
        bottom: 0;
        max-height: 90vh;
        border-radius: var(--border-radius) var(--border-radius) 0 0;
        animation: slideUp var(--drilldown-transition-slow) !important;
    }

    @keyframes slideUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }

    /* Add drag handle for mobile bottom sheet */
    .drill-down-panel__content::before {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        background: var(--text-muted);
        border-radius: 2px;
        margin: 0.75rem auto 0;
    }
}

/* ============================================================================
   ACCESSIBILITY UTILITIES
   ============================================================================ */

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Focus visible polyfill */
.drill-down-modal:focus-visible,
.drill-down-panel:focus-visible,
[tabindex]:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* ============================================================================
   PRINT STYLES
   ============================================================================ */

@media print {
    .drill-down-modal__backdrop,
    .drill-down-panel__backdrop {
        display: none;
    }

    .drill-down-modal__content,
    .drill-down-panel__content {
        position: static;
        box-shadow: none;
        max-height: none;
    }
}

/* ============================================================================
   POLISHED DRILL-DOWN CONTENT STYLES
   ============================================================================ */

/* Modal Header Enhancement */
.drill-down-modal__header {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    padding: 1.25rem 1.5rem;
}

.drill-down-modal__title {
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.drill-down-modal__title::before {
    content: '';
    width: 4px;
    height: 1.25rem;
    background: var(--accent-primary);
    border-radius: 2px;
}

/* Close Button Polish */
.drill-down-modal__close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 1.25rem;
    font-weight: 300;
}

.drill-down-modal__close:hover {
    background: var(--danger-bg, rgba(239, 68, 68, 0.1));
    color: var(--danger-color, #ef4444);
    transform: scale(1.1);
}

/* Content Area */
.drill-down-content {
    padding: 0;
}

.drill-down-content h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.drill-down-content h4 {
    margin: 0 0 0.75rem 0;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Industry/Category Header */
.industry-header,
.category-header,
.domain-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
}

.industry-stats,
.category-stats,
.domain-stats {
    display: flex;
    gap: 1.5rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Risk Summary Section */
.risk-summary {
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
}

.risk-distribution-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Risk Badges - Polished */
.risk-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.375rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
    letter-spacing: 0.02em;
}

.risk-badge.critical {
    background: linear-gradient(135deg, rgba(220, 38, 38, 0.15) 0%, rgba(185, 28, 28, 0.2) 100%);
    color: #dc2626;
    border: 1px solid rgba(220, 38, 38, 0.3);
}

.risk-badge.high {
    background: linear-gradient(135deg, rgba(234, 88, 12, 0.15) 0%, rgba(194, 65, 12, 0.2) 100%);
    color: #ea580c;
    border: 1px solid rgba(234, 88, 12, 0.3);
}

.risk-badge.medium {
    background: linear-gradient(135deg, rgba(202, 138, 4, 0.15) 0%, rgba(161, 98, 7, 0.2) 100%);
    color: #ca8a04;
    border: 1px solid rgba(202, 138, 4, 0.3);
}

.risk-badge.low {
    background: linear-gradient(135deg, rgba(22, 163, 74, 0.15) 0%, rgba(21, 128, 61, 0.2) 100%);
    color: #16a34a;
    border: 1px solid rgba(22, 163, 74, 0.3);
}

/* Score Badge */
.score-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-weight: 700;
    font-size: 0.875rem;
}

.score-badge.critical {
    background: linear-gradient(135deg, rgba(220, 38, 38, 0.2) 0%, rgba(185, 28, 28, 0.3) 100%);
    color: #dc2626;
}

.score-badge.high {
    background: linear-gradient(135deg, rgba(234, 88, 12, 0.2) 0%, rgba(194, 65, 12, 0.3) 100%);
    color: #ea580c;
}

.score-badge.medium {
    background: linear-gradient(135deg, rgba(202, 138, 4, 0.2) 0%, rgba(161, 98, 7, 0.3) 100%);
    color: #ca8a04;
}

.score-badge.low {
    background: linear-gradient(135deg, rgba(22, 163, 74, 0.2) 0%, rgba(21, 128, 61, 0.3) 100%);
    color: #16a34a;
}

/* Score Pill (for tables) */
.score-pill {
    display: inline-block;
    padding: 0.25rem 0.625rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* Companies/Items List Section */
.companies-list,
.items-list,
.domain-companies {
    margin-top: 1rem;
}

/* Drill-Down Table Wrapper */
.drill-down-table-wrapper {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    margin-top: 0.75rem;
}

/* Drill-Down Table - Polished */
.drill-down-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.drill-down-table thead {
    background: var(--bg-tertiary);
}

.drill-down-table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-color);
}

.drill-down-table td {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.drill-down-table tbody tr:last-child td {
    border-bottom: none;
}

/* Clickable Row Styles */
.drill-down-row {
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
}

.drill-down-row:hover {
    background: var(--bg-card-hover, rgba(99, 102, 241, 0.05));
}

.drill-down-row:hover td:first-child {
    padding-left: calc(1rem + 4px);
}

.drill-down-row:hover::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--accent-primary);
}

.drill-down-row:active {
    background: var(--bg-tertiary);
}

/* Row Click Hint */
.drill-down-row td:last-child::after {
    content: '\203A';
    display: inline-block;
    margin-left: 0.5rem;
    opacity: 0;
    transition: opacity 0.15s ease, transform 0.15s ease;
    color: var(--accent-primary);
    font-size: 1.25rem;
    font-weight: 300;
}

.drill-down-row:hover td:last-child::after {
    opacity: 1;
    transform: translateX(4px);
}

/* Company Name Column */
.drill-down-table td:first-child {
    font-weight: 500;
    color: var(--text-primary);
}

/* Detail Section for Company Detail */
.company-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-top: 1rem;
}

.detail-section {
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 1.25rem;
}

.detail-section h4 {
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.detail-section p {
    margin: 0.5rem 0;
    font-size: 0.875rem;
}

.detail-section ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.detail-section li {
    padding: 0.375rem 0;
    font-size: 0.875rem;
    border-bottom: 1px dotted var(--border-color);
}

.detail-section li:last-child {
    border-bottom: none;
}

/* Domain Performance Grid */
.domain-performance-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.domain-card {
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.domain-card__name {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.domain-card__score {
    font-size: 1.5rem;
    font-weight: 700;
}

/* Progress Bars in Drill-Down */
.drill-down-progress {
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 0.5rem;
}

.drill-down-progress__bar {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
}

/* Empty State */
.drill-down-empty {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-secondary);
}

.drill-down-empty__icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.drill-down-empty__text {
    font-size: 0.9rem;
}

/* Error State */
.drill-down-error {
    text-align: center;
    padding: 2rem;
    background: rgba(239, 68, 68, 0.1);
    border-radius: 8px;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.drill-down-error__icon {
    font-size: 2.5rem;
    color: #ef4444;
    margin-bottom: 0.75rem;
}

.drill-down-error__text {
    color: #ef4444;
    font-weight: 500;
}

/* Action Buttons inside Drill-Down */
.drill-down-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.drill-down-btn {
    padding: 0.625rem 1.25rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    border: none;
}

.drill-down-btn--primary {
    background: var(--accent-primary);
    color: #fff;
}

.drill-down-btn--primary:hover {
    background: var(--accent-primary-dark, #4f46e5);
    transform: translateY(-1px);
}

.drill-down-btn--secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.drill-down-btn--secondary:hover {
    background: var(--bg-card-hover);
}

/* Breadcrumb Navigation for Nested Drill-Downs */
.drill-down-breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.drill-down-breadcrumb__item {
    cursor: pointer;
    transition: color 0.15s ease;
}

.drill-down-breadcrumb__item:hover {
    color: var(--accent-primary);
}

.drill-down-breadcrumb__separator {
    color: var(--text-muted);
}

.drill-down-breadcrumb__current {
    color: var(--text-primary);
    font-weight: 500;
}

/* Dark mode adjustments */
@media (prefers-color-scheme: dark) {
    .score-pill {
        text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    }

    .risk-badge.critical {
        background: linear-gradient(135deg, rgba(220, 38, 38, 0.25) 0%, rgba(185, 28, 28, 0.35) 100%);
    }

    .risk-badge.high {
        background: linear-gradient(135deg, rgba(234, 88, 12, 0.25) 0%, rgba(194, 65, 12, 0.35) 100%);
    }

    .risk-badge.medium {
        background: linear-gradient(135deg, rgba(202, 138, 4, 0.25) 0%, rgba(161, 98, 7, 0.35) 100%);
    }

    .risk-badge.low {
        background: linear-gradient(135deg, rgba(22, 163, 74, 0.25) 0%, rgba(21, 128, 61, 0.35) 100%);
    }
}
