/*
    IMPORTANT: Shared site styles including header/nav/banner layout.
    The header is injected by layout.js from header-template.js.
    Do not remove header-related selectors or override z-index/positioning
    without checking header-template.js and layout.js behavior.
*/
body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f4f4f4;
    -webkit-tap-highlight-color: rgba(76, 175, 80, 0.3);
    -webkit-text-size-adjust: 100%;
}

header {
    /*background-color: #4CAF50;*/
    /* Add banner background image - uncomment when image is added */
    background-image: url('/images/banner.png');
    background-size: cover;
    background-position: center center;
    background-repeat: no-repeat;
    color: white;
    height: 10vh; /* banner is 10% of viewport height */
    min-height: 80px; /* minimum height for readability */
    padding: 0 16px 0 120px; /* reserve ample space for the logo on the left */
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center; /* keeps nav centered */
    /* Optional: Add overlay for better text readability */
    background-blend-mode: overlay;
}

.site-logo {
    position: absolute;
    left: 10px;
    top: 0;
    bottom: 0;
    display: inline-flex;
    align-items: center; /* vertically center within header */
}
.site-logo { z-index: 1; }
.site-logo img {
    height: 100%; /* match banner height */
    width: auto;
    display: block;
}

/* Ensure user info does not cover nav */
#user-info { position: absolute; right: 16px; top: 10px; z-index: 5; }

nav {
    position: relative;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 4px;
}

nav a {
    color: white;
    padding: 8px 12px;
    text-decoration: none;
    border-radius: 4px;
    transition: background-color 0.2s;
    white-space: nowrap;
}

nav a:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

#nav-username {
    color: white;
    padding: 8px 12px;
    white-space: nowrap;
    font-weight: 600;
}

/* Hamburger menu button (hidden on desktop) */
.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    margin: 0;
    line-height: 1;
}

/* Mobile menu overlay backdrop */
.nav-overlay {
    display: none;
    position: fixed;
    top: 10vh;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 9;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease-in-out;
}

.nav-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

main {
    padding: 20px;
}

form {
    display: flex;
    flex-direction: column;
    max-width: 400px;
    margin: 0 auto;
    padding: 0 16px;
}

form label {
    margin-top: 8px;
    font-weight: 600;
    color: #333;
    display: block;
    min-height: 24px;
}

input, button {
    margin: 10px 0;
    padding: 10px;
    font-size: 16px;
    border: 1px solid #ccc;
    border-radius: 4px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    touch-action: manipulation;
}

select {
    margin: 10px 0;
    padding: 10px;
    font-size: 16px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background-color: white;
    cursor: pointer;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    touch-action: manipulation;
}

select:focus {
    outline: 2px solid #4CAF50;
    outline-offset: 2px;
    border-color: #4CAF50;
}

input:focus {
    outline: 2px solid #4CAF50;
    outline-offset: 2px;
    border-color: #4CAF50;
}

/* Ensure proper touch targets on mobile */
@media (hover: none) and (pointer: coarse) {
    input, button, select {
        min-height: 44px;
        font-size: 16px;
    }
    
    button {
        min-height: 48px;
    }
    
    nav a {
        min-height: 44px;
        display: flex;
        align-items: center;
    }
}

button {
    background-color: #4CAF50;
    color: white;
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: background-color 0.2s;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
}

button:hover {
    background-color: #45a049;
}

button:active {
    background-color: #3d8b40;
}

button[type="button"] {
    background-color: #757575;
}

button[type="button"]:hover {
    background-color: #616161;
}

button[type="button"]:active {
    background-color: #4a4a4a;
}

/* Section spacing */
section {
    margin-bottom: 32px;
}

section h2 {
    color: #333;
    margin-bottom: 16px;
}

#chat-messages {
    border: 1px solid #ccc;
    padding: 10px;
    height: 300px;
    overflow-y: scroll;
}

.chat-container { max-width: 800px; margin: 0 auto; }
.chat-messages { 
    border: 1px solid #ddd; 
    background: #fff; 
    padding: 12px; 
    height: 320px; 
    overflow-y: auto; 
    border-radius: 6px;
    margin-bottom: 8px;
}
.chat-form { 
    display: flex; 
    gap: 8px; 
    margin-top: 8px;
}
.chat-form input[type="text"] { 
    flex: 1; 
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 16px;
}
.chat-form input[type="text"]:focus {
    outline: 2px solid #4CAF50;
    outline-offset: 2px;
    border-color: #4CAF50;
}
.chat-form button {
    padding: 12px 24px;
    min-width: 80px;
}
.chat-msg { 
    padding: 10px; 
    border-bottom: 1px solid #f0f0f0;
    border-radius: 4px;
    margin-bottom: 4px;
}
.chat-msg:hover {
    background-color: #f9f9f9;
}
.chat-meta { 
    font-size: 12px; 
    color: #666; 
    margin-bottom: 6px;
}
.chat-username { 
    font-weight: 700; 
    color: #4CAF50; 
    margin-right: 8px;
}
.chat-text { 
    font-size: 14px; 
    color: #111;
    line-height: 1.4;
    word-wrap: break-word;
}
.chat-preview { margin-bottom: 6px; }

/* Home page chat preview */
#chat-preview { max-width: 900px; margin: 12px auto; }
#chat-content { background: #fff; border: 1px solid #e6e6e6; border-radius: 8px; padding: 12px; }
.chat-preview-list { display: flex; flex-direction: column; gap: 10px; }
.chat-preview-item { display: flex; gap: 10px; align-items: flex-start; padding: 8px 6px; border-bottom: 1px solid #f3f3f3; }
.chat-preview-item:last-child { border-bottom: none; }
.chat-preview-avatar { width: 32px; height: 32px; border-radius: 50%; background: #4CAF50; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; }
.chat-preview-body { flex: 1; }
.chat-preview-meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.chat-preview-username { font-weight: 700; color: #222; }
.chat-preview-time { font-size: 12px; color: #777; }
.chat-preview-text { color: #111; line-height: 1.3; }
.chat-preview-actions { text-align: right; padding-top: 8px; }
.btn-link { color: #2b6cb0; text-decoration: none; font-weight: 600; }
.btn-link:hover { text-decoration: underline; }

.admin-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
    background-color: white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.admin-table th, .admin-table td {
    border: 1px solid #ddd;
    padding: 12px 8px;
    text-align: left;
}
.admin-table thead {
    background-color: #4CAF50;
    color: white;
}
.admin-table th {
    font-weight: 600;
}
.admin-table tr:nth-child(even) { 
    background-color: #f9f9f9; 
}
.admin-table tr:hover {
    background-color: #f5f5f5;
}

/* Admin tables: action button spacing */
.admin-actions button { 
    margin-right: 8px;
    padding: 6px 12px;
    font-size: 14px;
}
.admin-actions button:last-child { 
    margin-right: 0; 
}

/* Admin form styling */
.admin-form label {
    display: block;
    margin-bottom: 4px;
}

.admin-form input[type="text"],
.admin-form input[type="password"],
.admin-form input[type="number"],
.admin-form input[type="date"],
.admin-form select {
    width: 100%;
    box-sizing: border-box;
}

/* Inline validation styling */
.form-error { color: #b00020; font-size: 12px; margin-top: -6px; margin-bottom: 8px; display: block; }
.invalid { border-color: #b00020 !important; outline-color: #b00020 !important; }

/* Tablet and mobile navigation */
@media (max-width: 900px) {
    header {
        padding: 0 16px 0 100px;
        min-height: 70px;
        background-size: cover;
        background-position: center center;
    }
    
    nav a {
        padding: 6px 8px;
        font-size: 14px;
    }
    
    #chat-preview,
    .chat-container {
        max-width: 100%;
        padding: 0 8px;
    }
    
    .chat-messages {
        height: 280px;
        padding: 8px;
    }
    
    .chat-form input[type="text"] {
        padding: 10px;
    }
    
    .chat-form button {
        padding: 10px 16px;
        min-width: 70px;
    }
    
    section {
        padding: 0 8px;
    }
    
    section h2 {
        font-size: 1.5rem;
    }
    
    #profile-form {
        padding: 16px !important;
    }
    
    .icon-grid {
        grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
        gap: 8px;
    }
    
    .icon-tile {
        padding: 8px;
        min-height: 52px;
    }
    
    .icon-emoji {
        font-size: 24px;
    }
    
    /* Scorecard tables */
    #scorecard-container,
    #net-scorecard-container {
        border: 1px solid #ddd;
        border-radius: 4px;
        position: relative;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    #scorecard-table,
    #net-scorecard-table {
        width: 100%;
        border-collapse: separate;
        border-spacing: 0;
    }
    
    /* Sticky first column for scorecard tables */
    #scorecard-table th:first-child,
    #scorecard-table td:first-child,
    #net-scorecard-table th:first-child,
    #net-scorecard-table td:first-child {
        position: -webkit-sticky;
        position: sticky;
        left: 0;
        z-index: 2;
        background: white;
        box-shadow: 2px 0 4px rgba(0, 0, 0, 0.1);
        min-width: 60px;
    }
    
    #scorecard-table thead th:first-child,
    #net-scorecard-table thead th:first-child {
        z-index: 3;
    }
    
    /* Preserve background colors for specific rows when sticky */
    #scorecard-table thead tr:first-child th:first-child,
    #net-scorecard-table thead tr:first-child th:first-child {
        background: #f0f0f0;
    }
    
    #scorecard-table thead tr:nth-child(2) td:first-child,
    #net-scorecard-table thead tr:nth-child(2) td:first-child {
        background: #fff8e1;
    }
    
    #scorecard-table thead tr:nth-child(3) td:first-child,
    #net-scorecard-table thead tr:nth-child(3) td:first-child {
        background: #e3f2fd;
    }
    
    #scorecard-table tbody tr:nth-child(odd) td:first-child,
    #net-scorecard-table tbody tr:nth-child(odd) td:first-child {
        background: white;
    }
    
    #scorecard-table tbody tr:nth-child(even) td:first-child,
    #net-scorecard-table tbody tr:nth-child(even) td:first-child {
        background: #f9f9f9;
    }
    
    /* Score inputs - larger touch targets for mobile */
    .score-input {
        width: 48px;
        height: 36px;
        text-align: center;
        font-size: 16px;
        font-weight: 600;
        border: 2px solid #ddd;
        border-radius: 4px;
        padding: 4px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(76, 175, 80, 0.2);
    }
    
    .score-input:focus {
        outline: none;
        border-color: #4CAF50;
        background-color: #f0f8f0;
    }
    
    /* Admin table compact buttons for mobile */
    .btn-compact {
        padding: 6px 12px;
        font-size: 14px;
        border: none;
        border-radius: 4px;
        cursor: pointer;
        transition: background-color 0.2s;
        touch-action: manipulation;
        white-space: nowrap;
    }
    
    .btn-edit {
        background-color: #4CAF50;
        color: white;
    }
    
    .btn-edit:hover {
        background-color: #45a049;
    }
    
    .btn-delete {
        background-color: #f44336;
        color: white;
    }
    
    .btn-delete:hover {
        background-color: #da190b;
    }
    
    .admin-actions {
        display: flex;
        gap: 6px;
        flex-wrap: wrap;
    }
    
    /* Show full text on desktop, icons on mobile */
    .btn-text-short {
        display: none;
    }
    
    @media (max-width: 768px) {
        .btn-text-full {
            display: none;
        }
        
        .btn-text-short {
            display: inline;
        }
        
        .btn-compact {
            padding: 8px;
            min-width: 36px;
            font-size: 16px;
        }
    }
    
    #scores-form {
        padding: 16px !important;
    }
    
    #scores-form > div[style*="flex"] {
        flex-direction: column !important;
    }
    
    #scores-form button {
        width: 100% !important;
        min-width: 0 !important;
    }
    
    /* Admin page responsive */
    .admin-form {
        padding: 16px !important;
    }
    
    .admin-form > div[style*="flex"] {
        flex-direction: column !important;
    }
    
    .admin-form button {
        width: 100% !important;
        min-width: 0 !important;
    }
    
    .admin-actions button {
        padding: 5px 8px;
        font-size: 13px;
        margin-right: 4px;
    }
}

@media (max-width: 768px) {
    header {
        padding: 0 60px 0 90px;
        min-height: 60px;
        height: 12vh; /* Slightly taller on mobile for better visibility */
        background-size: cover;
        background-position: center center;
    }
    
    .site-logo img {
        height: 80%;
    }
    
    .nav-toggle {
        display: block;
        position: absolute;
        right: 16px;
        top: 50%;
        transform: translateY(-50%);
        z-index: 15;
    }
    
    .nav-overlay {
        display: block;
    }
    
    nav {
        position: fixed;
        top: 10vh;
        right: -100%;
        width: 250px;
        height: calc(100vh - 10vh);
        background-color: #4CAF50;
        flex-direction: column;
        align-items: flex-start;
        gap: 0;
        padding: 20px 0;
        box-shadow: -2px 0 8px rgba(0, 0, 0, 0.2);
        transition: right 0.3s ease-in-out;
        overflow-y: auto;
    }
    
    nav.active {
        right: 0;
    }
    
    nav a {
        width: 100%;
        padding: 14px 20px;
        border-radius: 0;
        font-size: 16px;
    }
    
    nav a:hover {
        background-color: rgba(255, 255, 255, 0.15);
    }
    
    #nav-username {
        width: 100%;
        padding: 14px 20px;
        border-top: 1px solid rgba(255, 255, 255, 0.2);
        margin-top: 8px;
        padding-top: 16px;
    }
    
    #nav-logout {
        border-bottom: 1px solid rgba(255, 255, 255, 0.2);
        padding-bottom: 16px;
        margin-bottom: 8px;
    }
}

@media (max-width: 480px) {
    header {
        padding: 0 50px 0 70px;
        min-height: 60px;
        height: 12vh;
        background-size: cover;
        background-position: center center;
    }
    
    .site-logo {
        left: 5px;
    }
    
    .site-logo img {
        height: 70%;
    }
    
    nav {
        width: 220px;
    }
    
    main {
        padding: 12px;
    }
    
    form {
        max-width: 100%;
        padding: 0 8px;
    }
    
    section h2 {
        font-size: 1.3rem;
    }
    
    .chat-messages {
        height: 240px;
        padding: 6px;
        font-size: 14px;
    }
    
    .chat-form {
        flex-direction: column;
        gap: 8px;
    }
    
    .chat-form input[type="text"] {
        width: 100%;
    }
    
    .chat-form button {
        width: 100%;
        padding: 12px;
    }
    
    #profile-form {
        padding: 12px !important;
        box-shadow: none !important;
    }
    
    .icon-grid {
        grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
        gap: 6px;
    }
    
    .icon-tile {
        padding: 6px;
        min-height: 48px;
    }
    
    .icon-emoji {
        font-size: 22px;
    }
    
    fieldset {
        padding: 12px !important;
    }
    
    .admin-table {
        font-size: 14px;
    }
    
    select {
        padding: 8px;
        font-size: 15px;
    }
    
    /* Make scorecard inputs smaller on mobile */
    #scorecard-table input[type=\"number\"],
    #net-scorecard-table input[type=\"number\"] {
        width: 35px;
        padding: 4px 2px;
        font-size: 14px;
    }
    
    #scorecard-table,
    #net-scorecard-table {
        font-size: 13px;
    }
    
    #scorecard-table th,
    #scorecard-table td,
    #net-scorecard-table th,
    #net-scorecard-table td {
        padding: 4px 2px !important;
    }
    
    #match-form {
        padding: 16px !important;
        box-shadow: none !important;
    }
    
    #match-role {
        display: block !important;
        margin-left: 0 !important;
        margin-top: 8px !important;
        font-size: 14px;
    }
    
    /* Admin forms and tables */
    .admin-form {
        padding: 12px !important;
        box-shadow: none !important;
    }
    
    .admin-table {
        font-size: 13px;
    }
    
    .admin-table th,
    .admin-table td {
        padding: 6px 4px !important;
    }
    
    .admin-actions button {
        padding: 4px 6px;
        font-size: 12px;
        margin-right: 3px;
        margin-bottom: 3px;
    }
    
    /* Stack table on very small screens for better readability */
    .admin-table.responsive {
        border: 0;
    }
    
    .admin-table.responsive thead {
        display: none;
    }
    
    .admin-table.responsive tr {
        display: block;
        margin-bottom: 16px;
        border: 1px solid #ddd;
        border-radius: 4px;
        background-color: white;
    }
    
    .admin-table.responsive td {
        display: flex;
        justify-content: space-between;
        padding: 10px;
        border: none;
        border-bottom: 1px solid #f0f0f0;
    }
    
    .admin-table.responsive td:last-child {
        border-bottom: none;
    }
    
    .admin-table.responsive td:before {
        content: attr(data-label);
        font-weight: 600;
        color: #666;
    }
    
    /* Allow horizontal scroll for large tables on small screens */
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Very small screens */
@media (max-width: 360px) {
    header {
        padding: 0 45px 0 60px;
    }
    
    .site-logo img {
        height: 60%;
    }
    
    nav {
        width: 200px;
    }
    
    input, button {
        padding: 8px;
        font-size: 15px;
    }
    
    section h2 {
        font-size: 1.2rem;
    }
    
    .chat-msg {
        padding: 8px;
        font-size: 13px;
    }
    
    .chat-meta {
        font-size: 11px;
    }
    
    .icon-grid {
        grid-template-columns: repeat(auto-fill, minmax(45px, 1fr));
    }
    
    #scorecard-table input[type=\"number\"],
    #net-scorecard-table input[type=\"number\"] {
        width: 32px;
        padding: 3px 1px;
        font-size: 13px;
    }
    
    #scorecard-table,
    #net-scorecard-table {
        font-size: 12px;
    }
    
    #scores-form h3 {
        font-size: 1.1rem;
    }
    
    .admin-actions button {
        display: block;
        width: 100%;
        margin-right: 0;
        margin-bottom: 4px;
    }
}

/* Login page specific styles */
@media (max-width: 480px) {
    #login {
        margin: 20px auto !important;
        padding: 16px !important;
        border-radius: 4px !important;
    }
    
    #login h2 {
        font-size: 1.5rem !important;
    }
}

/* Profile icon grid */
.icon-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); 
    gap: 10px; 
    max-width: 100%;
    margin: 8px 0 12px;
}
.icon-tile { 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    padding: 10px; 
    border: 2px solid #e0e0e0; 
    border-radius: 8px; 
    background: #fff; 
    cursor: pointer; 
    user-select: none;
    transition: all 0.2s;
    min-height: 60px;
}
.icon-tile:hover { 
    border-color: #4CAF50;
    transform: scale(1.05);
}
.icon-tile input[type="radio"] { 
    display: none; 
}
.icon-emoji { 
    font-size: 28px; 
    line-height: 1;
}
.icon-tile.selected { 
    outline: 3px solid #4CAF50; 
    outline-offset: 1px;
    border-color: #4CAF50;
    background-color: #f0f8f0;
}

/* Small helper note for form fields */
.form-note { font-size: 12px; color: #666; margin-top: -6px; margin-bottom: 8px; }

/* Match result cards */
.match-result-card {
    transition: transform 0.2s, box-shadow 0.2s;
}

.match-result-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15) !important;
}

.match-teams {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

@media (max-width: 768px) {
    .match-teams {
        flex-direction: column !important;
        gap: 12px !important;
    }
    
    .match-teams > div {
        text-align: center !important;
        width: 100%;
    }
    
    .match-teams > div:first-child,
    .match-teams > div:last-child {
        min-width: 100% !important;
    }
}

@media (max-width: 480px) {
    .match-result-card > div:first-child {
        flex-direction: column !important;
        align-items: flex-start !important;
    }
    
    .match-result-card h3 {
        font-size: 1.1rem;
    }
}