/* Base Styles */
:root {
    --bg-app: #f1f5f9;
    --white: #ffffff;
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --text-main: #1e293b;
    --text-light: #64748b;
    --border-light: #e2e8f0;
    --success: #10b981;
    --danger: #ef4444;

    /* Stats Colors */
    --accent-green: #10b981;
    --accent-orange: #f59e0b;
    --accent-red: #ef4444;
    --accent-purple: #8b5cf6;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-app);
    color: var(--text-main);
    line-height: 1.5;
    min-height: 100vh;
}

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

/* Navbar */
.navbar {
    background: var(--white);
    border-bottom: 1px solid var(--border-light);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--text-main);
    text-decoration: none;
}

.nav-links {
    display: flex;
    gap: 1.5rem;
}

.nav-links a {
    color: var(--text-light);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s;
    font-weight: 500;
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--primary);
}

/* Login */
.login-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.login-box {
    background: var(--white);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 2.5rem;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.login-box h1 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.login-box p {
    color: var(--text-light);
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}

.login-box input,
.settings-box input,
.settings-container input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    font-size: 1rem;
    margin-bottom: 1rem;
    background: #f8fafc;
}

.login-box input:focus,
.settings-box input:focus,
.settings-container input:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--white);
}

.login-box button,
.btn-save {
    width: 100%;
    padding: 0.75rem 1.5rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.login-box button:hover,
.btn-save:hover {
    background: var(--primary-dark);
}

.error {
    background: #fef2f2;
    color: var(--danger);
    padding: 0.75rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    border: 1px solid #fecaca;
}

/* Dashboard */
.dashboard {
    flex: 1;
    padding: 2rem;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

.dashboard h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-main);
}

/* Weekly Section */
.weekly-section {
    margin-bottom: 2rem;
}

.weekly-cards {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.weekly-card {
    background: var(--white);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 1rem 1.5rem;
    min-width: 150px;
    text-align: center;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.weekly-card.positive {
    border-color: var(--success);
    background: #f0fdf4;
}

.weekly-card.negative {
    border-color: var(--danger);
    background: #fef2f2;
}

.weekly-card.positive .weekly-value {
    color: var(--success);
}

.weekly-card.negative .weekly-value {
    color: var(--danger);
}

.weekly-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-light);
    text-transform: uppercase;
    margin-bottom: 0.25rem;
    font-weight: 600;
}

.weekly-value {
    font-size: 1.25rem;
    font-weight: 700;
}

/* Stats Grid */
.current-stats {
    margin-bottom: 3rem;
}

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

.stat-card {
    background: var(--white);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 1.5rem;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
}

.stat-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.stat-value {
    display: block;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-main);
}

.stat-unit {
    display: block;
    font-size: 0.85rem;
    color: var(--text-light);
    margin-top: 0.25rem;
}

.last-update {
    margin-top: 1rem;
    font-size: 0.85rem;
    color: var(--text-light);
}

/* Charts */
.charts-section h2 {
    margin-bottom: 1.5rem;
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
    gap: 1.5rem;
}

.chart-box {
    background: var(--white);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.chart-box h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 1rem;
}

.chart-box canvas {
    width: 100% !important;
    height: 240px !important;
}

/* Settings Page */
.settings-page {
    flex: 1;
    display: flex;
    justify-content: center;
    padding: 2rem;
}

.settings-container {
    width: 100%;
    max-width: 700px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.settings-box {
    background: var(--white);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.settings-box h2 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

.settings-desc {
    color: var(--text-light);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.radio-row {
    display: flex;
    gap: 2rem;
    margin-top: 0.5rem;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.95rem;
}

.radio-label input[type="radio"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}


/* =========== COACH / CHAT UI =========== */
.coach-layout {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.chat-wrapper {
    flex: 1;
    display: flex;
    justify-content: center;
    padding: 1.5rem;
    overflow: hidden;
    /* Prevent body scroll */
}

.chat-container {
    width: 100%;
    max-width: 900px;
    background: var(--white);
    border-radius: 16px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    position: relative;
}

/* Chat Header */
.chat-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: 1rem;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
}

.avatar {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #2563eb, #8b5cf6);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.2);
}

.header-info {
    flex: 1;
}

.header-info h2 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-main);
}

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background-color: var(--success);
    border-radius: 50%;
    margin-right: 4px;
}

.status-text {
    font-size: 0.8rem;
    color: var(--text-light);
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    background: #f0f9ff;
    color: var(--primary);
    border: 1px solid rgba(37, 99, 235, 0.2);
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.action-btn:hover {
    background: #e0f2fe;
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.action-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Chat Area */
.chat-area {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    background: #f8fafc;
}

.message-bubble {
    max-width: 80%;
    padding: 1rem;
    border-radius: 16px;
    font-size: 0.95rem;
    line-height: 1.6;
    position: relative;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* MARKDOWN CONTENT STYLING */
.message-bubble p {
    margin-bottom: 0.75rem;
}

.message-bubble p:last-child {
    margin-bottom: 0;
}

.message-bubble strong {
    font-weight: 600;
    color: inherit;
}

.message-bubble em {
    font-style: italic;
}

.message-bubble ul,
.message-bubble ol {
    margin-left: 1.25rem;
    margin-bottom: 0.75rem;
}

.message-bubble li {
    margin-bottom: 0.25rem;
}

.message-bubble pre {
    background: rgba(0, 0, 0, 0.05);
    padding: 0.75rem;
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 0.75rem;
}

.message-bubble code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 4px;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: monospace;
}

/* Tables in Chat */
.message-bubble table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 8px;
    overflow: hidden;
}

.message-bubble th,
.message-bubble td {
    padding: 0.5rem 0.75rem;
    border: 1px solid rgba(0, 0, 0, 0.1);
    text-align: left;
}

.message-bubble th {
    background: rgba(0, 0, 0, 0.05);
    font-weight: 600;
}

/* System/Assistant Message */
.message-bubble.system,
.message-bubble.assistant {
    background: var(--white);
    color: var(--text-main);
    border-top-left-radius: 4px;
    align-self: flex-start;
}

/* User Message */
.message-bubble.user {
    background: var(--primary);
    color: white;
    border-top-right-radius: 4px;
    align-self: flex-end;
}

/* Adjust colors for user bubbles */
.message-bubble.user code,
.message-bubble.user pre,
.message-bubble.user table {
    background: rgba(255, 255, 255, 0.2);
}

.message-bubble.user th,
.message-bubble.user td {
    border-color: rgba(255, 255, 255, 0.3);
}

.message-bubble.user th {
    background: rgba(255, 255, 255, 0.2);
}

.message-bubble.error {
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid var(--danger);
    align-self: center;
    font-size: 0.9rem;
    max-width: 90%;
}

/* Input Area */
.chat-input-area {
    padding: 1.5rem;
    background: var(--white);
    border-top: 1px solid var(--border-light);
}

#chat-form {
    display: flex;
    gap: 0.75rem;
    background: #f1f5f9;
    padding: 0.5rem;
    border-radius: 12px;
    border: 1px solid transparent;
    transition: all 0.2s;
}

#chat-form:focus-within {
    background: var(--white);
    box-shadow: 0 0 0 2px var(--primary);
}

#chat-input {
    flex: 1;
    background: transparent;
    border: none;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    color: var(--text-main);
}

#chat-input:focus {
    outline: none;
}

#send-btn {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    border: none;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

#send-btn:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

#send-btn:disabled {
    background: var(--text-light);
    cursor: default;
    transform: none;
}

/* Loading Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 1rem;
    background: var(--white);
    border-radius: 12px;
    border-top-left-radius: 4px;
    align-self: flex-start;
    width: fit-content;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: #cbd5e1;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* Responsive */
@media (max-width: 768px) {
    .navbar {
        padding: 0.75rem 1.25rem;
    }

    .nav-links {
        gap: 1rem;
    }

    .chat-wrapper {
        padding: 0;
    }

    .chat-container {
        border-radius: 0;
        height: 100%;
        border: none;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }
}