/* MeshWatch Dashboard Styles */

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #0f3460;
    --text-primary: #eee;
    --text-secondary: #a0a0a0;
    --accent-primary: #e94560;
    --accent-success: #4ade80;
    --accent-warning: #fbbf24;
    --accent-danger: #ef4444;
    --accent-info: #38bdf8;
    --border-color: #2d4a7c;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

/* Header Styles */
.dashboard-header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.dashboard-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.dashboard-header h1::before {
    content: '';
    width: 8px;
    height: 8px;
    background: var(--accent-success);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

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

.header-info {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.header-info .status-badge {
    font-size: 0.875rem;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-weight: 600;
}

.refresh-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.refresh-indicator.loading {
    color: var(--accent-info);
}

.refresh-indicator.paused {
    color: var(--accent-warning);
}

/* Refresh Toggle Button */
.refresh-toggle-btn {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.refresh-toggle-btn:hover {
    background: var(--accent-info);
    border-color: var(--accent-info);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(56, 189, 248, 0.3);
}

.refresh-toggle-btn.paused {
    background: var(--accent-warning);
    border-color: var(--accent-warning);
}

.refresh-toggle-btn.paused:hover {
    background: #f59e0b;
    border-color: #f59e0b;
}

/* Main Container */
.dashboard-container {
    padding: 1.5rem;
    max-width: 1800px;
    margin: 0 auto;
}

/* Grid Layout */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

/* Balanced 2-column layout for larger screens */
@media (min-width: 1024px) {
    .metrics-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* 3-column layout for very large screens */
@media (min-width: 1600px) {
    .metrics-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* 2x2 Grid for top MQTT metrics */
.metrics-grid-2x2 {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

@media (min-width: 768px) {
    .metrics-grid-2x2 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Full width single column */
.metrics-grid-full {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

/* Full width with 2 columns (for cache and circuit breakers) */
.metrics-grid-full-2col {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

@media (min-width: 768px) {
    .metrics-grid-full-2col {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Card Styles */
.metric-card {
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.metric-card.wide {
    grid-column: span 2;
}

@media (max-width: 900px) {
    .metric-card.wide {
        grid-column: span 1;
    }
}

.card-header {
    background: rgba(0, 0, 0, 0.2);
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-header h2 {
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-header .status-badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-weight: 500;
}

.status-badge.healthy {
    background: rgba(74, 222, 128, 0.2);
    color: var(--accent-success);
}

.status-badge.warning {
    background: rgba(251, 191, 36, 0.2);
    color: var(--accent-warning);
}

.status-badge.critical {
    background: rgba(239, 68, 68, 0.2);
    color: var(--accent-danger);
}

.card-body {
    padding: 1.25rem;
}

/* Stat Grid */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.stat-item {
    text-align: center;
    padding: 0.75rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-info);
    margin-bottom: 0.25rem;
}

.stat-value.success {
    color: var(--accent-success);
}

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

.stat-value.danger {
    color: var(--accent-danger);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Rate Bar */
.rate-bars {
    margin-top: 1rem;
}

.rate-bar-item {
    margin-bottom: 0.75rem;
}

.rate-bar-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
}

.rate-bar {
    height: 8px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    overflow: hidden;
}

.rate-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
}

.rate-bar-fill.success {
    background: linear-gradient(90deg, var(--accent-success), #22c55e);
}

.rate-bar-fill.warning {
    background: linear-gradient(90deg, var(--accent-warning), #f59e0b);
}

.rate-bar-fill.danger {
    background: linear-gradient(90deg, var(--accent-danger), #dc2626);
}

/* Chart Container */
.chart-container {
    position: relative;
    height: 250px;
    margin-top: 1rem;
}

.chart-container.small {
    height: 180px;
}

/* Thread List */
.thread-list {
    list-style: none;
}

.thread-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    margin-bottom: 0.5rem;
}

.thread-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.thread-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.thread-status-dot.healthy {
    background: var(--accent-success);
    box-shadow: 0 0 8px var(--accent-success);
}

.thread-status-dot.unhealthy {
    background: var(--accent-danger);
    box-shadow: 0 0 8px var(--accent-danger);
}

.thread-name {
    font-weight: 500;
}

.thread-stats {
    display: flex;
    gap: 1rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Circuit Breaker States */
.circuit-breakers {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.circuit-breaker-item {
    background: rgba(0, 0, 0, 0.2);
    padding: 1rem;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.cb-name {
    font-weight: 600;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.cb-state {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
    min-width: 90px;
    text-align: center;
}

.cb-state.CLOSED {
    background: rgba(74, 222, 128, 0.2);
    color: var(--accent-success);
}

.cb-state.OPEN {
    background: rgba(239, 68, 68, 0.2);
    color: var(--accent-danger);
}

.cb-state.HALF_OPEN {
    background: rgba(251, 191, 36, 0.2);
    color: var(--accent-warning);
}

.cb-stats {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Cache Stats */
.cache-list {
    display: none;
}

.cache-item {
    background: rgba(0, 0, 0, 0.2);
    padding: 1rem;
    border-radius: 8px;
}

.cache-name {
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cache-hit-rate {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-success);
    margin-bottom: 0.25rem;
}

.cache-details {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Error State */
.error-message {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--accent-danger);
    border-radius: 8px;
    padding: 1rem;
    color: var(--accent-danger);
    text-align: center;
    margin: 1rem 0;
}

/* Loading State */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-info);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    .dashboard-header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

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

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

    .header-info {
        flex-direction: column;
        gap: 0.5rem;
    }
}

@media (max-width: 480px) {
    .dashboard-container {
        padding: 1rem;
    }

    .card-body {
        padding: 1rem;
    }

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

/* Topic Bar Chart */
.topics-bar-chart {
    display: flex;
    align-items: stretch;
    gap: 0.25rem;
    height: 220px;
    padding: 0.5rem 0 0;
}

.topic-bar-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.topic-bar-container:hover {
    opacity: 0.8;
}

.topic-bar {
    width: 100%;
    margin-top: auto;
    background: linear-gradient(180deg, var(--accent-info), rgba(56, 189, 248, 0.6));
    border-radius: 4px 4px 0 0;
    min-height: 4px;
    transition: all 0.3s ease;
}

.topic-bar:hover {
    background: linear-gradient(180deg, var(--accent-primary), rgba(233, 69, 96, 0.6));
}

.topic-bar-label {
    font-size: 0.65rem;
    color: var(--text-secondary);
    font-weight: 600;
    padding: 0.4rem 0.15rem 0;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

/* Queue Depth Bars */
.queue-depths {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: 0.5rem;
    margin-top: 1rem;
}

.queue-bar {
    text-align: center;
}

.queue-bar-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.queue-bar-container {
    height: 60px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    overflow: hidden;
}

.queue-bar-fill {
    background: var(--accent-info);
    transition: height 0.5s ease;
    min-height: 2px;
}

.queue-bar-value {
    font-size: 0.7rem;
    margin-top: 0.25rem;
}
