/* ============================================================================
   TOURNAMENT MANAGER - MASTER STYLESHEET
   ============================================================================ */

/* TABLE OF CONTENTS:
   1. CSS Custom Properties (Variables)
   2. Base Styles & Layout
   3. Typography
   4. Forms & Inputs
   5. Buttons
   6. Cards & Containers
   7. Tables
   8. Navigation
   9. Badges & Status Indicators
   10. Modals & Overlays
   11. Tournament-Specific Components
   12. Admin & User Management
   13. Authentication
   14. Utility Classes
   15. Animations & Transitions
   16. Media Queries (Mobile-First)
   17. Accessibility & Print Styles
   ============================================================================ */

/* ============================================================================
   1. CSS CUSTOM PROPERTIES (VARIABLES)
   ============================================================================ */
:root {
    /* Color Palette */
    --primary-color: #0d6efd;
    --secondary-color: #6c757d;
    --success-color: #198754;
    --warning-color: #ffc107;
    --danger-color: #dc3545;
    --info-color: #0dcaf0;

    /* Grays */
    --gray-50: #f8f9fa;
    --gray-100: #e9ecef;
    --gray-200: #dee2e6;
    --gray-300: #ced4da;
    --gray-600: #6c757d;
    --gray-900: #212529;

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-xxl: 3rem;

    /* Border radius */
    --border-radius-sm: 0.25rem;
    --border-radius: 0.375rem;
    --border-radius-lg: 0.5rem;
    --border-radius-xl: 1rem;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-base: 0.2s ease;
    --transition-slow: 0.3s ease;

    /* Z-index scale */
    --z-dropdown: 1000;
    --z-sticky: 1020;
    --z-fixed: 1030;
    --z-modal-backdrop: 1040;
    --z-modal: 1050;
    --z-popover: 1060;
    --z-tooltip: 1070;
}

/* ============================================================================
   2. BASE STYLES & LAYOUT
   ============================================================================ */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--gray-50);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    line-height: 1.6;
    color: var(--gray-900);
}

/* Layout containers */
.content-container {
    padding: var(--spacing-lg);
    max-width: 1200px;
    margin: 0 auto;
}

.content-container.narrow {
    max-width: 800px;
}

.content-container.wide {
    max-width: 1400px;
}

/* ============================================================================
   3. TYPOGRAPHY
   ============================================================================ */
.logo-text {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.logo-text.large {
    font-size: 1.75rem;
    margin-bottom: var(--spacing-lg);
}

.page-header {
    margin-bottom: var(--spacing-xl);
    padding-bottom: var(--spacing-md);
    border-bottom: 1px solid var(--gray-200);
}

.section-header {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: var(--spacing-md);
    padding-bottom: var(--spacing-xs);
    border-bottom: 1px solid var(--gray-100);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

/* ============================================================================
   4. FORMS & INPUTS
   ============================================================================ */
.form-group {
    margin-bottom: var(--spacing-lg);
}

.form-floating {
    margin-bottom: var(--spacing-lg);
}

.form-label {
    font-weight: 500;
    margin-bottom: var(--spacing-xs);
}

.form-text.required,
.form-text.tournament-required {
    color: var(--danger-color);
    font-weight: 500;
}

.form-card {
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    background-color: white;
    margin-bottom: var(--spacing-lg);
    transition: box-shadow var(--transition-slow);
    border: 1px solid var(--gray-100);
}

.form-card:hover {
    box-shadow: var(--shadow-lg);
}

.form-card .card-header {
    background-color: rgba(13, 110, 253, 0.05);
    font-weight: 600;
    border-bottom: 1px solid var(--gray-100);
}

/* Form validation states */
.validation-error {
    border-color: var(--danger-color) !important;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25) !important;
}

.validation-success {
    border-color: var(--success-color) !important;
    box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25) !important;
}

/* ============================================================================
   5. BUTTONS
   ============================================================================ */
.btn {
    border-radius: var(--border-radius);
    font-weight: 500;
    transition: all var(--transition-base);
}

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

.btn-primary:hover {
    background-color: #0b5ed7;
    border-color: #0a58ca;
}

.btn-outline-primary:hover {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-success {
    background-color: var(--success-color);
    border-color: var(--success-color);
}

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

.btn-warning {
    background-color: var(--warning-color);
    border-color: var(--warning-color);
    color: #000;
}

.btn-info {
    background-color: var(--info-color);
    border-color: var(--info-color);
    color: #000;
}

.btn-secondary {
    background-color: var(--secondary-color);
    border-color: var(--secondary-color);
}

/* ============================================================================
   6. CARDS & CONTAINERS
   ============================================================================ */
.card {
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
    transition: box-shadow var(--transition-base);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    background-color: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    font-weight: 600;
}

.dashboard-card {
    cursor: pointer;
    transition: all var(--transition-base);
    border: 2px solid transparent;
}

.dashboard-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
}

.dashboard-icon {
    font-size: 3rem;
    color: var(--primary-color);
}

.dashboard-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: var(--spacing-sm);
}

.dashboard-description {
    color: var(--gray-600);
    margin-bottom: var(--spacing-md);
}

.dashboard-stats {
    font-size: 0.9rem;
}

/* ============================================================================
   7. TABLES
   ============================================================================ */
.table {
    margin-bottom: 0;
}

.table th {
    font-weight: 600;
    border-bottom: 2px solid var(--gray-200);
    color: var(--gray-900);
}

.table td {
    vertical-align: middle;
}

.table-striped > tbody > tr:nth-of-type(odd) > td {
    background-color: rgba(0, 0, 0, 0.025);
}

.table-hover > tbody > tr:hover > td {
    background-color: rgba(13, 110, 253, 0.075);
}

/* ============================================================================
   8. NAVIGATION
   ============================================================================ */
.dropdown-menu .dropdown-item {
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.dropdown-menu .dropdown-item i.bi {
    width: 1.2em;
    text-align: center;
    flex-shrink: 0;
}

.dropdown-toggle.d-flex.align-items-center span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

/* ============================================================================
   9. BADGES & STATUS INDICATORS
   ============================================================================ */
.badge {
    font-weight: 500;
    border-radius: var(--border-radius-sm);
}

.badge-mine {
    background-color: var(--info-color);
    color: white;
}

.badge-role {
    font-size: 0.8rem;
    padding: 0.3rem 0.6rem;
}

.badge-count {
    background-color: var(--gray-600);
    color: white;
    font-size: 0.8rem;
    padding: 3px 6px;
    border-radius: 10px;
    margin-left: 5px;
}

/* Tournament status badges */
.tournament-status {
    font-size: 0.85em;
}

.creator-badge {
    background-color: #e7f3ff;
    color: #0066cc;
}

.public-badge {
    background-color: #e8f5e8;
    color: #006600;
}

.private-badge {
    background-color: #fff3cd;
    color: #856404;
}

.registration-open {
    background-color: #d4edda;
    color: #155724;
}

.registration-closed {
    background-color: #f8d7da;
    color: #721c24;
}

/* ============================================================================
   10. MODALS & OVERLAYS
   ============================================================================ */
.modal-content {
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
}

.modal-header {
    border-bottom: 1px solid var(--gray-200);
}

.modal-footer {
    border-top: 1px solid var(--gray-200);
}

/* Search results styling */
#email-search-results {
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    position: relative;
    z-index: 1000;
}

#email-search-results .list-group-item:hover:not(.disabled) {
    background-color: #f8f9fa;
}

#email-search-results .list-group-item.disabled {
    opacity: 0.6;
}

#team-email-search-results {
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    position: relative;
    z-index: 1000;
}

#team-email-search-results .list-group-item:hover:not(.disabled) {
    background-color: #f8f9fa;
}

#team-email-search-results .list-group-item.disabled {
    opacity: 0.6;
}

/* Army list text display */
.army-list-text {
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
    line-height: 1.4;
    max-height: 400px;
    overflow-y: auto;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    padding: 1rem;
    margin: 0;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Button group styling for army list actions */
.btn-group .btn {
    border-radius: 0.375rem;
}

.btn-group .btn:not(:last-child) {
    margin-right: 0.25rem;
}

/* Modal enhancements */
#viewUserArmyListModal .modal-dialog {
    max-width: 800px;
}

#viewUserArmyListModal .card {
    border: 1px solid #dee2e6;
}

#viewUserArmyListModal .input-group .form-control {
    font-family: monospace;
    font-size: 0.875rem;
}


/* ============================================================================
   11. TOURNAMENT-SPECIFIC COMPONENTS
   ============================================================================ */
.tournament-card {
    border-radius: var(--border-radius-lg);
    transition: all var(--transition-base);
    border: 1px solid var(--gray-200);
}

.tournament-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.tournament-code {
    font-family: 'Courier New', monospace;
    font-weight: bold;
    background-color: var(--gray-100);
    padding: 0.25rem 0.5rem;
    border-radius: var(--border-radius-sm);
}

/* Army List Management Styles */
.army-list-management-card {
    border-left: 4px solid var(--primary-color);
}

.army-list-management-card.deadline-status-overdue {
    border-left-color: var(--danger-color);
}

.army-list-management-card.deadline-status-urgent {
    border-left-color: var(--warning-color);
}

.army-list-management-card.deadline-status-upcoming {
    border-left-color: var(--info-color);
}

.army-list-management-card.deadline-status-future {
    border-left-color: var(--secondary-color);
}

.list-deadline-card {
    border-radius: var(--border-radius);
    margin: 0.75rem;
    transition: all 0.2s ease;
}

.list-deadline-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transform: translateY(-1px);
}

.deadline-status-overdue {
    border-left: 4px solid var(--danger-color);
}

.deadline-status-urgent {
    border-left: 4px solid #fd7e14;
}

.deadline-status-upcoming {
    border-left: 4px solid var(--warning-color);
}

.deadline-status-future {
    border-left: 4px solid #20c997;
}

.list-status-submitted {
    color: var(--success-color);
}

.list-status-pending {
    color: var(--danger-color);
}

.deadline-badge-overdue {
    background-color: var(--danger-color) !important;
}

.deadline-badge-urgent {
    background-color: #fd7e14 !important;
}

.deadline-badge-upcoming {
    background-color: var(--warning-color) !important;
    color: #000 !important;
}

.deadline-badge-future {
    background-color: #20c997 !important;
}

/* ============================================================================
   12. ADMIN & USER MANAGEMENT
   ============================================================================ */
.admin-header,
.tournament-header {
    background-color: var(--gray-50);
    border-radius: var(--border-radius);
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
    border-left: 4px solid var(--primary-color);
}

.admin-header {
    border-left-color: var(--danger-color);
}

.permission-icon {
    font-size: 2rem;
    margin-right: var(--spacing-md);
    color: var(--primary-color);
}

.admin-warning {
    background: linear-gradient(135deg, var(--danger-color), #b02a37);
    color: white;
    border-radius: var(--border-radius-lg);
    padding: var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
}

.danger-zone {
    border: 2px solid var(--danger-color);
    border-radius: var(--border-radius-lg);
    background-color: #fff5f5;
    padding: var(--spacing-lg);
    margin-top: var(--spacing-xl);
}

.danger-zone h4 {
    color: var(--danger-color);
    font-size: 1.2rem;
    margin-bottom: var(--spacing-md);
}

/* Admin search functionality */
.admin-search-container {
    position: relative;
}

.admin-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: var(--z-dropdown);
    background: white;
    border: 1px solid var(--gray-300);
    border-top: none;
    border-radius: 0 0 var(--border-radius) var(--border-radius);
    box-shadow: var(--shadow-md);
    max-height: 300px;
    overflow-y: auto;
    display: none;
}

.admin-search-results.show {
    display: block;
}

.admin-search-result {
    padding: var(--spacing-sm) var(--spacing-md);
    cursor: pointer;
    border-bottom: 1px solid var(--gray-100);
    transition: background-color var(--transition-fast);
}

.admin-search-result:hover,
.admin-search-result.highlighted {
    background-color: var(--gray-50);
}

.admin-search-result:last-child {
    border-bottom: none;
}

.admin-search-result .result-name {
    font-weight: 500;
    color: var(--gray-900);
}

.admin-search-result .result-email {
    font-size: 0.875rem;
    color: var(--gray-600);
    margin-top: 2px;
}

/* ============================================================================
   13. AUTHENTICATION
   ============================================================================ */
.login-container,
.register-container {
    max-width: 400px;
    margin: 2rem auto;
    padding: 2rem;
    background-color: white;
    border-radius: var(--border-radius-xl);
    box-shadow: var(--shadow-lg);
}

.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-color), #0056b3);
}

.public-access-alert {
    background-color: rgba(13, 202, 240, 0.1);
    border: 1px solid var(--info-color);
    border-radius: var(--border-radius);
}

.password-requirements {
    font-size: 0.875rem;
    color: var(--gray-600);
    margin-top: 0.25rem;
}

.links {
    text-align: center;
    margin-top: var(--spacing-lg);
}

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

.links a:hover {
    text-decoration: underline;
}

/* ============================================================================
   14. UTILITY CLASSES
   ============================================================================ */

/* Display utilities */
.js-hidden {
    display: none !important;
}

.js-visible {
    display: block !important;
}

.js-flex {
    display: flex !important;
}

/* Cursor utilities */
.cursor-pointer {
    cursor: pointer;
}

.cursor-not-allowed {
    cursor: not-allowed;
}

.cursor-wait {
    cursor: wait;
}

/* Loading states */
.loading-state {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

.loading-state::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

/* Spinner containers */
.spinner-container-small {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100px;
}

.spinner-container-medium {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
}

.spinner-container-large {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 300px;
}

/* Empty states */
.empty-state {
    text-align: center;
    padding: var(--spacing-xxl) var(--spacing-md);
    color: var(--gray-600);
}

/* Spacing utilities */
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 1rem; }
.gap-4 { gap: 1.5rem; }

/* State utilities */
.is-loading {
    opacity: 0.6;
    pointer-events: none;
}

.is-disabled {
    opacity: 0.5;
    pointer-events: none;
}

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

/* ============================================================================
   15. ANIMATIONS & TRANSITIONS
   ============================================================================ */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInFromTop {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.fade-in {
    animation: fadeIn 0.3s ease forwards;
}

.slide-in {
    animation: slideInFromTop 0.6s ease-out;
}

.pulse-hover:hover {
    animation: pulse 1s infinite;
}

/* ============================================================================
   16. MEDIA QUERIES (MOBILE-FIRST)
   ============================================================================ */

/* Small devices (landscape phones, 576px and up) */
@media (min-width: 576px) {
    .content-container {
        padding: var(--spacing-xl);
    }
}

/* Medium devices (tablets, 768px and up) */
@media (min-width: 768px) {
    .dashboard-card {
        min-height: 200px;
    }

    .login-container,
    .register-container {
        max-width: 500px;
    }
}

/* Large devices (desktops, 992px and up) */
@media (min-width: 992px) {
    .content-container {
        padding: var(--spacing-xl) var(--spacing-lg);
    }
}

/* Extra large devices (large desktops, 1200px and up) */
@media (min-width: 1200px) {
    .content-container {
        max-width: 1200px;
    }

    .content-container.wide {
        max-width: 1400px;
    }
}

/* Mobile-specific adjustments */
@media (max-width: 767.98px) {
    .dashboard-icon {
        font-size: 2.5rem;
    }

    .dashboard-title {
        font-size: 1.1rem;
    }

    .table-responsive {
        font-size: 0.875rem;
    }

    .btn {
        padding: 0.5rem 1rem;
    }

    .modal-dialog {
        margin: 0.5rem;
    }

    .content-container {
        padding: var(--spacing-md);
    }
}

/* ============================================================================
   17. ACCESSIBILITY & PRINT STYLES
   ============================================================================ */

/* Focus states for accessibility */
.btn:focus,
.form-control:focus,
.form-select:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .card {
        border: 2px solid var(--gray-900);
    }

    .btn {
        border-width: 2px;
    }
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Print styles */
@media print {
    .btn,
    .nav,
    .modal,
    .dropdown {
        display: none !important;
    }

    .card {
        border: 1px solid #000;
        box-shadow: none;
    }

    .table {
        border-collapse: collapse;
    }

    .table th,
    .table td {
        border: 1px solid #000;
    }
}

/* Location Autocomplete Styles */
.location-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: var(--z-dropdown);
    background: white;
    border: 1px solid var(--gray-300);
    border-top: none;
    border-radius: 0 0 var(--border-radius) var(--border-radius);
    box-shadow: var(--shadow-md);
    max-height: 300px;
    overflow-y: auto;
}

.location-suggestion {
    padding: var(--spacing-sm) var(--spacing-md);
    cursor: pointer;
    border-bottom: 1px solid var(--gray-100);
    transition: background-color var(--transition-fast);
}

.location-suggestion:hover,
.location-suggestion.highlighted {
    background-color: var(--gray-50);
}

.location-suggestion:last-child {
    border-bottom: none;
}

.location-suggestion .location-name {
    font-weight: 500;
    color: var(--gray-900);
}

.location-suggestion .location-details {
    font-size: 0.875rem;
    color: var(--gray-600);
    margin-top: 2px;
}

.location-input-container {
    position: relative;
}