/* CSS Variables for theming */
:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --info-color: #3b82f6;

    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;

    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;

    --border-color: #e2e8f0;
    --border-radius: 12px;
    --border-radius-sm: 8px;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);

    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

/* Reset and base styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary-color) 0%, #7c3aed 100%);
    color: white;
    padding: 2rem 1.5rem;
    text-align: center;
}

.header-content {
    max-width: 800px;
    margin: 0 auto;
}

.logo-section {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.logo {
    width: 48px;
    height: 48px;
}

.header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

.tagline {
    color: rgba(255, 255, 255, 0.85);
    font-size: 1rem;
    margin-top: 0.5rem;
}

/* Main Content */
.main-content {
    flex: 1;
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
    width: 100%;
}

/* Card Component */
.card {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 1rem 0 0.75rem;
    color: var(--text-secondary);
}

/* URL Section */
.url-input-group {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.url-input {
    flex: 1;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.url-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.quick-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    font-size: 0.9375rem;
    font-weight: 500;
    border: none;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

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

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

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-hover);
}

.btn-secondary {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--border-color);
}

.btn-success {
    background-color: var(--success-color);
    color: white;
}

.btn-success:hover:not(:disabled) {
    background-color: #059669;
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background-color: #dc2626;
}

.btn-outline {
    background-color: transparent;
    border: 2px solid var(--border-color);
    color: var(--text-secondary);
}

.btn-outline:hover:not(:disabled) {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-small {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
}

/* Recording Section */
.recording-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.recording-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 1.125rem;
    color: var(--text-secondary);
}

.indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: var(--text-muted);
}

.indicator.recording {
    background-color: var(--danger-color);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.recording-info {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    background-color: var(--bg-tertiary);
    border-radius: var(--border-radius-sm);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.record-icon {
    color: var(--danger-color);
}

/* Metrics Grid */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.metric-card {
    background: var(--bg-tertiary);
    border-radius: var(--border-radius-sm);
    padding: 1.25rem;
    text-align: center;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.metric-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.metric-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.metric-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
    line-height: 1.2;
}

.metric-value.good {
    color: var(--success-color);
}

.metric-value.warning {
    color: var(--warning-color);
}

.metric-value.poor {
    color: var(--danger-color);
}

.metric-unit {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Resource Summary */
.resource-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 2rem;
    padding: 1rem;
    background: var(--bg-tertiary);
    border-radius: var(--border-radius-sm);
    margin-bottom: 1.5rem;
}

.summary-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.summary-label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

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

/* Resource Breakdown Chart */
.resource-breakdown {
    margin-bottom: 1.5rem;
}

.chart-container {
    display: flex;
    align-items: center;
    gap: 2rem;
    flex-wrap: wrap;
}

#resourceChart {
    max-width: 250px;
    max-height: 250px;
}

.chart-legend {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 4px;
}

/* Resource Table */
.resource-table-container {
    overflow: hidden;
}

.table-controls {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.filter-input, .filter-select {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: var(--bg-secondary);
}

.filter-input {
    flex: 1;
    min-width: 200px;
}

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

.table-wrapper {
    overflow-x: auto;
}

.resource-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.resource-table th,
.resource-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.resource-table th {
    background: var(--bg-tertiary);
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.resource-table th:hover {
    background: var(--border-color);
}

.sort-icon {
    margin-left: 0.25rem;
    opacity: 0.5;
}

.resource-table tbody tr:hover {
    background: var(--bg-tertiary);
}

.resource-table .resource-name {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.resource-type {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 4px;
    text-transform: uppercase;
}

.resource-type.script { background: #fef3c7; color: #92400e; }
.resource-type.css { background: #dbeafe; color: #1e40af; }
.resource-type.img { background: #dcfce7; color: #166534; }
.resource-type.font { background: #f3e8ff; color: #7c3aed; }
.resource-type.fetch { background: #fce7f3; color: #be185d; }
.resource-type.other { background: var(--bg-tertiary); color: var(--text-secondary); }

.status-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 4px;
}

.status-badge.success { background: #dcfce7; color: #166534; }
.status-badge.error { background: #fee2e2; color: #991b1b; }
.status-badge.pending { background: #fef3c7; color: #92400e; }

.empty-row td {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
}

/* Timeline */
.timeline-controls {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.timeline-container {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    overflow: hidden;
}

.timeline-header {
    display: flex;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    padding: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.timeline-content {
    min-height: 200px;
    max-height: 400px;
    overflow: auto;
    padding: 1rem;
}

.timeline-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 168px;
    color: var(--text-muted);
    font-size: 0.9375rem;
}

.timeline-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
}

.timeline-row:last-child {
    border-bottom: none;
}

.timeline-label {
    width: 150px;
    font-size: 0.8125rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex-shrink: 0;
}

.timeline-bar-container {
    flex: 1;
    height: 20px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

.timeline-bar {
    position: absolute;
    height: 100%;
    border-radius: 4px;
    min-width: 2px;
}

.timeline-bar.navigation { background: #8b5cf6; }
.timeline-bar.resource { background: #3b82f6; }
.timeline-bar.script { background: #f59e0b; }
.timeline-bar.paint { background: #10b981; }
.timeline-bar.layout { background: #ef4444; }

.timeline-duration {
    width: 70px;
    text-align: right;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

/* Bottleneck Detection */
.bottleneck-results {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.no-issues {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2rem;
    color: var(--text-muted);
}

.no-issues .check-icon {
    font-size: 2rem;
    color: var(--success-color);
    margin-bottom: 0.5rem;
}

.bottleneck-item {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    border-radius: var(--border-radius-sm);
    border-left: 4px solid;
}

.bottleneck-item.critical {
    background: #fef2f2;
    border-color: var(--danger-color);
}

.bottleneck-item.warning {
    background: #fffbeb;
    border-color: var(--warning-color);
}

.bottleneck-item.info {
    background: #eff6ff;
    border-color: var(--info-color);
}

.bottleneck-icon {
    font-size: 1.5rem;
}

.bottleneck-content {
    flex: 1;
}

.bottleneck-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.bottleneck-description {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.bottleneck-suggestion {
    font-size: 0.8125rem;
    color: var(--primary-color);
    margin-top: 0.5rem;
}

/* Reports Section */
.report-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.export-icon {
    font-size: 1rem;
}

.history-list {
    max-height: 300px;
    overflow-y: auto;
}

.no-history {
    color: var(--text-muted);
    text-align: center;
    padding: 1.5rem;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--bg-tertiary);
    border-radius: var(--border-radius-sm);
    margin-bottom: 0.5rem;
}

.history-item:last-child {
    margin-bottom: 0;
}

.history-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.history-url {
    font-weight: 500;
    font-size: 0.875rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 300px;
}

.history-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.history-actions {
    display: flex;
    gap: 0.5rem;
}

/* Footer */
.footer {
    background: var(--text-primary);
    color: white;
    padding: 1.5rem;
    text-align: center;
    margin-top: auto;
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
}

.footer a {
    color: #a5b4fc;
    text-decoration: none;
    font-weight: 500;
    transition: color var(--transition-fast);
}

.footer a:hover {
    color: white;
    text-decoration: underline;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 0.75rem 1.5rem;
    background: var(--text-primary);
    color: white;
    border-radius: var(--border-radius-sm);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: all var(--transition-normal);
    z-index: 1000;
    white-space: nowrap;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.success {
    background: var(--success-color);
}

.toast.error {
    background: var(--danger-color);
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .header {
        padding: 1.5rem 1rem;
    }

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

    .logo-section {
        flex-direction: column;
        gap: 0.5rem;
    }

    .main-content {
        padding: 1rem;
    }

    .card {
        padding: 1rem;
    }

    .url-input-group {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }

    .quick-actions {
        flex-direction: column;
    }

    .recording-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .recording-status {
        justify-content: center;
        margin-top: 0.5rem;
    }

    .metrics-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .metric-card {
        padding: 1rem;
    }

    .metric-value {
        font-size: 1.5rem;
    }

    .resource-summary {
        flex-direction: column;
        gap: 1rem;
    }

    .chart-container {
        flex-direction: column;
        align-items: flex-start;
    }

    #resourceChart {
        max-width: 200px;
        margin: 0 auto;
    }

    .table-controls {
        flex-direction: column;
    }

    .filter-input {
        min-width: unset;
        width: 100%;
    }

    .resource-table th,
    .resource-table td {
        padding: 0.5rem;
    }

    .timeline-label {
        width: 100px;
        font-size: 0.75rem;
    }

    .timeline-duration {
        width: 50px;
        font-size: 0.75rem;
    }

    .report-actions {
        flex-direction: column;
    }

    .history-url {
        max-width: 150px;
    }
}

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

    .timeline-controls {
        flex-wrap: wrap;
    }

    .btn-small {
        flex: 1;
    }
}

/* Print Styles */
@media print {
    .header {
        background: none;
        color: var(--text-primary);
        padding: 1rem 0;
    }

    .url-section,
    .recording-section,
    .timeline-controls,
    .report-actions,
    .table-controls,
    .footer {
        display: none;
    }

    .card {
        box-shadow: none;
        border: 1px solid var(--border-color);
        break-inside: avoid;
    }

    .metric-card {
        break-inside: avoid;
    }
}
