/* Global Design Tokens & Variables */
:root {
    --bg-color: #0b0f19;
    --card-bg: rgba(17, 24, 39, 0.55);
    --card-border: rgba(255, 255, 255, 0.06);
    --card-hover-border: rgba(255, 255, 255, 0.12);
    
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;

    /* Service Type Colors */
    --color-app: #a855f7;       /* Purple */
    --color-app-glow: rgba(168, 85, 247, 0.15);
    --color-static: #10b981;    /* Green */
    --color-static-glow: rgba(16, 185, 129, 0.15);
    --color-redirect: #f59e0b;  /* Amber */
    --color-redirect-glow: rgba(245, 158, 11, 0.15);

    /* Health Status Colors */
    --color-online: #10b981;
    --color-offline: #ef4444;
    --color-checking: #3b82f6;

    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;
    
    --transition-smooth: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Base resets & backgrounds */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-body);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
    padding-bottom: 60px;
}

/* Modern ambient mesh gradients */
.mesh-gradient {
    position: absolute;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.12;
    z-index: -1;
    pointer-events: none;
}

.bg-mesh-1 {
    background: radial-gradient(circle, var(--color-app) 0%, transparent 70%);
    top: -10%;
    left: -10%;
}

.bg-mesh-2 {
    background: radial-gradient(circle, #3b82f6 0%, transparent 70%);
    bottom: 10%;
    right: -10%;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}
::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Page Layout */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 40px 24px;
}

/* Header Area */
.app-header {
    text-align: center;
    margin-bottom: 48px;
}

.logo-area {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.logo-icon {
    width: 32px;
    height: 32px;
}

.logo-text {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.25rem;
    letter-spacing: 1px;
    background: linear-gradient(135deg, #a855f7 0%, #3b82f6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.main-title {
    font-family: var(--font-heading);
    font-size: 2.75rem;
    font-weight: 800;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
    background: linear-gradient(to right, #ffffff, #e5e7eb);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    font-size: 1.05rem;
    color: var(--text-secondary);
    font-weight: 400;
}

/* Search & Filters Panel */
.controls-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: rgba(15, 23, 42, 0.3);
    border: 1px solid var(--card-border);
    backdrop-filter: blur(8px);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 36px;
}

@media (min-width: 768px) {
    .controls-panel {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
}

/* Search input */
.search-wrapper {
    position: relative;
    flex: 1;
    max-width: 500px;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 14px;
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    transition: var(--transition-smooth);
    pointer-events: none;
}

.search-wrapper input {
    width: 100%;
    padding: 12px 40px 12px 42px;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.95rem;
    outline: none;
    transition: var(--transition-smooth);
}

.search-wrapper input:focus {
    border-color: rgba(168, 85, 247, 0.5);
    box-shadow: 0 0 15px rgba(168, 85, 247, 0.1);
    background: rgba(0, 0, 0, 0.4);
}

.search-wrapper input:focus + .search-icon {
    color: var(--color-app);
}

.clear-btn {
    position: absolute;
    right: 12px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
    transition: var(--transition-smooth);
}

.clear-btn:hover {
    color: var(--text-primary);
}

/* Filter buttons */
.filters-wrapper {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    color: var(--text-secondary);
    padding: 10px 16px;
    font-size: 0.85rem;
    font-family: var(--font-body);
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition-smooth);
}

.filter-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
    border-color: var(--card-hover-border);
}

.filter-btn.active {
    background: rgba(168, 85, 247, 0.15);
    border-color: rgba(168, 85, 247, 0.4);
    color: #f3e8ff;
}

.filter-count {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-muted);
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 6px;
    font-weight: 600;
    transition: var(--transition-smooth);
}

.filter-btn.active .filter-count {
    background: rgba(168, 85, 247, 0.25);
    color: #f3e8ff;
}

/* Grid layout & cards */
.catalogue-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
    min-height: 200px;
}

/* Glassmorphic Card */
.route-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 16px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 20px;
    transition: var(--transition-smooth);
    position: relative;
    overflow: hidden;
}

.route-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: var(--theme-color, var(--color-app));
    opacity: 0.7;
}

/* Hover effect on Card */
.route-card:hover {
    transform: translateY(-4px);
    border-color: var(--card-hover-border);
    box-shadow: 0 12px 30px -10px var(--theme-glow, var(--color-app-glow)),
                0 0 1px 1px var(--theme-color, var(--color-app)) inset;
}

/* Types styles mapped inside js dynamically */
.route-card.type-app {
    --theme-color: var(--color-app);
    --theme-glow: var(--color-app-glow);
}
.route-card.type-static {
    --theme-color: var(--color-static);
    --theme-glow: var(--color-static-glow);
}
.route-card.type-redirect {
    --theme-color: var(--color-redirect);
    --theme-glow: var(--color-redirect-glow);
}

/* Top Section of Card */
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.badge-type {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 4px 10px;
    border-radius: 9999px;
}

.type-app .badge-type {
    background: rgba(168, 85, 247, 0.15);
    color: #e9d5ff;
    border: 1px solid rgba(168, 85, 247, 0.2);
}

.type-static .badge-type {
    background: rgba(16, 185, 129, 0.15);
    color: #d1fae5;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.type-redirect .badge-type {
    background: rgba(245, 158, 11, 0.15);
    color: #fef3c7;
    border: 1px solid rgba(245, 158, 11, 0.2);
}

/* Status Indicator */
.status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: rgba(0, 0, 0, 0.2);
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    position: relative;
}

/* Pulsing effects */
.status-dot.online {
    background-color: var(--color-online);
    box-shadow: 0 0 8px var(--color-online);
}
.status-dot.online::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    border-radius: 50%;
    border: 2px solid var(--color-online);
    animation: statusPulse 1.8s infinite ease-in-out;
}

.status-dot.offline {
    background-color: var(--color-offline);
    box-shadow: 0 0 8px var(--color-offline);
}

.status-dot.checking {
    background-color: var(--color-checking);
}
.status-dot.checking::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    border-radius: 50%;
    border: 2px solid var(--color-checking);
    animation: statusPulse 1.2s infinite ease-in-out;
}

@keyframes statusPulse {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(2.4); opacity: 0; }
}

/* Card Content */
.card-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.site-name {
    font-family: var(--font-heading);
    font-size: 1.35rem;
    font-weight: 600;
    color: #ffffff;
    line-height: 1.2;
}

.site-domain {
    font-size: 0.85rem;
    color: var(--text-secondary);
    word-break: break-all;
    font-family: monospace;
}

.site-description {
    font-size: 0.88rem;
    color: var(--text-muted);
    line-height: 1.4;
    margin-top: 6px;
}

/* Aliases sublist */
.aliases-list {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.04);
}
.alias-tag {
    display: inline-block;
    font-size: 0.72rem;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.03);
    padding: 2px 6px;
    border-radius: 4px;
    margin-right: 4px;
    margin-top: 4px;
    font-family: monospace;
}

/* Card Footer / Actions */
.card-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: auto;
}

.launch-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 600;
    color: #ffffff;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 8px 16px;
    border-radius: 8px;
    transition: var(--transition-smooth);
}

.launch-link svg {
    width: 14px;
    height: 14px;
    transition: var(--transition-smooth);
}

.launch-link:hover {
    background: var(--theme-color, var(--color-app));
    color: #ffffff;
    border-color: transparent;
    box-shadow: 0 4px 12px var(--theme-glow, var(--color-app-glow));
}

.launch-link:hover svg {
    transform: translate(2px, -2px);
}

/* Loading, Error and Empty states */
.loading-state, .error-state, .empty-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    background: rgba(15, 23, 42, 0.25);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    backdrop-filter: blur(4px);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(168, 85, 247, 0.1);
    border-top: 3px solid var(--color-app);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

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

.loading-state p, .error-state p, .empty-state p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.error-icon, .empty-icon {
    width: 48px;
    height: 48px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.error-icon {
    color: var(--color-offline);
}

.retry-btn, .retry-btn:focus {
    margin-top: 16px;
    background: rgba(239, 68, 68, 0.1);
    color: #fecaca;
    border: 1px solid rgba(239, 68, 68, 0.2);
    padding: 8px 20px;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.retry-btn:hover {
    background: var(--color-offline);
    color: #ffffff;
    border-color: transparent;
}

/* Footer layout */
.app-footer {
    text-align: center;
    margin-top: 64px;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.badge-proxy {
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--text-secondary);
}

/* Actions wrapper for controls */
.controls-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

/* Toggle Switch Styling */
.toggle-container {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 8px 14px;
    height: 38px;
    user-select: none;
    transition: var(--transition-smooth);
}

.toggle-container:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--card-hover-border);
}

.toggle-text {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: var(--transition-smooth);
}

.toggle-container:hover .toggle-text {
    color: var(--text-primary);
}

.switch {
    position: relative;
    display: inline-block;
    width: 34px;
    height: 20px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .3s;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.slider:before {
    position: absolute;
    content: "";
    height: 12px;
    width: 12px;
    left: 3px;
    bottom: 3.5px;
    background-color: var(--text-secondary);
    transition: .3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: rgba(168, 85, 247, 0.25);
    border-color: rgba(168, 85, 247, 0.4);
}

input:checked + .slider:before {
    transform: translateX(14px);
    background-color: var(--color-app);
    box-shadow: 0 0 8px var(--color-app);
}

/* Rules for hiding offline routes by default */
body.hide-offline .route-card.state-offline {
    display: none !important;
}
