/* ============================================
   Knuckleball AI - MLB Themed Frontend Styles
   ============================================ */

/* === CSS Variables === */
:root {
    /* MLB Official Colors */
    --mlb-navy: #002D72;
    --mlb-navy-dark: #001d4a;
    --mlb-red: #CE1141;
    --mlb-red-dark: #a00d33;
    --mlb-gold: #FFB81C;
    
    /* UI Colors */
    --bg-primary: #0a0f1c;
    --bg-secondary: #111827;
    --bg-card: #1a2235;
    --bg-card-hover: #1f2943;
    
    --text-primary: #f9fafb;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    
    --border-color: rgba(255, 255, 255, 0.1);
    --border-focus: var(--mlb-navy);
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 40px rgba(0, 45, 114, 0.3);
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms ease;
}

/* === Reset & Base === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* === Background Pattern === */
.background-pattern {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: -1;
    background: 
        radial-gradient(ellipse at top, rgba(0, 45, 114, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at bottom right, rgba(206, 17, 65, 0.1) 0%, transparent 50%),
        linear-gradient(180deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
}

.background-pattern::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.02'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    opacity: 0.5;
}

/* === Container === */
.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
    position: relative;
}

/* === Header === */
.header {
    text-align: center;
    margin-bottom: 2.5rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border-color);
}

.logo-section {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.title {
    font-family: 'Bebas Neue', sans-serif;
    font-size: clamp(2.5rem, 8vw, 4rem);
    font-weight: 400;
    letter-spacing: 0.05em;
    background: linear-gradient(135deg, var(--mlb-navy) 0%, #1e5799 50%, var(--mlb-red) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 40px rgba(0, 45, 114, 0.5);
}

.subtitle {
    font-size: 1.1rem;
    color: var(--mlb-red);
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.credit {
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* === Examples Section === */
.examples-section {
    margin-bottom: 2rem;
}

.examples-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-normal);
}

.examples-toggle:hover {
    background: var(--bg-card-hover);
    border-color: var(--mlb-navy);
}

.examples-toggle .chevron {
    width: 20px;
    height: 20px;
    transition: transform var(--transition-normal);
}

.examples-toggle.open .chevron {
    transform: rotate(180deg);
}

.examples-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height var(--transition-slow);
}

.examples-content.open {
    max-height: 600px;
}

.example-category {
    padding: 1rem 1.25rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 12px 12px;
}

.example-category:first-child {
    border-radius: 0;
    margin-top: 0.5rem;
    border-top: 1px solid var(--border-color);
    border-radius: 12px 12px 0 0;
}

.example-category:last-child {
    border-radius: 0 0 12px 12px;
}

.example-category h4 {
    color: var(--mlb-gold);
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
}

.example-category ul {
    list-style: none;
}

.example-category li {
    padding: 0.5rem 0.75rem;
    margin: 0.25rem 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.example-category li:hover {
    background: rgba(0, 45, 114, 0.2);
    color: var(--text-primary);
    transform: translateX(4px);
}

/* === Input Section === */
.input-section {
    margin-bottom: 2rem;
}

.section-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.input-wrapper {
    position: relative;
    margin-bottom: 1rem;
}

textarea {
    width: 100%;
    padding: 1rem 1.25rem;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    resize: vertical;
    min-height: 100px;
    transition: all var(--transition-normal);
}

textarea:focus {
    outline: none;
    border-color: var(--mlb-navy);
    box-shadow: 0 0 0 3px rgba(0, 45, 114, 0.2);
}

textarea::placeholder {
    color: var(--text-muted);
}

/* === Submit Button === */
.submit-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 1rem 2rem;
    font-family: inherit;
    font-size: 1.1rem;
    font-weight: 600;
    color: white;
    background: linear-gradient(135deg, var(--mlb-navy) 0%, var(--mlb-navy-dark) 100%);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all var(--transition-normal);
    box-shadow: var(--shadow-md);
}

.submit-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, var(--mlb-red) 0%, var(--mlb-red-dark) 100%);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.submit-btn:active:not(:disabled) {
    transform: translateY(0);
}

.submit-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.submit-btn .btn-icon {
    width: 20px;
    height: 20px;
    transition: transform var(--transition-normal);
}

.submit-btn:hover:not(:disabled) .btn-icon {
    transform: translateX(4px);
}

/* === Loading Spinner === */
.loading-container {
    text-align: center;
    padding: 3rem 0;
}

.spinner-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

/* Baseball Spinner */
.baseball-spinner {
    width: 80px;
    height: 80px;
    animation: spin 1.5s linear infinite;
}

.ball {
    width: 100%;
    height: 100%;
    background: linear-gradient(145deg, #ffffff 0%, #e8e8e8 100%);
    border-radius: 50%;
    position: relative;
    box-shadow: 
        inset -5px -5px 15px rgba(0, 0, 0, 0.1),
        0 10px 30px rgba(0, 0, 0, 0.3);
}

.seam {
    position: absolute;
    width: 100%;
    height: 100%;
}

.seam-1::before, .seam-1::after,
.seam-2::before, .seam-2::after {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    background: var(--mlb-red);
    border-radius: 50%;
}

.seam-1::before { top: 15%; left: 35%; }
.seam-1::after { top: 25%; left: 25%; }
.seam-2::before { bottom: 15%; right: 35%; }
.seam-2::after { bottom: 25%; right: 25%; }

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

#loadingStatus {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.loading-stages {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
    max-width: 280px;
}

.stage {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    background: var(--bg-card);
    border-radius: 8px;
    transition: all var(--transition-normal);
}

.stage::before {
    content: '';
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: all var(--transition-normal);
}

.stage.active {
    color: var(--text-primary);
    background: rgba(0, 45, 114, 0.2);
}

.stage.active::before {
    background: var(--mlb-gold);
    box-shadow: 0 0 10px var(--mlb-gold);
    animation: pulse 1s ease-in-out infinite;
}

.stage.complete {
    color: var(--text-secondary);
}

.stage.complete::before {
    background: #10b981;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.2); }
}

.loading-subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-top: 1rem;
}

/* === Response Section === */
.response-section {
    margin-bottom: 2rem;
    animation: fadeIn 0.5s ease;
}

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

.response-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--mlb-red);
    border-radius: 12px;
    overflow: hidden;
}

.response-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--border-color);
}

.response-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--mlb-gold);
}

.response-time {
    font-size: 0.8rem;
    color: var(--text-muted);
    padding: 0.25rem 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 20px;
}

.response-content {
    padding: 1.5rem;
    font-size: 1rem;
    line-height: 1.7;
    color: var(--text-primary);
}

.response-content p {
    margin-bottom: 1rem;
}

.response-content p:last-child {
    margin-bottom: 0;
}

.response-content strong {
    color: var(--mlb-gold);
    font-weight: 600;
}

.response-content code {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.2em 0.4em;
    border-radius: 4px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.9em;
}

/* Markdown Tables */
.markdown-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    font-size: 0.95rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    overflow: hidden;
}

.markdown-table thead {
    background: linear-gradient(135deg, var(--mlb-navy) 0%, var(--mlb-navy-dark) 100%);
}

.markdown-table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    color: white;
    border-bottom: 2px solid var(--mlb-red);
    white-space: nowrap;
}

.markdown-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

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

.markdown-table tbody tr:hover {
    background: rgba(0, 45, 114, 0.15);
}

.markdown-table tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

.markdown-table tbody tr:nth-child(even):hover {
    background: rgba(0, 45, 114, 0.15);
}

/* Structured Data Tables (from JSON response) */
.table-container {
    margin: 1.5rem 0;
    overflow-x: auto;
}

.table-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--mlb-gold);
    margin-bottom: 0.75rem;
    padding-left: 0.25rem;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.data-table thead {
    background: linear-gradient(135deg, var(--mlb-navy) 0%, var(--mlb-navy-dark) 100%);
}

.data-table th {
    padding: 0.875rem 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.85rem;
    color: white;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 2px solid var(--mlb-red);
    white-space: nowrap;
}

.data-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

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

.data-table tbody tr:hover {
    background: rgba(0, 45, 114, 0.15);
}

.data-table tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

.data-table tbody tr:nth-child(even):hover {
    background: rgba(0, 45, 114, 0.15);
}

/* Responsive table for mobile */
@media (max-width: 640px) {
    .table-container {
        margin: 1rem -0.5rem;
        padding: 0 0.5rem;
    }
    
    .data-table th,
    .data-table td {
        padding: 0.625rem 0.75rem;
        font-size: 0.8rem;
    }
}

/* === Explain Section === */
.explain-section {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.explain-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all var(--transition-normal);
}

.explain-btn:hover {
    background: var(--bg-card-hover);
    border-color: var(--mlb-navy);
}

.explain-btn svg {
    width: 18px;
    height: 18px;
}

.explain-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* === Explanation Card === */
.explanation-card {
    margin-top: 1.5rem;
    padding: 1.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    animation: fadeIn 0.3s ease;
}

.explanation-card h4 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
}

.explanation-card h5 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--mlb-gold);
    margin-bottom: 0.75rem;
}

.sql-section {
    margin-bottom: 1.5rem;
}

.sql-code {
    padding: 1rem;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.85rem;
    line-height: 1.5;
    color: #e2e8f0;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.explanation-text {
    line-height: 1.7;
    color: var(--text-secondary);
}

/* === Error Card === */
.error-card {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1.25rem;
    background: rgba(206, 17, 65, 0.1);
    border: 1px solid var(--mlb-red);
    border-radius: 12px;
    margin-bottom: 2rem;
    animation: shake 0.5s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

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

.error-content h4 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--mlb-red);
    margin-bottom: 0.5rem;
}

.error-content p {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* === Footer === */
.footer {
    text-align: center;
    padding: 2rem 0;
    border-top: 1px solid var(--border-color);
    margin-top: 2rem;
}

.footer p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* === Responsive === */
@media (max-width: 640px) {
    .container {
        padding: 1.5rem 1rem;
    }
    
    .logo-section {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .title {
        font-size: 2.5rem;
    }
    
    .explain-section {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* === Scrollbar === */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--mlb-navy);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--mlb-red);
}

/* === Selection === */
::selection {
    background: rgba(0, 45, 114, 0.3);
    color: var(--text-primary);
}

