/* ============================================================
   Tija Survey — Design System (refonte UI/UX)
   Vert pharma raffiné · cibles tactiles larges · wizard mobile
   Backend (server/domain/storage/surveys) non touché.
   ============================================================ */

:root {
  color-scheme: light;

  /* Palette */
  --bg: #f7f8f5;
  --bg-soft: #eef1ed;
  --surface: #ffffff;
  --surface-strong: #173f32;
  --surface-strong-2: #173f32;
  --text: #17211c;
  --text-soft: #3f4d46;
  --muted: #707a74;
  --line: #e3e7e2;
  --line-strong: #cbd5cf;

  --accent: #13795b;
  --accent-strong: #0f6048;
  --accent-soft: #eef7f2;
  --accent-ink: #124d3c;

  --gold: #a97920;
  --gold-soft: #fbf3df;
  --danger: #b23b2e;
  --danger-soft: #fbe7e3;
  --success: #0f8a5f;

  --radius-sm: 8px;
  --radius: 8px;
  --radius-lg: 10px;

  --shadow-sm: 0 1px 2px rgba(20, 32, 26, 0.06);
  --shadow: 0 6px 16px rgba(20, 32, 26, 0.08);
  --shadow-lg: 0 14px 32px rgba(20, 32, 26, 0.12);

  --tap: 50px;                    /* hauteur min cible tactile terrain */
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);

  font-family:
    "Inter", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 16px;
}

body, input, select, textarea, button {
  font: inherit;
  letter-spacing: 0;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { letter-spacing: 0; }

:focus-visible {
  outline: 3px solid rgba(15, 138, 95, 0.45);
  outline-offset: 2px;
}

/* ============================================================
   Layout shells
   ============================================================ */

.shell,
.dashboard-shell {
  width: min(1140px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 56px;
}

.mobile-shell {
  width: min(560px, 100%);
  margin: 0 auto;
  min-height: 100svh;
  padding: 0 0 82px;        /* place pour barre nav fixe du wizard */
}

/* ============================================================
   Brand mark
   ============================================================ */

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--text);
  text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand .mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent);
  box-shadow: none;
  font-size: 15px;
  color: #fff;
}
.brand .name { font-size: 1.05rem; }
.brand .name b { font-weight: inherit; }

/* ============================================================
   Home page
   ============================================================ */

.home-hero {
  position: relative;
  color: var(--text);
  padding: 18px 0 22px;
  border-bottom: 1px solid var(--line);
}
.home-hero .eyebrow { color: var(--accent); }
.home-hero h1 {
  margin: 6px 0 10px;
  font-size: clamp(1.42rem, 3.4vw, 2rem);
  font-weight: 700;
  line-height: 1.1;
  max-width: 560px;
}
.home-hero p {
  margin: 0;
  max-width: 520px;
  color: var(--muted);
  line-height: 1.6;
}

.survey-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 18px;
  margin-top: 22px;
}

.survey-card {
  display: flex;
  flex-direction: column;
  gap: 18px;
  justify-content: space-between;
  min-height: 190px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: none;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.survey-card:hover { border-color: var(--line-strong); box-shadow: none; }

.survey-card .eyebrow { margin: 0 0 8px; }
.survey-card h2 { margin: 0 0 8px; font-size: 1.25rem; font-weight: 700; }
.survey-card p { margin: 0; color: var(--muted); line-height: 1.55; }

.card-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ============================================================
   Buttons
   ============================================================ */

.button {
  display: inline-flex;
  min-height: var(--tap);
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.97rem;
  text-decoration: none;
  transition: transform 0.08s var(--ease), background 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.button:active { transform: scale(0.98); }
.button.primary { background: var(--accent); color: #fff; box-shadow: none; }
.button.primary:hover { background: var(--accent-strong); text-decoration: none; }
.button.secondary { background: var(--surface); color: var(--accent-ink); border-color: var(--line-strong); }
.button.secondary:hover { background: #f7faf8; text-decoration: none; }
.button.ghost { background: transparent; color: var(--muted); border-color: transparent; }
.button.ghost:hover { color: var(--text); text-decoration: none; }
.button.wide { width: 100%; }
.button:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }

.text-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  color: inherit;
  text-decoration: none;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--gold);
  font-size: 0.84rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

/* ============================================================
   WIZARD — Questionnaire terrain (refonte principale)
   ============================================================ */

.wizard-topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.97);
  color: var(--text);
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  box-shadow: none;
  backdrop-filter: saturate(160%) blur(8px);
}
.wizard-topbar .topbar-row {
  width: min(560px, 100%);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
.wizard-topbar .brand { font-size: 0.9rem; }
.wizard-topbar .brand .mark {
  width: 28px;
  height: 28px;
  font-size: 14px;
}
.wizard-topbar .brand .name { font-size: 1rem; }
.wizard-topbar .netbadge {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: var(--radius-sm);
  background: #f7faf8;
  border: 1px solid var(--line);
  color: var(--muted);
}
.wizard-topbar .netbadge .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); box-shadow: none;
}
.wizard-topbar .netbadge.off .dot { background: #d29922; box-shadow: 0 0 0 3px rgba(210, 153, 34, 0.25); }

.wizard-progress {
  width: min(560px, 100%);
  margin: 7px auto 0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.wizard-progress .track {
  flex: 1;
  height: 5px;
  border-radius: 999px;
  background: var(--bg-soft);
  overflow: hidden;
}
.wizard-progress .track .fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.35s var(--ease);
}
.wizard-progress .label { font-size: 0.8rem; font-weight: 600; color: var(--muted); white-space: nowrap; }

/* Steps */
.wizard-body {
  width: min(560px, 100%);
  margin: 14px auto 0;
  padding: 0 14px 18px;
}
.step {
  display: none;
  animation: stepIn 0.18s var(--ease);
}
.step.active { display: block; }
@keyframes stepIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.step-head { margin-bottom: 14px; }
.step-head .step-num {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--accent);
  background: transparent;
  padding: 0;
  border-radius: 0;
  margin-bottom: 7px;
}
.step-head h2 {
  margin: 0 0 6px;
  font-size: clamp(1.28rem, 5vw, 1.52rem);
  font-weight: 700;
  line-height: 1.15;
}
.step-head p { margin: 0; color: var(--muted); font-size: 0.95rem; line-height: 1.4; }

/* Form fields */
.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}
.field > span,
.choice-group legend,
.choice-stack legend {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-soft);
}
.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  min-height: var(--tap);
  padding: 11px 13px;
  outline: none;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.field input::placeholder, .field textarea::placeholder { color: #9aa49e; }
.field textarea { resize: vertical; line-height: 1.5; min-height: 96px; }
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(19, 121, 91, 0.12);
}

/* Choice cards (radio) — grosses cibles terrain */
.choice-group { border: 0; margin: 0 0 16px; padding: 0; }
.choice-group legend { margin-bottom: 9px; line-height: 1.35; }
.choice-group .legend-hint { font-size: 0.76rem; font-weight: 500; color: var(--muted); }

/* Branch hint : guide l'agent lors d'une clôture / parcours adaptatif */
.branch-hint {
  margin: 9px 0 13px;
  padding: 10px 11px;
  border-radius: var(--radius-sm);
  background: var(--gold-soft);
  border-left: 3px solid var(--gold);
  font-size: 0.86rem;
  color: #6b4f12;
  line-height: 1.45;
}

/* État invalide d'un groupe de choix */
.choice-group.invalid legend {
  color: var(--danger);
}
.choice-group.invalid .choices { outline: 2px dashed rgba(178, 59, 46, 0.35); outline-offset: 6px; border-radius: var(--radius-sm); }

.choices {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
@media (min-width: 300px) {
  .choices.two,
  .choices.compact { grid-template-columns: 1fr; }
}
@media (min-width: 480px) {
  .choices.two,
  .choices.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.choice { position: relative; }
.choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.choice span {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 10px 12px;
  font-size: 0.96rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s var(--ease), border-color 0.12s var(--ease);
}
.choice span::before {
  content: "";
  flex: 0 0 auto;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  background: var(--surface);
  transition: all 0.15s var(--ease);
}
.choice input:checked + span {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
  box-shadow: none;
}
.choice input:checked + span::before {
  border-color: var(--accent);
  background: radial-gradient(circle at center, var(--accent) 0 6px, transparent 7px);
  box-shadow: inset 0 0 0 4px #fff;
}
.choice input:focus-visible + span { outline: 3px solid rgba(15, 138, 95, 0.4); outline-offset: 2px; }

/* Checkboxes : marque carrée + coche */
.choice.check span::before { border-radius: 6px; width: 24px; height: 24px; }
.choices.compact .choice span,
.choices.two .choice span {
  min-height: 48px;
}
.choice.check input:checked + span::before {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: none;
  background-image: linear-gradient(45deg, transparent 40%, #fff 40% 47%, transparent 47%),
                   linear-gradient(-45deg, transparent 60%, #fff 60% 67%, transparent 67%);
  background-repeat: no-repeat;
  background-position: 5px 8px, 4px 11px;
  background-size: 6px 3px, 12px 3px;
}

/* Conditional blocks */
[data-conditional] { overflow: hidden; }

/* Wizard footer (sticky) */
.wizard-foot {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: saturate(160%) blur(8px);
  border-top: 1px solid var(--line);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}
.wizard-foot .foot-inner {
  width: min(560px, 100%);
  margin: 0 auto;
  display: flex;
  gap: 8px;
  align-items: center;
}
.wizard-foot .button { flex: 1; min-height: 52px; }
.wizard-foot .button.ghost { flex: 0 0 auto; min-width: 96px; padding-left: 8px; padding-right: 8px; }

#submit-status {
  width: min(560px, 100%);
  margin: 4px auto 0;
  min-height: 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
}
#submit-status:empty { display: none; }
#submit-status[data-tone="success"] { color: var(--accent-strong); }
#submit-status[data-tone="warning"] { color: var(--gold); }
#submit-status[data-tone="error"], .form-error { color: var(--danger); }

.hp-field { position: absolute; left: -9999px; }

/* Success screen */
.success-screen {
  display: none;
  width: min(560px, 100%);
  margin: 36px auto 0;
  padding: 0 14px;
  text-align: center;
}
.success-screen.active { display: block; animation: stepIn 0.3s var(--ease); }
.success-screen .check {
  width: 78px; height: 78px;
  margin: 0 auto 18px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 40px;
  box-shadow: none;
  animation: pop 0.4s var(--ease);
}
@keyframes pop { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.success-screen h2 { font-size: 1.6rem; font-weight: 700; margin: 0 0 8px; }
.success-screen p { color: var(--muted); margin: 0 0 22px; }
.success-screen .summary {
  display: inline-flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 auto 22px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: left;
  min-width: 260px;
}
.success-screen .summary div { display: flex; justify-content: space-between; gap: 16px; font-size: 0.92rem; }
.success-screen .summary span { color: var(--muted); }
.success-screen .summary b { font-weight: 700; color: var(--text); }

/* ============================================================
   DASHBOARD
   ============================================================ */

.dash-hero {
  background: transparent;
  color: var(--text);
  border-radius: 0;
  padding: 8px 0 14px;
  box-shadow: none;
  border-bottom: 1px solid var(--line);
}
.dash-hero .top { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.dash-hero .brand { color: var(--text); }
.dash-hero h1 {
  margin: 12px 0 6px;
  font-size: clamp(1.45rem, 4vw, 2.15rem);
  font-weight: 700;
  line-height: 1.1;
}
.dash-hero p { margin: 0; color: var(--muted); max-width: 560px; }

.dash-live {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 16px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent-ink);
  letter-spacing: 0;
  text-transform: none;
}
.dash-live .pulse {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent); position: relative;
}
.dash-live .pulse::after { content: none; }

.dashboard-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.dashboard-actions .button { min-height: 50px; padding: 11px 18px; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin: 18px 0;
}
.metric-card {
  position: relative;
  padding: 15px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: none;
  overflow: hidden;
}
.metric-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--accent);
}
.metric-card span { display: block; color: var(--muted); font-size: 0.82rem; font-weight: 600; }
.metric-card strong { display: block; margin-top: 5px; font-weight: 700; font-size: clamp(1.65rem, 4vw, 2.2rem); letter-spacing: 0; }

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}
.dashboard-grid .panel:last-child:nth-child(odd) { grid-column: 1 / -1; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: none;
  padding: 16px;
}
.panel h2 { margin: 0 0 16px; font-size: 1.02rem; font-weight: 700; }

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}
.panel-title-row h2 { margin: 0; }
.panel-title-row #last-updated { font-size: 0.78rem; }

.bar-list { display: grid; gap: 14px; }
.bar-row { display: grid; gap: 6px; }
.bar-meta { display: flex; justify-content: space-between; gap: 14px; font-size: 0.92rem; }
.bar-meta strong { font-weight: 700; }
.bar-track {
  height: 12px;
  border-radius: 999px;
  background: var(--bg-soft);
  overflow: hidden;
}
.bar-track span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.6s var(--ease);
}
.bar-row:nth-child(2n) .bar-track span { background: var(--gold); }

.lead-list { display: grid; gap: 10px; }
.lead-card {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: var(--surface);
  transition: border-color 0.15s var(--ease);
}
.lead-card:hover { border-color: var(--line-strong); }
.lead-card h3 { margin: 0 0 4px; font-size: 1.02rem; font-weight: 700; }
.lead-card p { margin: 0; font-size: 0.86rem; color: var(--text-soft); }
.lead-card p.muted { color: var(--muted); font-size: 0.82rem; margin-top: 3px; }
.lead-side { display: grid; gap: 3px; justify-items: end; min-width: 110px; text-align: right; }
.lead-side strong { color: var(--accent-strong); font-size: 1.45rem; font-weight: 700; }
.lead-side span { font-size: 0.82rem; color: var(--muted); }

.empty, .muted { color: var(--muted); }
.empty { font-size: 0.9rem; font-style: italic; }

/* ============================================================
   Login
   ============================================================ */

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 18px;
  background: var(--bg);
}
.login-card {
  width: min(420px, 100%);
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.login-card h1 { margin: 0 0 8px; font-size: 1.55rem; font-weight: 700; color: var(--text); }
.login-card p { color: var(--muted); margin: 0 0 18px; line-height: 1.55; }
.login-card .field { margin-top: 6px; }
.login-card .button { margin-top: 14px; }

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 820px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-hero .top { flex-direction: column; }
  .dashboard-actions { width: 100%; }
  .dashboard-actions .button { flex: 1; }
}

@media (max-width: 560px) {
  .shell, .dashboard-shell { width: min(100% - 20px, 1140px); padding-top: 10px; padding-bottom: 30px; }
  .home-hero { padding: 20px 0 22px; }
  .dash-hero { padding: 16px; }
  .dash-hero h1 { font-size: 1.45rem; line-height: 1.12; }
  .dash-hero p { font-size: 0.92rem; }
  .dash-live { margin-top: 12px; }
  .dashboard-actions { gap: 8px; }
  .dashboard-actions .button { min-height: 46px; padding: 9px 12px; font-size: 0.9rem; }
  .metric-grid { gap: 10px; margin: 12px 0; }
  .metric-card { padding: 12px; }
  .metric-card span { font-size: 0.76rem; }
  .metric-card strong { font-size: 1.65rem; margin-top: 3px; }
  .panel { padding: 13px; }
  .panel h2 { margin-bottom: 12px; font-size: 0.98rem; }
  .bar-list { gap: 11px; }
  .bar-meta { font-size: 0.87rem; }
  .bar-track { height: 10px; }
  .lead-card { flex-direction: column; align-items: stretch; }
  .lead-side { justify-items: start; text-align: left; }
  .lead-card h3 { font-size: 0.98rem; }
  .lead-card p { font-size: 0.82rem; }
}

@media (max-width: 360px) {
  .wizard-topbar { padding-left: 10px; padding-right: 10px; }
  .wizard-topbar .brand .name { font-size: 0.95rem; }
  .wizard-topbar .netbadge { font-size: 0.72rem; padding: 4px 8px; }
  .wizard-progress { gap: 8px; }
  .wizard-progress .label { font-size: 0.74rem; }
  .wizard-body { margin-top: 12px; padding-left: 12px; padding-right: 12px; }
  .step-head h2 { font-size: 1.24rem; }
  .step-head p,
  .field > span,
  .choice-group legend,
  .choice-stack legend { font-size: 0.9rem; }
  .choice span { font-size: 0.9rem; padding: 9px 10px; gap: 8px; }
  .choice span::before { width: 19px; height: 19px; }
  .wizard-foot .button.ghost { min-width: 86px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
