/* --- Google Fonts Import --- */
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;600;700&family=Inter:wght@400;500;600&display=swap');

/* --- CSS Variables (Custom Properties) for "Dynamisk Precision" --- */
:root {
    --font-heading: 'Montserrat', sans-serif;
    --font-body: 'Inter', sans-serif;

    --color-primary: #0077FF;
    --color-primary-dark: #005ECC;
    --color-primary-light-bg: #E6F0F8; /* För hover på clickable & ghost buttons */

    --color-accent: #20C997;          /* Livlig Teal/Turkos */
    --color-accent-dark: #1BAA80;

    --color-text-base: #343A40;
    --color-text-light: #FFFFFF;
    --color-text-muted: #6C757D;
    --color-text-on-primary: var(--color-text-light);
    --color-text-on-accent: var(--color-text-light);

    --color-bg-page: #F8F9FA;
    --color-bg-container: #FFFFFF;
    --color-bg-section-alt: #F1F3F5;
    --color-border: #DEE2E6;
    --color-border-input: #CED4DA;

    --color-status-ready: #10B981;      /* Uppdaterad, renare Smaragdgrön */
    --color-status-ready-bg: #ECFDF5;   /* Uppdaterad ljus Smaragdgrön bakgrund */
    --color-status-ready-dark-hover: #0D9488; /* För knappar */

    --color-status-eliminated: #DC3545;
    --color-status-winner-bg: #D1FAE5;
    --color-status-completed-bg: #F5F5F5;
    --color-status-completed-border: #E0E0E0;
    --color-status-bye-tbd-bg: #E9ECEF;

    --shadow-card: 0 3px 7px rgba(0, 0, 0, 0.07);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.06), 0 2px 4px -1px rgba(0, 0, 0, 0.04); /* För Toasts */
    --shadow-focus-primary: 0 0 0 0.2rem rgba(0,119,255,0.25);
    --shadow-focus-accent: 0 0 0 0.2rem rgba(32,201,151,0.25);
    --border-radius-main: 5px;
    --border-radius-small: 4px;
    --transition-main: all 0.15s ease-in-out;
}

/* --- Basic Layout & Styling --- */
body {
    font-family: var(--font-body); margin: 0; padding: 20px; font-size: 15px;
    background-color: var(--color-bg-page); color: var(--color-text-base);
    line-height: 1.65; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
.container { max-width: 1450px; margin: 0 auto; background-color: var(--color-bg-container); padding: 30px; border-radius: var(--border-radius-main); box-shadow: var(--shadow-card); }

/* Toast container styling */
#toastContainer { position: fixed; bottom: 25px; right: 25px; z-index: 1050; display: flex; flex-direction: column; align-items: flex-end; gap: 12px; width: auto; max-width: 380px; }
.toast-message { padding: 12px 20px; border-radius: var(--border-radius-main); box-shadow: var(--shadow-md); color: var(--color-text-light); font-size: 0.95em; font-weight: 500; opacity: 0; transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out; transform: translateX(20px); width: fit-content; min-width: 250px; box-sizing: border-box; position: relative; overflow: hidden; display: flex; justify-content: space-between; align-items: center; }
.toast-message.show { opacity: 1; transform: translateX(0); }
.toast-message.toast-success { background-color: var(--color-status-ready); }
.toast-message.toast-error { background-color: var(--color-status-eliminated); }
.toast-message.toast-info { background-color: var(--color-primary); }
.toast-message .toast-content { flex-grow: 1; }
.toast-message .close-toast-btn { background: none; border: none; color: inherit; opacity: 0.8; font-size: 1.4em; line-height: 1; cursor: pointer; padding: 0 0 0 15px; margin-left: 10px; font-weight: bold; }
.toast-message .close-toast-btn:hover { opacity: 1; }
.loading-indicator { font-style: italic; color: var(--color-text-muted); padding: 15px; text-align: center; }

/* Rubriker */
h1, h2, h3, h4, h5, h6 { font-family: var(--font-heading); color: var(--color-text-base); margin-top: 0; font-weight: 600; }
h1 { color: var(--color-primary); text-align: center; margin-bottom: 35px; font-size: 2.3em; font-weight: 700; }
h2 { text-align: center; margin-bottom: 25px; color: var(--color-primary-dark); font-size: 1.9em; }
h3 { margin-bottom: 18px; color: var(--color-text-base); border-bottom: 1px solid var(--color-border); padding-bottom: 10px; font-size: 1.4em; font-weight: 600; text-align: center; }
/* Sektioner */
.setup-section, .players-section, .tournament-section, .mondags-cup-archive-container #archiveListContainer, .mondags-cup-archive-container #archiveDisplayArea { margin-bottom: 30px; padding: 25px; border: 1px solid var(--color-border); border-radius: var(--border-radius-main); background-color: var(--color-bg-container); box-shadow: var(--shadow-card); }
.mondags-cup-archive-container #archiveDisplayArea { margin-bottom: 0; }

/* Spelarlista */
.players-section ul#playerList { list-style: none; padding: 15px; margin: 0; display: flex; flex-wrap: wrap; gap: 10px; background-color: var(--color-bg-section-alt); border: 1px solid var(--color-border); border-radius: var(--border-radius-main); min-height: 50px; }
.players-section ul#playerList li { background-color: var(--color-primary); color: var(--color-text-on-primary); margin: 0; padding: 7px 14px; border-radius: 18px; display: flex; align-items: center; font-size: 0.95em; font-weight: 500; border: none; box-shadow: 0 1px 3px rgba(0,0,0,0.1); transition: var(--transition-main); }
.players-section ul#playerList li:hover { transform: translateY(-1px); background-color: var(--color-primary-dark); }
.players-section ul#playerList li span { margin-right: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.players-section ul#playerList li.eliminated { background-color: var(--color-status-eliminated); color: var(--color-text-light); font-style: italic; opacity: 0.85; }
.players-section ul#playerList li.eliminated span { text-decoration: line-through; }
.players-section ul#playerList li button.remove-player-btn { background-color: rgba(255,255,255,0.2); color: var(--color-text-on-primary); border: none; border-radius: 50%; padding: 0; width: 20px; height: 20px; font-size: 13px; line-height: 20px; text-align: center; cursor: pointer; margin-left: 8px; font-weight: 600; transition: background-color 0.2s ease; }
.players-section ul#playerList li button.remove-player-btn:hover:not(:disabled) { background-color: rgba(0,0,0,0.2); }
.players-section ul#playerList li button.remove-player-btn:disabled { background-color: rgba(120,120,120,0.1); color: rgba(255,255,255,0.5); cursor: not-allowed; }

/* Knappar & Input */
.setup-section input[type="text"] { padding: 10px 14px; font-size: 1em; font-family: var(--font-body); margin-right: 10px; border: 1px solid var(--color-border-input); border-radius: var(--border-radius-main); box-sizing: border-box; max-width: 240px; transition: border-color 0.2s ease, box-shadow 0.2s ease; }
.setup-section input[type="text"]:focus { border-color: var(--color-primary); box-shadow: var(--shadow-focus-primary); outline: none; }
.setup-section button, .auto-assign-scorekeeper-btn { padding: 10px 20px; font-size: 1em; font-weight: 600; font-family: var(--font-heading); margin: 5px; cursor: pointer; border: 1px solid transparent; border-radius: var(--border-radius-main); transition: var(--transition-main); line-height: 1.4; text-transform: none; letter-spacing: 0.3px; }
/* Primära knappar */
.setup-section button#addPlayerBtn, .setup-section button#startBtn, .setup-section button#saveBtn { background-color: var(--color-primary); color: var(--color-text-on-primary); border-color: var(--color-primary); }
.setup-section button#addPlayerBtn:hover:not(:disabled), .setup-section button#startBtn:hover:not(:disabled), .setup-section button#saveBtn:hover:not(:disabled) { background-color: var(--color-primary-dark); border-color: var(--color-primary-dark); transform: translateY(-1px); box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
/* Ghost buttons för sekundära */
.setup-section button#resetBtn, .setup-section button#loadBtn, .setup-section button#undoBtn { background-color: transparent; color: var(--color-primary); border: 1px solid var(--color-primary); }
.setup-section button#resetBtn:hover:not(:disabled), .setup-section button#loadBtn:hover:not(:disabled), .setup-section button#undoBtn:hover:not(:disabled) { background-color: var(--color-primary-light-bg); color: var(--color-primary-dark); border-color: var(--color-primary-dark); transform: translateY(-1px); box-shadow: none; }
/* Arkivera-knappen (använder accent) */
.setup-section button#archiveTournamentBtn, .setup-section button#archiveTournamentBtnTest { background-color: var(--color-accent); color: var(--color-text-on-accent); border-color: var(--color-accent); }
.setup-section button#archiveTournamentBtn:hover:not(:disabled), .setup-section button#archiveTournamentBtnTest:hover:not(:disabled) { background-color: var(--color-accent-dark); border-color: var(--color-accent-dark); transform: translateY(-1px); box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.setup-section button:disabled { background-color: var(--color-status-bye-tbd-bg); color: var(--color-text-muted); border-color: var(--color-border); cursor: not-allowed; opacity: 0.7; transform: none; box-shadow: none; }
/* Manuella vinnarknappar */
.manual-winner-buttons { margin-top: 10px; display: flex; justify-content: center; gap: 6px; width: 100%; border-top: 1px solid var(--color-border); padding-top: 10px; }
.manual-winner-buttons button { padding: 5px 10px; font-size: 0.9em; font-family: var(--font-body); background-color: var(--color-text-muted); color: var(--color-text-light); border: none; border-radius: var(--border-radius-small); transition: background-color 0.2s ease; cursor: pointer; }
.manual-winner-buttons button:hover:not(:disabled) { background-color: #5A6268; }
.manual-winner-buttons button:disabled { background-color: var(--color-status-bye-tbd-bg); color: #999; opacity: 0.7; }

/* --- Bracket Container & Layout --- */
.brackets-container { display: flex; flex-direction: column; gap: 30px; margin-bottom: 0; padding-bottom: 0; }
.bracket { border: none; padding: 0; background-color: transparent; border-radius: 0; min-height: auto; width: 100%; box-shadow: none; }
.bracket h2 { margin-top: 0; margin-bottom: 20px; color: var(--color-primary-dark); font-size: 1.6em; border-bottom: none; padding-bottom: 0; text-align: left; }
.bracket-rounds { display: flex; gap: 40px; align-items: flex-start; min-height: 280px; padding: 10px 5px; width: 100%; overflow-x: auto; margin-top: 10px; flex-grow: 1; box-sizing: border-box; background-color: var(--color-bg-section-alt); border-radius: var(--border-radius-small); border: 1px solid var(--color-border); }
.round { display: flex; flex-direction: column; justify-content: flex-start; gap: 25px; flex-shrink: 0; align-items: center; }
.round h3 { text-align: center; border: none; padding: 0; margin-top: 0; margin-bottom: 15px; white-space: nowrap; font-size: 1.15em; color: var(--color-text-muted); font-weight: 500; }

/* --- Matchup Styling (Version A-logik) --- */
.matchup { border: 1px solid var(--color-border); padding: 10px 12px; background-color: var(--color-bg-container); border-radius: var(--border-radius-main); position: relative; font-size: 0.9em; line-height: 1.5; min-width: 170px; text-align: center; transition: var(--transition-main); box-shadow: var(--shadow-card); display: flex; flex-direction: column; justify-content: center; align-items: center; }
.matchup::after, .matchup::before { display: none !important; }
.matchup.ready { border-color: var(--color-status-ready); background-color: var(--color-status-ready-bg); box-shadow: 0 0 0 1px var(--color-status-ready), var(--shadow-card); }
.matchup.completed { border-color: var(--color-status-completed-border); background-color: var(--color-status-completed-bg); opacity: 0.9; }
.matchup .player-info-wrapper { display: flex; justify-content: space-between; align-items: center; width: 100%; padding: 2px 0; }
.matchup .player-result { padding: 3px 6px; border-radius: var(--border-radius-small); max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; transition: var(--transition-main); font-weight: 500; text-align: center; flex-grow: 1; }
/* Justering för Version A - Klickbara namn */
.matchup.ready .player-result.clickable-winner { cursor: pointer; color: var(--color-text-base); border-radius: var(--border-radius-small); padding: 2px 4px; margin: -2px -4px; transition: background-color 0.15s ease-in-out, color 0.15s ease-in-out; }
.matchup.ready .player-result.clickable-winner:hover { background-color: var(--color-primary-light-bg); color: var(--color-primary-dark) !important; }
/* Fortsättning matchup styling */
.matchup .vs { color: var(--color-text-muted); font-size: 0.9em; font-weight: 600; margin: 0 5px; flex-shrink: 0; }
.matchup.completed .player-result.winner { background-color: var(--color-status-winner-bg); color: var(--color-text-base); font-weight: 600; }
.matchup.completed .player-result.loser { text-decoration: line-through; color: var(--color-text-muted); background-color: transparent; font-weight: 400; opacity: 0.7; }
.matchup .player-result.bye, .matchup .player-result.tbd { font-style: italic; color: var(--color-text-muted); background-color: var(--color-status-bye-tbd-bg); font-weight: 400; flex-grow: 0; padding: 3px 8px; }
.matchup .player-result.eliminated { color: var(--color-status-eliminated); text-decoration: line-through; opacity: 0.6; }
.match-static-lane { display: block; font-size: 0.8em; color: var(--color-text-muted); margin-bottom: 6px; font-style: normal; text-align: center; width: 100%; }
/* Detaljer & Skrivare */
.match-details-wrapper { font-size: 0.9em; color: var(--color-text-base); margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--color-border); display: flex; flex-direction: column; gap: 8px; align-items: center; width: 100%; }
.scorekeeper-info { width: 100%; text-align: center; }
.scorekeeper-controls-container { margin-top: 5px; display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; width: 100%; }
.scorekeeper-select { padding: 5px 8px; border-radius: var(--border-radius-main); border: 1px solid var(--color-border-input); font-size: 0.9em; font-family: var(--font-body); background-color: var(--color-bg-container); color: var(--color-text-base); }
.scorekeeper-select:focus { border-color: var(--color-accent); box-shadow: var(--shadow-focus-accent); outline: none; }
.auto-assign-scorekeeper-btn { background-color: var(--color-status-ready); color: var(--color-text-light); border-color: var(--color-status-ready); padding: 6px 12px; font-size: 0.9em; }
.auto-assign-scorekeeper-btn:hover:not(:disabled) { background-color: var(--color-status-ready-dark-hover); border-color: var(--color-status-ready-dark-hover); }

/* --- Grand Final & Winner Styling --- */
#grandFinalArea { margin-top: 30px; padding: 25px; border: 1px solid var(--color-primary); border-radius: var(--border-radius-main); text-align: center; background-color: var(--color-bg-section-alt); box-shadow: var(--shadow-card); }
#grandFinalArea h3 { color: var(--color-primary-dark); margin-top: 0; margin-bottom: 20px; border-bottom: 1px solid var(--color-primary); padding-bottom: 10px; font-size: 1.5em; }
#grandFinalArea .matchup { margin: 0 auto; min-width: 220px; box-shadow: var(--shadow-card); }
#tournamentWinnerArea { margin-top: 30px; padding: 30px; background: linear-gradient(135deg, var(--color-primary), var(--color-accent)); color: var(--color-text-light); border: none; border-radius: var(--border-radius-main); text-align: center; box-shadow: 0 5px 15px rgba(0,119,255,0.25); }
#tournamentWinnerArea h2 { margin: 0; color: var(--color-text-light); font-size: 2.2em; text-shadow: 1px 1px 3px rgba(0,0,0,0.2); font-weight: 700; }

/* --- Styling för rankinglistan --- */
#finalRankingsArea { background-color: var(--color-bg-container); padding: 30px; border: 1px solid var(--color-border); border-radius: var(--border-radius-main); margin-top: 35px; box-shadow: var(--shadow-card); }
#finalRankingsArea h2 { color: var(--color-primary-dark); margin-bottom: 25px; border-bottom: 2px solid var(--color-primary); padding-bottom: 12px; font-size: 1.7em; text-align: left; }
#finalRankingsArea h3 { color: var(--color-text-base); margin-top: 25px; margin-bottom: 12px; border-bottom: none; text-align: left; font-size: 1.3em; font-weight: 600; }
#finalRankingsArea ol, #finalRankingsArea ul { padding-left: 20px; margin: 0 0 20px 0; list-style-type: decimal; }
#finalRankingsArea ul { list-style-type: disc; }
#finalRankingsArea li { padding: 10px 5px; border-bottom: 1px solid var(--color-border); font-size: 1em; color: var(--color-text-base); text-align: left; }
#finalRankingsArea li:last-child { border-bottom: none; }
#finalRankingsArea li strong { color: var(--color-primary-dark); min-width: 60px; display: inline-block; margin-right: 10px; font-weight: 600; }

/* Styling för arkivlistan */
.archive-list { margin-top: 0; padding-top: 0; border-top: none; }
.archive-items-list { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 15px; }
.archive-items-list li { margin: 0; padding: 0; }
.archive-item-button { display: block; width: 100%; padding: 12px 15px; font-size: 1em; font-weight: 500; font-family: var(--font-body); text-align: center; cursor: pointer; border: 1px solid var(--color-border); border-radius: var(--border-radius-main); background-color: var(--color-bg-container); color: var(--color-primary); transition: var(--transition-main); box-shadow: var(--shadow-sm); }
.archive-item-button:hover, .archive-item-button.selected { background-color: var(--color-primary-light-bg); border-color: var(--color-primary); color: var(--color-primary-dark); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.archive-item-button.selected { font-weight: 600; }
/* Styling för området där ett valt arkiv ska visas */
.archive-display { margin-top: 30px; padding-top: 0; border-top: none; }


/* --- Responsive Design --- */
@media (max-width: 1200px) { .bracket-rounds { gap: 30px; } .matchup { min-width: 160px; } .matchup .player-result { max-width: 65px; } }
@media (max-width: 900px) { body { padding: 15px; } .container { padding: 20px; } .setup-section button, .auto-assign-scorekeeper-btn { padding: 9px 16px; font-size: 0.95em; } .setup-section input[type="text"] { padding: 9px; font-size: 0.95em; max-width: 200px;} .matchup { min-width: 150px; font-size: 0.85em; } .matchup .player-result { max-width: 60px; } h1 { font-size: 2em; } h2 { font-size: 1.7em; } }
@media (max-width: 600px) { body { padding: 10px; } .container { padding: 15px; } .bracket-rounds { gap: 20px; padding: 5px 0;} .matchup { min-width: 130px; font-size: 0.8em; padding: 8px 10px; } .matchup .player-result { max-width: 50px; } #grandFinalArea .matchup { min-width: 100%; } .matchup .player-info-wrapper { flex-direction: column; gap: 3px; } .matchup .vs { display: block; margin: 1px 0; } .setup-section { display: flex; flex-direction: column; gap: 12px; } .setup-section input[type="text"] { width: 100%; max-width: none; margin-right: 0; } .setup-section button { width: 100%; margin-left: 0; margin-right: 0; } h1 { font-size: 1.7em; } h2 { font-size: 1.5em; } h3 { font-size: 1.2em; } .archive-items-list { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); } }