/* ============================================
   CSS Variables & Reset
   ============================================ */
:root {
    --primary-color: #007AFF;
    --secondary-color: #5856D6;
    --success-color: #34C759;
    --warning-color: #FF9500;
    --error-color: #FF3B30;
    --background-color: #F2F2F7;
    --surface-color: #FFFFFF;
    --text-primary: #000000;
    --text-secondary: #8E8E93;
    --border-color: rgba(0, 0, 0, 0.1);
    --shadow-color: rgba(0, 0, 0, 0.1);
    --glass-bg: rgba(255, 255, 255, 0.75);
    --glass-border: rgba(255, 255, 255, 0.3);
    --adendorf-highlight: linear-gradient(135deg, rgba(255, 149, 0, 0.25), rgba(255, 149, 0, 0.15));
    --adendorf-color: #FF9500;
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow-x: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
    background: linear-gradient(135deg, 
        rgba(0, 122, 255, 0.1), 
        rgba(88, 86, 214, 0.05), 
        rgba(255, 45, 85, 0.05));
    background-attachment: fixed;
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

/* ============================================
   Header
   ============================================ */
.app-header {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 1.5rem 1rem 1rem;
    box-shadow: 0 4px 12px var(--shadow-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-icon {
    font-size: 2.5rem;
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

.header-text h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.header-text p {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* ============================================
   Tab Navigation
   ============================================ */
.tab-nav {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 88px;
    z-index: 90;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

.tab-scroll {
    display: flex;
    padding: 0.75rem 1rem;
    gap: 0.75rem;
    min-width: min-content;
}

.tab-button {
    background: none;
    border: none;
    padding: 0.6rem 1.25rem;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-primary);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.tab-button.active {
    background: var(--primary-color);
    color: white;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}

.tab-button:hover:not(.active) {
    background: rgba(0, 122, 255, 0.1);
}

/* ============================================
   View Mode Switcher
   ============================================ */
.view-mode-switcher {
    padding: 1rem;
    max-width: 1200px;
    margin: 0 auto;
}

.segmented-control {
    display: flex;
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 0.25rem;
    box-shadow: 0 2px 8px var(--shadow-color);
}

.segment {
    flex: 1;
    background: none;
    border: none;
    padding: 0.7rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}

.segment.active {
    background: white;
    color: var(--primary-color);
    font-weight: 600;
    box-shadow: 0 2px 6px var(--shadow-color);
}

/* ============================================
   Main Content
   ============================================ */
.content {
    flex: 1;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 1rem;
}

/* ============================================
   Loading State
   ============================================ */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    gap: 1rem;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(0, 122, 255, 0.2);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-state p {
    color: var(--text-secondary);
    font-weight: 500;
}

/* ============================================
   Error State
   ============================================ */
.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 3rem 2rem;
    gap: 1rem;
    text-align: center;
}

.error-icon {
    font-size: 4rem;
}

.error-state h3 {
    font-size: 1.5rem;
    color: var(--error-color);
}

.error-state p {
    color: var(--text-secondary);
    max-width: 400px;
}

.retry-button {
    margin-top: 1rem;
    padding: 0.75rem 1.5rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
    transition: transform 0.2s;
}

.retry-button:active {
    transform: scale(0.95);
}

/* ============================================
   Glass Card Effect
   ============================================ */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: 0 8px 32px var(--shadow-color);
    overflow: hidden;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem;
    background: rgba(255, 255, 255, 0.95);
    border-bottom: 1px solid var(--border-color);
}

.card-header .icon {
    font-size: 1.75rem;
}

.card-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
}

.card-header p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* ============================================
   Table View
   ============================================ */
.table-container {
    margin-bottom: 1.5rem;
}

.table-content {
    padding: 1rem;
}

.table-row {
    display: grid;
    grid-template-columns: 40px 1fr auto auto auto;
    gap: 0.5rem;
    align-items: center;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: rgba(0, 122, 255, 0.05);
    border-radius: 12px;
    transition: all 0.2s ease;
}

.table-row:hover {
    background: rgba(0, 122, 255, 0.1);
    transform: translateX(2px);
}

.table-row.highlighted {
    background: var(--adendorf-highlight);
    border: 1.5px solid var(--adendorf-color);
    font-weight: 600;
}

.position {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary-color);
    text-align: center;
}

.table-row.highlighted .position {
    color: var(--adendorf-color);
}

.team-name {
    font-size: 0.9rem;
    line-height: 1.3;
}

.table-row.highlighted .team-name {
    color: var(--adendorf-color);
}

.stats-compact {
    display: flex;
    gap: 0.5rem;
    font-size: 0.85rem;
}

.stat-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 32px;
}

.stat-value {
    font-weight: 600;
    font-family: 'Courier New', monospace;
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.stat-cell.wins .stat-value { color: var(--success-color); }
.stat-cell.draws .stat-value { color: var(--warning-color); }
.stat-cell.losses .stat-value { color: var(--error-color); }

.points {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 50px;
}

.points-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-color);
    font-family: 'Courier New', monospace;
}

.table-row.highlighted .points-value {
    color: var(--adendorf-color);
}

.points-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

/* ============================================
   Matches View
   ============================================ */
.matches-container {
    margin-bottom: 1.5rem;
}

.match-row {
    padding: 1rem;
    margin-bottom: 0.75rem;
    background: rgba(142, 142, 147, 0.1);
    border-radius: 14px;
    transition: all 0.2s ease;
}

.match-row:hover {
    background: rgba(142, 142, 147, 0.15);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-color);
}

.match-row.adendorf-match {
    background: var(--adendorf-highlight);
    border: 1.5px solid rgba(255, 149, 0, 0.3);
}

.match-info {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.match-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.4rem 0.75rem;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
}

.match-badge.date { color: var(--primary-color); }
.match-badge.time { color: var(--success-color); }

.match-teams {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 0.75rem;
    align-items: center;
}

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

.team.home {
    text-align: right;
    align-items: flex-end;
}

.team.away {
    text-align: left;
    align-items: flex-start;
}

.team-name-match {
    font-size: 0.95rem;
    line-height: 1.3;
}

.team-name-match.adendorf {
    font-weight: 700;
    color: var(--adendorf-color);
}

.team-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.5rem;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.team-badge.away {
    background: linear-gradient(135deg, var(--secondary-color), #9F3EB6);
}

.match-result {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 60px;
    padding: 0.6rem;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border-radius: 12px;
    font-weight: 700;
    font-size: 1.1rem;
}

.match-result.no-result {
    background: linear-gradient(135deg, rgba(142, 142, 147, 0.5), rgba(142, 142, 147, 0.3));
    font-size: 0.9rem;
}

/* ============================================
   Stats View
   ============================================ */
.stats-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.stats-card {
    padding: 0;
}

.stats-content {
    padding: 1.5rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1.5rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-color);
}

.team-overview h3 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    padding-left: 0.5rem;
}

.team-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
}

.team-card {
    padding: 1.25rem;
}

.team-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.team-card h4 {
    font-size: 1rem;
    font-weight: 600;
}

.team-position {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.team-stats {
    display: flex;
    gap: 1rem;
    font-size: 0.85rem;
}

.team-stat {
    display: flex;
    flex-direction: column;
}

.team-stat-label {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.team-stat-value {
    font-weight: 600;
    font-size: 1.1rem;
}

/* ============================================
   Footer
   ============================================ */
.app-footer {
    margin-top: auto;
    padding: 2rem 1rem 1rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.footer-hint {
    margin-top: 0.5rem;
    font-size: 0.8rem;
    opacity: 0.7;
}

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

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 768px) {
    .header-text h1 { font-size: 1.25rem; }
    
    .table-row {
        font-size: 0.85rem;
        grid-template-columns: 35px 1fr auto auto;
    }
    
    .stats-compact {
        flex-direction: column;
        gap: 0.25rem;
    }
    
    .stat-cell {
        flex-direction: row;
        gap: 0.25rem;
    }
    
    .match-teams {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .team.home, .team.away {
        text-align: center;
        align-items: center;
    }
}

@media (max-width: 480px) {
    .content { padding: 0.75rem; }
    .tab-button { font-size: 0.85rem; padding: 0.5rem 1rem; }
    .segment { font-size: 0.85rem; padding: 0.6rem; }
}

html { scroll-behavior: smooth; }
