/* ====================================
   CSS Variables & Reset
   ==================================== */
:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --success-color: #27ae60;
    --danger-color: #e74c3c;
    --warning-color: #f39c12;
    --light-bg: #ecf0f1;
    --dark-text: #2c3e50;
    --light-text: #7f8c8d;
    --white: #ffffff;
    --border-color: #bdc3c7;
    --shadow: 0 2px 4px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 8px rgba(0,0,0,0.15);
    --transition: all 0.3s ease;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: var(--dark-text);
    background-color: var(--light-bg);
}

/* ====================================
   Container & Layout
   ==================================== */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ====================================
   Header
   ==================================== */
.app-header {
    background-color: var(--primary-color);
    color: var(--white);
    padding: 1rem 0;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.online-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--success-color);
    animation: pulse 2s infinite;
}

.status-indicator.offline {
    background-color: var(--danger-color);
    animation: none;
}

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

/* ====================================
   Navigation
   ==================================== */
.app-nav {
    background-color: var(--white);
    border-bottom: 2px solid var(--border-color);
    position: sticky;
    top: 63px;
    z-index: 99;
}

.nav-menu {
    list-style: none;
    display: flex;
    gap: 0;
    overflow-x: auto;
}

.nav-menu li {
    flex: 1;
    min-width: fit-content;
}

.nav-link {
    display: block;
    padding: 1rem 1.5rem;
    text-decoration: none;
    color: var(--dark-text);
    border-bottom: 3px solid transparent;
    transition: var(--transition);
    text-align: center;
    font-weight: 500;
}

.nav-link:hover {
    background-color: var(--light-bg);
}

.nav-link.active {
    color: var(--secondary-color);
    border-bottom-color: var(--secondary-color);
}

/* ====================================
   Main Content
   ==================================== */
.app-main {
    flex: 1;
    padding: 2rem 0;
}

#page-content {
    background-color: var(--white);
    padding: 2rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    min-height: 400px;
}

/* ====================================
   Footer
   ==================================== */
.app-footer {
    background-color: var(--primary-color);
    color: var(--white);
    padding: 1.5rem 0;
    text-align: center;
    margin-top: auto;
}

.app-footer p {
    margin: 0.25rem 0;
    font-size: 0.9rem;
}

.app-version {
    color: var(--light-bg);
    font-size: 0.8rem;
}

/* ====================================
   Components - Buttons
   ==================================== */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    text-align: center;
}

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

.btn-primary:hover {
    background-color: #2980b9;
}

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

.btn-success:hover {
    background-color: #229954;
}

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

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

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

.btn-secondary:hover {
    background-color: #95a5a6;
}

/* ====================================
   Components - Forms
   ==================================== */
.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--dark-text);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
    font-family: inherit;
    transition: var(--transition);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.form-textarea {
    resize: vertical;
    min-height: 100px;
}

/* ====================================
   Components - Cards
   ==================================== */
.card {
    background-color: var(--white);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

.card-header {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--light-bg);
}

.card-body {
    color: var(--dark-text);
}

/* ====================================
   Components - Tables
   ==================================== */
.table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5rem;
}

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

.table th {
    background-color: var(--light-bg);
    font-weight: 600;
    color: var(--dark-text);
}

.table tbody tr:hover {
    background-color: var(--light-bg);
}

/* Tied scores highlighting */
.table tbody tr.tie-group {
    background-color: #fff3cd;
}

.table tbody tr.tie-group:hover {
    background-color: #ffe69c;
}

/* Rank adjustment buttons */
.rank-controls {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.rank-btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    background-color: var(--secondary-color);
    color: var(--white);
    border: none;
    border-radius: 3px;
    cursor: pointer;
    transition: var(--transition);
}

.rank-btn:hover {
    background-color: #2980b9;
}

.rank-btn:disabled {
    background-color: var(--border-color);
    cursor: not-allowed;
    opacity: 0.5;
}

/* ====================================
   Components - Loading
   ==================================== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.loading-overlay.hidden {
    display: none;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--light-bg);
    border-top-color: var(--secondary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ====================================
   Components - Toast Notifications
   ==================================== */
.toast-container {
    position: fixed;
    top: 80px;
    right: 1rem;
    z-index: 1001;
    max-width: 350px;
}

.toast {
    background-color: var(--white);
    padding: 1rem;
    margin-bottom: 0.5rem;
    border-radius: 4px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 1rem;
    animation: slideIn 0.3s ease;
}

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

.toast.success {
    border-left: 4px solid var(--success-color);
}

.toast.error {
    border-left: 4px solid var(--danger-color);
}

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

.toast.info {
    border-left: 4px solid var(--secondary-color);
}

/* ====================================
   Modal
   ==================================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden {
    display: none !important;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
}

.modal-content {
    position: relative;
    background: var(--white);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    z-index: 1001;
    animation: modalSlideIn 0.3s ease;
}

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

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    margin: 0;
    color: var(--dark-text);
    font-size: 1.25rem;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* ====================================
   Utilities
   ==================================== */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

/* ====================================
   Responsive Design
   ==================================== */
@media (max-width: 768px) {
    .app-header h1 {
        font-size: 1.2rem;
    }
    
    .nav-link {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }
    
    #page-content {
        padding: 1rem;
    }
    
    .table {
        font-size: 0.9rem;
    }
    
    .table th,
    .table td {
        padding: 0.5rem;
    }
}

@media (max-width: 480px) {
    .app-header h1 {
        font-size: 1rem;
    }
    
    .online-status {
        font-size: 0.8rem;
    }
    
    .nav-link {
        padding: 0.75rem 0.5rem;
        font-size: 0.85rem;
    }
}

/* ====================================
   Print Styles
   ==================================== */
@media print {
    /* Hide non-printable elements */
    .no-print,
    .app-header,
    .app-nav,
    .app-footer {
        display: none !important;
    }
    
    /* Ensure page breaks work properly */
    .ranking-section {
        page-break-inside: avoid;
    }
    
    /* Reset page margins for printing */
    @page {
        margin: 1cm;
    }
    
    /* Ensure tables don't break awkwardly */
    table {
        page-break-inside: auto;
    }
    
    tr {
        page-break-inside: avoid;
        page-break-after: auto;
    }
    
    /* Make sure content uses full width when printing */
    .container {
        max-width: 100%;
        padding: 0;
    }
    
    /* Better contrast for printing */
    body {
        background: white;
        color: black;
    }
    
    .card {
        border: 1px solid #000;
        box-shadow: none;
    }
    
    .table {
        border: 1px solid #000;
    }
    
    .table th,
    .table td {
        border: 1px solid #000;
    }
}
