/* ============================================================
   MENSURA — Design Sporty & Énergie
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=DM+Mono:wght@400;500&display=swap');

/* --- Tokens ------------------------------------------------- */
:root {
  /* Brand */
  --primary:       #7C3AED;
  --primary-dark:  #5B21B6;
  --primary-light: #A78BFA;
  --primary-soft:  #EDE9FE;

  /* Energy */
  --energy:        #F97316;
  --energy-dark:   #EA580C;
  --energy-soft:   #FFF7ED;

  /* Semantic */
  --success:       #10B981;
  --success-soft:  #ECFDF5;
  --warning:       #F59E0B;
  --warning-soft:  #FFFBEB;
  --danger:        #EF4444;
  --danger-soft:   #FEF2F2;

  /* Neutral */
  --bg:            #F5F3FF;
  --surface:       #FFFFFF;
  --border:        #EDE9FE;
  --border-strong: #C4B5FD;

  /* Text */
  --text-primary:   #1E1B4B;
  --text-secondary: #4B5563;
  --text-muted:     #9CA3AF;

  /* Gradients */
  --gradient-brand:  linear-gradient(135deg, #4F46E5 0%, #7C3AED 100%);
  --gradient-hero:   linear-gradient(160deg, #312E81 0%, #4F46E5 40%, #7C3AED 80%, #A855F7 100%);

  /* Radius */
  --radius-sm: 8px;
  --radius:    14px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  /* Shadow */
  --shadow-sm:      0 1px 4px rgba(124,58,237,0.08);
  --shadow:         0 4px 20px rgba(124,58,237,0.12);
  --shadow-lg:      0 8px 32px rgba(124,58,237,0.18);
  --shadow-primary: 0 4px 20px rgba(124,58,237,0.4);

  /* Font */
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'DM Mono', 'Courier New', monospace;

  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  height: 100%;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  overscroll-behavior: none;
}

/* --- Screens ----------------------------------------------- */
.screen {
  display: none;
  flex-direction: column;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom, 16px);
}
.screen.active { display: flex; }

/* --- Top Bar ----------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}
.topbar-sub {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-top: 1px;
}
.topbar-logo {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ============================================================
   HOME SCREEN
   ============================================================ */

/* Hero */
.home-hero {
  background: var(--gradient-hero);
  padding: 20px 20px 30px;
  color: white;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}
.home-hero::before {
  content: '';
  position: absolute;
  top: -60px; right: -60px;
  width: 220px; height: 220px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  pointer-events: none;
}
.home-hero::after {
  content: '';
  position: absolute;
  bottom: -80px; left: -50px;
  width: 200px; height: 200px;
  border-radius: 50%;
  background: rgba(255,255,255,0.04);
  pointer-events: none;
}
.home-hero-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.home-hero-brand {
  font-size: 15px;
  font-weight: 700;
  color: rgba(255,255,255,0.85);
  letter-spacing: 0.02em;
}
.home-hero-greeting {
  font-size: 23px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.025em;
  margin-bottom: 6px;
}
.home-hero-sub {
  font-size: 12px;
  color: rgba(255,255,255,0.65);
  font-family: var(--font-mono);
}

/* Sync badge sur fond hero */
.home-hero .sync-badge {
  background: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.9);
  border: 1px solid rgba(255,255,255,0.2);
}
.home-hero .sync-badge.ok    { background: rgba(16,185,129,0.25); border-color: rgba(16,185,129,0.4); }
.home-hero .sync-badge.error { background: rgba(239,68,68,0.25);  border-color: rgba(239,68,68,0.4); }

/* Home content */
.home-content {
  padding: 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Recap Card */
.recap-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}
.recap-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.recap-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.recap-switch {
  display: flex;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}
.recap-switch button {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
  transition: var(--transition);
  font-family: var(--font-body);
}
.recap-switch button.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 8px rgba(124,58,237,0.3);
}

.recap-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.recap-item {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  border: 1px solid transparent;
  transition: var(--transition);
}
.recap-item.has-positive { background: var(--success-soft); border-color: rgba(16,185,129,0.2); }
.recap-item.has-negative { background: var(--danger-soft);  border-color: rgba(239,68,68,0.15); }

.recap-label {
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.recap-value {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
}
.recap-value.positive { color: var(--success); }
.recap-value.negative { color: var(--danger); }
.recap-value.neutral  { color: var(--text-muted); }

/* Buttons */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--gradient-brand);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 17px 24px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font-body);
  letter-spacing: -0.01em;
  box-shadow: var(--shadow-primary);
  transition: var(--transition);
  width: 100%;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary:active {
  transform: scale(0.97);
  box-shadow: 0 2px 8px rgba(124,58,237,0.3);
}

.btn-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--surface);
  color: var(--primary);
  border: 2px solid var(--primary-soft);
  border-radius: var(--radius);
  padding: 15px 24px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-body);
  transition: var(--transition);
  width: 100%;
  -webkit-tap-highlight-color: transparent;
}
.btn-secondary:active { background: var(--primary-soft); }

/* Session Info (draft) */
.session-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--energy-soft);
  border-radius: var(--radius);
  border: 1px solid rgba(249,115,22,0.25);
  cursor: pointer;
}
.session-info-icon { font-size: 16px; }
.session-info-text { font-size: 13px; color: var(--energy); font-weight: 600; }

/* Sync status */
.sync-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 600;
}
.sync-badge.ok      { background: var(--success-soft); color: var(--success); }
.sync-badge.pending { background: var(--warning-soft); color: var(--warning); }
.sync-badge.error   { background: var(--danger-soft);  color: var(--danger); }
.sync-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ============================================================
   SAISIE SCREEN
   ============================================================ */

.saisie-progress {
  padding: 14px 20px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.progress-steps {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}
.progress-step {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  transition: background var(--transition);
}
.progress-step.done    { background: var(--success); }
.progress-step.current { background: var(--primary); }
.progress-step.skipped { background: var(--border-strong); }

.progress-label {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-weight: 500;
}

/* Silhouette */
.silhouette-zone {
  display: flex;
  justify-content: center;
  padding: 16px 20px 8px;
  background: var(--surface);
}
.silhouette-wrap {
  position: relative;
  width: 110px;
  height: 220px;
}
.silhouette-wrap svg { width: 100%; height: 100%; }

/* Saisie card */
.saisie-card {
  background: var(--surface);
  margin: 12px 16px 0;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.saisie-card-header {
  padding: 14px 20px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.saisie-measure-name {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--primary);
}
.saisie-measure-unit {
  font-size: 14px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* Display value */
.saisie-display {
  padding: 16px 20px 12px;
  text-align: center;
  background: var(--primary-soft);
}
.saisie-value {
  font-family: var(--font-mono);
  font-size: 56px;
  font-weight: 500;
  letter-spacing: -0.04em;
  color: var(--primary);
  min-height: 68px;
  line-height: 1.2;
}
.saisie-value.empty { color: var(--border-strong); }
.saisie-unit-label {
  font-size: 14px;
  color: var(--primary-light);
  margin-top: -4px;
}

/* Numpad */
.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--border);
}
.numpad-key {
  background: var(--surface);
  border: none;
  padding: 0;
  height: 72px;
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--transition);
  user-select: none;
}
.numpad-key:active { background: var(--primary-soft); color: var(--primary); }
.numpad-key.key-del { font-size: 20px; color: var(--text-secondary); }
.numpad-key.key-dot { font-size: 30px; }

/* Saisie nav */
.saisie-nav {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
}
.btn-nav {
  flex: 1;
  height: 52px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-secondary);
  -webkit-tap-highlight-color: transparent;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn-nav:active { background: var(--bg); }
.btn-nav.btn-next {
  background: var(--gradient-brand);
  border-color: transparent;
  color: white;
  box-shadow: var(--shadow-primary);
}
.btn-nav.btn-next:active { opacity: 0.9; box-shadow: none; }
.btn-nav.btn-skip {
  border-style: dashed;
  color: var(--text-muted);
  flex: 0 0 auto;
  padding: 0 16px;
  font-size: 13px;
}

/* ============================================================
   CONFIRMATION SCREEN
   ============================================================ */

.confirm-content {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}
.confirm-title {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 4px;
}
.confirm-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-bottom: 20px;
}
.confirm-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.confirm-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}
.confirm-row:last-child { border-bottom: none; }
.confirm-row-label { font-size: 14px; color: var(--text-secondary); }
.confirm-row-value {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 500;
  color: var(--primary);
}
.confirm-row-value.skipped { color: var(--text-muted); font-size: 13px; font-family: var(--font-body); }

.confirm-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 0 20px;
}

/* Sending overlay */
.sending-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(245,243,255,0.92);
  backdrop-filter: blur(6px);
  z-index: 100;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.sending-overlay.active { display: flex; }
.sending-spinner {
  width: 44px;
  height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.sending-text { font-size: 15px; color: var(--primary); font-weight: 600; }

/* ============================================================
   GRAPHS SCREEN
   ============================================================ */

.graphs-content {
  padding: 16px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.view-toggle {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  padding: 3px;
  gap: 3px;
}
.view-toggle button {
  flex: 1;
  padding: 10px 6px;
  border: none;
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-body);
  color: var(--text-muted);
  transition: var(--transition);
  border-radius: calc(var(--radius) - 3px);
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.view-toggle button.active {
  background: var(--gradient-brand);
  color: white;
  box-shadow: var(--shadow-primary);
}

/* Measure tabs */
.measure-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.measure-tabs::-webkit-scrollbar { display: none; }
.measure-tab {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-body);
  color: var(--text-secondary);
  -webkit-tap-highlight-color: transparent;
  transition: var(--transition);
  white-space: nowrap;
}
.measure-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  box-shadow: 0 2px 10px rgba(124,58,237,0.3);
}

/* Chart card */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 16px 16px;
  box-shadow: var(--shadow-sm);
}
.chart-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
}
.chart-card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}
.chart-card-stats { text-align: right; }
.chart-stat-main {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 500;
}
.chart-stat-main.positive { color: var(--success); }
.chart-stat-main.negative { color: var(--danger); }
.chart-stat-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

canvas.chart-canvas { width: 100% !important; }

/* Global chart legend */
.global-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.global-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
}
.global-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Table */
.data-table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  padding: 10px 12px;
  text-align: left;
  background: var(--primary-soft);
  font-weight: 700;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 13px;
  white-space: nowrap;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table td.date-cell {
  font-weight: 600;
  font-family: var(--font-body);
  color: var(--primary);
  font-size: 12px;
}
.data-table td.empty-cell { color: var(--border-strong); }

/* ============================================================
   CONFIG SCREEN
   ============================================================ */

.config-content {
  padding: 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.config-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.config-row {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.config-row:last-child { border-bottom: none; }
.config-row label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--primary);
  margin-bottom: 6px;
}
.config-input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font-mono);
  color: var(--text-primary);
  background: var(--bg);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.config-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.1);
}
.config-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.5;
}

/* ============================================================
   BOTTOM NAV
   ============================================================ */
.bottom-nav {
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  position: sticky;
  bottom: 0;
  z-index: 10;
}
.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 8px 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  transition: color var(--transition);
}
.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-icon { font-size: 20px; line-height: 1; }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  gap: 12px;
}
.empty-icon  { font-size: 40px; opacity: 0.5; }
.empty-title { font-size: 16px; font-weight: 700; color: var(--text-secondary); }
.empty-sub   { font-size: 13px; color: var(--text-muted); line-height: 1.5; }

/* ============================================================
   LOGIN SCREEN
   ============================================================ */
.screen-login {
  background: var(--gradient-hero);
  justify-content: flex-end;
  min-height: 100dvh;
}
.login-content {
  width: 100%;
  background: var(--bg);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: 32px 24px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}
.login-hero { text-align: center; padding: 8px 0; }
.login-logo-icon { font-size: 48px; margin-bottom: 10px; }
.login-logo-title {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--text-primary);
}
.login-logo-tagline {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.5;
}
.login-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
}
.login-card-title { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }
.login-card-sub   { font-size: 13px; color: var(--text-secondary); line-height: 1.6; }
.login-google-btn-wrap {
  display: flex;
  justify-content: center;
  width: 100%;
  margin-top: 8px;
}
.login-config-link {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  width: 100%;
  cursor: pointer;
}
.login-config-link span { color: var(--primary); text-decoration: underline; }

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text-primary);
  color: white;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 200;
  white-space: nowrap;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
