/* === CSS Custom Properties === */
:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #252540;
    --bg-card: rgba(30, 30, 50, 0.8);
    --bg-glass: rgba(255, 255, 255, 0.05);

    --text-primary: #ffffff;
    --text-secondary: #a0a0b0;
    --text-muted: #606070;

    --primary-color: #2563eb;
    --accent-color: #3b82f6;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --unknown-color: #64748b;

    --card-border: rgba(255, 255, 255, 0.1);
    --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);

    --transition: all 0.3s ease;

    /* Extended variables */
    --accent-primary: #6366f1;
    --accent-secondary: #8b5cf6;
    --accent-gradient: linear-gradient(135deg, #6366f1, #8b5cf6);

    --success: #10b981;
    --success-glow: rgba(16, 185, 129, 0.4);
    --warning: #f59e0b;
    --warning-glow: rgba(245, 158, 11, 0.4);
    --danger: #ef4444;
    --danger-glow: rgba(239, 68, 68, 0.4);

    --border-color: rgba(255, 255, 255, 0.1);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;

    --sidebar-width: 280px;
    --header-height: 80px;
}

/* === Reset & Base === */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Animated background gradient */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse at 20% 20%, rgba(99, 102, 241, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(139, 92, 246, 0.1) 0%, transparent 50%);
    pointer-events: none;
    z-index: -1;
}

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

/* === Header === */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(15, 15, 26, 0.9);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    height: var(--header-height);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 1800px;
    margin: 0 auto;
    padding: 0 2rem;
    height: 100%;
}

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

.logo-icon {
    font-size: 2rem;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 600;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.stats {
    display: flex;
    gap: 2rem;
}

.stat {
    text-align: center;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    min-width: 80px;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

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

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

/* === Main Layout === */
.main {
    display: flex;
    flex: 1;
    max-width: 1800px;
    margin: 0 auto;
    width: 100%;
}

/* === Sidebar === */
.sidebar {
    width: var(--sidebar-width);
    padding: 1.5rem;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    height: calc(100vh - var(--header-height));
    position: sticky;
    top: var(--header-height);
    overflow-y: auto;
}

.search-box {
    margin-bottom: 1.5rem;
}

.search-box input {
    width: 100%;
    padding: 0.875rem 1rem;
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: var(--transition);
}

.search-box input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.categories h2,
.filters h2 {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0.75rem;
}

.categories ul,
.filters ul {
    list-style: none;
}

.category,
.filter {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 0.25rem;
}

.category:hover,
.filter:hover {
    background: var(--bg-glass);
}

.category.active,
.filter.active {
    background: var(--accent-gradient);
}

.category-count {
    background: var(--bg-tertiary);
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.filters {
    margin-top: 1.5rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 0.5rem;
}

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

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

.status-dot.degraded {
    background: var(--warning);
    box-shadow: 0 0 8px var(--warning-glow);
}

.status-dot.unknown {
    background: var(--text-muted);
}

/* === Content Area === */
.content {
    flex: 1;
    padding: 1.5rem 2rem;
    overflow-y: auto;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.results-count {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.view-options {
    display: flex;
    gap: 0.5rem;
}

.view-btn {
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.view-btn:hover,
.view-btn.active {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}

/* === Services Grid === */
.services-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.25rem;
}

.services-grid.list-view {
    grid-template-columns: 1fr;
}

/* === Service Card === */
.service-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    transition: var(--transition);
    backdrop-filter: blur(10px);
    position: relative;
    overflow: hidden;
}

.service-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--accent-gradient);
    opacity: 0;
    transition: var(--transition);
}

.service-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--accent-primary);
}

.service-card:hover::before {
    opacity: 1;
}

.service-card.healthy::before {
    background: var(--success);
    opacity: 1;
}

.service-card.unhealthy::before {
    background: var(--danger);
    opacity: 1;
}

.card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.service-name {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.75rem;
    padding: 0.25rem 0.625rem;
    border-radius: 999px;
    font-weight: 500;
}

.status-indicator.healthy {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
}

.status-indicator.unhealthy {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.status-indicator.degraded {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
}

.status-indicator.unknown {
    background: rgba(107, 107, 128, 0.15);
    color: var(--text-muted);
}

.status-indicator .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    animation: blink 1.5s ease-in-out infinite;
}

.status-indicator.healthy .dot {
    background: var(--success);
}

.status-indicator.unhealthy .dot {
    background: var(--danger);
}

.status-indicator.unknown .dot {
    background: var(--text-muted);
    animation: none;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }
}

.service-description {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 1rem;
    line-height: 1.5;
}

.service-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.meta-tag {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    padding: 0.25rem 0.625rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 500;
}

.meta-tag.category {
    background: rgba(99, 102, 241, 0.2);
    color: var(--accent-primary);
}

.meta-tag.version {
    background: rgba(139, 92, 246, 0.2);
    color: var(--accent-secondary);
}

.meta-tag.port {
    font-family: 'SF Mono', 'Consolas', monospace;
}

.service-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.test-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-tertiary);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
}

.test-link {
    flex: 1;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-decoration: none;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.test-link:hover {
    color: var(--primary-color);
}

.test-btn {
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: var(--bg-glass);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.75rem;
    transition: var(--transition);
}

.test-btn.success {
    background: rgba(16, 185, 129, 0.2);
    border-color: var(--success);
}

.test-btn.error {
    background: rgba(239, 68, 68, 0.2);
    border-color: var(--error);
}

.action-row {
    display: flex;
    gap: 0.5rem;
}

.category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.test-all-btn {
    margin-top: 0.25rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.65rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: var(--bg-glass);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    width: 100%;
}

.test-all-btn:hover {
    background: var(--primary-color);
    color: var(--bg-primary);
    border-color: var(--primary-color);
}

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

.action-btn {
    flex: 1;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    text-align: center;
}

.action-btn:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.action-btn.primary {
    background: var(--accent-gradient);
    border: none;
    color: white;
}

.action-btn.primary:hover {
    opacity: 0.9;
}

/* Response time indicator */
.response-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.response-time.fast {
    color: var(--success);
}

.response-time.medium {
    color: var(--warning);
}

.response-time.slow {
    color: var(--danger);
}

/* === List View Styles === */
.services-grid.list-view .service-card {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 1rem 1.5rem;
}

.services-grid.list-view .card-header {
    flex: 0 0 200px;
    margin-bottom: 0;
}

.services-grid.list-view .service-description {
    flex: 1;
    margin-bottom: 0;
}

.services-grid.list-view .service-meta {
    flex: 0 0 auto;
    margin-bottom: 0;
}

.services-grid.list-view .service-actions {
    flex: 0 0 auto;
    border-top: none;
    padding-top: 0;
}

/* === Loading State === */
.loading {
    text-align: center;
    padding: 4rem;
    color: var(--text-muted);
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

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

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: 4rem;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* === Responsive === */
@media (max-width: 1200px) {
    .services-grid {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    }
}

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        left: -100%;
        top: var(--header-height);
        height: calc(100vh - var(--header-height));
        z-index: 50;
        transition: var(--transition);
    }

    .sidebar.open {
        left: 0;
    }

    .content {
        padding: 1rem;
    }

    .stats {
        display: none;
    }
}

@media (max-width: 600px) {
    .header-content {
        padding: 0 1rem;
    }

    .logo h1 {
        font-size: 1.2rem;
    }

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

    .services-grid.list-view .service-card {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* === Refresh Controls === */
.refresh-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-left: 1.5rem;
    border-left: 1px solid var(--border-color);
}

.refresh-btn {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.refresh-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

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

.countdown {
    font-size: 0.8rem;
    color: var(--text-muted);
    background: var(--bg-glass);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-family: monospace;
}

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

/* === Service Timing === */
.service-timing {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin: 0.5rem 0;
}

.response-time {
    font-weight: 500;
    padding: 0.2rem 0.5rem;
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
}

.response-time.fast {
    color: var(--success);
    background: rgba(16, 185, 129, 0.15);
}

.response-time.medium {
    color: var(--warning);
    background: rgba(245, 158, 11, 0.15);
}

.response-time.slow {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.15);
}

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

/* === Health History === */
.health-history {
    display: flex;
    gap: 4px;
    margin: 0.5rem 0;
    padding: 0.5rem;
    background: var(--bg-glass);
    border-radius: var(--radius-sm);
}

.history-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    transition: var(--transition);
}

.history-dot.healthy {
    background: var(--success);
    box-shadow: 0 0 6px var(--success-glow);
}

.history-dot.unhealthy {
    background: var(--danger);
    box-shadow: 0 0 6px var(--danger-glow);
}

.history-dot:hover {
    transform: scale(1.3);
}

/* === Test Button Error State === */
.test-btn.error {
    background: rgba(239, 68, 68, 0.2);
    border-color: var(--danger);
    color: var(--danger);
}

.test-btn.error:hover {
    background: rgba(239, 68, 68, 0.3);
}

.test-btn.success {
    background: rgba(16, 185, 129, 0.2);
    border-color: var(--success);
    color: var(--success);
}

.test-btn.success:hover {
    background: rgba(16, 185, 129, 0.3);
}