/* ============================================
   FIT60 — Design System
   Dark theme, mobile-first, PWA-ready
   ============================================ */

:root {
    --bg: #07090e;
    --bg2: #0d1117;
    --bg3: #161b22;
    --bg4: #1c2333;
    --border: #21262d;
    --border2: #30363d;
    --text: #e6edf3;
    --text2: #8b949e;
    --text3: #6e7681;

    --o: #ff6b35;
    --c: #00d4ff;
    --g: #00e676;
    --p: #c77dff;
    --y: #ffd166;
    --r: #ff5252;
    --teal: #00bfa5;

    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --shadow: 0 4px 24px rgba(0,0,0,.4);
    --transition: all .2s ease;

    --nav-height: 64px;
    --header-height: 56px;
}

/* ── Light theme ── */
[data-theme="light"] {
    --bg: #f0f2f5;
    --bg2: #ffffff;
    --bg3: #e8eaef;
    --bg4: #dcdfe6;
    --border: #c5c9d2;
    --border2: #adb3bf;
    --text: #111827;
    --text2: #374151;
    --text3: #555e6e;

    --shadow: 0 4px 24px rgba(0,0,0,.1);
}
[data-theme="light"] .app-header {
    background: rgba(255,255,255,.95);
    border-bottom-color: var(--border);
}
[data-theme="light"] .nav-bottom {
    background: rgba(255,255,255,.97);
    border-top-color: var(--border);
}
[data-theme="light"] input,
[data-theme="light"] select,
[data-theme="light"] textarea {
    background: var(--bg3) !important;
    color: var(--text) !important;
    border-color: var(--border) !important;
}
[data-theme="light"] .btn-primary {
    color: #fff !important;
}
[data-theme="light"] .auth-body {
    background: linear-gradient(135deg, #e8ecf1, #f5f6fa);
}
[data-theme="light"] .auth-card {
    background: #fff;
    border-color: var(--border);
}
/* Mental module overrides for light theme */
[data-theme="light"] .mental-tab {
    color: var(--text2) !important;
    background: var(--bg3) !important;
    border-color: var(--border) !important;
}
[data-theme="light"] .mental-tab.active {
    background: var(--teal) !important;
    color: #fff !important;
    border-color: var(--teal) !important;
}
[data-theme="light"] .form-card,
[data-theme="light"] .chart-container,
[data-theme="light"] .stat-mini,
[data-theme="light"] .med-card,
[data-theme="light"] .mood-card,
[data-theme="light"] .sleep-card,
[data-theme="light"] .gratitude-card {
    background: var(--bg3) !important;
    border-color: var(--border) !important;
}
[data-theme="light"] .section-title {
    color: var(--text) !important;
}
[data-theme="light"] .breath-circle {
    border-color: var(--border) !important;
}
[data-theme="light"] .quick-btn {
    background: rgba(0,191,165,.08) !important;
    border-color: rgba(0,191,165,.3) !important;
}
[data-theme="light"] .mood-btn,
[data-theme="light"] .sleep-qual-btn {
    border-color: var(--border) !important;
    background: var(--bg3) !important;
}
[data-theme="light"] .cal-day {
    background: var(--bg3) !important;
    color: var(--text2) !important;
}
[data-theme="light"] .streak-badge {
    color: var(--text) !important;
}
/* General light theme fixes for inline rgba styles */
[data-theme="light"] [style*="rgba(255,255,255,0.0"],
[data-theme="light"] [style*="rgba(255,255,255,.0"] {
    background: var(--bg3) !important;
}
[data-theme="light"] .card {
    background: var(--bg2);
    border-color: var(--border);
}
[data-theme="light"] .kpi-card {
    background: var(--bg2);
    border-color: var(--border);
}
/* Forcer les textes inline rgba(255,255,255,...) à être lisibles en clair */
[data-theme="light"] [style*="color:rgba(255,255,255"] {
    color: var(--text2) !important;
}
[data-theme="light"] [style*="color:#fff"] {
    color: var(--text) !important;
}
[data-theme="light"] [style*="color: rgba(255,255,255"] {
    color: var(--text2) !important;
}
/* Boutons primaires doivent garder le texte blanc */
[data-theme="light"] .btn-primary,
[data-theme="light"] .btn-primary [style*="color:#fff"],
[data-theme="light"] [style*="background:var(--o)"],
[data-theme="light"] [style*="background:var(--g)"],
[data-theme="light"] [style*="background:var(--c)"],
[data-theme="light"] [style*="background:var(--teal)"] {
    color: #fff !important;
}
/* Fond des sections avec rgba(255,255,255,0.0x) */
[data-theme="light"] [style*="background:rgba(255,255,255,0.0"] {
    background: var(--bg3) !important;
}
[data-theme="light"] [style*="background:rgba(255,255,255,.0"] {
    background: var(--bg3) !important;
}
/* Header greeting et labels */
[data-theme="light"] .header-greeting {
    color: var(--text2) !important;
}
[data-theme="light"] .logo-fit {
    color: var(--text) !important;
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    padding-bottom: calc(var(--nav-height) + 16px);
}

a {
    color: var(--c);
    text-decoration: none;
    transition: var(--transition);
}
a:hover { opacity: .85; }

img { max-width: 100%; height: auto; }

/* ============================================
   Typography
   ============================================ */
h1, h2, h3, h4 {
    font-family: 'Syne', sans-serif;
    font-weight: 700;
    line-height: 1.2;
}

h1 { font-size: 1.75rem; margin-bottom: .75rem; }
h2 { font-size: 1.375rem; margin-bottom: .5rem; }
h3 { font-size: 1.125rem; margin-bottom: .5rem; }

.text-gradient {
    background: linear-gradient(135deg, var(--o), var(--c));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ============================================
   Layout
   ============================================ */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: rgba(7, 9, 14, .92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 100;
}

.app-main {
    margin-top: var(--header-height);
    padding: 1rem;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

/* Logo */
.logo { display: flex; align-items: center; gap: 0; }
.logo-fit {
    font-family: 'Syne', sans-serif;
    font-weight: 800;
    font-size: 1.5rem;
    color: var(--text);
}
.logo-60 {
    font-family: 'Syne', sans-serif;
    font-weight: 800;
    font-size: 1.5rem;
    color: var(--o);
}

.header-right {
    display: flex;
    align-items: center;
    gap: .75rem;
}

.header-greeting {
    font-size: .85rem;
    color: var(--text2);
}

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    color: var(--text2);
    transition: var(--transition);
}
.btn-icon:hover {
    background: var(--bg3);
    color: var(--text);
}

/* ============================================
   Bottom Navigation
   ============================================ */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: rgba(13, 17, 23, .95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 12px;
    color: var(--text3);
    font-size: .65rem;
    font-weight: 500;
    transition: var(--transition);
    border-radius: var(--radius-sm);
    -webkit-tap-highlight-color: transparent;
}

.nav-item.active {
    color: var(--o);
}

.nav-item:hover {
    color: var(--text);
    background: var(--bg3);
}

/* More Menu */
.more-menu {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
}
.more-menu.open { display: block; }

.more-menu-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.7);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.more-menu-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg2);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 1.5rem;
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
    transform: translateY(0);
    animation: slideUp .3s ease;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.more-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    font-family: 'Syne', sans-serif;
    font-weight: 600;
    font-size: 1.1rem;
}

.more-menu-header button {
    background: none;
    border: none;
    color: var(--text2);
    font-size: 1.5rem;
    cursor: pointer;
}

.more-menu-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: .75rem;
}

.more-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .5rem;
    padding: .75rem .25rem;
    border-radius: var(--radius);
    color: var(--text);
    font-size: .75rem;
    font-weight: 500;
    transition: var(--transition);
}
.more-item:hover { background: var(--bg3); }

.more-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    opacity: .85;
}

/* ============================================
   Cards
   ============================================ */
.card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
    transition: var(--transition);
    overflow: hidden;
}

.card:hover {
    border-color: var(--border2);
}

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

.card-title {
    font-family: 'Syne', sans-serif;
    font-weight: 600;
    font-size: 1rem;
}

.card-badge {
    font-size: .7rem;
    padding: .2rem .6rem;
    border-radius: 999px;
    font-weight: 600;
}

/* ============================================
   Buttons
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: .7rem 1.5rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    font-size: .9rem;
    cursor: pointer;
    transition: var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.btn-primary {
    background: linear-gradient(135deg, var(--o), #ff8f35);
    color: #fff;
}
.btn-primary:hover {
    opacity: .9;
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(255, 107, 53, .3);
}

.btn-secondary {
    background: var(--bg3);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg4); }

.btn-ghost {
    background: transparent;
    color: var(--c);
    border: 1px solid var(--c);
}

.btn-full { width: 100%; }

.btn-sm {
    padding: .4rem .8rem;
    font-size: .8rem;
}

/* ============================================
   Forms
   ============================================ */
.form-group {
    position: relative;
    margin-bottom: 1rem;
    min-width: 0;
}

.form-group label {
    display: block;
    font-size: .85rem;
    font-weight: 500;
    color: var(--text2);
    margin-bottom: .35rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="url"],
select,
textarea {
    width: 100%;
    max-width: 100%;
    padding: .7rem 1rem;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: 'Outfit', sans-serif;
    font-size: .9rem;
    transition: var(--transition);
}

input[type="time"] {
    padding-left: .5rem;
    padding-right: .5rem;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--o);
    box-shadow: 0 0 0 3px rgba(255, 107, 53, .15);
}

input::placeholder, textarea::placeholder {
    color: var(--text3);
}

.toggle-password {
    position: absolute;
    right: .75rem;
    top: 2.2rem;
    background: none;
    border: none;
    color: var(--text3);
    cursor: pointer;
}

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

select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b949e' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right .75rem center;
    padding-right: 2.5rem;
}

/* ============================================
   Alerts
   ============================================ */
.alert {
    padding: .75rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: .85rem;
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: .5rem;
}

.alert-error {
    background: rgba(255, 82, 82, .1);
    border: 1px solid rgba(255, 82, 82, .3);
    color: var(--r);
}

.alert-success {
    background: rgba(0, 230, 118, .1);
    border: 1px solid rgba(0, 230, 118, .3);
    color: var(--g);
}

.alert-warning {
    background: rgba(255, 209, 102, .1);
    border: 1px solid rgba(255, 209, 102, .3);
    color: var(--y);
}

.alert-info {
    background: rgba(0, 212, 255, .1);
    border: 1px solid rgba(0, 212, 255, .3);
    color: var(--c);
}

.alert-close {
    background: none;
    border: none;
    color: inherit;
    font-size: 1.2rem;
    cursor: pointer;
    margin-left: auto;
    line-height: 1;
}

#flash-container {
    position: fixed;
    bottom: calc(var(--nav-height) + 12px);
    left: 1rem;
    right: 1rem;
    z-index: 150;
    max-width: 600px;
    margin: 0 auto;
    pointer-events: none;
}

#flash-container .alert {
    pointer-events: auto;
    box-shadow: 0 4px 20px rgba(0,0,0,.5);
}

/* ============================================
   KPI Grid (Dashboard)
   ============================================ */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: .75rem;
    margin-bottom: 1rem;
}

.kpi-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
}

.kpi-value {
    font-family: 'Syne', sans-serif;
    font-weight: 700;
    font-size: 1.5rem;
    line-height: 1.2;
}

.kpi-label {
    font-size: .75rem;
    color: var(--text2);
    margin-top: .25rem;
}

.kpi-trend {
    font-size: .7rem;
    margin-top: .25rem;
    font-weight: 600;
}
.kpi-trend.up { color: var(--g); }
.kpi-trend.down { color: var(--r); }
.kpi-trend.neutral { color: var(--text3); }

/* ============================================
   Progress Bars
   ============================================ */
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg3);
    border-radius: 999px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 999px;
    transition: width .6s ease;
    background: linear-gradient(90deg, var(--o), var(--c));
}

/* ============================================
   Streak display
   ============================================ */
.streak-display {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-weight: 600;
}

.streak-fire {
    font-size: 1.5rem;
    animation: flicker 1.5s infinite alternate;
}

@keyframes flicker {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: .8; transform: scale(1.1); }
}

/* ============================================
   Chart containers
   ============================================ */
.chart-container {
    position: relative;
    width: 100%;
    height: 250px;
    margin: 1rem 0;
}

/* ============================================
   Timer (Entraînement)
   ============================================ */
.timer-display {
    text-align: center;
    padding: 2rem;
}

.timer-circle {
    width: 160px;
    height: 160px;
    border-radius: 50%;
    border: 4px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
    position: relative;
}

.timer-circle svg {
    position: absolute;
    transform: rotate(-90deg);
}

.timer-value {
    font-family: 'Syne', sans-serif;
    font-size: 2.5rem;
    font-weight: 700;
}

/* ============================================
   Tables
   ============================================ */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: .6rem .75rem;
    text-align: left;
    font-size: .85rem;
    border-bottom: 1px solid var(--border);
}

th {
    font-weight: 600;
    color: var(--text2);
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .05em;
}

/* ============================================
   Utilities
   ============================================ */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: .85rem; }
.text-xs { font-size: .75rem; }
.text-muted { color: var(--text2); }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.gap-1 { gap: .5rem; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; min-width: 0; }
.grid-2 > * { min-width: 0; overflow: hidden; }
@media (max-width: 400px) { .grid-2 { grid-template-columns: 1fr; } }
.w-full { width: 100%; }
.hidden { display: none !important; }

.color-o { color: var(--o); }
.color-c { color: var(--c); }
.color-g { color: var(--g); }
.color-p { color: var(--p); }
.color-y { color: var(--y); }
.color-r { color: var(--r); }
.color-teal { color: var(--teal); }

.bg-o { background: var(--o); }
.bg-c { background: var(--c); }
.bg-g { background: var(--g); }

/* Tags / Pills */
.pill {
    display: inline-flex;
    align-items: center;
    padding: .2rem .6rem;
    border-radius: 999px;
    font-size: .7rem;
    font-weight: 600;
}

/* Section headers */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: .75rem;
}

.section-title {
    font-family: 'Syne', sans-serif;
    font-weight: 600;
    font-size: 1.1rem;
}

/* Empty states */
.empty-state {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text3);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: .75rem;
    opacity: .5;
}

/* ============================================
   Responsive — tablette+
   ============================================ */
@media (min-width: 768px) {
    .app-main {
        max-width: 720px;
        padding: 1.5rem;
    }

    .kpi-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .more-menu-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ============================================
   Scrollbar custom
   ============================================ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ============================================
   PWA install prompt
   ============================================ */
.pwa-install-banner {
    position: fixed;
    bottom: calc(var(--nav-height) + 8px);
    left: 1rem;
    right: 1rem;
    background: var(--bg3);
    border: 1px solid var(--o);
    border-radius: var(--radius);
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: .75rem;
    z-index: 90;
    box-shadow: var(--shadow);
    max-width: 600px;
    margin: 0 auto;
}

/* ============================================
   Animations
   ============================================ */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.card {
    animation: fadeIn .3s ease;
}
