/**
 * Pickleball Knockout Tournament Styles
 * Version: 2.3.1
 */

:root {
    --pkt-primary-color: #3182ce;
    --pkt-primary-hover: #2b6cb0;
    --pkt-danger-color: #e53e3e;
    --pkt-danger-hover: #c53030;
    --pkt-border-color: #e2e8f0;
    --pkt-background-light: #f7fafc;
    --pkt-text-color: #2d3748;
    --pkt-success-bg: #c6f6d5;
    --pkt-success-text: #22543d;
    --pkt-error-bg: #fed7d7;
    --pkt-error-text: #742a2a;
    --pkt-warning-bg: #fffaf0;
    --pkt-warning-text: #c05621;
    --pkt-warning-border: #dd6b20;
}

body {
    color: var(--pkt-text-color);
}

.pkt-container {
    max-width: 950px;
    margin: 20px auto;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    font-size: 15px;
    padding: 0 15px;
}

.pkt-card {
    background: #fff;
    border: 1px solid var(--pkt-border-color);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -1px rgba(0,0,0,.04);
}

.pkt-input, 
.pkt-select,
.pkt-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    margin-bottom: 12px;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
    font-size: inherit;
}
.pkt-input:focus,
.pkt-select:focus,
.pkt-textarea:focus {
    outline: none;
    border-color: var(--pkt-primary-color);
    box-shadow: 0 0 0 2px rgba(49, 130, 206, 0.2);
}
.pkt-input:disabled,
.pkt-select:disabled {
    background-color: #edf2f7;
    color: #a0aec0;
    cursor: not-allowed;
}


.pkt-checkbox-label {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
    cursor: pointer;
}

.pkt-checkbox-label input {
    margin-right: 10px;
    height: 16px;
    width: 16px;
}

.pkt-button {
    background-color: var(--pkt-primary-color);
    color: white;
    padding: 12px 18px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    font-size: 15px;
    transition: background-color 0.2s;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.pkt-button:hover {
    background-color: var(--pkt-primary-hover);
}
.pkt-button:disabled {
    background-color: #a0aec0;
    cursor: not-allowed;
}

.pkt-button-danger {
    background-color: var(--pkt-danger-color);
} 
.pkt-button-danger:hover {
    background-color: var(--pkt-danger-hover);
}

.pkt-feedback {
    margin-top: 15px;
    padding: 12px;
    border-radius: 6px;
    display: none;
    border: 1px solid transparent;
}
.pkt-feedback.success { background-color: var(--pkt-success-bg); color: var(--pkt-success-text); border-color: #9ae6b4;}
.pkt-feedback.error { background-color: var(--pkt-error-bg); color: var(--pkt-error-text); border-color: #feb2b2;}

.pkt-warning {
    padding: 15px;
    background-color: var(--pkt-warning-bg);
    color: var(--pkt-warning-text);
    border-radius: 6px;
    border: 1px solid var(--pkt-warning-border);
    border-left-width: 4px;
    margin-bottom: 20px;
}


.pkt-admin-header, 
.pkt-public-header {
    text-align: center;
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--pkt-border-color);
}
.pkt-public-header h2 { margin-bottom: 10px; }
.pkt-public-header p { margin: 5px 0; color: #718096; }


/* Tabs */
.pkt-tabs {
    display: flex;
    flex-wrap: wrap;
    border-bottom: 2px solid var(--pkt-border-color);
    margin-bottom: 20px;
}
.pkt-tab-link {
    background: none;
    color: #4a5568;
    border: none;
    padding: 12px 18px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    margin-bottom: -2px;
    border-bottom: 3px solid transparent;
    transition: color 0.2s, border-color 0.2s;
}
.pkt-tab-link:hover {
    color: var(--pkt-primary-color);
}
.pkt-tab-link.active {
    border-bottom-color: var(--pkt-primary-color);
    font-weight: 600;
    color: var(--pkt-primary-color);
}
.pkt-tab-content { display: none; }
.pkt-public-view .pkt-card {
    border-top: none;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    box-shadow: none;
    border-color: transparent;
    padding-top: 0;
}


/* Form Layout */
.pkt-form-row {
    display: flex;
    gap: 20px;
    margin-bottom: 15px;
}
.pkt-form-col {
    flex: 1;
}

.pkt-password-form {
    display: flex;
    gap: 10px;
}
.pkt-password-form .pkt-input {
    flex-grow: 1;
    margin-bottom: 0;
}
.pkt-password-input {
    max-width: 300px;
}


/* Team Lists */
#pkt-team-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

/* Groups Tab */
.pkt-group-actions {
    margin-bottom: 20px;
}
.pkt-groups-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-top: 20px;
}
.pkt-group-col {
    border: 1px solid var(--pkt-border-color);
    padding: 15px;
    border-radius: 8px;
    background: var(--pkt-background-light);
}
.pkt-group-col h4 { margin-top: 0; }
.pkt-team-item, .pkt-team-item-unassigned { padding: 8px 0; border-bottom: 1px solid #eee; }
.pkt-team-item:last-child, .pkt-team-item-unassigned:last-child { border-bottom: none; }

.pkt-team-item-unassigned {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.pkt-team-item-unassigned select { width: 120px; margin-left: 10px; padding: 6px; }

/* Tables */
.pkt-schedule-container, 
.pkt-standings-bracket-container,
.pkt-table-container,
.pkt-bracket-container {
    overflow-x: auto;
}
.pkt-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 25px;
    font-size: 14px;
}
.pkt-table th, 
.pkt-table td {
    padding: 12px 10px;
    border: 1px solid var(--pkt-border-color);
    text-align: center;
    vertical-align: middle;
}
.pkt-table th {
    background-color: var(--pkt-background-light);
    font-weight: 600;
}
.pkt-table tr:nth-child(even) { background-color: #fdfdfd; }
.pkt-table .team-name { text-align: left; }
.pkt-winner { font-weight: bold; color: var(--pkt-primary-color); }

/* Input Styles inside Tables */
.pkt-score-input, 
.pkt-court-input, 
.pkt-status-select,
.pkt-knockout-team-input,
.pkt-knockout-team-select,
.pkt-wildcard-select,
.pkt-rr-score-input,
.pkt-rr-court-input,
.pkt-rr-status-select {
    padding: 6px;
    border: 1px solid #ccc;
    border-radius: 4px;
    text-align: center;
    font-size: 14px;
    width: 100%;
    box-sizing: border-box;
}
.pkt-score-input,
.pkt-rr-score-input { width: 50px; }

.pkt-court-input,
.pkt-rr-court-input { width: 80px; }

.pkt-status-select,
.pkt-rr-status-select { min-width: 110px; }

.pkt-wildcard-select { text-align: left; }

/* Status & Rank Colors */
tr.status-inprogress,
tr.status-inprogress td,
tr.status-inprogress select { 
    background-color: #ebf8ff !important;
    color: #3182ce;
    font-weight: bold; 
}
.pkt-table tr.rank-advance td,
.pkt-table tr.rank-1 td {
    background-color: #f0fff4;
    color: #38a169;
    font-weight: bold;
}
.pkt-table tr.rank-2 td {
    background-color: #e2e8f0;
}
.pkt-table tr.rank-3 td {
    background-color: #feebc8;
}

tr.dragging {
    opacity: 0.7;
    background: #cce5ff;
}

/* Bracket Styles */
.pkt-bracket {
    display: flex;
    padding-bottom: 15px;
    align-items: flex-start;
}
.pkt-round {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    padding: 0 15px;
    min-width: 150px;
}
.pkt-round-title {
    font-weight: bold;
    text-align: center;
    margin-bottom: 30px;
    font-size: 1.1em;
    white-space: nowrap;
}
.pkt-match {
    position: relative;
    margin-bottom: 25px; 
}
.pkt-match:last-child {
    margin-bottom: 0;
}
.pkt-match-teams {
    background: white;
    border: 1px solid #ccc;
    border-radius: 6px;
    width: 100%;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.team-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    min-height: 42px;
}
.team-container:first-child {
    border-bottom: 1px solid #eee;
}
.team-container.winner .team-name {
    font-weight: bold;
    color: var(--pkt-primary-color);
}
.pkt-match .team-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-grow: 1;
}
.pkt-match .team-score {
    flex-shrink: 0;
    padding-left: 10px;
    font-weight: bold;
}
.team-slot {
    color: #999;
    font-style: italic;
}
.pkt-match-sets-score {
    padding: 8px 10px;
    text-align: center;
    font-size: 0.9em;
    color: #718096;
    border-top: 1px solid #eee;
}


/* Final Rankings Column Styles */
.pkt-final-rankings {
}
.pkt-ranking-item {
    text-align: center;
    margin-bottom: 20px;
}
.pkt-ranking-title {
    font-size: 1.1em;
    font-weight: 600;
    margin-bottom: 8px;
}
.pkt-ranking-team {
    font-size: 1em;
    padding: 10px;
    background: #f7fafc;
    border-radius: 6px;
    min-height: 42px;
}

/* Tournament Description */
.pkt-tournament-description {
    padding: 15px;
    border: 1px solid var(--pkt-border-color);
    border-radius: 8px;
    background: var(--pkt-background-light);
    line-height: 1.6;
}
.pkt-tournament-description p:first-child { margin-top: 0; }
.pkt-tournament-description p:last-child { margin-bottom: 0; }
.pkt-tournament-description p { margin-top: 0; margin-bottom: 1em; }
.pkt-tournament-description br { display: block; margin-bottom: 0.5em; content: ""; }


/* Public Group View */
.pkt-public-groups-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
}

.pkt-public-group-col {
     border: 1px solid var(--pkt-border-color);
     padding: 15px;
     border-radius: 8px;
     background: var(--pkt-background-light);
     height: 100%;
}
.pkt-public-group-col-inner {
     height: 100%;
}

/* Round Robin Setup Box & Round Headers */
.pkt-rr-setup-box {
    background: #f8f9fa;
    border: 1px solid #ccd0d4;
    padding: 25px;
    border-radius: 8px;
    margin-bottom: 25px;
}
.pkt-rr-setup-box h4 {
    margin-top: 0;
    border-bottom: 1px solid #e2e4e7;
    padding-bottom: 15px;
    margin-bottom: 20px;
    color: #1d2327;
    font-size: 1.2em;
}
.pkt-rr-setup-box label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #4a5568;
}
.pkt-rr-setup-box small {
    display: block;
    margin-top: 6px;
    color: #718096;
    font-style: italic;
    font-size: 0.9em;
}

/* Style for Round Robin Section Headers (e.g. "Vòng 1") */
.pkt-round-header td {
    background-color: #edf2f7 !important;
    color: #2d3748;
    font-weight: bold;
    text-align: left;
    padding: 10px 15px;
    border-bottom: 2px solid #cbd5e0;
}


/* Responsive Styles */
@media (max-width: 768px) {
    .pkt-container {
        font-size: 14px;
    }
    .pkt-button, .pkt-input, .pkt-select, .pkt-textarea {
        padding: 12px;
        font-size: 14px;
    }
    .pkt-tabs {
        margin-left: -15px;
        margin-right: -15px;
        padding: 0 10px;
    }
    .pkt-tab-link {
        padding: 10px;
        font-size: 14px;
        flex-grow: 1;
        text-align: center;
    }
    .pkt-card {
        padding: 15px;
    }
    .pkt-table th, .pkt-table td {
        padding: 10px 8px;
    }
    .pkt-form-row {
        flex-direction: column;
        gap: 0;
        margin-bottom: 0;
    }
    .pkt-public-groups-grid {
        grid-template-columns: 1fr;
    }
    .pkt-password-form {
        flex-direction: column;
    }
    .pkt-password-input {
        max-width: none;
    }
}

@media (max-width: 480px) {
    .pkt-public-header h2 {
        font-size: 1.5em;
    }
    .pkt-round {
        padding: 0 10px;
    }
    .team-container {
        padding: 8px;
        min-height: 38px;
    }
}

.pkt-round {
    padding: 0 10px;
    width: 220px;
}

.pkt-feedback.pkt-success {
    border-left-color: #4CAF50;
}