:root {
    --color-bg: #0a0a0a;
    --color-surface: #141414;
    --color-surface-accent: #1e1e1e;
    --color-primary: #7289da;
    --color-secondary: #5865f2;
    --color-success: #43b581;
    --color-danger: #f04747;
    --color-warning: #faa61a;
    --color-text: #ffffff;
    --color-text-muted: #72767d;
    --font-main: 'Inter', sans-serif;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.2);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.3);
    --transition: all 0.3s ease;
    --color-success-rgb: 67, 181, 129; /* RGB values for rgba */
    --color-danger-rgb: 240, 71, 71;   /* RGB values for rgba */
}

/* Global Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-main);
}

body {
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
}

/* Command Center Header */
.command-center {
    background: var(--color-surface);
    padding: 1.5rem;
    box-shadow: var(--shadow-lg);
}

.header-grid {
    max-width: 1400px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2rem;
    align-items: center;
}

/* Brand Section */
.brand-section {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-container {
    font-size: 2.5rem;
    color: var(--color-primary);
}

.title-stack h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.subtitle {
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

/* Control Deck */
.control-deck {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Search Matrix */
.search-field {
    position: relative;
    width: 100%;
}

.search-field input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.5rem;
    background: var(--color-surface-accent);
    border: 1px solid var(--color-surface);
    border-radius: 6px;
    color: var(--color-text);
    font-size: 1rem;
}

.search-field .mdi-magnify {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-muted);
}

/* Filter Chips */
.filter-chips {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.chip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--color-surface-accent);
    border: none;
    border-radius: 20px;
    color: var(--color-text);
    cursor: pointer;
    transition: var(--transition);
}

.chip:hover {
    background: var(--color-primary);
}

/* Metrics Dashboard */

.view-tabs {
    display: flex;
    justify-content: center;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--color-surface-accent);
}

.tab-button {
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 1rem;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tab-button:hover {
    color: var(--color-text);
}

.tab-button.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.metrics-dashboard {
    display: flex;
    gap: 2rem;
    margin-top: 1rem;
}

.metric {
    display: flex;
    flex-direction: column;
}

.metric-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-primary);
}

.metric-label {
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

/* Server Grid & Cards (Modified for 4-column grid) */
.server-grid {
    display: grid; /* Use CSS Grid */
    grid-template-columns: repeat(4, 1fr); /* Create 4 equal columns */
    gap: 0.5rem; /* Gap between grid items */
    padding: 0.5rem; /* Padding around the grid */
}

.server-card {
    background: var(--color-surface);
    padding: 0.75rem;
    cursor: pointer;
    transition: var(--transition);
    border-radius: 6px; /* Add a subtle border-radius for the square look */
    box-shadow: var(--shadow-sm); /* Add a subtle shadow to lift the cards */
    display: flex;
    flex-direction: column; /* Stack content within the card vertically */
    align-items: flex-start; /* Align content to the left */
    /* Remove the bottom border as it's no longer needed in a grid */
    border-bottom: none;
}

.server-card:last-child {
    border-bottom: none; /* Remove border from the last item */
}

.server-card:hover {
    transform: translateY(-2px); /* More pronounced hover effect for individual cards */
    border-color: var(--color-primary); /* Keep the border color change on hover */
    box-shadow: var(--shadow-lg); /* Enhance shadow on hover */
}

.server-main-info {
    display: flex;
    align-items: center;
    gap: 0.5rem; /* Reduced gap for better alignment in the square */
    width: 100%; /* Ensure it takes the full width of the card */
    margin-bottom: 0.3rem; /* Add some space below the main info */
}

.server-rank {
    color: var(--color-text-muted);
    font-weight: 500;
    font-size: 0.9rem;
    margin-right: 0.3rem;
}

.server-rank.top-3 {
    color: var(--color-primary);
}

.server-name {
    font-size: 1rem;
    font-weight: 600;
    flex-grow: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.server-players {
    color: var(--color-text-muted);
    font-size: 0.85rem;
    margin-left: auto; /* Push to the right within the main info */
}

.server-status {
    display: inline-block;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    margin-left: 0.3rem;
}

.server-status.online {
    background: rgba(var(--color-success-rgb), 0.2);
    color: var(--color-success);
}

.server-status.offline {
    background: rgba(var(--color-danger-rgb), 0.2);
    color: var(--color-danger);
}

.server-categories {
    display: flex;
    gap: 0.2rem;
    margin-top: 0.3rem;
    flex-wrap: wrap; /* Allow tags to wrap if they don't fit */
    width: 100%; /* Take full width within the card */
}

.category-tag {
    display: inline-block;
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    font-size: 0.65rem; /* Slightly smaller for better fit */
    color: white;
    font-weight: 500;
    margin-bottom: 0.2rem; /* Space between wrapped tags */
}

.favorite-btn {
    background: transparent;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    font-size: 1rem;
    z-index: 1;
    transition: var(--transition);
    /* Adjust positioning for the top right of the square */
    margin-left: auto;
}

.favorite-btn.active {
    color: var(--color-warning);
}

/* Modal Styles */
.intel-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
}

.modal-matrix {
    position: relative;
    background: var(--color-surface);
    max-width: 600px;
    width: 90%;
    margin: 2rem auto;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.close-modal {
    background: transparent;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    font-size: 1.5rem;
}

.server-detail {
    margin: 1rem 0;
    padding: 0.5rem;
    background: var(--color-surface-accent);
    border-radius: 4px;
}

.server-detail-label {
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

.server-detail-value {
    color: var(--color-text);
    font-weight: 500;
}

/* Tag System (Old tag styles removed) */

/* Loading & Error States */
.loading-matrix,
.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 2rem;
    text-align: center;
    color: var(--color-text-muted);
}

.loading-matrix .mdi,
.error-state .mdi {
    font-size: 2rem;
    color: var(--color-primary);
}

/* Status Indicators */
.status-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
}

.status-online {
    background: var(--color-success);
    color: white;
}

.status-offline {
    background: var(--color-danger);
    color: white;
}

/* Footer Styles */
.command-footer {
    background: var(--color-surface);
    padding: 1rem;
    margin-top: auto;
}

.footer-grid {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.footer-metrics {
    display: flex;
    gap: 1rem;
}

/* Responsive Design (Adjusted for single column list) */
@media (max-width: 1200px) {
    .server-grid {
        grid-template-columns: repeat(3, 1fr); /* Adjust to 3 columns on medium screens */
    }
}

@media (max-width: 900px) {
    .server-grid {
        grid-template-columns: repeat(2, 1fr); /* Adjust to 2 columns on smaller screens */
    }
}

@media (max-width: 600px) {
    .server-grid {
        grid-template-columns: 1fr; /* Back to single column on very small screens */
    }

    .metrics-dashboard {
        flex-wrap: wrap;
    }

    .server-grid {
        /* Remains flex column */
        padding: 0.5rem;
    }

    .modal-matrix {
        width: 95%;
        margin: 1rem auto;
        padding: 1rem;
    }

    .footer-grid {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    .footer-metrics {
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .filter-chips {
        flex-wrap: wrap;
        justify-content: center;
    }

    .server-main-info {
        flex-direction: column; /* Stack name and players/status on smaller screens */
        align-items: flex-start;
    }

    .server-players {
        margin-left: 0; /* Reset margin */
    }

    .server-status {
        margin-left: 0; /* Reset margin */
        margin-top: 0.2rem;
    }

    .server-categories {
        margin-top: 0.5rem; /* More space for categories */
    }

    .tag-container {
        justify-content: center;
    }

    .server-card {
        padding: 0.75rem;
        flex-direction: column; /* Stack main info and favorite button */
        align-items: flex-start;
    }

    .favorite-btn {
        margin-left: 0;
        margin-top: 0.5rem;
        align-self: flex-end; /* Push to the right in the stacked layout */
    }

    .rank {
        width: 1.75rem;
        height: 1.75rem;
        font-size: 0.8rem;
    }
}

/* Favorites Section */
#favorites-section {
    margin-top: 1.5rem;
    padding: 1rem;
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
    border-radius: 6px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.section-header h2 {
    font-size: 1.2rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-meta {
    color: var(--color-text-muted);
    font-size: 0.8rem;
}

#favorites-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
}

/* Empty state styling */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    text-align: center;
    color: var(--color-text-muted);
    grid-column: 1 / -1;
}

.empty-state .mdi {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: var(--color-primary);
}

.empty-state p {
    max-width: 300px;
    line-height: 1.5;
}

/* Responsive design for favorites container */
@media (max-width: 1200px) {
    #favorites-container {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 900px) {
    #favorites-container {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    #favorites-container {
        grid-template-columns: 1fr;
    }
}
