:root {
    --bg-color: #f8fafc;
    /* Crisp light slate/mint background */
    --card-bg: rgba(255, 255, 255, 0.85);
    --card-border: rgba(16, 185, 129, 0.15);
    --primary-color: #059669;
    /* Emerald 600 */
    --primary-glow: rgba(16, 185, 129, 0.2);
    --accent-color: #10b981;
    /* Emerald 500 */
    --text-primary: #064e3b;
    /* Dark emerald for maximum readability */
    --text-secondary: #475569;
    /* Slate grey for secondary info */
    --danger: #ef4444;

    --glass-blur: blur(16px);
    --transition-speed: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    background-image:
        radial-gradient(circle at 10% 20%, rgba(16, 185, 129, 0.08) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(59, 130, 246, 0.05) 0%, transparent 40%);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
}

#app-container {
    width: 100%;
    max-width: 920px;
    min-height: 100vh;
    position: relative;
    background: transparent;
}

/* --- Screens & Transitions --- */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
    padding: 24px;
    display: flex;
    flex-direction: column;
}

.screen.active {
    opacity: 1;
    pointer-events: auto;
    z-index: 10;
}

.screen.hidden,
.hidden {
    display: none !important;
}

#main-app.screen.active,
#finance-app.screen.active,
#maintenance-app.screen.active,
#hub-screen.screen.active,
#draft-app.screen.active {
    display: block;
    position: relative;
    background: var(--bg-color);
    /* Hide anything behind it */
    min-height: 100vh;
}

/* --- Typography --- */
h1,
h2,
h3 {
    font-weight: 700;
    letter-spacing: -0.02em;
}

h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

h2 {
    font-size: 1.5rem;
    color: var(--text-primary);
}

h3 {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.subtitle {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

/* --- Components --- */
.glass-card {
    background: var(--card-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 24px;
    box-shadow: 0 10px 40px rgba(0, 70, 50, 0.06);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), #0d9488);
    color: #fff;
    border: none;
    padding: 12px 24px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 15px var(--primary-glow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--primary-glow);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-text {
    background: none;
    border: none;
    color: #0d9488;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: color 0.2s;
}

.btn-text:hover {
    color: var(--primary-color);
}

.full-width {
    width: 100%;
}

/* --- Login Screen --- */
#login-screen {
    justify-content: center;
    align-items: center;
}

.login-card {
    width: 100%;
    max-width: 480px;
}

/* --- Forms --- */
.input-group {
    margin-bottom: 1.25rem;
    flex: 1;
}

.form-row {
    display: flex;
    gap: 12px;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: #334155;
    font-weight: 600;
}

input,
select,
textarea {
    width: 100%;
    background: #fff;
    border: 1px solid #e2e8f0;
    color: #0f172a;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px var(--primary-glow);
}

/* --- App Header --- */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding: 12px 0;
}

.logo {
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.main-nav ul {
    display: flex;
    list-style: none;
    gap: 12px;
}

.nav-link {
    text-decoration: none;
    color: #64748b;
    font-size: 0.9rem;
    padding: 6px 10px;
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.2s;
}

.nav-link.active,
.nav-link:hover {
    color: var(--primary-color);
    background: rgba(16, 185, 129, 0.08);
}

/* --- Dashboard --- */
.date-display {
    color: var(--primary-color);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: #fff;
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 16px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 50, 40, 0.04);
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 800;
    margin: 8px 0;
    color: var(--primary-color);
}

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

.trend-arrow {
    font-size: 1rem;
    margin-left: 2px;
    vertical-align: middle;
    display: inline-block;
}

.trend-up {
    color: var(--primary-color);
}

.trend-down {
    color: var(--danger);
}

.trend-sideways {
    color: var(--text-secondary);
    transform: rotate(0deg);
}

/* --- Plan Section --- */
.pill-nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    padding-bottom: 8px;
}

.pill-nav button {
    background: #fff;
    border: 1px solid #e2e8f0;
    color: #475569;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.pill-nav button.active {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px var(--primary-glow);
}

.option-nav {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--card-border);
    padding-bottom: 12px;
}

.option-nav button {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.option-nav button.active {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

.history-item {
    background: #fff;
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0, 50, 40, 0.03);
}

/* --- Hub Screen --- */
.hub-header {
    text-align: center;
    margin-bottom: 40px;
}

.hub-header h1 {
    color: var(--text-primary);
}

.hub-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
    max-width: 800px;
    margin: 0 auto;
}

.hub-card {
    background: #fff;
    border: 1px solid rgba(16, 185, 129, 0.1);
    box-shadow: 0 10px 30px rgba(0, 50, 40, 0.05);
}

.hub-card:hover {
    transform: translateY(-8px);
    border-color: var(--primary-color);
    box-shadow: 0 15px 40px rgba(16, 185, 129, 0.15);
    background: #fff;
}

.hub-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

/* --- Shared Navigation --- */
.hub-nav-btn {
    background: white;
    border: 1px solid #e2e8f0;
    color: #475569;
    font-weight: 700;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.hub-nav-btn:hover {
    background: var(--bg-color);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* --- Specific Finance Adjustments --- */
#finance-age-display {
    color: #b45309;
    /* Warm amber for contrast */
}

.asset-item-value {
    color: #059669;
    font-weight: 700;
}

#logout-btn,
#logout-btn-finance {
    color: #94a3b8;
}

#logout-btn:hover,
#logout-btn-finance:hover {
    color: var(--danger);
}

.chart-card {
    background: white;
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 24px;
    position: relative;
    overflow: hidden;
    z-index: 1;
}

.rigid-chart-container {
    width: 100% !important;
    height: 350px !important;
    position: relative !important;
    overflow: hidden !important;
    display: block !important;
}

/* --- Views Logic --- */
.view {
    display: none;
}

.view.active {
    display: block;
    animation: fadeIn 0.4s ease;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Chat Interface --- */
#chat-history::-webkit-scrollbar {
    width: 6px;
}

#chat-history::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
}

.chat-message {
    padding: 12px 16px;
    border-radius: 16px;
    max-width: 85%;
    margin-bottom: 8px;
    line-height: 1.5;
    word-wrap: break-word;
    font-size: 0.95rem;
}

.chat-message.user {
    align-self: flex-end;
    background: var(--primary-color);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 12px var(--primary-glow);
}

.chat-message.coach {
    align-self: flex-start;
    background: #f1f5f9;
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    border: 1px solid #e2e8f0;
}

.chat-message p {
    margin: 0;
}

/* --- Recommendation Card --- */
.recommendation-text {
    line-height: 1.6;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.recommendation-text strong {
    color: var(--text-primary);
    font-weight: 700;
}

.recommendation-text ul {
    margin-top: 10px;
    padding-left: 20px;
}

.recommendation-text li {
    margin-bottom: 6px;
}

.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(16, 185, 129, 0.2);
    border-radius: 50%;
    border-top-color: var(--primary-color);
    animation: spin 1s ease-in-out infinite;
    margin-right: 8px;
    vertical-align: middle;
}

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

/* --- Maintenance Section --- */
#maintenance-app .stat-card {
    transition: all 0.3s ease;
}

#maintenance-app .stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0, 70, 50, 0.08);
}

.complete-maint {
    background: linear-gradient(135deg, var(--primary-color), #0d9488);
}

.delete-maint:hover {
    color: #dc2626 !important;
    transform: scale(1.2);
    transition: transform 0.2s;
}

#reminder-list p {
    padding: 10px;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 10px;
    border-left: 4px solid #f59e0b;
    margin-bottom: 12px;
}

/* --- Fantasy Draft Tool --- */
.plan-list {
    list-style: none;
    padding: 0;
}

.plan-list li {
    padding: 10px;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 12px;
    border-left: 4px solid var(--primary-color);
    margin-bottom: 8px;
    font-size: 0.9rem;
    display: flex;
    justify-content: space-between;
}

.analysis-box {
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 24px;
    line-height: 1.7;
    font-size: 1rem;
    color: var(--text-primary);
    max-height: 500px;
    overflow-y: auto;
}

.analysis-box strong {
    color: var(--primary-color);
}

.draft-rosters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

#draft-app .app-header {
    border-bottom: 1px solid var(--card-border);
    padding-bottom: 20px;
}

#draft-app .nav-link.active,
#travel-app .nav-link.active {
    background: var(--primary-glow);
    color: var(--primary-color);
}

/* --- Travel Specific --- */
.trip-card {
    transition: transform 0.3s ease;
}

.trip-card:hover {
    transform: translateY(-5px);
}

.funding-container {
    margin-top: 12px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
    height: 8px;
    overflow: hidden;
    position: relative;
}

.funding-bar {
    height: 100%;
    background: var(--success-color);
    transition: width 0.5s ease-out;
}

.trip-status-badge {
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
}

.status-past {
    background: var(--primary-glow);
    color: var(--primary-color);
}

.status-planned {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success-color);
}

.status-bucket {
    background: rgba(107, 114, 128, 0.1);
    color: var(--text-secondary);
}

#travel-map-container {
    height: 500px;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.1);
    background: #f8fafc;
}

/* Fix Leaflet Z-Index and integration */
.leaflet-container {
    font-family: 'Outfit', sans-serif !important;
}

.leaflet-popup-content-wrapper {
    background: rgba(255, 255, 255, 0.9) !important;
    backdrop-filter: blur(10px);
    border-radius: 12px !important;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1) !important;
}

/* Open Run Styles */
.event-card {
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.event-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
}

.sport-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

.sport-basketball {
    background: rgba(249, 115, 22, 0.1);
    color: #f97316;
}

.sport-volleyball {
    background: rgba(14, 165, 233, 0.1);
    color: #0ea5e9;
}

#open-run-map-container {
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* BMI Gauge Styles */
.bmi-gauge-container {
    margin-top: 15px;
    position: relative;
    height: 12px;
    background: #e2e8f0;
    border-radius: 6px;
    overflow: visible;
    /* Allow marker to pop out slightly */
}

.bmi-gauge-bar {
    height: 100%;
    width: 100%;
    display: flex;
    border-radius: 6px;
    overflow: hidden;
}

.bmi-segment {
    height: 100%;
}

.bmi-marker {
    position: absolute;
    top: -6px;
    width: 4px;
    height: 24px;
    background: var(--text-primary);
    border-radius: 2px;
    transform: translateX(-50%);
    transition: left 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 2;
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.2);
}

.bmi-labels {
    display: flex;
    font-size: 0.65rem;
    color: var(--text-secondary);
    margin-top: 8px;
    font-weight: 600;
}

.bmi-labels span {
    text-align: center;
}

.label-underweight {
    width: 18.5%;
}

.label-normal {
    width: 6.5%;
}

.label-overweight {
    width: 5%;
}

.label-obese {
    width: 70%;
}