/* ════════════ DESIGN TOKENS ════════════ */
:root {
  /* Background — graphite profond */
  --bg-0: #0a0a0b;
  --bg-1: #131316;
  --bg-2: #1c1c21;
  --bg-3: #25252b;

  /* Accents — palette tech premium */
  --accent: #8b5cf6;        /* violet électrique - signature */
  --accent-2: #a78bfa;
  --green: #10b981;          /* émeraude - succès */
  --orange: #f59e0b;         /* ambre - attention */
  --red: #ef4444;            /* rouge */
  --blue: #3b82f6;           /* info */

  /* Text */
  --text: #f4f4f5;
  --text-2: #a1a1aa;
  --text-3: #71717a;
  --text-4: #52525b;

  /* Glass effects */
  --glass: rgba(255,255,255,.04);
  --glass-2: rgba(255,255,255,.06);
  --border: rgba(255,255,255,.08);
  --border-2: rgba(255,255,255,.12);

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0,0,0,.3);
  --shadow-md: 0 8px 24px rgba(0,0,0,.4);

  /* Radius */
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 24px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg-0);
  color: var(--text);
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
body {
  padding-bottom: 100px;
  background:
    radial-gradient(ellipse at top, rgba(139,92,246,.08) 0%, transparent 50%),
    radial-gradient(ellipse at bottom right, rgba(16,185,129,.04) 0%, transparent 50%),
    var(--bg-0);
  min-height: 100vh;
  background-attachment: fixed;
}

.mono { font-family: 'JetBrains Mono', 'SF Mono', Menlo, monospace; font-feature-settings: 'tnum'; }

/* ════════════ HEADER ════════════ */
.header {
  padding: 20px 20px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-3);
  letter-spacing: .8px;
  text-transform: uppercase;
}
.header-date {
  font-size: 13px;
  color: var(--text-3);
  text-transform: capitalize;
}
.greeting {
  padding: 0 20px 24px;
}
.greeting h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -.02em;
}
.greeting p {
  margin: 4px 0 0;
  color: var(--text-2);
  font-size: 14px;
}

/* ════════════ TABS (bottom) ════════════ */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(13,13,16,.85);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid var(--border);
  padding: 8px 0 calc(env(safe-area-inset-bottom) + 8px);
  display: flex;
  z-index: 100;
}
.tab {
  flex: 1;
  background: none;
  border: none;
  padding: 8px 4px;
  color: var(--text-3);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: color .2s;
}
.tab .icon {
  font-size: 22px;
  line-height: 1;
  transition: transform .2s;
}
.tab.active { color: var(--accent-2); }
.tab.active .icon { transform: scale(1.1); }
.tab:active { opacity: .6; }

/* ════════════ PANELS ════════════ */
.panel { display: none; padding: 0 20px; }
.panel.active { display: block; animation: fadein .3s; }
@keyframes fadein {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ════════════ CARDS ════════════ */
.card {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 18px;
  margin-bottom: 14px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.card-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-title .badge-mini {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--bg-3);
  color: var(--text-2);
  font-weight: 500;
  letter-spacing: .3px;
}

/* ════════════ HERO RING (anneau central de progression) ════════════ */
.hero-card {
  background: linear-gradient(135deg, rgba(139,92,246,.12) 0%, rgba(139,92,246,.02) 100%);
  border: 1px solid rgba(139,92,246,.2);
  border-radius: var(--r-lg);
  padding: 24px 20px;
  margin-bottom: 14px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.hero-card::before {
  content: '';
  position: absolute;
  top: -50%; right: -50%;
  width: 200%; height: 200%;
  background: radial-gradient(circle, rgba(139,92,246,.08) 0%, transparent 30%);
  pointer-events: none;
}
.ring-wrap {
  position: relative;
  width: 200px;
  height: 200px;
  margin: 0 auto 16px;
}
.ring-wrap svg { transform: rotate(-90deg); width: 100%; height: 100%; }
.ring-bg { fill: none; stroke: var(--bg-3); stroke-width: 14; }
.ring-fg {
  fill: none; stroke: url(#ringGrad);
  stroke-width: 14; stroke-linecap: round;
  transition: stroke-dashoffset 1s cubic-bezier(.4,0,.2,1);
  filter: drop-shadow(0 0 8px rgba(139,92,246,.4));
}
.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.ring-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 38px;
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1;
}
.ring-unit {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 6px;
  letter-spacing: .5px;
  text-transform: uppercase;
}
.ring-pct {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-2);
  margin-top: 4px;
}
.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  position: relative;
}
.hero-stat {
  text-align: center;
  padding: 10px 4px;
}
.hero-stat-label {
  font-size: 10px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .8px;
  margin-bottom: 4px;
}
.hero-stat-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 17px;
  font-weight: 600;
}
.hero-stat-value.green { color: var(--green); }
.hero-stat-value.red { color: var(--red); }

/* ════════════ MINI RINGS (3 anneaux quotidiens) ════════════ */
.mini-rings {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.mini-ring-card {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 8px;
  text-align: center;
  cursor: pointer;
  transition: transform .15s, border-color .15s;
}
.mini-ring-card:active { transform: scale(.97); }
.mini-ring-card.active { border-color: rgba(139,92,246,.3); background: rgba(139,92,246,.05); }
.mini-ring {
  width: 64px; height: 64px;
  margin: 0 auto 8px;
  position: relative;
}
.mini-ring svg { transform: rotate(-90deg); width: 100%; height: 100%; }
.mini-ring .bg-circle { fill: none; stroke: var(--bg-3); stroke-width: 6; }
.mini-ring .fg-circle {
  fill: none; stroke-width: 6; stroke-linecap: round;
  transition: stroke-dashoffset .8s cubic-bezier(.4,0,.2,1);
}
.mini-ring-center {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.mini-ring-label {
  font-size: 10px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 2px;
}
.mini-ring-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  font-weight: 600;
}

/* ════════════ QUICK ACTIONS ════════════ */
.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.qa-btn {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 16px 14px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: all .15s;
}
.qa-btn:active { transform: scale(.97); background: var(--glass-2); }
.qa-btn .qa-icon {
  font-size: 22px;
  line-height: 1;
}
.qa-btn .qa-text {
  flex: 1;
}
.qa-btn .qa-sub {
  display: block;
  font-size: 11px;
  color: var(--text-3);
  margin-top: 2px;
}

/* ════════════ INPUTS ════════════ */
input, select, textarea, button {
  font-family: inherit;
  font-size: 15px;
}
input[type=number], input[type=text], input[type=date], input[type=password], select, textarea {
  width: 100%;
  padding: 14px;
  min-height: 48px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--r-sm);
  -webkit-appearance: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}
label {
  display: block;
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: .8px;
  text-transform: uppercase;
  margin-bottom: 6px;
  font-weight: 500;
}
.form-row { margin-bottom: 12px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

button.btn {
  width: 100%;
  padding: 14px;
  min-height: 48px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--r-sm);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: .3px;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
}
button.btn:active { transform: scale(.98); }
button.btn.ghost {
  background: var(--glass);
  border: 1px solid var(--border);
  color: var(--text);
}
button.btn.danger { background: var(--red); }
button.btn.small { padding: 10px; min-height: 40px; font-size: 13px; }

/* ════════════ CHIPS (sélection rapide) ════════════ */
.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.chip {
  padding: 8px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
}
.chip:active, .chip.active {
  background: rgba(139,92,246,.15);
  border-color: var(--accent);
  color: var(--accent-2);
}

/* ════════════ STEPPERS (+/− pour saisie rapide) ════════════ */
.stepper {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-2);
  border-radius: var(--r-sm);
  padding: 6px;
  border: 1px solid var(--border);
}
.stepper button {
  width: 44px; height: 44px;
  border: none;
  background: var(--bg-3);
  color: var(--text);
  border-radius: 8px;
  font-size: 22px;
  font-weight: 600;
  cursor: pointer;
}
.stepper button:active { background: var(--accent); }
.stepper-value {
  flex: 1;
  text-align: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 18px;
  font-weight: 600;
}

/* ════════════ LISTS ════════════ */
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.list-item .li-icon {
  width: 36px; height: 36px;
  background: var(--bg-3);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.list-item .li-content { flex: 1; min-width: 0; }
.list-item .li-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}
.list-item .li-sub {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 2px;
}
.list-item .li-action {
  flex-shrink: 0;
  color: var(--text-3);
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
}

/* ════════════ ALERTS / INSIGHTS ════════════ */
.insight {
  padding: 14px 16px;
  border-radius: var(--r-md);
  margin-bottom: 10px;
  font-size: 13px;
  line-height: 1.5;
  border: 1px solid transparent;
  display: flex;
  gap: 12px;
}
.insight-icon { flex-shrink: 0; font-size: 18px; line-height: 1.2; }
.insight-content { flex: 1; }
.insight-content b { font-weight: 600; }
.insight.info { background: rgba(59,130,246,.08); border-color: rgba(59,130,246,.2); color: #93c5fd; }
.insight.success { background: rgba(16,185,129,.08); border-color: rgba(16,185,129,.2); color: #6ee7b7; }
.insight.warn { background: rgba(245,158,11,.08); border-color: rgba(245,158,11,.2); color: #fcd34d; }
.insight.danger { background: rgba(239,68,68,.08); border-color: rgba(239,68,68,.2); color: #fca5a5; }

/* ════════════ MODAL (overlay glass) ════════════ */
.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 200;
  display: none;
  align-items: flex-end;
  justify-content: center;
  animation: fadein .2s;
}
.modal-bg.active { display: flex; }
.modal {
  background: var(--bg-1);
  border-top: 1px solid var(--border-2);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px 20px calc(env(safe-area-inset-bottom) + 24px);
  animation: slideup .3s cubic-bezier(.4,0,.2,1);
}
@keyframes slideup {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-handle {
  width: 36px; height: 4px;
  background: var(--bg-3);
  border-radius: 2px;
  margin: 0 auto 16px;
}
.modal-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 16px;
}
.modal-close {
  position: absolute;
  top: 16px; right: 16px;
  width: 32px; height: 32px;
  background: var(--bg-3);
  border: none;
  border-radius: 50%;
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
}

/* ════════════ SECTIONS ════════════ */
.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 24px 4px 10px;
}

/* ════════════ EMPTY STATE ════════════ */
.empty {
  text-align: center;
  padding: 32px 20px;
  color: var(--text-3);
  font-size: 13px;
}
.empty-icon { font-size: 36px; margin-bottom: 12px; opacity: .5; }

/* ════════════ CHART WRAPPERS ════════════ */
/* Contrainte de hauteur fixe — Chart.js lit la hauteur du parent en responsive:true */
.chart-wrap    { height: 220px; position: relative; width: 100%; }
.chart-wrap-sm { height: 160px; }

/* ════════════ MISC ════════════ */
canvas { max-width: 100%; }
.text-muted { color: var(--text-3); }
.text-mono { font-family: 'JetBrains Mono', monospace; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
::placeholder { color: var(--text-4); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stack-12 > * + * { margin-top: 12px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }

/* ════════════ WEIGHT STEPPER ════════════ */
.weight-stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin: 20px 0 8px;
}
.stepper-btn {
  width: 60px; height: 60px;
  border: none;
  border-radius: 16px;
  font-size: 28px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  transition: transform .1s cubic-bezier(.4,0,.2,1), opacity .1s;
  user-select: none;
  -webkit-user-select: none;
  flex-shrink: 0;
}
.stepper-btn:active { transform: scale(.9); }
.stepper-btn.minus { background: var(--bg-3); }
.stepper-btn.plus  { background: var(--accent); }
.weight-value {
  font-size: 56px;
  font-weight: 700;
  color: var(--accent-2);
  letter-spacing: -.02em;
  min-width: 130px;
  text-align: center;
  user-select: none;
  -webkit-user-select: none;
  line-height: 1;
}
.weight-date-toggle {
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 8px;
  font-family: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ════════════ TOAST SYSTEM ════════════ */
#toast-container {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 90px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  animation: toast-in 250ms cubic-bezier(.4,0,.2,1) both;
}
.toast.out { animation: toast-out 250ms cubic-bezier(.4,0,.6,1) both; }
.toast.success {
  background: rgba(16,185,129,.95);
  color: #fff;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.toast.error {
  background: rgba(239,68,68,.95);
  color: #fff;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.toast.info {
  background: var(--glass-2);
  border: 1px solid var(--border-2);
  color: var(--text);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

/* ════════════ ANIMATIONS ════════════ */
@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px) scale(.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(12px) scale(.95); }
}
@keyframes hero-pulse {
  0%   { filter: drop-shadow(0 0 8px rgba(139,92,246,.4)); }
  40%  { filter: drop-shadow(0 0 24px rgba(139,92,246,1)); }
  100% { filter: drop-shadow(0 0 8px rgba(139,92,246,.4)); }
}

/* ════════════ PHOTO IA — Phase 3 ════════════ */

/* États */
.photo-states { position: relative; }
.photo-state  { display: none; }
.photo-state.active { display: block; }

/* Upload hint */
.photo-upload-hint {
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
  padding: 12px 16px;
  background: var(--bg-2);
  border-radius: var(--r-sm);
  border: 1px dashed var(--border-2);
}

/* Skeleton shimmer */
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}
.skeleton {
  background: linear-gradient(90deg, var(--bg-2) 25%, var(--bg-3) 50%, var(--bg-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: var(--r-sm);
  margin-bottom: 10px;
}
.skeleton-title  { height: 18px; width: 65%; }
.skeleton-row    { height: 44px; width: 100%; }
.skeleton-row.short { width: 50%; }
.skeleton-macros { height: 88px; width: 100%; border-radius: var(--r-md); margin-top: 6px; }

/* Confidence badges */
.confidence-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  white-space: nowrap;
}
.confidence-badge.haute   { background: rgba(16,185,129,.15); color: var(--green); }
.confidence-badge.moyenne { background: rgba(245,158,11,.15);  color: var(--orange); }
.confidence-badge.faible  { background: rgba(239,68,68,.15);   color: var(--red); }

/* Element row */
.element-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}
.element-row:last-child { border-bottom: none; }
.element-info  { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.element-name  { font-size: 14px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.element-portion { font-size: 11px; color: var(--text-3); }
.element-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.element-kcal  { font-size: 13px; font-weight: 600; color: var(--text-2); }

/* Invisible section (native details) */
.invisible-section {
  margin: 10px 0;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
}
.invisible-section summary {
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text-3);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  list-style: none;
  background: var(--bg-2);
}
.invisible-section summary::-webkit-details-marker { display: none; }
.invisible-section[open] summary { border-bottom: 1px solid var(--border); }
.invisible-section > div { padding: 4px 12px 8px; }

/* Action buttons column */
.action-buttons { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

/* Multi-photo previews */
.photo-previews {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.photo-preview {
  position: relative;
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-2);
}
.photo-preview img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.photo-preview-remove {
  position: absolute;
  top: 4px; right: 4px;
  width: 24px; height: 24px;
  background: rgba(0,0,0,.75);
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.photo-count-info {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 8px;
  text-align: center;
}

/* Precise textarea */
.precise-textarea {
  width: 100%;
  min-height: 96px;
  padding: 14px;
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
  outline: none;
}
.precise-textarea:focus { border-color: var(--accent); }
