/* Mobile First Approach */
@media (max-width: 768px) {
    /* Container Adjustments */
    .container {
        margin: 0;
        max-width: 100%;
    }

    /* Header */
    .header {
        padding: 12px 16px;
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }

    .header-title {
        text-align: center;
        margin-bottom: 0;
    }

    .header-title h1 {
        font-size: 20px;
    }

    .header-subtitle {
        font-size: 13px;
    }

    .header-controls {
        flex-direction: column;
        gap: 8px;
    }

    .firm-selection-container,
    .settings-container {
        width: 100%;
    }

    /* Main Layout */
    .main-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        grid-template-areas:
            "tabs"
            "content";
        gap: 0;
        height: calc(100vh - 120px); /* Adjust based on header height */
    }

    .sources-panel {
        grid-area: tabs;
        max-height: none;
        border-right: none;
        border-bottom: 1px solid #e5e7eb;
    }

    .insights-panel {
        grid-area: content;
    }

    /* Tabs */
    .tab-buttons {
        display: flex;
        overflow-x: auto;
        scrollbar-width: none;
        -ms-overflow-style: none;
        padding: 0 16px;
        gap: 8px;
    }

    .tab-buttons::-webkit-scrollbar {
        display: none;
    }

    .tab-button {
        flex-shrink: 0;
        padding: 12px 16px;
        font-size: 13px;
        white-space: nowrap;
        min-width: fit-content;
    }

    .tab-content {
        max-height: 300px;
        overflow-y: auto;
    }

    /* Insight Cards */
    .insight-card {
        margin: 0 16px 16px;
        border-radius: 8px;
    }

    .insight-header {
        padding: 16px 20px 0;
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }

    .insight-meta {
        justify-content: center;
        flex-wrap: wrap;
    }

    .insight-scores {
        justify-content: center;
        gap: 12px;
    }

    .insight-headline {
        padding: 12px 20px 8px;
        font-size: 16px;
    }

    .insight-summary {
        padding: 0 20px 12px;
        font-size: 14px;
    }

    .insight-sources {
        padding: 12px 20px;
    }

    .insight-actions {
        padding: 12px 20px;
        justify-content: center;
        flex-wrap: wrap;
    }

    .insight-footer {
        padding: 10px 20px;
        flex-direction: column;
        gap: 8px;
        align-items: center;
        text-align: center;
    }

    /* Buttons */
    .btn-primary, .btn-secondary, .btn-success, .btn-purple, .btn-gray {
        padding: 10px 20px;
        font-size: 13px;
    }

    .insight-actions button {
        padding: 8px 12px;
        font-size: 11px;
    }

    /* Overview Stats */
    .overview-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        padding: 0 16px;
    }

    .stat-card {
        padding: 16px;
    }

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

    /* Consolidation Summary */
    .consolidation-summary {
        margin: 0 16px;
        padding: 16px;
    }

    .consolidation-summary h4 {
        font-size: 16px;
    }

    /* Source Content */
    .source-content {
        padding: 0 16px;
    }

    .crawl-summary {
        gap: 8px;
    }

    .crawl-stat {
        padding: 10px 12px;
        flex-direction: column;
        gap: 4px;
        align-items: stretch;
        text-align: center;
    }

    /* Settings */
    .settings-modal .modal-content {
        margin: 20px;
        width: auto;
        max-width: none;
    }

    .settings-modal .modal-header {
        padding: 16px 20px;
    }

    .settings-modal .modal-body {
        padding: 16px 20px;
    }

    .setting-group {
        margin-bottom: 16px;
    }

    /* No Insights State */
    .no-insights {
        padding: 32px 16px;
    }

    .no-insights i {
        font-size: 36px;
    }

    .no-insights h4 {
        font-size: 18px;
    }

    /* Loading States */
    .loading-container {
        padding: 32px 16px;
    }

    .loading-text {
        font-size: 14px;
    }
}

/* Tablet Adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
    .main-layout {
        grid-template-columns: 350px 1fr;
    }

    .insight-card {
        margin: 0 20px 20px;
    }

    .consolidation-summary {
        margin: 0 20px;
    }

    .source-content {
        padding: 0 20px;
    }
}

/* Large Screen Optimizations */
@media (min-width: 1400px) {
    .container {
        max-width: 1400px;
    }

    .main-layout {
        grid-template-columns: 450px 1fr;
    }

    .insight-card {
        margin: 0 0 32px 0;
    }

    .insight-headline {
        font-size: 18px;
    }

    .insight-summary {
        font-size: 14px;
    }

    .overview-stats {
        grid-template-columns: repeat(3, 1fr);
        gap: 24px;
    }
}

/* Print Styles */
@media print {
    .header-controls,
    .tab-buttons,
    .insight-actions,
    .sources-panel {
        display: none !important;
    }

    .main-layout {
        grid-template-columns: 1fr;
        grid-template-areas: "content";
    }

    .insights-panel {
        grid-area: content;
    }

    .insight-card {
        break-inside: avoid;
        margin: 16px 0;
        box-shadow: none;
        border: 1px solid #ccc;
    }

    .insight-card:hover {
        transform: none;
    }

    .insight-sources {
        background: #f9f9f9 !important;
    }

    body {
        font-size: 12px;
    }

    .insight-headline {
        font-size: 14px;
    }

    .insight-summary {
        font-size: 11px;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .insight-card:hover {
        transform: none;
    }

    .btn-primary:hover,
    .btn-secondary:hover,
    .btn-success:hover,
    .btn-purple:hover,
    .btn-gray:hover {
        transform: none;
    }

    .stat-card:hover {
        transform: none;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .insight-card {
        border: 2px solid #000;
    }

    .insight-card.multi-source {
        border-left: 6px solid #000;
    }

    .btn-primary,
    .btn-secondary,
    .btn-success,
    .btn-purple,
    .btn-gray {
        border: 2px solid;
    }

    .tab-button.active {
        border: 2px solid #000;
    }

    .stat-card {
        border: 2px solid #000;
    }
}

/* Dark Mode Compatibility */
@media (prefers-color-scheme: dark) {
    /* Note: This is prepared for future dark mode implementation */
    .insight-card {
        background: #1f2937;
        border-color: #374151;
        color: #f9fafb;
    }

    .insight-headline {
        color: #f9fafb;
    }

    .insight-summary {
        color: #d1d5db;
    }

    .insight-sources {
        background: #111827;
        border-color: #374151;
    }

    .source-link {
        background: #1f2937;
        border-color: #374151;
        color: #d1d5db;
    }

    .source-link:hover {
        background: #374151;
        border-color: #6366f1;
        color: #6366f1;
    }
}

/* Focus Management for Accessibility */
@media (min-width: 769px) {
    .tab-button:focus,
    .btn-primary:focus,
    .btn-secondary:focus,
    .btn-success:focus,
    .btn-purple:focus,
    .btn-gray:focus,
    .source-link:focus {
        outline: 2px solid #6366f1;
        outline-offset: 2px;
    }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
    .tab-button {
        min-height: 44px;
        padding: 12px 20px;
    }

    .btn-primary,
    .btn-secondary,
    .btn-success,
    .btn-purple,
    .btn-gray {
        min-height: 44px;
        padding: 12px 24px;
    }

    .source-link {
        min-height: 44px;
        padding: 12px;
    }

    .insight-card {
        margin-bottom: 20px;
    }

    .insight-card:hover {
        transform: none;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }
}
