* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    min-height: 100dvh;
    color: #333;
    overflow-x: hidden;
    font-size: 1rem;
}

.mobile-container {
    width: 100%;
    max-width: min(480px, 100vw);
    margin: 0 auto;
    padding: min(15px, 3vw);
    min-height: 100vh;
    min-height: 100dvh;
}

.page {
    display: none;
    animation: slideIn 0.3s ease;
}

.page.active {
    display: block;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

h1 {
    color: white;
    text-align: center;
    font-size: clamp(1.5rem, 5vw, 1.8rem);
    margin-bottom: clamp(15px, 4vw, 20px);
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}

h2 {
    color: #2d3748;
    font-size: clamp(1.1rem, 3.5vw, 1.3rem);
}

.calendar-container {
    background: white;
    border-radius: clamp(12px, 3vw, 15px);
    padding: clamp(15px, 4vw, 20px);
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    width: 100%;
}

.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: clamp(15px, 4vw, 20px);
    gap: 10px;
}

#currentMonth {
    font-size: clamp(1rem, 3vw, 1.1rem);
    font-weight: 600;
    color: #4a5568;
    text-align: center;
    flex: 1;
}

.nav-btn {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    width: clamp(32px, 8vw, 36px);
    height: clamp(32px, 8vw, 36px);
    border-radius: 50%;
    cursor: pointer;
    font-size: clamp(0.9rem, 2.5vw, 1rem);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    flex-shrink: 0;
}

.nav-btn:active {
    transform: scale(0.95);
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 5px;
}

.calendar-day-header {
    text-align: center;
    font-weight: 600;
    color: #718096;
    padding: 8px 0;
    font-size: 0.8rem;
}

.calendar-day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f7fafc;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
}

.calendar-day:active {
    transform: scale(0.95);
}

.calendar-day.other-month {
    color: #cbd5e0;
    background: #fafafa;
}

.calendar-day.has-schedule {
    background: linear-gradient(135deg, #84fab0 0%, #8fd3f4 100%);
    color: white;
    font-weight: 600;
}

.calendar-day.selected {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    box-shadow: 0 4px 10px rgba(102, 126, 234, 0.3);
}

.page-header {
    background: white;
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.back-btn {
    background: #f0f4ff;
    color: #667eea;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.back-btn:active {
    transform: scale(0.95);
}

.date-display {
    font-size: 0.9rem;
    color: #718096;
}

.time-select {
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    background: white;
    font-size: 0.85rem;
    color: #4a5568;
}

.player-controls, .schedule-controls {
    background: white;
    border-radius: 12px;
    padding: clamp(12px, 3vw, 15px);
    margin-bottom: 15px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    display: flex;
    flex-wrap: wrap;
    gap: clamp(8px, 2vw, 10px);
    align-items: center;
}

.schedule-controls {
    justify-content: space-between;
}

@media (max-width: 360px) {
    .schedule-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .schedule-controls button {
        width: 100%;
    }
    
    .player-count {
        margin-top: 8px;
        text-align: center;
    }
}

.primary-btn {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    padding: clamp(8px, 2vw, 10px) clamp(15px, 4vw, 20px);
    border-radius: 8px;
    font-weight: 600;
    font-size: clamp(0.85rem, 2.5vw, 0.9rem);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.primary-btn:active {
    transform: scale(0.95);
}

.warning-btn {
    background: linear-gradient(135deg, #f093fb, #f5576c);
    color: white;
    border: none;
    padding: clamp(8px, 2vw, 10px) clamp(15px, 4vw, 20px);
    border-radius: 8px;
    font-weight: 600;
    font-size: clamp(0.85rem, 2.5vw, 0.9rem);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.warning-btn:active {
    transform: scale(0.95);
}

.clear-all-btn {
    background: #ef4444;
    color: white;
    border: none;
    padding: clamp(8px, 2vw, 10px) clamp(15px, 4vw, 20px);
    border-radius: 8px;
    font-weight: 600;
    font-size: clamp(0.85rem, 2.5vw, 0.9rem);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.clear-all-btn:active {
    transform: scale(0.95);
}

.player-count {
    margin-left: auto;
    font-size: 0.85rem;
    color: #718096;
}

.player-list {
    background: white;
    border-radius: 12px;
    padding: 10px;
    margin-bottom: 15px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    max-height: 400px;
    overflow-y: auto;
}

.player-item {
    padding: 12px;
    border-bottom: 1px solid #f1f5f9;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.player-item:last-child {
    border-bottom: none;
}

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

.player-info {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.info-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-high {
    background: #fef3c7;
    color: #92400e;
}

.badge-medium {
    background: #dbeafe;
    color: #1e40af;
}

.badge-low {
    background: #d1fae5;
    color: #065f46;
}

.badge-paid {
    background: #d1fae5;
    color: #065f46;
}

.badge-unpaid {
    background: #fee2e2;
    color: #991b1b;
}

.player-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.edit-btn, .delete-btn {
    padding: 6px 12px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    flex: 1;
}

.edit-btn {
    background: #e0e7ff;
    color: #4338ca;
}

.delete-btn {
    background: #fee2e2;
    color: #dc2626;
}

.navigation-bar {
    position: sticky;
    bottom: 0;
    background: white;
    padding: 15px;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -4px 10px rgba(0,0,0,0.1);
    margin: 0 -15px;
}

.nav-button {
    width: 100%;
    background: linear-gradient(135deg, #84fab0, #8fd3f4);
    color: white;
    border: none;
    padding: 14px;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.nav-button:active {
    transform: scale(0.98);
}

.schedule-wrapper {
    background: white;
    border-radius: 12px;
    padding: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
}

.schedule-table {
    width: max-content;
    min-width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.schedule-table thead tr {
    background: linear-gradient(135deg, #667eea, #764ba2);
}

.schedule-table thead th {
    color: white;
    padding: clamp(8px, 2vw, 10px) clamp(6px, 1.5vw, 8px);
    text-align: center;
    font-weight: 600;
    font-size: clamp(0.7rem, 2vw, 0.8rem);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 10;
    min-width: 40px;
}

.schedule-table thead th:first-child {
    text-align: left;
    padding-left: clamp(10px, 2.5vw, 12px);
    padding-right: clamp(10px, 2.5vw, 12px);
    border-radius: 8px 0 0 0;
    min-width: 90px;
    position: sticky;
    left: 0;
    z-index: 20;
}

.schedule-table thead th:last-child {
    border-radius: 0 8px 0 0;
}

.schedule-table tbody tr {
    transition: background-color 0.15s ease;
}

.schedule-table tbody td {
    padding: clamp(6px, 1.5vw, 8px);
    text-align: center;
    border-bottom: 1px solid #f1f5f9;
    font-size: clamp(0.75rem, 2vw, 0.85rem);
    background: white;
}

.schedule-table tbody td:first-child {
    text-align: left;
    font-weight: 600;
    color: #4a5568;
    background: white;
    position: sticky;
    left: 0;
    z-index: 5;
    white-space: nowrap;
    padding-left: clamp(10px, 2.5vw, 12px);
    padding-right: clamp(10px, 2.5vw, 12px);
    min-width: 90px;
    border-right: 2px solid #e2e8f0;
}

.court-cell {
    padding: clamp(6px, 1.5vw, 8px);
    min-width: 40px;
    min-height: 32px;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 6px;
    font-weight: 600;
    font-size: clamp(0.9rem, 2.5vw, 1rem);
    position: relative;
    user-select: none;
}

.court-cell:active {
    transform: scale(0.95);
}

.court-cell.assigned-1 {
    background: #fef3c7;
    color: #92400e;
}

.court-cell.assigned-2 {
    background: #fed7aa;
    color: #c2410c;
    border: 2px solid #fb923c;
}

.court-cell.assigned-3 {
    background: #bfdbfe;
    color: #1e40af;
    border: 2px solid #60a5fa;
}

.court-cell.assigned-4 {
    background: #a7f3d0;
    color: #065f46;
    border: 2px solid #34d399;
}

.court-cell.assigned-5 {
    background: #e9d5ff;
    color: #6b21a8;
}

.court-cell.rest {
    color: #cbd5e0;
    font-weight: normal;
}

.court-cell.locked {
    position: relative;
}

.court-cell.locked::after {
    content: '🔒';
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 0.6rem;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    animation: fadeIn 0.2s ease;
}

.modal.active {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: white;
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
    animation: slideUp 0.3s ease;
}

.modal-content.compact {
    max-width: 320px;
}

@keyframes slideUp {
    from { transform: translateY(50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    padding: 18px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    color: #2d3748;
    font-size: 1.1rem;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #718096;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-body {
    padding: 18px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: #4a5568;
    font-size: 0.9rem;
}

.form-group input, .form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.95rem;
    transition: all 0.2s;
    background: white;
}

.form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.modal-footer {
    padding: 15px 18px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 10px;
}

.save-btn, .cancel-btn {
    flex: 1;
    padding: 10px;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.save-btn {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
}

.cancel-btn {
    background: #f7fafc;
    color: #4a5568;
}

.court-buttons {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 20px;
}

.court-btn {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    border: 2px solid #e2e8f0;
    background: white;
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    color: #4a5568;
}

.court-btn:active {
    transform: scale(0.9);
}

.court-btn.priority {
    border-color: #fb923c;
    background: #fff7ed;
}

.court-btn.selected {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border-color: #667eea;
}

.action-buttons {
    display: flex;
    gap: 10px;
}

.clear-btn, .auto-btn {
    flex: 1;
    padding: 10px;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.clear-btn {
    background: #fee2e2;
    color: #dc2626;
}

.auto-btn {
    background: linear-gradient(135deg, #84fab0, #8fd3f4);
    color: white;
}

@media (max-width: 390px) {
    html {
        font-size: 14px;
    }
    
    .mobile-container {
        padding: 10px;
    }
    
    .calendar-grid {
        gap: 3px;
    }
    
    .calendar-day {
        font-size: 0.8rem;
    }
}

@media (min-width: 481px) {
    .mobile-container {
        border-radius: 20px;
        margin-top: 20px;
        margin-bottom: 20px;
        box-shadow: 0 20px 40px rgba(0,0,0,0.15);
        background: rgba(255, 255, 255, 0.05);
    }
}

@media (max-height: 600px) and (orientation: landscape) {
    .mobile-container {
        max-width: 100%;
        padding: 10px 20px;
    }
    
    h1 {
        font-size: 1.3rem;
        margin-bottom: 10px;
    }
    
    .page-header {
        padding: 10px;
        margin-bottom: 10px;
    }
    
    .navigation-bar {
        padding: 10px;
    }
}

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .court-cell {
        font-weight: 500;
    }
}

.player-name-cell {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.payment-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: linear-gradient(135deg, #60a5fa 0%, #3b82f6 100%);
    box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.2);
    flex-shrink: 0;
}
