/* ── RESET & BASE ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; background: #0f172a; color: #f1f5f9; font-family: system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: 15px; overscroll-behavior: none; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }
::-webkit-scrollbar { display: none; }

/* ── SCREENS ──────────────────────────────────────────────────────────────── */
.screen { display: none; min-height: 100dvh; }
.screen.active { display: flex; flex-direction: column; }
#screen-app.active { padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px)); }

/* ── LOGIN ────────────────────────────────────────────────────────────────── */
#screen-login { background: linear-gradient(160deg, #0f172a 0%, #1e1b4b 100%); align-items: center; justify-content: center; padding: 24px; }
.login-wrap { width: 100%; max-width: 400px; }
.login-logo { text-align: center; margin-bottom: 32px; }
.logo-icon { font-size: 52px; margin-bottom: 12px; }
.login-logo h1 { font-size: 28px; font-weight: 900; letter-spacing: -1px; color: #f8fafc; }
.login-logo h1 span { color: #f59e0b; }
.login-logo p { color: #64748b; font-size: 13px; margin-top: 4px; }
.login-footer { text-align: center; color: #334155; font-size: 11px; margin-top: 20px; }

/* ── SETUP / START ────────────────────────────────────────────────────────── */
#screen-setup, #screen-start { background: #0f172a; padding: 24px; overflow-y: auto; }
.start-wrap { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 40px 20px; max-width: 440px; margin: 0 auto; }
.start-icon { font-size: 64px; margin-bottom: 20px; }
.start-wrap h2 { font-size: 26px; font-weight: 800; margin-bottom: 12px; }
.start-wrap p { color: #94a3b8; line-height: 1.6; }
.page-header { padding: 20px 20px 0; margin-bottom: 12px; }
.page-header h2 { font-size: 22px; font-weight: 800; }
.page-header p { color: #64748b; font-size: 13px; margin-top: 4px; }

/* ── CARDS ────────────────────────────────────────────────────────────────── */
.card { background: #1e293b; border: 1px solid #334155; border-radius: 14px; padding: 16px; margin-bottom: 12px; }
.card-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.card-title { font-weight: 700; font-size: 14px; color: #f1f5f9; margin-bottom: 10px; }
.section-title { font-weight: 700; font-size: 15px; color: #f1f5f9; margin-bottom: 12px; }

/* ── FIELDS ───────────────────────────────────────────────────────────────── */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: #94a3b8; font-weight: 600; margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.5px; }
.field-label { font-size: 10px; color: #64748b; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 3px; }
input[type="text"], input[type="password"], input[type="number"], input[type="email"], select, textarea {
  width: 100%; max-width: 100%; background: #0f172a; border: 1px solid #334155; border-radius: 10px;
  padding: 11px 14px; color: #f1f5f9; outline: none; transition: border-color .2s;
}
input:focus, select:focus, textarea:focus { border-color: #f59e0b; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748b' stroke-width='1.5' fill='none'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }
textarea { resize: vertical; min-height: 72px; font-family: inherit; line-height: 1.5; }
.input-sm { padding: 7px 10px; border-radius: 8px; font-size: 13px; }
.select-sm { padding: 7px 10px; border-radius: 8px; font-size: 13px; padding-right: 30px; background-size: 10px; }

/* ── BUTTONS ──────────────────────────────────────────────────────────────── */
.btn { display: block; width: 100%; padding: 13px; border: none; border-radius: 12px; font-weight: 700; cursor: pointer; font-size: 15px; text-align: center; transition: opacity .15s, transform .1s; }
.btn:active { transform: scale(0.98); opacity: 0.9; }
.btn-primary { background: #f59e0b; color: #000; }
.btn-secondary { background: #334155; color: #f1f5f9; }
.btn-danger { background: #7f1d1d; color: #fca5a5; }
.btn-ghost { background: transparent; color: #64748b; border: 1px solid #334155; }
.btn-sm { width: auto; display: inline-block; padding: 6px 14px; font-size: 12px; border-radius: 8px; }
.btn-xl { padding: 18px; font-size: 17px; }
.btn-icon { width: auto; display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; }

/* ── NAV ──────────────────────────────────────────────────────────────────── */
#app-nav { position: fixed; bottom: 0; left: 0; right: 0; background: #1e293b; border-top: 1px solid #334155; display: flex; padding: 6px 0; padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px)); z-index: 100; }
.nav-btn { flex: 1; background: none; border: none; color: #64748b; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; padding: 4px 0; transition: color .15s; }
.nav-btn.active { color: #f59e0b; }
.nav-icon { font-size: 20px; line-height: 1; }
.nav-btn span:last-child { font-size: 9px; font-weight: 600; }

/* ── PAGE LAYOUT ──────────────────────────────────────────────────────────── */
#app-content { flex: 1; overflow-y: auto; }
.page { padding: 16px 14px 8px; max-width: 520px; margin: 0 auto; }
.page-title { font-size: 22px; font-weight: 900; letter-spacing: -0.5px; margin-bottom: 16px; color: #f8fafc; }

/* ── PROGRESS BAR ─────────────────────────────────────────────────────────── */
.progress-bar { height: 8px; background: #334155; border-radius: 8px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, #16a34a, #4ade80); border-radius: 8px; transition: width .6s ease; }

/* ── BADGES ───────────────────────────────────────────────────────────────── */
.badge { background: #334155; color: #f1f5f9; border-radius: 20px; padding: 2px 10px; font-size: 12px; font-weight: 700; display: inline-block; }
.badge-amber { background: #78350f; color: #fcd34d; }
.badge-green { background: #14532d; color: #4ade80; }
.badge-blue { background: #1e3a5f; color: #60a5fa; }
.badge-red { background: #450a0a; color: #fca5a5; }
.cat-badge { border-radius: 6px; padding: 2px 7px; font-size: 10px; font-weight: 700; display: inline-block; }

/* ── ALERTS ───────────────────────────────────────────────────────────────── */
.alert { padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 10px; line-height: 1.5; }
.alert-danger { background: #450a0a; border: 1px solid #dc2626; color: #fca5a5; }
.alert-warning { background: #1c1408; border: 1px solid #d97706; color: #fcd34d; }
.alert-info { background: #0f172a; border: 1px solid #3b82f6; color: #93c5fd; }
.alert-success { background: #052e16; border: 1px solid #16a34a; color: #4ade80; }
.hidden { display: none !important; }

/* ── CHECKLIST ────────────────────────────────────────────────────────────── */
.check-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid #1e293b; cursor: pointer; font-size: 14px; }
.check-row:last-child { border-bottom: none; }
.check-box { width: 24px; height: 24px; border-radius: 7px; border: 2px solid #334155; background: transparent; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: all .15s; cursor: pointer; }
.check-box.checked { background: #4ade80; border-color: #4ade80; }
.check-box.checked::after { content: '✓'; color: #000; font-weight: 900; font-size: 14px; }
.check-label { flex: 1; }
.check-label.done { text-decoration: line-through; color: #475569; }

/* ── EXERCISE CARD ────────────────────────────────────────────────────────── */
.exercise-card { background: #1e293b; border: 1px solid #334155; border-radius: 12px; padding: 14px; margin-bottom: 10px; border-left: 3px solid #475569; }
.exercise-card.done { opacity: 0.55; }
.ex-muscle { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.ex-name { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.ex-detail { color: #64748b; font-size: 12px; }
.ex-check { width: 30px; height: 30px; border-radius: 8px; border: 2px solid #334155; background: transparent; display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; transition: all .15s; }
.ex-check.done { background: #4ade80; border-color: #4ade80; color: #000; font-weight: 900; }
.diff-row { display: flex; gap: 6px; margin-top: 10px; align-items: center; }
.diff-btn { background: transparent; border: 1px solid transparent; border-radius: 8px; padding: 3px 8px; cursor: pointer; font-size: 18px; transition: all .15s; }
.diff-btn.active { background: #334155; border-color: #475569; }

/* ── MENU GRID ────────────────────────────────────────────────────────────── */
.menu-line { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid #334155; font-size: 13px; }
.menu-line:last-child { border-bottom: none; }
.day-menu-card { border-left: 3px solid #475569; margin-bottom: 10px; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 8px; }
@media (min-width: 480px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

/* ── MACROS ───────────────────────────────────────────────────────────────── */
.macro-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.macro-pill { background: #334155; border-radius: 20px; padding: 3px 9px; font-size: 11px; color: #cbd5e1; }

/* ── FOOD CARD ────────────────────────────────────────────────────────────── */
.food-card { background: #1e293b; border: 1px solid #334155; border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; }

/* ── CHART SVG ────────────────────────────────────────────────────────────── */
.chart-wrap { width: 100%; overflow-x: auto; }
.chart-wrap svg { display: block; width: 100%; height: auto; }

/* ── TABS ─────────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tab-btn { flex: 1; padding: 9px; background: #334155; color: #94a3b8; border: none; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 13px; transition: all .15s; }
.tab-btn.active { background: #f59e0b; color: #000; }

/* ── ADMIN ────────────────────────────────────────────────────────────────── */
.admin-header { display: flex; justify-content: space-between; align-items: center; padding: 16px; border-bottom: 1px solid #334155; background: #1e293b; position: sticky; top: 0; z-index: 10; }
.admin-tabs { display: flex; border-bottom: 1px solid #334155; background: #1e293b; }
.admin-tab { flex: 1; padding: 12px; background: none; border: none; color: #64748b; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; transition: all .15s; }
.admin-tab.active { color: #f59e0b; border-bottom-color: #f59e0b; }
#admin-content { padding: 16px; overflow-y: auto; overflow-x: hidden; max-height: calc(100dvh - 120px); }

/* ── USER LIST ────────────────────────────────────────────────────────────── */
.user-card { background: #1e293b; border: 1px solid #334155; border-radius: 12px; padding: 14px; margin-bottom: 10px; }
.user-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.user-ecrou { font-weight: 800; font-size: 15px; }
.user-name { color: #94a3b8; font-size: 13px; }
.user-stats { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }

/* ── MUTED & UTILS ────────────────────────────────────────────────────────── */
.muted { color: #64748b; font-size: 12px; }
.text-amber { color: #f59e0b; }
.text-green { color: #4ade80; }
.text-blue { color: #60a5fa; }
.text-red { color: #f87171; }
.text-right { text-align: right; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; }
.note-box { background: #334155; border-radius: 10px; padding: 10px 12px; font-size: 12px; color: #cbd5e1; line-height: 1.6; margin-top: 8px; }
.spacer { height: 20px; }

/* ── MINI CALENDAR ────────────────────────────────────────────────────────── */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-header-cell { text-align: center; font-size: 10px; font-weight: 700; color: #64748b; padding-bottom: 4px; }
.cal-day { border-radius: 6px; padding: 4px 1px; font-size: 10px; text-align: center; cursor: pointer; border: 1px solid #1e293b; transition: all .1s; background: #1e293b; color: #94a3b8; }
.cal-day:hover { background: #334155; }
.cal-day.today { background: #1e3a5f; border-color: #3b82f6; color: #93c5fd; font-weight: 700; }
.cal-day.selected { background: #f59e0b; border-color: #f59e0b; color: #000; font-weight: 700; }
.cal-day.complete { background: #14532d; color: #4ade80; }
.cal-day.past { color: #475569; }

/* ── STAT BOXES ───────────────────────────────────────────────────────────── */
.stat-box { text-align: center; }
.stat-value { font-size: 26px; font-weight: 800; line-height: 1; }
.stat-label { font-size: 11px; color: #64748b; margin-top: 3px; }
.stats-row { display: flex; justify-content: space-around; padding: 8px 0; }

/* ── LOADER ───────────────────────────────────────────────────────────────── */
.loader { display: flex; align-items: center; justify-content: center; padding: 40px; color: #64748b; }
.loader::after { content: ''; width: 24px; height: 24px; border: 2px solid #334155; border-top-color: #f59e0b; border-radius: 50%; animation: spin .7s linear infinite; margin-left: 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── RESPONSIVE ───────────────────────────────────────────────────────────── */
@media (min-width: 520px) {
  .page { padding: 20px 20px 12px; }
  #screen-login { padding: 40px 24px; }
}

/* ── MOBILE FIXES iPhone ─────────────────────────────────────────────────── */
#screen-admin { display: none; flex-direction: column; min-height: 100dvh; overflow: hidden; }
#screen-admin.active { display: flex; }
#admin-content { padding: 14px; overflow-y: auto; overflow-x: hidden; flex: 1; -webkit-overflow-scrolling: touch; }

/* Tous les inputs/selects limités à la largeur du parent */
input, select, textarea { box-sizing: border-box; max-width: 100%; }

/* Boutons tactiles minimum 44px */
.btn-sm { min-height: 36px; }
.nav-btn { min-width: 44px; min-height: 44px; }

/* Empêcher le débordement horizontal global */
.page, #admin-content, .card { overflow-x: hidden; }

/* Fix select chevron sur mobile */
select { background-position: right 10px center; padding-right: 32px; }

/* Admin tabs plus grands sur mobile */
.admin-tab { padding: 14px 8px; font-size: 14px; }
.admin-header { padding: 14px 16px; }
.admin-header h2 { font-size: 18px; }

/* Semaine nav buttons alignés */
#admin-content .btn-sm { padding: 8px 14px; font-size: 13px; }

/* Cards dans admin sans overflow */
#admin-content .card, #admin-content > div { max-width: 100%; }


/* ── SAFE AREA iPhone — barre de statut fixe ─────────────────────────────── */
#status-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: env(safe-area-inset-top, 50px);
  background: #0f172a;
  z-index: 9999;
}
.screen.active {
  padding-top: env(safe-area-inset-top, 50px);
}
#screen-login.active {
  padding-top: calc(env(safe-area-inset-top, 50px) + 24px);
  background: linear-gradient(160deg, #0f172a 0%, #1e1b4b 100%);
}
#app-nav {
  padding-bottom: calc(env(safe-area-inset-bottom, 20px) + 6px) !important;
}
