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

:root {
    --primary-color: #2ecc71;
    --secondary-color: #3498db;
    --background: #1a1a2e;
    --card-bg: #16213e;
    --text-color: #eaeaea;
    --border-color: #2d3561;
    --hover-color: #0f3460;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --danger-color: #e74c3c;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--background);
    color: var(--text-color);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    text-align: center;
    padding: 30px 0;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 30px;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

header h1 {
    font-size: 2.5em;
    color: var(--primary-color);
    margin-bottom: 10px;
}

.subtitle {
    color: #95a5a6;
    font-size: 1.1em;
}

/* Auth Section */
.auth-section {
    display: flex;
    align-items: center;
    gap: 15px;
}

.login-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    background: white;
    color: #333;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.3s;
}

.login-btn:hover {
    background: #f0f0f0;
    transform: translateY(-2px);
}

.google-icon {
    width: 20px;
    height: 20px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    background: var(--card-bg);
    border-radius: 8px;
    border: 2px solid var(--border-color);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

.user-details {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.user-name {
    color: var(--text-color);
    font-weight: 600;
}

.user-id {
    color: #95a5a6;
    font-size: 0.85em;
    display: flex;
    align-items: center;
    gap: 6px;
}

.role-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75em;
    font-weight: 600;
    gap: 4px;
}

.role-badge.admin {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.role-badge.premium {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(245, 87, 108, 0.3);
}

.role-icon {
    width: 14px;
    height: 14px;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
}

.logout-btn {
    padding: 6px 16px;
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background 0.3s;
}

.logout-btn:hover {
    background: #c0392b;
}

/* Icone SVG */
.icon {
    width: 24px;
    height: 24px;
    vertical-align: middle;
    margin-right: 8px;
    display: inline-block;
}

.icon-btn {
    width: 16px;
    height: 16px;
    vertical-align: middle;
    margin-right: 6px;
    display: inline-block;
}

.icon-small {
    width: 18px;
    height: 18px;
    vertical-align: middle;
    margin-right: 6px;
    display: inline-block;
}

h2 {
    display: flex;
    align-items: center;
}

/* Sections */
section {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 25px;
    margin-bottom: 30px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

section h2 {
    color: var(--primary-color);
    margin-bottom: 20px;
    font-size: 1.8em;
}

/* Search Section */
.search-controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 20px;
}

.search-container {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.online-players-container {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.online-players-container.hidden {
    display: none;
}

#searchInput {
    flex: 1;
    min-width: 250px;
    padding: 12px 20px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--background);
    color: var(--text-color);
    font-size: 1em;
    transition: border-color 0.3s;
}

#searchInput:focus {
    outline: none;
    border-color: var(--secondary-color);
}

.server-filter {
    padding: 12px 20px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--background);
    color: var(--text-color);
    font-size: 1em;
    cursor: pointer;
    min-width: 200px;
    transition: border-color 0.3s;
}

.server-filter:focus {
    outline: none;
    border-color: var(--secondary-color);
}

#searchBtn {
    padding: 12px 30px;
    background: var(--secondary-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    transition: background 0.3s, transform 0.1s;
}

#searchBtn:hover {
    background: #2980b9;
}

#searchBtn:active {
    transform: scale(0.98);
}

#searchBtn:disabled {
    background: #7f8c8d;
    cursor: not-allowed;
    opacity: 0.6;
}

.btn-online {
    padding: 12px 25px;
    background: var(--success-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.3s, transform 0.1s;
}

.btn-online:hover {
    background: #229954;
}

.btn-online:active {
    transform: scale(0.98);
}

.search-results {
    max-height: 400px;
    overflow-y: auto;
}

.search-result-item {
    background: var(--card-bg);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 10px;
    border-left: 4px solid var(--primary-color);
    display: grid;
    grid-template-columns: 2fr 1fr 2fr 1fr;
    gap: 15px;
    align-items: center;
}

.search-result-item div {
    padding: 5px;
}

.search-result-item-inline {
    background: var(--card-bg);
    padding: 15px 20px;
    border-radius: 8px;
    margin-bottom: 10px;
    border-left: 4px solid var(--primary-color);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 0.95em;
}

.result-inline-field {
    display: inline-flex;
    align-items: center;
    color: var(--text-color);
}

.result-inline-field.status-online {
    color: var(--success-color);
    font-weight: 600;
}

.result-inline-field.status-offline {
    color: var(--danger-color);
    font-weight: 600;
}

.result-inline-field.result-muted {
    color: #95a5a6;
    font-size: 0.9em;
}

.result-separator {
    color: #4a5568;
    font-weight: bold;
}

.search-result-label {
    font-size: 0.85em;
    color: #95a5a6;
    display: flex;
    align-items: center;
    margin-bottom: 3px;
}

.icon-label {
    width: 16px;
    height: 16px;
    margin-right: 6px;
    flex-shrink: 0;
}

.icon-status {
    width: 14px;
    height: 14px;
    margin-right: 6px;
    vertical-align: middle;
}

.search-result-value {
    font-weight: 600;
    color: var(--text-color);
    display: flex;
    align-items: center;
}

.search-result-value.status-online {
    color: var(--success-color);
    font-weight: 700;
}

.search-result-value.status-offline {
    color: var(--danger-color);
    font-weight: 700;
}

.no-results {
    text-align: center;
    padding: 40px;
    color: #95a5a6;
    font-style: italic;
}

/* Chart Section */
.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.chart-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

.btn-zoom, .btn-toggle {
    padding: 10px 20px;
    background: var(--secondary-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 600;
    transition: background 0.3s, transform 0.1s;
}

.btn-zoom:hover, .btn-toggle:hover {
    background: #2980b9;
}

.btn-zoom:active, .btn-toggle:active {
    transform: scale(0.95);
}

.btn-favorites {
    padding: 10px 20px;
    background: var(--warning-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 600;
    transition: background 0.3s, transform 0.1s;
}

.btn-favorites:hover {
    background: #e67e22;
}

.btn-favorites:active {
    transform: scale(0.95);
}

.btn-favorites.active {
    background: var(--success-color);
}

.btn-download {
    padding: 10px 20px;
    background: #9b59b6;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.3s, transform 0.1s;
}

.btn-download:hover {
    background: #8e44ad;
}

.btn-download:active {
    transform: scale(0.95);
}

.btn-sort {
    padding: 10px 20px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 600;
    transition: background 0.3s, transform 0.1s;
}

.btn-sort:hover {
    background: var(--success-color);
}

.btn-sort:active {
    transform: scale(0.95);
}

/* Next Update Timer */
.next-update {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 15px;
    background: var(--card-bg);
    border-radius: 8px;
    border: 2px solid var(--border-color);
}

.update-label {
    color: var(--text-secondary);
    font-size: 0.9em;
    font-weight: 500;
}

.update-label .short-text {
    display: none;
}

.timer {
    color: var(--primary-color);
    font-size: 1.1em;
    font-weight: 700;
    font-family: 'Courier New', monospace;
    min-width: 60px;
    text-align: center;
}

.days-select {
    padding: 10px 15px;
    background: var(--background);
    color: var(--text-color);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.95em;
    cursor: pointer;
}

.days-select:focus {
    outline: none;
    border-color: var(--secondary-color);
}

/* Server Filters */
.server-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
    padding: 15px;
    background: var(--background);
    border-radius: 8px;
}

.filter-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 15px;
    background: var(--card-bg);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.3s;
    border: 2px solid var(--border-color);
}

.filter-checkbox:hover {
    background: var(--hover-color);
}

.filter-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.filter-checkbox label {
    cursor: pointer;
    font-size: 0.95em;
    user-select: none;
}

.filter-all {
    background: var(--primary-color);
    color: white;
    font-weight: 600;
}

.filter-all:hover {
    background: var(--success-color);
}

/* Chart */
.chart-wrapper {
    position: relative;
    height: 500px;
    background: var(--background);
    border-radius: 8px;
    padding: 20px;
}

/* Server Table */
.servers-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.header-controls {
    display: flex;
    gap: 15px;
    align-items: center;
}

.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scroll su iOS */
    scrollbar-width: thin; /* Firefox */
    scrollbar-color: var(--primary-color) var(--background);
}

/* Scrollbar personalizzata (WebKit) */
.table-container::-webkit-scrollbar {
    height: 8px;
}

.table-container::-webkit-scrollbar-track {
    background: var(--background);
    border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--background);
    border-radius: 8px;
    overflow: hidden;
}

thead {
    background: var(--hover-color);
}

th {
    padding: 15px;
    text-align: left;
    font-weight: 600;
    color: var(--primary-color);
    border-bottom: 2px solid var(--border-color);
}

th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background 0.3s;
}

th.sortable:hover {
    background: var(--border-color);
}

th.sort-active {
    color: var(--secondary-color);
}

.sort-icon {
    display: inline-block;
    margin-left: 5px;
    font-size: 0.9em;
}

td {
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
}

tbody tr {
    transition: background 0.2s;
}

tbody tr:hover {
    background: var(--hover-color);
}

.favorite-star {
    cursor: pointer;
    font-size: 1.3em;
    user-select: none;
    transition: transform 0.2s, filter 0.2s;
    display: inline-block;
}

.favorite-star:hover {
    transform: scale(1.2);
    filter: brightness(1.3);
}

.favorite-star.active {
    color: var(--warning-color);
}

.favorite-star.inactive {
    color: #555;
    opacity: 0.4;
}

.server-name {
    font-weight: 700;
}

.sort-highlight {
    font-weight: 700;
}

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

.status-value {
    font-weight: 600;
    color: var(--text-color);
}

.peak-max-number {
    display: block;
    font-size: 1.1em;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 3px;
}

.peak-max-date {
    display: block;
    font-size: 0.75em;
    color: #888;
    font-weight: 400;
}

/* Footer */
footer {
    text-align: center;
    padding: 20px;
    color: #95a5a6;
    font-size: 0.9em;
}

#lastUpdate {
    color: var(--primary-color);
    font-weight: 600;
}

/* Loading State */
.loading {
    text-align: center;
    padding: 40px;
    color: #95a5a6;
}

.loading::after {
    content: "...";
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0%, 20% { content: "."; }
    40% { content: ".."; }
    60%, 100% { content: "..."; }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--background);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--hover-color);
}

/* Responsive */
@media (max-width: 768px) {
    /* Header */
    header h1 {
        font-size: 1.8em;
    }

    /* Sections */
    section {
        padding: 12px;
        margin: 15px 0;
    }

    /* Stats header - bottoni più piccoli */
    .stats-header {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }

    .sort-button {
        width: 100%;
        justify-content: center;
        padding: 12px;
    }

    /* Header controls - wrappa su mobile */
    .header-controls {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }

    .btn-sort {
        width: 100%;
        justify-content: center;
    }

    .next-update {
        flex-wrap: wrap;
        justify-content: center;
        padding: 10px;
        gap: 8px;
    }

    .update-label {
        font-size: 0.85em;
    }

    .update-label .full-text {
        display: none;
    }

    .update-label .short-text {
        display: inline;
    }

    .timer {
        font-size: 1em;
        min-width: 50px;
    }

    /* Chart controls */
    .chart-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .chart-controls {
        flex-direction: column;
        gap: 10px;
    }

    .chart-controls select,
    .chart-controls button {
        width: 100%;
    }

    .chart-wrapper {
        height: 250px;
    }

    /* Tabella - scroll orizzontale */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        font-size: 0.85em;
        min-width: 600px; /* Forza scroll orizzontale invece di comprimere */
    }

    th, td {
        padding: 8px 6px;
        font-size: 0.9em;
    }

    /* Nascondi colonne meno importanti su mobile */
    table th:nth-child(4), /* Picco 7d */
    table td:nth-child(4) {
        display: none;
    }

    /* Server name più piccolo */
    .server-name {
        font-size: 0.9em;
    }

    /* Search */
    .search-container {
        flex-direction: column;
    }

    #searchInput {
        width: 100%;
    }

    .search-result-item {
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 12px;
    }

    /* User info */
    .user-info {
        flex-direction: column;
        align-items: center;
        gap: 10px;
        text-align: center;
    }

    .user-avatar {
        width: 50px;
        height: 50px;
    }

    .user-details {
        align-items: center;
    }

    /* Online players grid */
    .online-players-grid {
        grid-template-columns: 1fr !important;
    }

    /* Modal */
    .modal-content {
        padding: 25px;
        width: 95%;
        max-width: 350px;
    }

    .modal-title {
        font-size: 1.3em;
    }

    .modal-message {
        font-size: 0.95em;
    }

    .modal-buttons {
        flex-direction: column;
        gap: 10px;
    }

    .modal-btn {
        width: 100%;
        justify-content: center;
    }

    /* Peak max - mantieni leggibile */
    .peak-max-number {
        font-size: 1em;
    }

    .peak-max-date {
        font-size: 0.7em;
    }

    /* Next update timer */
    #nextUpdate {
        font-size: 0.9em;
    }
}

/* Extra small devices (portrait phones, less than 576px) */
@media (max-width: 576px) {
    header h1 {
        font-size: 1.5em;
    }

    section {
        padding: 10px;
        margin: 10px 0;
    }

    /* Next update - ancora più compatto */
    .next-update {
        padding: 8px;
        font-size: 0.9em;
    }

    .update-label {
        font-size: 0.8em;
    }

    .timer {
        font-size: 0.95em;
        min-width: 45px;
    }

    .icon-small {
        width: 14px;
        height: 14px;
    }

    /* Nascondi anche la colonna Media su schermi piccoli */
    table th:last-child,
    table td:last-child {
        display: none;
    }

    table {
        font-size: 0.8em;
        min-width: 500px;
    }

    th, td {
        padding: 6px 4px;
    }

    .chart-wrapper {
        height: 200px;
    }

    /* Favorite star più piccola */
    .favorite-star {
        font-size: 1.1em;
    }
}

/* Landscape phones */
@media (max-width: 896px) and (orientation: landscape) {
    .chart-wrapper {
        height: 200px;
    }

    section {
        margin: 10px 0;
    }
}

/* Custom Modal/Popup */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal-overlay.show {
    display: flex;
    opacity: 1;
}

.modal-overlay.hiding {
    opacity: 0;
}

.modal-content {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 35px;
    max-width: 450px;
    width: 90%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border-color);
    text-align: center;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.modal-overlay.show .modal-content {
    transform: scale(1);
}

.modal-overlay.hiding .modal-content {
    transform: scale(0.9);
}

.modal-image {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    opacity: 0.9;
}

.modal-title {
    color: var(--primary-color);
    font-size: 1.5em;
    font-weight: 700;
    margin-bottom: 15px;
}

.modal-message {
    color: var(--text-color);
    font-size: 1em;
    line-height: 1.6;
    margin-bottom: 30px;
}

.modal-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.modal-btn {
    padding: 12px 28px;
    border: 2px solid transparent;
    border-radius: 8px;
    font-size: 0.95em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: 'Inter', sans-serif;
}

.modal-btn-primary {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.modal-btn-primary:hover {
    background: var(--secondary-color);
    border-color: var(--secondary-color);
}

.modal-btn-secondary {
    background: transparent;
    color: var(--text-color);
    border-color: var(--border-color);
}

.modal-btn-secondary:hover {
    background: var(--hover-color);
    border-color: var(--text-color);
}

/* Mobile scroll hint */
@media (max-width: 768px) {
    .table-container::after {
        content: '← Scorri →';
        display: block;
        text-align: center;
        font-size: 0.75em;
        color: #666;
        padding: 8px;
        animation: fadeInOut 3s ease-in-out;
        pointer-events: none;
    }

    @keyframes fadeInOut {
        0%, 100% { opacity: 0; }
        50% { opacity: 0.7; }
    }
}
