:root {
    --bg-dark: #000000;
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.6);
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);

    --gender-m-bg: #4A90E2;
    --gender-d-bg: #E91E63;

    --reserve-bg: #2C2C2E;
    --inactive-bg: #1C1C1E;
}

body {
    margin: 0;
    padding: 0;
    background: var(--bg-dark);
    color: var(--text-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    overflow-x: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
    animation: fadeInPage 0.5s ease-out forwards;
}

@keyframes fadeInPage {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

body.fade-out {
    animation: fadeOutPage 0.3s ease-in forwards;
}

@keyframes fadeOutPage {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-10px); }
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(20px);
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.back-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: color 0.2s;
}

.back-link:hover {
    color: white;
}

.app-header h1 {
    margin: 0;
    font-size: 1.25rem;
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.header-buttons {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.verify-btn {
    border-color: #ffcc00 !important;
    color: #ffcc00 !important;
}

.global-stats {
    display: flex;
    gap: 1rem;
}

.stat-badge {
    background: var(--glass-bg);
    padding: 0.4rem 0.8rem;
    border-radius: 2rem;
    font-size: 0.8rem;
    border: 1px solid var(--glass-border);
}

.season-dropdown {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: white;
    padding: 0.4rem 0.8rem;
    border-radius: 0.5rem;
    font-size: 0.9rem;
    outline: none;
    margin-left: 1rem;
    cursor: pointer;
}

.season-dropdown option {
    background: #111;
    color: white;
}

/* Base Buttons */
button {
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}

.primary-btn {
    background: white;
    color: black;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 0.75rem;
    font-weight: 600;
    font-size: 0.9rem;
}

.primary-btn:hover {
    transform: translateY(-1px);
    opacity: 0.9;
}

.secondary-btn {
    background: transparent;
    color: white;
    border: 1px solid var(--glass-border);
    padding: 0.5rem 1rem;
    border-radius: 0.75rem;
    font-weight: 500;
}

/* Layout */
.planner-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    padding: 1rem;
    gap: 1.5rem;
}

/* Teams Container (Horizontal Scroll) */
.teams-scroll-container {
    flex: 1;
    overflow-x: auto;
    overflow-y: hidden;
    min-width: 0;
}

.teams-wrapper {
    display: flex;
    gap: 1rem;
    height: 100%;
    align-items: flex-start;
}

/* Individual Team Column */
.team-col {
    width: 280px;
    flex-shrink: 0;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 120px);
}

.team-header {
    padding: 0.75rem;
    text-align: center;
    border-top-left-radius: 1rem;
    border-top-right-radius: 1rem;
    position: relative;
    cursor: grab;
}

.team-header:active {
    cursor: grabbing;
}

.team-header-title {
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 0.2rem;
}

.team-header-league {
    font-size: 0.8rem;
    opacity: 0.9;
}

.delete-team-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: rgba(0, 0, 0, 0.3);
    border: none;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    opacity: 0;
}

.edit-team-btn {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    background: rgba(0, 0, 0, 0.3);
    border: none;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    opacity: 0;
}

.team-header:hover .delete-team-btn,
.team-header:hover .edit-team-btn {
    opacity: 1;
}

.team-stats {
    background: rgba(255, 255, 255, 0.02);
    padding: 0.5rem 0.8rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--glass-border);
}

.clear-team-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.7rem;
    cursor: pointer;
    text-decoration: underline;
    opacity: 0.7;
}

.clear-team-btn:hover {
    color: #ff453a;
    opacity: 1;
}

/* Lists and Items */
.sortable-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
    min-height: 50px;
    /* Drop target area */
}

/* The Player Item */
.player-item {
    background: #111;
    border: 1px solid var(--glass-border);
    border-radius: 0.5rem;
    padding: 0;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    cursor: grab;
    user-select: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.player-item:active {
    cursor: grabbing;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    transform: scale(1.02);
}

.player-item.invalid-player {
    border: 1px solid #ff453a;
    box-shadow: 0 0 8px rgba(255, 69, 58, 0.5);
    background: rgba(255, 69, 58, 0.1);
}

.player-item.warning-player {
    border: 1px solid #ffcc00;
    box-shadow: 0 0 8px rgba(255, 204, 0, 0.5);
    background: rgba(255, 204, 0, 0.1);
}

.player-item.valid-player {
    border: 1px solid #1d78cb;
    box-shadow: 0 0 8px rgba(29, 120, 203, 0.3);
    background: rgba(29, 120, 203, 0.05);
}

.warning-badge {
    display: inline-block;
    background: #ffcc00;
    color: #000;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 0.65rem;
    margin-bottom: 2px;
}

.player-item.invalid-player .warning-badge {
    background: #ff453a;
    color: #fff;
}

.gender-badge {
    width: 2.2rem;
    align-self: stretch;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    border-top-left-radius: 0.4rem;
    border-bottom-left-radius: 0.4rem;
}

.gender-M {
    background: var(--gender-m-bg);
}

.gender-D {
    background: var(--gender-d-bg);
}

.player-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 0.4rem 0.75rem;
    min-width: 0;
}

.player-name {
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-subtitle {
    font-size: 0.7rem;
    color: var(--text-secondary);
    line-height: 1.2;
    margin-top: 0.1rem;
}

.player-subtitle.warning-text {
    color: var(--text-primary);
}

.player-actions {
    display: flex;
    gap: 0.25rem;
    padding-right: 0.5rem;
    opacity: 0;
    transition: opacity 0.2s;
}

.player-item:hover .player-actions {
    opacity: 1;
}

.edit-player-btn,
.delete-player-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.4rem;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 4px;
}

.edit-player-btn:hover {
    color: white;
    background: rgba(255, 255, 255, 0.1);
}

.delete-player-btn:hover {
    color: #ff453a;
    background: rgba(255, 69, 58, 0.1);
}

/* Add Button in lists */
.add-player-btn {
    width: calc(100% - 1rem);
    margin: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px dashed var(--glass-border);
    color: var(--text-secondary);
    padding: 0.5rem;
    border-radius: 0.5rem;
    font-size: 0.8rem;
}

.add-player-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

/* Sidebar Panels (Right Side) */
.sidebar-panels {
    width: 280px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    height: calc(100vh - 120px);
}

.panel-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-radius: 1rem;
    border: 1px solid var(--glass-border);
    overflow: hidden;
}

.ersatz-panel {
    background: var(--reserve-bg);
}

.inactive-panel {
    background: var(--inactive-bg);
}

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

.panel-header h2 {
    margin: 0;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.panel-header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.panel-count {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.1rem 0.6rem;
    border-radius: 1rem;
    font-size: 0.8rem;
}

.clear-btn {
    background: transparent;
    border: none;
    font-size: 0.9rem;
    cursor: pointer;
    padding: 2px;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.clear-btn:hover {
    opacity: 1;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.2s;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: #111;
    border: 1px solid var(--glass-border);
    border-radius: 1.5rem;
    padding: 2rem;
    width: 90%;
    max-width: 400px;
}

.modal-content h3 {
    margin-top: 0;
    margin-bottom: 1.5rem;
}

.input-group {
    margin-bottom: 1.5rem;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.input-group input,
.input-group select {
    width: 100%;
    box-sizing: border-box;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: white;
    padding: 0.75rem;
    border-radius: 0.75rem;
    font-size: 1rem;
    outline: none;
}

.input-group select {
    color-scheme: dark;
    /* Solid bg so the native popup panel inherits a dark colour
       (alpha bg above renders white over the browser's default canvas). */
    background: #1a1a1a;
}

.input-group select option {
    background-color: #1a1a1a;
    color: var(--text-primary);
}

.input-group select option:checked,
.input-group select option:hover {
    background-color: #2a2a2a;
}

.input-group input[type="color"] {
    padding: 0.2rem;
    height: 3rem;
    cursor: pointer;
}

.input-group input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

.input-group input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 0.5rem;
}

.color-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.swatch {
    width: 2rem;
    height: 2rem;
    border-radius: 0.5rem;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.swatch:hover {
    transform: scale(1.1);
}

.swatch.active {
    border-color: white;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.4);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

/* SortableJS Ghost/Drag Styles */
.sortable-ghost {
    opacity: 0.3;
    background: #333;
}

.sortable-drag {
    cursor: grabbing !important;
}

/* Auto Save Indicator */
.save-indicator {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 999;
}

.save-indicator.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.save-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ffcc00;
}

.save-dot.success {
    background: #1d78cb;
}

/* Player Search Popup */
.player-popup {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #1c1c1e;
    border: 1px solid var(--glass-border);
    border-radius: 0.5rem;
    max-height: 200px;
    overflow-y: auto;
    z-index: 2000;
    margin-top: 0.5rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.player-popup.hidden {
    display: none;
}

.player-popup-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.player-popup-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.player-popup-item:last-child {
    border-bottom: none;
}

/* Mobile Adaptations */
@media (max-width: 768px) {
    .app-container {
        height: auto;
        min-height: 100vh;
        overflow-y: auto;
    }

    .planner-layout {
        flex-direction: column;
        overflow: visible;
        padding: 1rem;
        gap: 1.5rem;
        height: auto;
    }

    .teams-scroll-container {
        overflow-x: auto;
        overflow-y: visible;
        flex: none;
    }

    .teams-wrapper {
        flex-direction: row;
        /* Keep teams horizontal on mobile too, or switch to column if preferred? User said 'not fixed', but usually teams are the main scroll. Let's keep them horizontal but ensure layout flows. */
        height: auto;
        padding-bottom: 1rem;
    }

    .team-col {
        width: 85vw;
        /* Slightly narrower than full screen to show next team */
        max-height: none;
    }

    .sidebar-panels {
        width: 100%;
        height: auto;
        flex-shrink: 0;
        position: relative;
        /* Ensure not fixed */
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }

    .panel-section {
        height: auto;
        max-height: 400px;
        /* Limit height of lists on mobile to avoid endless scrolling */
    }

    .app-header {
        flex-direction: column;
        gap: 1rem;
        align-items: center;
        text-align: center;
        padding: 1rem 0.5rem;
    }

    .header-left {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    .toolbar-actions {
        width: 100%;
        flex-direction: column;
        gap: 0.75rem;
    }

    .header-buttons {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    .header-buttons button {
        flex: 1;
        min-width: 120px;
        font-size: 0.8rem;
        padding: 0.5rem 0.25rem;
    }

    .global-stats {
        width: 100%;
        justify-content: center;
    }

    .delete-team-btn,
    .delete-player-btn,
    .edit-team-btn,
    .player-actions {
        opacity: 1;
    }
}
/* Season Management */
.season-manage-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 1.5rem;
    padding-right: 0.5rem;
}

.season-manage-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.season-manage-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.season-name-display {
    font-weight: 500;
}

.season-delete-btn {
    background: rgba(255, 0, 0, 0.1);
    border: 1px solid rgba(255, 0, 0, 0.2);
    color: #ff4444;
    cursor: pointer;
    padding: 0.4rem 0.6rem;
    border-radius: 0.4rem;
    font-size: 0.8rem;
    transition: all 0.2s;
}

.season-delete-btn:hover {
    background: rgba(255, 0, 0, 0.2);
    border-color: rgba(255, 0, 0, 0.4);
}

/* Read Mode Overrides */
body.read-mode .verify-btn,
body.read-mode button[onclick*='ImportModal'],
body.read-mode .primary-btn,
body.read-mode .edit-team-btn,
body.read-mode .delete-team-btn,
body.read-mode .clear-team-btn,
body.read-mode .add-player-btn,
body.read-mode .clear-btn,
body.read-mode .edit-player-btn,
body.read-mode .delete-player-btn,
body.read-mode .season-delete-btn,
body.read-mode button[onclick*='EditSeasonModal'] {
    display: none !important;
}

