/* Scoped form styles */
.tournament-form {
    --bg: #0f1115;
    --bg-elev: #141821;
    --text: #e6e9ef;
    --muted: #9aa3b2;
    --primary: #4da3ff;
    --primary-700: #2a7fe0;
    --border: #273244;
    --danger: #ff6b6b;
    --focus: #6fb1ff;

    display: block;
    color-scheme: dark;
}

/* Accessibility helper if you need hidden headings */
.visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0);
    white-space: nowrap; border: 0;
}

.tournament-form .form-grid {
    display: grid;
    gap: 2rem;
    grid-template-columns: 1fr;
}

.actions-right {
    margin-left: auto;
}

#delete-tournament-btn {
    background: transparent;
    border: 1px solid rgba(199, 161, 91, 0.35);
    color: #e5e7eb;
}

#delete-tournament-btn:hover {
    background-color: rgba(255, 191, 105, 0.1);
    border-color: #ffbf69;
}


@media (min-width: 720px) {
    .tournament-form .form-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.tournament-form .field {
    display: flex;
    flex-direction: column;
}

.tournament-form .field--full {
    grid-column: 1 / -1;
}

.tournament-form label,
.tournament-form legend {
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.4rem;
}

.tournament-form .req {
    color: var(--danger);
    margin-left: 0.15rem;
}

.tournament-form input[type="text"],
.tournament-form input[type="date"],
.tournament-form input[type="number"],
.tournament-form input[type="url"],
.tournament-form input[type="file"],
.tournament-form select,
.tournament-form textarea {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    padding: 0.6rem 0.7rem;
    min-height: 44px;          /* Accessible touch target */
    box-sizing: border-box;
    line-height: 1.4;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    font-size: 16px;           /* Ensures readable text (and avoids mobile zoom) */
}

.tournament-form select option.format {
    background: #181412;
    color: var(--text);
}

/* Hover for the dungeon dropdown */
.tournament-form select[multiple] option:hover {
    background: rgba(111, 177, 255, 0.18);
}

/* Increase the size of the internal date text on Chromium/WebKit */
.tournament-form input[type="date"]::-webkit-datetime-edit-text,
.tournament-form input[type="date"]::-webkit-datetime-edit-year-field,
.tournament-form input[type="date"]::-webkit-datetime-edit-month-field,
.tournament-form input[type="date"]::-webkit-datetime-edit-day-field {
    font-size: 16px;
}
/* Slightly enlarge and align the calendar icon (Chromium/WebKit) */
.tournament-form input[type="date"]::-webkit-calendar-picker-indicator {
    width: 1.25rem;
    height: 1.25rem;
    margin-right: 4px;
}


/* Placeholder styling (shown only in some browsers for type=date) */
.tournament-form input[type="date"]::placeholder {
    font-size: 16px;
    opacity: 0.75;
}

.tournament-form textarea {
    resize: vertical;
}

.tournament-form input:focus,
.tournament-form select:focus,
.tournament-form textarea:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--focus);
    box-shadow: 0 0 0 3px rgba(111, 177, 255, 0.15);
    outline: none;
}

.tournament-form input:required:invalid,
.tournament-form select:required:invalid {
    border-color: rgba(255, 107, 107, 0.7);
}

.tournament-form .help-text {
    color: var(--muted);
    font-size: 0.85rem;
    margin-top: 0.35rem;
}

.tournament-form fieldset.field {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.75rem 0.9rem;
}

.tournament-form .choice {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.35rem 0;
}

.tournament-form .input-combo {
    display: grid;
    grid-template-columns: 0.7fr 1fr;
    gap: 0.5rem;
    align-items: center;
}

.tournament-form .form-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-top: 1.25rem;
}

.tournament-form .form-actions button {
    background: var(--primary);
    color: #0b0e14;
    border: none;
    border-radius: 10px;
    padding: 0.7rem 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.02s ease;
}

.tournament-form .form-actions button:hover {
    background: var(--primary-700);
}

.tournament-form .form-actions button:active {
    transform: translateY(1px);
}

.tournament-form .btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.65rem 1rem;
    text-decoration: none;
}

.tournament-form .btn-secondary:hover {
    border-color: #3a475e;
}

.tournament-form .form-note {
    margin-top: 0.75rem;
    color: var(--muted);
    min-height: 1.2em;
}

/* Participants: unify with panel/accent palette */
.participant {
    background: linear-gradient(
            180deg,
            color-mix(in srgb, var(--panel) 88%, transparent),
            color-mix(in srgb, var(--panel-2) 88%, transparent)
    );
    border: 1px solid rgba(199, 161, 91, 0.12); /* uses --accent tone */
    box-shadow: var(--glow);
    transition: border-color 120ms ease, background-color 120ms ease, transform 120ms ease;
}

.participant:hover {
    background: linear-gradient(
            180deg,
            color-mix(in srgb, var(--panel) 82%, transparent),
            color-mix(in srgb, var(--panel-2) 82%, transparent)
    );
    border-color: rgba(199, 161, 91, 0.28);
    transform: translateY(-1px);
}

/* Participant name and meta */
.participant .name {
    color: #e5e7eb;
}
.participant .meta { color: var(--muted); font-size: 0.9em; }

/* Class/role chips aligned with accent */
.class-chip {
    /*display: inline-block;*/
    padding: 0.18rem 0.55rem;
    border-radius: 999px;
    border: 1px solid rgba(199, 161, 91, 0.22);
    background: linear-gradient(180deg, rgba(199, 161, 91, 0.06), rgba(0, 0, 0, 0.06));
    color: #e5e7eb;
    font-size: 0.85em;
    letter-spacing: 0.02em;
    margin: 0.15rem 0.35rem 0.15rem 0;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.participants-list {
    display: grid;
    gap: 0.75rem;
}
.participant-row {
    display: flex;
    gap: 0.5rem 1rem;
    align-items: center;
    padding: 0.75rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);;
    border: 1px solid rgba(199, 161, 91, 0.35);
}

.participant-row:hover {
    border-color: #e3e3e3;
}

.participant-header {
    gap: 0.5rem;
    display: flex;
    align-items: center;
    grid-column: 1 / 2;
}

.participant-header strong {
    width: 5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.participant-meta {
    color: #777;
    margin-left: 0.5rem;
    font-size: 0.9em;
}
.participant-classes {
    flex: 1;
}
.participant-actions {
    margin-left: auto;
    display: flex;
    gap: 0.5rem;
}

.class-chip .avatar {
    --size: 1.25rem;
}
.class-chip__label {
    font-weight: 600;
    line-height: 2;
    font-size: 1.2em;
}

/* 1) Make the card header content align in a single row */
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between; /* space between title and counts */
    gap: 1rem;
}

/* 2) If you can add a class "roles-count" to the rolesCountContainer, use this */
.roles-count {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap; /* allows wrapping on narrow screens */
}
.roles-count p {
    margin: 0;
}

/* 3) If you cannot add a class, this targets the container appended to .card-header */
.card-header > div:last-child {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.card-header > div:last-child p {
    margin: 0;
}

.muted {
    color: #777;
}

/* css */
#participants-section .card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
}

#participants-section .card-toggle {
    font-size: 1rem;
    border: 0;
    cursor: pointer;
    padding: .25rem .35rem;
    border-radius: .25rem;
}

#participants-section .card-toggle:focus-visible {
    outline: 2px solid var(--accent, #4a90e2);
    outline-offset: 2px;
}

/* Simple chevron */
#participants-section .card-toggle::after {
    content: "▾";
    display: inline-block;
    font-size: 1.6rem;
    transition: transform .2s ease;
}

/* Rotate chevron when collapsed */
#participants-section.collapsed .card-toggle::after {
    transform: rotate(-180deg);
}

/* Smooth expand/collapse via height transition */
#participants-section .card-body {
    overflow: hidden;              /* hide content when collapsing */
    transition: height .05s ease;  /* height is controlled by JS */
}

#participants-section.collapsed .participants-list,
#participants-section.collapsed .teams-preview {
    visibility: hidden;            /* Hide content when collapsed */
}

/* Only show these once the app has been revealed */
:not(.app-loading) #participants-section .participants-list,
:not(.app-loading) #participants-section .teams-preview {
    visibility: visible;
    transition: visibility 0.1s;
}

/* Defensive: ensure they stay hidden while loading */
.app-loading #participants-section .participants-list,
.app-loading #participants-section .teams-preview {
    visibility: hidden !important;
}

#participants-section .card-body.is-collapsing {
    overflow: hidden;
}

/* Ensure the container collapses properly */
#participants-section.collapsed .card-body {
    height: 0 !important;         /* Force height 0 when collapsed */
    padding: 0;                   /* Remove padding when collapsed */
    border: none;                 /* Remove border when collapsed */
}


@media (prefers-reduced-motion: reduce) {
    #participants-section .card-body {
        transition: none;
    }
    #participants-section .card-toggle::after {
        transition: none;
    }
}

/* TEAMS */
/* Inline team assignment control next to participants */
.participant-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.assign-select {
    background: transparent;
    border: 1px solid rgba(199, 161, 91, 0.35);
    color: #e5e7eb;
    border-radius: .5rem;
    padding: .25rem .45rem;
    font-size: .95rem;
    max-width: 200px;
}
.assign-select:hover {
    background-color: rgba(255, 191, 105, 0.1);
    border-color: #ffbf69;
}

/* Teams preview grid + cards */
.team-columns {
    align-items: stretch;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--team-col-min, 380px), 1fr));
    gap: 1rem 1.25rem;
    margin-top: .5rem;
}
/* Example: widen columns globally (adjust the value as needed) */
.team-columns {
    --team-col-min: 420px; /* try 420–480px for noticeably wider cards */
}


.team-card {
    overflow: hidden; /* prevents visual spill outside the card */
    gap: .5rem;
    padding: .75rem;
    border: 1px solid rgba(199, 161, 91, 0.12);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(0, 0, 0, 0.08));
    border-radius: 12px;
    box-shadow: var(--glow);
    grid-template-rows: auto 1fr auto; /* footer stays at bottom */
    min-height: 180px;                 /* adjust as needed */
    display: flex;
    flex-direction: column;
    height: auto;         /* no fixed height */
}

/* Always one column inside each team-card */
.team-card .team-members {
    display: grid;
    grid-template-columns: 1fr; /* single column */
    gap: 0.5rem;
    align-items: start;
    min-width: 0;
}



.team-card__header {
    display: flex;
    align-items: center;
    gap: .5rem;
    justify-content: space-between;
}

.team-name-input {
    flex: 1;
    min-width: 0;
    background: rgba(255, 255, 255, 0.06);
    color: #e5e7eb;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    padding: .45rem .5rem;
}

.team-card__actions {
    display: inline-flex;
    gap: .35rem;
}

.team-members {
    flex-wrap: wrap;
    min-height: 0;   /* required for proper scrolling in flex containers */
    flex: 0 0 auto;       /* content sizes itself naturally */
    overflow: visible;    /* ensure nothing is clipped */
    min-width: 0; /* lets flex items shrink within the container */
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(var(--chip-col-width, 180px), 1fr));
    gap: 0.5rem;
    align-items: start;
}

.team-card__footer {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-top: auto;     /* pushes footer to the bottom of the card */
    opacity: .9;
}

.team-size {
    font-size: .9rem;
    color: var(--muted);
}

/* Slim buttons for card actions */
.btn-slim {
    font-size: .9rem;
    background: transparent;
    border: 1px solid rgba(199, 161, 91, 0.35);
    color: #e5e7eb;
    border-radius: .5rem;
    padding: .25rem .5rem;
}
#remove-participant {
    background: transparent;
    border: 1px solid rgba(199, 161, 91, 0.35);
    color: #e5e7eb;
}
#remove-participant:hover {
    background-color: rgba(255, 191, 105, 0.1);
    border-color: #ffbf69;
}

/* Chips fill the full row width and truncate long names */
.team-card .participant-chip {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;

    display: inline-flex;
    align-items: center;
    gap: 0.5rem 1rem;

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.team-card .participant-chip .chip-name {
    white-space: inherit;
    flex: 1 1 auto;  /* take remaining space */
    min-width: 0;    /* allow text to shrink */
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Member chip (used inside team cards) */
.participant-chip {
    padding: .35rem .5rem;
    border: 1px solid rgba(199, 161, 91, 0.18);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(0, 0, 0, 0.06));
    border-radius: 999px;
    box-shadow: var(--glow);
    min-width: 0;          /* allow shrink */
    max-width: 100%;       /* cap width to container */
    width: 100%;
    box-sizing: border-box;

    /* Truncate long names without changing chip width */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;

    display: inline-flex;        /* keeps content aligned nicely */
    align-items: center;
    gap: 0.5rem;
}

.participant-chip .chip-name {
    color: #e5e7eb;
    font-weight: 600;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: inherit;
}
.participant-chip .avatar,
.participant-chip .chip-icon,
.participant-chip .chip-action {
    flex: 0 0 auto;
}

.participant-chip__roles {
    gap: 0.5rem;
    display: flex;
}


/* Assign dropdown: style both group label and options */
.assign-select optgroup.format {
    /* Works in most browsers: color + weight */
    color: #e5e7eb;
    font-weight: 700;
    font-style: normal;
    /* Backgrounds/padding might be ignored by some UAs */
}

.assign-select optgroup.format option,
.tournament-form select option.format {
    color: #e5e7eb;
    background: #181412; /* some UAs ignore this; safe fallback */
}

/* Optional: give the group label a subtle uppercase look */
.assign-select optgroup.format[label] {
    letter-spacing: 0.02em;
    background: #181412; /* some UAs ignore this; safe fallback */
    /* If unsupported, it will simply be ignored */
}

@media (max-width: 480px) {
    .team-members {
        grid-template-columns: 1fr;
    }
}
