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

:root {
    --primary-color: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --background: #f8fafc;
    --surface: #ffffff;
    --surface-2: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --border-dark: #cbd5e1;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius: 8px;
    --radius-lg: 12px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    width: 100%;
    margin: 0;
    padding: 0;
}

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

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 1.5rem 0;
    box-shadow: var(--shadow-lg);
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    min-height: 60px;
}

.title {
    font-size: 2rem;
    font-weight: 700;
    margin: 0;
    text-align: center;
    letter-spacing: 0.025em;
}

.header-stats {
    display: flex;
    gap: 3rem;
    align-items: flex-start;
    justify-content: center;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    min-width: 100px;
    text-align: center;
}

.stat-label {
    font-size: 0.75rem;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
    white-space: nowrap;
    min-height: 1rem;
    display: flex;
    align-items: center;
}

.stat-value {
    font-weight: 600;
    font-size: 0.875rem;
    line-height: 1.2;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 1.5rem;
}

#connectionStatus {
    color: var(--success-color);
    font-size: 1.25rem;
    line-height: 1;
}

#lastUpdate {
    font-size: 0.75rem;
    font-weight: 500;
}

#connectionStatus.disconnected {
    color: var(--danger-color);
}

/* Time Selector */
.time-selector {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 10;
}

.time-tabs {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    justify-content: center;
}

.time-tab {
    padding: 0.75rem 1.5rem;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-secondary);
    border-radius: var(--radius);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.time-tab:hover {
    background: var(--surface-2);
    border-color: var(--border-dark);
}

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

.custom-range {
    max-width: 1200px;
    margin: 1rem auto 0;
    padding: 0 1rem;
}

.date-inputs {
    display: flex;
    gap: 1rem;
    align-items: end;
    flex-wrap: wrap;
}

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

.date-input-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.date-input-group input {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
}

.apply-custom-range {
    padding: 0.5rem 1rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 500;
    transition: background 0.2s;
}

.apply-custom-range:hover {
    background: var(--primary-dark);
}

/* Main Dashboard */
.dashboard {
    flex: 1;
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: transform 0.2s, box-shadow 0.2s;
}

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

.stat-card.primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.stat-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: inherit;
}

.stat-card.primary .stat-header h3 {
    color: white;
}

.stat-icon {
    font-size: 1.5rem;
    opacity: 0.8;
}

.stat-value {
    font-size: 2.5rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 0.5rem;
    color: inherit;
}

.stat-subtitle {
    font-size: 0.875rem;
    opacity: 0.8;
    color: inherit;
}

.stat-card.primary .stat-subtitle {
    color: white;
}

.accepted {
    color: var(--success-color);
    font-weight: 600;
}

.rejected {
    color: var(--danger-color);
    font-weight: 600;
}

/* Charts Section */
.charts-section {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

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

.chart-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

.chart-controls {
    display: flex;
    gap: 0.5rem;
}

.chart-control {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-secondary);
    border-radius: var(--radius);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
}

.chart-control:hover {
    background: var(--surface-2);
}

.chart-control.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.chart-wrapper {
    position: relative;
    height: 400px;
}

.chart-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 400px;
    gap: 1rem;
    color: var(--text-secondary);
}

.chart-loading.hidden {
    display: none;
}

/* Blocks Section */
.blocks-section {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

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

.section-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

.section-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.refresh-btn {
    padding: 0.5rem 1rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.refresh-btn:hover {
    background: var(--border);
}

.limit-select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    background: var(--surface);
}

.blocks-container {
    position: relative;
}

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

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

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

.blocks-table th {
    background: var(--surface-2);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.blocks-table tr:hover {
    background: var(--surface-2);
}

.block-hash {
    font-family: 'SF Mono', Consolas, monospace;
    font-size: 0.75rem;
    background: var(--surface-2);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    display: inline-block;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.blocks-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    color: var(--text-secondary);
}

.blocks-loading.hidden {
    display: none;
}

/* Loading Spinner */
.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Footer */
.footer {
    background: var(--surface-2);
    border-top: 1px solid var(--border);
    padding: 2rem 0;
    margin-top: auto;
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.footer-content p {
    margin: 0.25rem 0;
}

/* Toast Notifications */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    max-width: 400px;
    transform: translateX(100%);
    transition: transform 0.3s ease-in-out;
    z-index: 1000;
}

.toast.show {
    transform: translateX(0);
}

.toast-content {
    display: flex;
    align-items: center;
    padding: 1rem;
    gap: 0.75rem;
}

.toast-icon {
    font-size: 1.25rem;
}

.toast-message {
    flex: 1;
    font-size: 0.875rem;
}

.toast-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.error-toast {
    border-left: 4px solid var(--danger-color);
}

.success-toast {
    border-left: 4px solid var(--success-color);
}

/* Responsive Design */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        text-align: center;
        position: static;
    }

    .title {
        font-size: 1.5rem;
    }

    .header-stats {
        gap: 1rem;
        position: static;
        transform: none;
    }

    .time-tabs {
        padding: 0 1rem;
    }

    .dashboard {
        padding: 1rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .chart-header {
        flex-direction: column;
        align-items: stretch;
    }

    .chart-controls {
        justify-content: center;
    }

    .section-header {
        flex-direction: column;
        align-items: stretch;
    }

    .section-controls {
        justify-content: space-between;
    }

    .date-inputs {
        flex-direction: column;
    }

    .blocks-table {
        font-size: 0.75rem;
    }

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

    .toast {
        right: 10px;
        left: 10px;
        max-width: none;
        transform: translateY(-100%);
    }

    .toast.show {
        transform: translateY(0);
    }
}

@media (max-width: 480px) {
    .chart-wrapper {
        height: 300px;
    }

    .chart-loading {
        height: 300px;
    }

    .stat-value {
        font-size: 2rem;
    }
}

/* Dark mode support (optional) */
@media (prefers-color-scheme: dark) {
    :root {
        --background: #0f172a;
        --surface: #1e293b;
        --surface-2: #334155;
        --text-primary: #f8fafc;
        --text-secondary: #cbd5e1;
        --text-muted: #64748b;
        --border: #334155;
        --border-dark: #475569;
    }
}
