/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Prevent horizontal overflow on all elements */
*, *::before, *::after {
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #0d32d5ff 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    line-height: 1.6;
    overflow-x: hidden;
    width: 100%;
}

/* Container and Layout */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    width: 100%;
    box-sizing: border-box;
}

/* Header */
.header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 2rem;
    margin-bottom: 2rem;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.header-main {
    text-align: left;
}

.header-auth {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-shrink: 0;
}

.user-info {
    color: #4a5568;
    font-weight: 500;
    font-size: 0.9rem;
}

.btn-sm {
    font-size: 0.875rem;
    padding: 0.5rem 1rem;
}

.header h1 {
    color: #2d3748;
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: #718096;
    font-size: 1.1rem;
}

/* Main Content */
.main-content {
    flex: 1;
    display: grid;
    gap: 2rem;
    grid-template-columns: 1fr;
}

/* Cards */
.card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
}

.card-header {
    margin-bottom: 1.5rem;
}

.card-header h2 {
    color: #2d3748;
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.card-header p {
    color: #718096;
}

/* Forms */
.scraper-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-weight: 500;
    color: #2d3748;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-input {
    padding: 0.75rem 1rem;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    background: white;
    width: 100%;
    max-width: 100%;
}

.form-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-hint {
    color: #718096;
    font-size: 0.85rem;
}

/* Form Actions */
.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    min-height: 48px;
    max-width: 100%;
    text-align: center;
    justify-content: center;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.3);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #e2e8f0;
    color: #2d3748;
}

.btn-secondary:hover:not(:disabled) {
    background: #cbd5e0;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-icon {
    font-size: 1.1rem;
}

/* Status Display */
.status-display {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: #f7fafc;
    border-radius: 8px;
}

.status-label {
    font-weight: 500;
    color: #2d3748;
    min-width: 120px;
}

.status-value {
    color: #4a5568;
    flex: 1;
}

/* Progress Bar */
.progress-container {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    width: 0%;
    transition: width 0.3s ease;
}

.progress-text {
    font-weight: 500;
    color: #2d3748;
    min-width: 80px;
    text-align: right;
}

/* Error Display */
.error-display {
    background: #fed7d7;
    border: 1px solid #fc8181;
    color: #c53030;
    padding: 1rem;
    border-radius: 8px;
}

.error-message {
    font-weight: 500;
}

/* Activity Log */
.activity-log {
    margin-top: 1.5rem;
    border-top: 1px solid #e2e8f0;
    padding-top: 1.5rem;
}

.activity-log h3 {
    color: #2d3748;
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.log-container {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #f7fafc;
}

.log-entry {
    display: flex;
    gap: 1rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e2e8f0;
    font-size: 0.9rem;
}

.log-entry:last-child {
    border-bottom: none;
}

.log-time {
    font-weight: 500;
    color: #667eea;
    min-width: 100px;
    font-family: monospace;
}

.log-message {
    color: #4a5568;
    flex: 1;
}

.log-entry.success .log-time {
    color: #38a169;
}

.log-entry.error .log-time {
    color: #e53e3e;
}

.log-entry.error .log-message {
    color: #c53030;
}

/* Instructions */
.instructions {
    color: #4a5568;
}

.instructions ol {
    padding-left: 1.5rem;
    margin-bottom: 1.5rem;
}

.instructions li {
    margin-bottom: 0.75rem;
}

.instructions strong {
    color: #2d3748;
}

.example-urls {
    background: #f7fafc;
    padding: 1rem;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.example-urls h4 {
    color: #2d3748;
    margin-bottom: 0.5rem;
}

.example-urls ul {
    list-style: none;
    padding: 0;
}

.example-urls li {
    margin-bottom: 0.25rem;
}

.example-urls code {
    background: #e2e8f0;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.85rem;
    color: #2d3748;
}

/* Footer */
.footer {
    margin-top: 2rem;
    text-align: center;
    color: rgba(255, 255, 255, 0.8);
    padding: 1rem;
}

/* Loading Animation */
.loading {
    position: relative;
    overflow: hidden;
}

.loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

/* Responsive Design */
@media (min-width: 768px) {
    .container {
        padding: 40px;
    }

    .header {
        padding: 3rem;
    }

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

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

    .card:first-child {
        grid-column: 1 / -1;
    }

    .form-actions {
        flex-direction: row;
    }

    .status-item {
        flex-direction: row;
        align-items: center;
    }
}

@media (min-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto auto;
    }

    .card:nth-child(1) {
        grid-column: 1;
        grid-row: 1;
    }

    .card:nth-child(2) {
        grid-column: 2;
        grid-row: 1 / 3;
    }

    .card:nth-child(3) {
        grid-column: 1;
        grid-row: 2;
    }
}

/* Status Indicators */
.status-running {
    animation: pulse 2s infinite;
}

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

/* Custom Scrollbar */
.log-container::-webkit-scrollbar {
    width: 8px;
}

.log-container::-webkit-scrollbar-track {
    background: #e2e8f0;
}

.log-container::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 4px;
}

.log-container::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* Mobile-first optimizations */
@media (max-width: 768px) {
    /* Improve touch targets */
    .btn, .form-input, .page-number, select {
        min-height: 44px;
    }

    /* Better spacing for mobile */
    .main-content {
        gap: 1.5rem;
    }

    /* Optimize typography for small screens */
    body {
        font-size: 14px;
        line-height: 1.5;
    }

    /* Improve scrolling on mobile */
    .results-table {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }

    /* Better mobile navigation */
    .pagination-controls {
        gap: 0.25rem;
    }

    /* Responsive text wrapping */
    .status-value, .log-message {
        word-break: break-word;
        overflow-wrap: break-word;
    }
}

/* Landscape orientation adjustments */
@media screen and (max-height: 500px) and (orientation: landscape) {
    .header {
        padding: 1rem;
        margin-bottom: 1rem;
    }

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

    .card {
        padding: 1rem;
    }

    .log-container {
        max-height: 120px;
    }
}

/* High DPI / Retina display optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .btn-icon {
        font-size: 1.2rem;
    }
}

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

/* Focus styles for keyboard navigation */
.btn:focus-visible,
.form-input:focus-visible {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* Results Interface Styles */
.filters-section {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid #e2e8f0;
}

.filter-controls {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr auto;
    gap: 1rem;
    align-items: end;
    margin-bottom: 1rem;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

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

.results-stats {
    display: flex;
    gap: 2rem;
    padding: 1rem;
    background: #f7fafc;
    border-radius: 8px;
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.stat-label {
    font-weight: 500;
    color: #2d3748;
}

.stat-value {
    font-weight: 600;
    color: #667eea;
    font-size: 1.1rem;
}

/* Results Container */
.results-container {
    margin-top: 1rem;
}

.loading-spinner {
    text-align: center;
    padding: 2rem;
    color: #718096;
    font-style: italic;
}

.results-table {
    overflow-x: auto;
    max-width: 100vw;
    width: 100%;
}

.results-table table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.results-table th,
.results-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
}

.results-table th {
    background: #f7fafc;
    font-weight: 600;
    color: #2d3748;
    border-bottom: 2px solid #e2e8f0;
}

.results-table tr:hover {
    background: #f7fafc;
}

.results-table tr:last-child td {
    border-bottom: none;
}

.results-table a {
    color: #667eea;
    text-decoration: none;
}

.results-table a:hover {
    text-decoration: underline;
}

.unprocessed {
    color: #718096;
    font-style: italic;
}

/* Badges */
.category-badge,
.lawsuit-badge {
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.category-badge {
    background: #667eea;
    color: white;
}

.lawsuit-yes {
    background: #e53e3e;
    color: white;
}

.lawsuit-no {
    background: #38a169;
    color: white;
}

.no-results {
    text-align: center;
    padding: 3rem;
    color: #718096;
}

.no-results p {
    font-size: 1.1rem;
}

/* Pagination */
.pagination-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1.5rem;
    padding: 1rem;
    background: #f7fafc;
    border-radius: 8px;
    flex-wrap: wrap;
    gap: 1rem;
}

.pagination-info {
    color: #718096;
    font-size: 0.9rem;
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.page-numbers {
    display: flex;
    gap: 0.25rem;
}

.page-number {
    padding: 0.5rem 0.75rem;
    border: 1px solid #e2e8f0;
    background: white;
    color: #4a5568;
    cursor: pointer;
    border-radius: 4px;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.page-number:hover {
    background: #f7fafc;
    border-color: #cbd5e0;
}

.page-number.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.page-number.active:hover {
    background: #5a67d8;
}

/* Button variants */
.btn-outline {
    background: white;
    color: #667eea;
    border: 1px solid #667eea;
}

.btn-outline:hover:not(:disabled) {
    background: #667eea;
    color: white;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    min-height: 36px;
}

/* Enhanced Mobile Responsiveness */
@media (max-width: 480px) {
    .container {
        padding: 10px;
    }

    .header {
        padding: 1.5rem;
        margin-bottom: 1rem;
    }

    .header h1 {
        font-size: 1.8rem;
        line-height: 1.2;
    }

    .subtitle {
        font-size: 1rem;
    }

    .card {
        padding: 1.5rem;
        border-radius: 12px;
    }

    .card-header h2 {
        font-size: 1.25rem;
    }

    .form-input {
        padding: 0.875rem;
        font-size: 16px; /* Prevents zoom on iOS */
    }

    .btn {
        padding: 0.875rem 1rem;
        font-size: 0.95rem;
        min-height: 44px; /* Touch target size */
    }

    .form-actions {
        flex-direction: column;
        gap: 0.75rem;
    }

    .status-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .status-label {
        min-width: auto;
        font-weight: 600;
    }

    .progress-container {
        width: 100%;
    }

    .log-container {
        max-height: 200px;
        font-size: 0.85rem;
    }

    .log-entry {
        flex-direction: column;
        gap: 0.25rem;
        padding: 0.75rem;
    }

    .log-time {
        min-width: auto;
        font-size: 0.8rem;
    }

    .results-table {
        font-size: 0.8rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .results-table table {
        min-width: 300px;
        max-width: 100%;
    }

    .results-table th,
    .results-table td {
        padding: 0.5rem 0.25rem;
        white-space: nowrap;
    }

    .results-table th:first-child,
    .results-table td:first-child {
        position: sticky;
        left: 0;
        background: white;
        z-index: 1;
        box-shadow: 2px 0 5px rgba(0,0,0,0.1);
    }

    .results-table th:first-child {
        background: #f7fafc;
    }

    .pagination-container {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    .page-numbers {
        justify-content: center;
        flex-wrap: wrap;
    }

    .page-number {
        min-width: 36px;
        padding: 0.5rem 0.25rem;
    }
}

/* Tablet Portrait */
@media (max-width: 768px) and (min-width: 481px) {
    .container {
        padding: 15px;
    }

    .header {
        padding: 2rem;
    }

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

    .form-actions {
        flex-direction: column;
        gap: 1rem;
    }

    .status-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .filter-controls {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .filter-actions {
        justify-content: stretch;
    }

    .filter-actions .btn {
        flex: 1;
    }

    .results-stats {
        flex-direction: column;
        gap: 0.5rem;
    }

    .pagination-container {
        flex-direction: column;
        text-align: center;
    }

    .results-table {
        font-size: 0.9rem;
    }

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

/* Grid layout updates for results */
@media (min-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto auto auto;
    }

    .card:nth-child(1) {
        grid-column: 1;
        grid-row: 1;
    }

    .card:nth-child(2) {
        grid-column: 1;
        grid-row: 2;
    }

    .card:nth-child(3) {
        grid-column: 1;
        grid-row: 3;
    }

    .card:nth-child(4) {
        grid-column: 1;
        grid-row: 4;
    }

    .card:nth-child(5) {
        grid-column: 1;
        grid-row: 5;
    }
}

/* Amount raised styling */
.amount-cell {
    font-weight: 600;
    color: #2d5016;
    text-align: right;
}

.amount-cell.unprocessed {
    color: #999;
    font-weight: 400;
}