/* Metrics Page Styles - Extracted from templates/pages/metrics.html */

/* Prevent horizontal overflow on metrics page */
.ldr-page.active {
    overflow-x: hidden;
    max-width: 100%;
}

.ldr-page.active > * {
    max-width: 100%;
}

.ldr-metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.ldr-metric-card {
    padding: 1.5rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    transition: transform 0.2s;
}

.ldr-metric-card:hover {
    transform: translateY(-2px);
}

.ldr-metric-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-color);
    margin: 0.5rem 0;
}

.ldr-metric-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 1 !important;
}

.ldr-metric-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-color);
    color: white;
    border-radius: 0.375rem;
    margin-bottom: 1rem;
}

.ldr-expandable-card {
    overflow: hidden;
}

.ldr-metric-main {
    position: relative;
    cursor: pointer;
    user-select: none;
}

.ldr-expand-icon {
    position: absolute;
    top: 1rem;
    right: 1rem;
    color: var(--text-secondary);
    transition: transform 0.3s ease;
}

.ldr-expand-icon.ldr-expanded {
    transform: rotate(180deg);
}

.ldr-metric-details {
    border-top: 1px solid var(--border-color);
    margin-top: 1rem;
    padding-top: 1rem;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        max-height: 0;
    }
    to {
        opacity: 1;
        max-height: 300px;
    }
}

.ldr-token-breakdown {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.ldr-breakdown-section h4 {
    margin: 0 0 0.75rem 0;
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.ldr-breakdown-grid {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.ldr-breakdown-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
}

.ldr-breakdown-item.ldr-total {
    border-top: 1px solid var(--border-color);
    font-weight: 600;
    color: var(--primary-color);
}

.ldr-breakdown-label {
    font-size: 0.875rem;
    color: var(--text-muted);  /* Changed to more visible grey */
    opacity: 1 !important;
}

.ldr-breakdown-value {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.ldr-breakdown-item.ldr-total .ldr-breakdown-value {
    color: var(--primary-color);
    font-weight: 600;
}

.ldr-chart-container {
    position: relative;
    height: 300px;
    margin-top: 2rem;
}

.ldr-model-usage-list {
    margin-top: 1rem;
}

.ldr-model-usage-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
}

.ldr-model-info {
    flex: 1;
}

.ldr-model-name {
    font-weight: 600;
    color: var(--text-primary);
}

.ldr-model-provider {
    font-size: 0.875rem;
    color: var(--text-muted);  /* Changed to more visible grey */
}

.ldr-model-stats {
    text-align: right;
}

.ldr-token-count {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--primary-color);
}

.ldr-call-count {
    font-size: 0.875rem;
    color: var(--text-muted);  /* Changed to more visible grey */
}

.ldr-recent-research-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    transition: background-color 0.2s;
}

.ldr-recent-research-item:hover {
    background-color: var(--border-color);
}

.ldr-research-query {
    flex: 1;
    margin-right: 1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ldr-research-tokens {
    font-weight: 600;
    color: var(--primary-color);
}

.ldr-loading-spinner {
    text-align: center;
    padding: 3rem;
}

.ldr-error-message {
    text-align: center;
    padding: 2rem;
    color: var(--error-color);
}

/* Compact section headings */
h4 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 0.75rem 0;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

/* Expandable details styling */
details summary {
    list-style: none;
    outline: none;
    transition: all 0.2s ease;
}

details summary::-webkit-details-marker {
    display: none;
}

details summary:hover {
    background: var(--bg-secondary) !important;
}

details[open] summary {
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

/* Time range selector */
.ldr-time-range-selector {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-left: auto;
}

.ldr-time-range-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-secondary);
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.875rem;
    font-weight: 500;
    /* WCAG 2.5.5: ensure a 44x44 CSS-pixel touch target. inline-flex
       centers the (shorter) text content vertically inside the
       enforced height. */
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.ldr-time-range-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

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

/* Tooltip styles */
.ldr-tooltip {
    position: relative;
    cursor: help;
}

.ldr-tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 150%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.95);
    color: white;
    padding: 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.75rem;
    line-height: 1.4;
    max-width: 280px;
    min-width: 200px;
    width: max-content;
    white-space: normal;
    word-wrap: break-word;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 1001;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Smart positioning for edge detection */
.ldr-tooltip.ldr-tooltip-left::after {
    left: 0;
    transform: translateX(0);
}

.ldr-tooltip.ldr-tooltip-right::after {
    left: auto;
    right: 0;
    transform: translateX(0);
}

.ldr-tooltip::before {
    content: '';
    position: absolute;
    bottom: 135%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.95);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 1001;
}

/* Arrow positioning for edge tooltips */
.ldr-tooltip.ldr-tooltip-left::before {
    left: 1rem;
    transform: translateX(0);
}

.ldr-tooltip.ldr-tooltip-right::before {
    left: auto;
    right: 1rem;
    transform: translateX(0);
}

.ldr-tooltip:hover::after,
.ldr-tooltip:hover::before {
    opacity: 1;
    transform: translateX(-50%) translateY(-2px);
}

/* Info icon for additional help */
.ldr-info-icon {
    color: var(--text-secondary);
    margin-left: 0.25rem;
    font-size: 0.875rem;
    cursor: help;
    opacity: 1 !important;
    display: inline-block;
}

.ldr-info-icon:hover {
    color: var(--primary-color);
}

/* Responsive grid fixes for all viewport sizes */
@media (max-width: 1400px) {
    /* Force inline style grids to be responsive */
    div[style*="grid-template-columns: 1fr 1fr"],
    div[style*="grid-template-columns:1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    div[style*="minmax(300px"],
    div[style*="minmax(280px"] {
        grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)) !important;
    }
}

/* Page header should wrap on narrow viewports */
.ldr-page-header {
    flex-wrap: wrap !important;
    gap: 1rem !important;
}

.ldr-page-header > div {
    flex-wrap: wrap !important;
}

/* Ensure all cards and grids respect container bounds */
.ldr-card,
.ldr-metric-card,
.ldr-chart-container {
    max-width: 100%;
    box-sizing: border-box;
}

canvas {
    max-width: 100% !important;
}

/* Navigation link buttons */
.ldr-nav-link-btn {
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    text-decoration: none;
    font-size: 0.875rem;
    transition: transform 0.2s, filter 0.2s;
}
.ldr-nav-link-btn:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}
.ldr-nav-link-btn.ldr-nav-accent {
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
}
.ldr-nav-link-btn.ldr-nav-success {
    background: var(--success-color);
}
.ldr-nav-link-btn.ldr-nav-warning {
    background: linear-gradient(135deg, var(--warning-color) 0%, var(--error-color) 100%);
}
.ldr-nav-link-btn.ldr-nav-info {
    background: linear-gradient(135deg, var(--accent-tertiary) 0%, var(--accent-primary) 100%);
}

/* Status color classes for JS-generated content */
.ldr-status-success { color: var(--success-color); }
.ldr-status-warning { color: var(--warning-color); }
.ldr-status-error { color: var(--error-color); }
.ldr-status-muted { color: var(--text-muted); }

/* Mobile responsive adjustments */
@media screen and (max-width: 767px) {
    /* Ensure content doesn't get hidden behind mobile nav */
    .ldr-page#metrics {
        padding-bottom: 120px;
    }

    /* Filter controls stack vertically on mobile */
    .ldr-filter-controls {
        flex-direction: column;
        gap: 1rem;
    }

    .ldr-filter-group {
        width: 100%;
    }

    /* Smaller metric values on mobile */
    .ldr-metric-value {
        font-size: 1.5rem;
    }
}

@media screen and (max-width: 480px) {
    /* Single column for metrics grid on very small screens */
    .ldr-metrics-grid {
        grid-template-columns: 1fr;
    }

    .ldr-metric-value {
        font-size: 1.25rem;
    }
}
