:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-900: #111827;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.5;
    color: var(--gray-900);
    background: var(--gray-50);
}

.navbar {
    background: var(--gray-900);
    color: white;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.navbar .brand {
    font-size: 1.25rem;
    font-weight: bold;
    color: white;
    text-decoration: none;
}

.nav-links {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

.nav-links a {
    color: var(--gray-300);
    text-decoration: none;
}

.nav-links a:hover {
    color: white;
}

.admin-badge {
    background: var(--primary);
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.875rem;
    color: white;
    text-decoration: none;
    cursor: pointer;
}

.admin-badge:hover {
    background: var(--primary-dark);
}

.admin-link {
    font-size: 0.875rem;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

h1 {
    margin-bottom: 1.5rem;
}

h2 {
    margin: 2rem 0 1rem;
}

/* Stats */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: white;
    padding: 1.5rem;
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.stat-card h3 {
    color: var(--gray-500);
    font-size: 0.875rem;
    font-weight: normal;
}

.stat-value {
    font-size: 2rem;
    font-weight: bold;
}

/* Forms */
.add-form {
    background: white;
    padding: 1.5rem;
    border-radius: 0.5rem;
    margin-bottom: 2rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.add-form h3 {
    margin-bottom: 1rem;
}

.form-row {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 500;
}

input[type="text"],
input[type="date"],
select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: 0.375rem;
    font-size: 1rem;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    background: var(--gray-200);
    border: none;
    border-radius: 0.375rem;
    font-size: 1rem;
    cursor: pointer;
    text-decoration: none;
    color: var(--gray-700);
}

.btn:hover {
    background: var(--gray-300);
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #b91c1c;
}

.btn-small {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
}

.btn-large {
    padding: 0.75rem 1.5rem;
    font-size: 1.125rem;
}

/* Spinner */
.spinner {
    display: none;
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--gray-300);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.htmx-request .spinner,
.htmx-request.spinner {
    display: inline-block;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Tables */
.data-table {
    width: 100%;
    background: white;
    border-collapse: collapse;
    border-radius: 0.5rem;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.data-table th,
.data-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
}

.data-table th {
    background: var(--gray-100);
    font-weight: 600;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr.inactive {
    opacity: 0.5;
}

/* Sortable headers */
.sort-header {
    color: inherit;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.sort-header:hover {
    color: var(--primary);
}

.data-table.sortable th {
    cursor: pointer;
}

.actions {
    display: flex;
    gap: 0.5rem;
}

/* Mode info box */
.mode-info {
    background: var(--gray-100);
    border-radius: 0.375rem;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.mode-info summary {
    cursor: pointer;
    font-weight: 500;
    color: var(--gray-700);
}

.mode-info-content {
    margin-top: 0.75rem;
    color: var(--gray-700);
}

.mode-info-content p {
    margin: 0.5rem 0;
}

.mode-info-content hr {
    border: none;
    border-top: 1px solid var(--gray-300);
    margin: 0.75rem 0;
}

/* Warnings */
.warnings {
    background: #fef3c7;
    border: 1px solid #f59e0b;
    border-radius: 0.375rem;
    padding: 1rem;
    margin-bottom: 1rem;
}

.warnings ul {
    margin: 0.5rem 0 0 1.5rem;
    padding: 0;
}

.warnings li {
    margin: 0.25rem 0;
}

/* Tags */
.tag {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    background: var(--gray-200);
    border-radius: 1rem;
    font-size: 0.75rem;
}

.tag.inactive {
    background: var(--danger);
    color: white;
}

/* Session list */
.session-list {
    list-style: none;
}

.session-list li {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--gray-200);
}

.session-list a {
    color: var(--primary);
    text-decoration: none;
}

.session-list a:hover {
    text-decoration: underline;
}

/* Attendance */
.attendance-section {
    background: white;
    padding: 1.5rem;
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.player-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.player-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background: var(--gray-100);
    border-radius: 0.375rem;
    cursor: pointer;
}

.player-checkbox:hover {
    background: var(--gray-200);
}

.player-checkbox.replacement {
    background: #fef3c7;
}

.generate-section {
    background: white;
    padding: 1.5rem;
    border-radius: 0.5rem;
    margin-bottom: 2rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.generate-section h2 {
    margin-top: 0;
    margin-bottom: 1rem;
}

.slot-config {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.slot-row {
    display: grid;
    grid-template-columns: 4rem minmax(180px, 1fr) minmax(180px, 1fr);
    align-items: center;
    gap: 0.5rem;
}

.slot-time {
    font-weight: bold;
    font-size: 1.1rem;
}

.slot-row select {
    width: 100%;
}

.slot-opt {
    min-height: 2.5rem;
    display: flex;
    align-items: center;
}

.slot-opt select {
    width: 100%;
}

.slot-opt .checkbox-label {
    padding: 0.5rem 0.75rem;
    background: white;
    border: 1px solid var(--gray-300);
    border-radius: 0.375rem;
    width: 100%;
    height: 2.5rem;
    display: flex;
    align-items: center;
}

.avoid-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 1rem 0;
    padding: 1rem;
    background: var(--gray-100);
    border-radius: 0.375rem;
}

.avoid-options .checkbox-label {
    font-size: 0.9rem;
}

.spread-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.spread-option label {
    font-size: 0.9rem;
    white-space: nowrap;
    width: 250px;
}

.spread-option select {
    flex: 1;
    max-width: 280px;
}

/* Locked sessions */
.locked {
    opacity: 0.6;
}

.locked fieldset {
    border: none;
    padding: 0;
    margin: 0;
}

/* Courts */
.courts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 1.5rem;
}

.court-card {
    background: white;
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    overflow: hidden;
}

.court-card h3 {
    background: var(--primary);
    color: white;
    padding: 0.75rem 1rem;
}

.match {
    padding: 1rem;
    border-bottom: 1px solid var(--gray-200);
}

.match:last-child {
    border-bottom: none;
}

.match-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.match-time {
    font-size: 1rem;
    font-weight: bold;
    color: var(--primary);
}

.match-type {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
}

.teams {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.team {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.vs {
    color: var(--gray-500);
    font-weight: bold;
}

.no-matchups {
    color: var(--gray-500);
    font-style: italic;
}

/* Quick actions */
.quick-actions {
    margin-top: 2rem;
}

.quick-actions .btn {
    margin-right: 0.5rem;
}

/* Dialog */
dialog {
    border: none;
    border-radius: 0.5rem;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
    padding: 1.5rem;
    max-width: 400px;
}

dialog::backdrop {
    background: rgba(0,0,0,0.5);
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.5rem;
}

/* Print styles */
@media print {
    @page {
        size: landscape;
        margin: 1cm;
    }

    .navbar,
    .attendance-section,
    .generate-section,
    .print-section,
    .btn,
    .match-type,
    .player-rating {
        display: none !important;
    }

    body {
        font-size: 12pt;
    }

    .container {
        padding: 0;
        max-width: 100%;
    }

    h1 {
        font-size: 16pt;
        margin-bottom: 0.5rem;
    }

    h2 {
        font-size: 14pt;
        margin: 0.5rem 0;
    }

    .courts-grid {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr);
        gap: 0.75rem;
    }

    .court-card {
        break-inside: avoid;
        margin-bottom: 0;
        box-shadow: none;
        border: 2px solid #000;
    }

    .court-card h3 {
        padding: 0.4rem 0.6rem;
        font-size: 12pt;
        background: #000 !important;
        color: #fff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .match {
        padding: 0.75rem 0.6rem;
    }

    .match-header {
        margin-bottom: 0.5rem;
    }

    .match-time {
        font-size: 20pt;
        font-weight: bold;
    }

    .teams {
        gap: 0.75rem;
    }

    .team {
        gap: 0.25rem;
        font-size: 18pt;
        white-space: nowrap;
    }

    .vs {
        font-size: 15pt;
    }

    /* Page break after first 3 courts */
    .court-card:nth-child(3) {
        break-after: page;
    }
}

/* Portrait print (mobile) - smaller fonts to fit */
@media print and (orientation: portrait) {
    .courts-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .match-time {
        font-size: 12pt;
    }

    .team {
        font-size: 10pt;
        white-space: nowrap;
    }

    .vs {
        font-size: 9pt;
    }

    .match {
        padding: 0.4rem;
    }

    .court-card h3 {
        font-size: 10pt;
        padding: 0.3rem 0.5rem;
    }

    /* 3 pages: 2+2+2 courts */
    .court-card:nth-child(2) {
        break-after: page;
    }
    .court-card:nth-child(4) {
        break-after: page;
    }
    .court-card:nth-child(3) {
        break-after: auto;
    }
}

/* Responsive */
@media (max-width: 768px) {
    .navbar {
        flex-direction: column;
        gap: 1rem;
    }

    .form-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .form-row input:not([type="checkbox"]),
    .form-row select,
    .form-row .btn,
    .form-row .checkbox-label {
        width: 100%;
        flex: 0 0 100%;
    }

    .form-row .checkbox-label {
        display: block;
        text-align: left;
    }
}
