/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    background: linear-gradient(135deg, #ea6666 0%, #f30000 100%);
    color: white;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 30px;
    text-align: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
}

/* Main content */
main {
    flex: 1;
}

/* Sections */
.section {
    background: white;
    padding: 25px;
    margin-bottom: 25px;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.section h2, .section h3 {
    color: #2c3e50;
    margin-bottom: 20px;
    font-weight: 600;
}

.section h2 {
    font-size: 1.8rem;
    border-bottom: 3px solid #3498db;
    padding-bottom: 10px;
}

.section h3 {
    font-size: 1.4rem;
    border-bottom: 2px solid #ecf0f1;
    padding-bottom: 8px;
}

.sort-note {
    font-size: 0.8rem;
    font-weight: 400;
    color: #7f8c8d;
    font-style: italic;
}

.goal-count {
    font-size: 0.8rem;
    font-weight: 400;
    color: #3498db;
    background: #ecf0f1;
    padding: 2px 8px;
    border-radius: 12px;
    margin-left: 8px;
}

/* Forms */
.form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.form-inline {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.input, .select {
    padding: 12px 15px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.3s ease;
    flex: 1;
    min-width: 200px;
}

.input:focus, .select:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

/* Buttons */
.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
    text-align: center;
    min-width: 120px;
}

.btn-primary {
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #2980b9, #1f4e79);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(52, 152, 219, 0.3);
}

.btn-secondary {
    background: linear-gradient(135deg, #95a5a6, #7f8c8d);
    color: white;
}

.btn-secondary:hover {
    background: linear-gradient(135deg, #7f8c8d, #6c7b7d);
    transform: translateY(-2px);
}

.btn-success {
    background: linear-gradient(135deg, #27ae60, #229954);
    color: white;
}

.btn-success:hover:not(:disabled) {
    background: linear-gradient(135deg, #229954, #1e8449);
    transform: translateY(-2px);
}

.btn-danger {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    color: white;
}

.btn-danger:hover {
    background: linear-gradient(135deg, #c0392b, #a93226);
    transform: translateY(-2px);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Goal buttons */
.btn-goal {
    font-size: 18px;
    font-weight: 700;
    padding: 15px 25px;
    min-width: 150px;
}

.home-goal {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
}

.away-goal {
    background: linear-gradient(135deg, #3498db, #2980b9);
}

/* Cards */
.match-card, .player-card {
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 15px;
    transition: all 0.3s ease;
}

.match-card:hover, .player-card:hover {
    border-color: #3498db;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

/* Match card states */
.active-match {
    border-left: 4px solid #27ae60;
    background: linear-gradient(135deg, #d5f4e6, #a8e6cf);
}

.completed-match {
    border-left: 4px solid #95a5a6;
    background: #f8f9fa;
    opacity: 0.8;
}

.completed-match:hover {
    opacity: 1;
}

.match-card h3 {
    color: #2c3e50;
    margin-bottom: 10px;
    font-size: 1.3rem;
}

.match-card p {
    color: #7f8c8d;
    margin-bottom: 15px;
}

/* Match actions */
.match-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 10px;
}

.match-actions .form-inline {
    margin: 0;
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.85rem;
    border-radius: 4px;
}

.btn-danger {
    background-color: #e74c3c;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: background-color 0.3s;
}

.btn-danger:hover {
    background-color: #c0392b;
}

/* Match timer on index page */
.match-timer {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px 0;
    padding: 8px 12px;
    background: #f8f9fa;
    border-radius: 6px;
    border: 1px solid #e9ecef;
}

.timer-label {
    font-size: 0.9rem;
    color: #6c757d;
    font-weight: 500;
}

.match-timer .countdown-display {
    font-size: 1.2rem;
    font-weight: bold;
    font-family: 'Courier New', monospace;
    color: #2c3e50;
    min-width: 60px;
    text-align: center;
}

.match-timer .countdown-display.negative {
    color: #e74c3c;
    animation: pulse 1s infinite;
}

/* Player cards */
.player-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.player-info {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: 1;
    min-width: 200px;
}

.player-name {
    font-weight: 600;
    font-size: 1.1rem;
    color: #2c3e50;
}

.time-display {
    font-size: 1.5rem;
    font-weight: 700;
    color: #e74c3c;
    font-family: 'Courier New', monospace;
}

.time-stats {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 0.9rem;
}

.time-label {
    color: #7f8c8d;
    font-size: 0.85rem;
}

/* Field vs Bench styling */
.field-player {
    border-color: #27ae60;
    background: linear-gradient(135deg, #d5f4e6, #a8e6cf);
}

.bench-player {
    border-color: #95a5a6;
    background: #f8f9fa;
}

/* Score display */
.score-controls {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.score-display {
    display: flex;
    gap: 30px;
    font-size: 1.5rem;
    font-weight: 700;
    color: #2c3e50;
}

.score {
    padding: 10px 20px;
    background: #ecf0f1;
    border-radius: 8px;
    min-width: 100px;
    text-align: center;
}

/* Goal history */
.goal-history {
    max-height: 200px;
    overflow-y: auto;
}

.goal-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 8px;
    border-left: 4px solid #3498db;
}

.goal-team {
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.9rem;
}

.goal-team.home {
    background: #e74c3c;
    color: white;
}

.goal-team.away {
    background: #3498db;
    color: white;
}

.goal-time {
    color: #7f8c8d;
    font-family: 'Courier New', monospace;
}

/* Empty states */
.no-matches, .no-players, .no-goals {
    text-align: center;
    color: #7f8c8d;
    font-style: italic;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 2px dashed #ddd;
}

/* Match navigation bar */
.match-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn-back {
    background: #95a5a6;
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    transition: background-color 0.3s ease;
}

.btn-back:hover {
    background: #7f8c8d;
    color: white;
    text-decoration: none;
}

.match-title {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.match-name {
    font-size: 1.2rem;
    font-weight: 600;
    color: #2c3e50;
}

.match-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
    min-width: 60px;
    min-height: 32px;
}

.match-status {
    font-size: 1rem;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 20px;
    margin-left: 15px;
}

.match-status.completed {
    background: #95a5a6;
    color: white;
}

.match-status.not-started {
    background: #f39c12;
    color: white;
}

.match-status.active {
    background: #27ae60;
    color: white;
}

.final-score {
    font-size: 2rem;
    font-weight: 700;
    text-align: center;
    padding: 20px;
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border-radius: 10px;
    border: 2px solid #dee2e6;
}

/* Compact score section */
.score-section {
    background: white;
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.score-display-compact {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    min-width: 80px;
}

.team-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: #2c3e50;
}

.score-number {
    font-size: 2rem;
    font-weight: 700;
    color: #2c3e50;
    font-family: 'Courier New', monospace;
}

.score-separator {
    font-size: 1.5rem;
    font-weight: 700;
    color: #7f8c8d;
    margin: 0 10px;
}

.btn-goal-small {
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    min-width: 40px;
    min-height: 28px;
    border-radius: 6px;
}

.score-display-compact.final .score-number {
    font-size: 2.5rem;
}

/* Match controls */
.match-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 25px;
    margin-bottom: 30px;
}

/* Responsive design */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    header {
        padding: 15px;
        margin-bottom: 20px;
    }
    
    header h1 {
        font-size: 1.8rem;
    }
    
    .section {
        padding: 15px;
        margin-bottom: 15px;
    }
    
    .section h2 {
        font-size: 1.5rem;
        margin-bottom: 15px;
    }
    
    .section h3 {
        font-size: 1.2rem;
        margin-bottom: 12px;
    }
    
    .form-inline {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    
    .input, .select {
        min-width: auto;
        padding: 10px 12px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .player-card {
        flex-direction: row;
        align-items: center;
        padding: 12px;
        margin-bottom: 8px;
    }
    
    .player-info {
        min-width: auto;
        text-align: left;
        flex: 1;
    }
    
    .player-name {
        font-size: 1rem;
        margin-bottom: 4px;
    }
    
    .time-stats {
        font-size: 0.8rem;
    }
    
    .time-display {
        font-size: 1.3rem;
    }
    
    .match-controls {
        grid-template-columns: 1fr;
        gap: 15px;
        margin-bottom: 20px;
    }
    
    .score-controls {
        flex-direction: row;
        gap: 10px;
        justify-content: center;
    }
    
    .score-display {
        flex-direction: row;
        gap: 15px;
        justify-content: center;
    }
    
    .match-nav {
        padding: 8px 12px;
        margin-bottom: 15px;
    }
    
    .btn-back {
        padding: 6px 10px;
        font-size: 12px;
    }
    
    .match-name {
        font-size: 1rem;
    }
    
    .match-status {
        font-size: 0.8rem;
        padding: 2px 8px;
    }
    
    .btn-small {
        padding: 4px 8px;
        font-size: 11px;
        min-width: 50px;
        min-height: 28px;
    }
    
    .score-section {
        padding: 12px;
        margin-bottom: 15px;
    }
    
    .score-display-compact {
        gap: 15px;
    }
    
    .score-item {
        min-width: 60px;
        gap: 6px;
    }
    
    .team-name {
        font-size: 0.8rem;
    }
    
    .score-number {
        font-size: 1.5rem;
    }
    
    .score-separator {
        font-size: 1.2rem;
        margin: 0 5px;
    }
    
    .btn-goal-small {
        padding: 4px 8px;
        font-size: 11px;
        min-width: 35px;
        min-height: 24px;
    }
    
    .score-display-compact.final .score-number {
        font-size: 2rem;
    }
    
    /* Mobile multiselect */
    .multiselect {
        min-height: 100px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .multiselect-info {
        justify-content: center;
    }
    
    /* Mobile setup player cards */
    .setup-player {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding: 10px;
    }
    
    .setup-player .player-info {
        text-align: center;
    }
    
    .setup-player .form-inline {
        display: flex;
        justify-content: center;
    }
    
    /* Make buttons more touch-friendly */
    .btn {
        padding: 12px 16px;
        font-size: 16px;
        min-width: 120px;
        min-height: 44px; /* iOS recommended touch target */
    }
    
    .btn-goal {
        font-size: 18px;
        padding: 14px 20px;
        min-width: 140px;
        min-height: 50px;
    }
    
    /* Compact goal history */
    .goal-history {
        max-height: 150px;
    }
    
    .goal-item {
        padding: 8px 12px;
        margin-bottom: 6px;
    }
    
    /* Reduce spacing in match cards */
    .match-card {
        padding: 15px;
        margin-bottom: 10px;
    }
    
    .match-card h3 {
        font-size: 1.2rem;
        margin-bottom: 8px;
    }
    
    .match-card p {
        font-size: 0.9rem;
        margin-bottom: 12px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 8px;
    }
    
    header {
        padding: 12px;
        margin-bottom: 15px;
    }
    
    header h1 {
        font-size: 1.6rem;
    }
    
    .section {
        padding: 12px;
        margin-bottom: 12px;
    }
    
    .section h2 {
        font-size: 1.3rem;
        margin-bottom: 12px;
    }
    
    .section h3 {
        font-size: 1.1rem;
        margin-bottom: 10px;
    }
    
    .btn {
        padding: 12px 14px;
        font-size: 15px;
        min-width: 110px;
        min-height: 44px;
    }
    
    .btn-goal {
        font-size: 16px;
        padding: 12px 18px;
        min-width: 130px;
        min-height: 48px;
    }
    
    .time-display {
        font-size: 1.1rem;
    }
    
    .score {
        font-size: 1.1rem;
        padding: 8px 12px;
    }
    
    .player-card {
        padding: 10px;
        margin-bottom: 6px;
    }
    
    /* Match actions mobile */
    .match-actions {
        flex-direction: column;
        gap: 8px;
        align-items: stretch;
    }
    
    .match-actions .btn {
        width: 100%;
        text-align: center;
    }
    
    .btn-small {
        padding: 10px 12px;
        font-size: 14px;
        min-height: 40px;
    }
    
    /* Match timer mobile */
    .match-timer {
        padding: 6px 10px;
        margin: 6px 0;
    }
    
    .timer-label {
        font-size: 0.85rem;
    }
    
    .match-timer .countdown-display {
        font-size: 1.1rem;
        min-width: 50px;
    }
    
    .player-name {
        font-size: 0.95rem;
    }
    
    .time-stats {
        font-size: 0.75rem;
    }
    
    .goal-history {
        max-height: 120px;
    }
    
    .goal-item {
        padding: 6px 10px;
        margin-bottom: 4px;
    }
    
    .match-card {
        padding: 12px;
        margin-bottom: 8px;
    }
}

/* Mobile-specific optimizations */
@media (max-width: 768px) {
    /* Make sections more compact */
    .home-container .section {
        margin-bottom: 12px;
    }
    
    /* Compact player lists */
    .player-list {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    
    .player-list .player-card {
        padding: 8px;
        margin-bottom: 0;
        text-align: center;
    }
    
    .player-list .player-name {
        font-size: 0.9rem;
    }
    
    /* Compact match cards */
    .match-list {
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    /* Reduce footer space */
    footer {
        padding: 15px;
        margin-top: 20px;
        font-size: 0.9rem;
    }
    
    /* Optimize sort notes */
    .sort-note {
        font-size: 0.7rem;
        display: block;
        margin-top: 2px;
    }
}

@media (max-width: 480px) {
    /* Even more compact on very small screens */
    .player-list {
        grid-template-columns: 1fr;
    }
    
    .player-list .player-card {
        padding: 6px;
    }
    
    .player-list .player-name {
        font-size: 0.85rem;
    }
    
    .sort-note {
        font-size: 0.65rem;
    }
}

/* Flash messages */
.flash-messages {
    margin-bottom: 20px;
}

.flash-message {
    padding: 12px 16px;
    margin-bottom: 10px;
    border-radius: 8px;
    font-weight: 600;
    animation: slideIn 0.3s ease;
}

.flash-success {
    background: #d5f4e6;
    color: #27ae60;
    border-left: 4px solid #27ae60;
}

.flash-info {
    background: #d1ecf1;
    color: #0c5460;
    border-left: 4px solid #17a2b8;
}

.flash-error {
    background: #f8d7da;
    color: #721c24;
    border-left: 4px solid #dc3545;
}

/* Multiselect styling */
.multiselect-container {
    margin-bottom: 15px;
}

.multiselect {
    width: 100%;
    min-height: 120px;
    padding: 8px;
    border: 2px solid #ddd;
    border-radius: 8px;
    background: white;
    font-size: 14px;
    line-height: 1.4;
}

.multiselect:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.multiselect option {
    padding: 8px 12px;
    margin: 2px 0;
    border-radius: 4px;
    cursor: pointer;
}

.multiselect option:checked {
    background: #3498db;
    color: white;
    font-weight: 600;
}

.multiselect-info {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 8px;
    padding: 8px 12px;
    background: #f8f9fa;
    border-radius: 6px;
    font-size: 14px;
}

.selection-count {
    color: #2c3e50;
    font-weight: 600;
}

.info-text {
    color: #7f8c8d;
    font-style: italic;
    font-size: 14px;
    margin-bottom: 12px;
    padding: 8px 12px;
    background: #ecf0f1;
    border-radius: 4px;
    border-left: 3px solid #3498db;
}

.match-score {
    color: #e74c3c;
    font-weight: bold;
}

/* Setup player cards */
.setup-player {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    margin-bottom: 8px;
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.setup-player:hover {
    border-color: #dc3545;
    box-shadow: 0 2px 4px rgba(220, 53, 69, 0.1);
}

.setup-player .player-info {
    flex: 1;
    text-align: left;
}

.setup-player .player-name {
    font-size: 1rem;
    font-weight: 600;
    color: #2c3e50;
    margin: 0;
}

.setup-player .form-inline {
    margin: 0;
}

/* Countdown Timer */
.countdown-timer {
    text-align: center;
    margin-top: 15px;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 2px solid #e9ecef;
}

#countdown-display {
    font-size: 2rem;
    font-weight: bold;
    font-family: 'Courier New', monospace;
    color: #2c3e50;
    display: inline-block;
    min-width: 80px;
    text-align: center;
}

#countdown-display.negative {
    color: #e74c3c;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.7; }
    100% { opacity: 1; }
}

/* Mobile responsive for countdown timer */
@media (max-width: 768px) {
    .countdown-timer {
        margin-top: 10px;
        padding: 8px;
    }
    
    #countdown-display {
        font-size: 1.5rem;
        min-width: 60px;
    }
}

/* Footer */
footer {
    text-align: center;
    padding: 20px;
    color: #7f8c8d;
    margin-top: 30px;
    border-top: 1px solid #ecf0f1;
}
