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

:root {
  --c-bg:        #0f1117;
  --c-surface:   #1a1d27;
  --c-border:    #2a2d3a;
  --c-text:      #e2e8f0;
  --c-muted:     #8892a4;
  --c-accent:    #6366f1;
  --c-accent-l:  #818cf8;
  --c-success:   #22c55e;
  --c-warn:      #f59e0b;
  --c-danger:    #ef4444;
  --c-hot:       #f97316;
  --c-cold:      #60a5fa;
  --radius:      8px;
  --shadow:      0 2px 8px rgba(0,0,0,.4);
  --sidebar-w:   220px;
  --header-h:    56px;
  --font:        'Inter', system-ui, -apple-system, sans-serif;
}

html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--c-bg);
  color: var(--c-text);
  line-height: 1.6;
  min-height: 100vh;
}

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

/* ─── Layout ───────────────────────────────────────────────── */
#app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: 1.2rem 1rem;
  font-weight: 700;
  font-size: 1.05rem;
  border-bottom: 1px solid var(--c-border);
  color: var(--c-text);
}
.sidebar-logo span { color: var(--c-accent-l); }

.sidebar-nav { flex: 1; padding: .5rem 0; overflow-y: auto; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .55rem 1rem;
  color: var(--c-muted);
  font-size: .875rem;
  border-radius: var(--radius);
  margin: 0 .4rem;
  transition: background .15s, color .15s;
}
.sidebar-nav a:hover, .sidebar-nav a.active {
  background: rgba(99,102,241,.12);
  color: var(--c-text);
  text-decoration: none;
}
.sidebar-nav a.active { color: var(--c-accent-l); }

.sidebar-footer {
  padding: 1rem;
  font-size: .8rem;
  color: var(--c-muted);
  border-top: 1px solid var(--c-border);
}

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--header-h);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title { font-weight: 600; font-size: 1rem; }
.topbar-right { display: flex; align-items: center; gap: 1rem; }

.view-content { padding: 1.5rem; flex: 1; }

/* ─── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--c-muted);
  margin-bottom: .75rem;
}

/* ─── KPI Grid ─────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.kpi-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
.kpi-label { font-size: .75rem; color: var(--c-muted); margin-bottom: .25rem; }
.kpi-value { font-size: 1.8rem; font-weight: 700; line-height: 1; }
.kpi-delta { font-size: .75rem; margin-top: .3rem; }
.kpi-delta.up { color: var(--c-success); }
.kpi-delta.down { color: var(--c-danger); }

/* ─── Sections ─────────────────────────────────────────────── */
.section-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* ─── Score Ring (SVG) ─────────────────────────────────────── */
.score-ring-wrap { display: inline-flex; flex-direction: column; align-items: center; gap: .4rem; }
.score-ring-label { font-size: .75rem; color: var(--c-muted); }

/* ─── Badges ───────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .2rem .6rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge-new       { background: #1e293b; color: #94a3b8; }
.badge-contacted { background: #1e3a5f; color: #60a5fa; }
.badge-qualified { background: #1c3728; color: #4ade80; }
.badge-hot       { background: #3d1f04; color: #f97316; }
.badge-appointment { background: #2d1f5e; color: #a78bfa; }
.badge-proposal  { background: #3b2a00; color: #fbbf24; }
.badge-won       { background: #14532d; color: #86efac; }
.badge-lost      { background: #450a0a; color: #fca5a5; }
.badge-critical  { background: #450a0a; color: #fca5a5; }
.badge-high      { background: #3d1f04; color: #f97316; }
.badge-medium    { background: #1c3728; color: #4ade80; }
.badge-low       { background: #1a1d27; color: #94a3b8; }

/* ─── Timeline ─────────────────────────────────────────────── */
.timeline { list-style: none; }
.timeline li {
  display: flex;
  gap: .75rem;
  padding: .5rem 0;
  border-left: 2px solid var(--c-border);
  padding-left: 1rem;
  position: relative;
  font-size: .85rem;
}
.timeline li::before {
  content: '';
  position: absolute;
  left: -5px; top: .9rem;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--c-accent);
}
.timeline-date { color: var(--c-muted); min-width: 100px; }

/* ─── Table ────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.data-table th {
  text-align: left;
  padding: .6rem .75rem;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--c-muted);
  border-bottom: 1px solid var(--c-border);
}
.data-table td {
  padding: .65rem .75rem;
  border-bottom: 1px solid rgba(255,255,255,.05);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(255,255,255,.02); }

/* ─── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .45rem .9rem;
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: opacity .15s, background .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--c-accent); color: #fff; }
.btn-primary:hover { opacity: .85; }
.btn-ghost { background: transparent; border-color: var(--c-border); color: var(--c-text); }
.btn-ghost:hover { background: rgba(255,255,255,.05); }
.btn-sm { padding: .3rem .7rem; font-size: .78rem; }

/* ─── Loading / Empty ──────────────────────────────────────── */
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--c-border);
  border-top-color: var(--c-accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--c-muted);
}
.empty-state h3 { margin-bottom: .5rem; color: var(--c-text); }

/* ─── Alert / Banner ───────────────────────────────────────── */
.alert {
  border-radius: var(--radius);
  padding: .75rem 1rem;
  font-size: .875rem;
  border: 1px solid;
  margin-bottom: 1rem;
}
.alert-warn { background: #2d200a; border-color: #78350f; color: #fbbf24; }
.alert-info { background: #0f1e3d; border-color: #1e3a5f; color: #93c5fd; }
.alert-error { background: #1f0a0a; border-color: #7f1d1d; color: #fca5a5; }

/* ─── Score Components ─────────────────────────────────────── */
.score-components { display: flex; flex-direction: column; gap: .5rem; }
.score-bar-row { display: flex; align-items: center; gap: .75rem; font-size: .82rem; }
.score-bar-label { min-width: 100px; color: var(--c-muted); }
.score-bar-track {
  flex: 1; height: 6px;
  background: var(--c-border);
  border-radius: 999px;
  overflow: hidden;
}
.score-bar-fill {
  height: 100%;
  background: var(--c-accent);
  border-radius: 999px;
  transition: width .4s ease;
}
.score-bar-value { min-width: 42px; text-align: right; font-weight: 600; }

/* ─── Misc ─────────────────────────────────────────────────── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.gap-1 { gap: .5rem; }
.gap-2 { gap: 1rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.text-muted { color: var(--c-muted); }
.text-sm { font-size: .85rem; }
.font-bold { font-weight: 700; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .section-grid { grid-template-columns: 1fr; }
}

/* ─── Phase 2: Status badges ───────────────────────────────── */
.badge-DRAFT              { background: #1e293b; color: #94a3b8; }
.badge-PENDING_APPROVAL   { background: #2d200a; color: #fbbf24; }
.badge-APPROVED           { background: #1c3728; color: #4ade80; }
.badge-REJECTED           { background: #450a0a; color: #fca5a5; }
.badge-EXPIRED            { background: #1a1d27; color: #64748b; }
.badge-EXECUTED           { background: #0f2d1c; color: #34d399; }
.badge-FAILED             { background: #450a0a; color: #f87171; }
.badge-draft              { background: #1e293b; color: #94a3b8; }
.badge-finalized          { background: #1c3728; color: #4ade80; }
.badge-archived           { background: #1a1d27; color: #64748b; }

/* Risk level badges */
.badge-risk-low      { background: #1c3728; color: #4ade80; }
.badge-risk-medium   { background: #2d200a; color: #fbbf24; }
.badge-risk-high     { background: #3d1f04; color: #f97316; }
.badge-risk-critical { background: #450a0a; color: #fca5a5; }

/* ─── Modal overlay ────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}
.modal {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: calc(var(--radius) * 1.5);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--c-border);
}
.modal-title { font-weight: 600; font-size: 1rem; }
.modal-close {
  background: none;
  border: none;
  color: var(--c-muted);
  cursor: pointer;
  font-size: 1.4rem;
  line-height: 1;
  padding: .2rem;
}
.modal-close:hover { color: var(--c-text); }
.modal-body { padding: 1.25rem; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: .75rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--c-border);
}

/* ─── Toast notifications ──────────────────────────────────── */
#toast-root {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  pointer-events: none;
}
.toast {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  font-size: .875rem;
  min-width: 260px;
  max-width: 380px;
  pointer-events: auto;
  box-shadow: var(--shadow);
  animation: toast-in .2s ease;
}
@keyframes toast-in {
  from { transform: translateX(120%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
.toast-success { border-left: 3px solid var(--c-success); }
.toast-error   { border-left: 3px solid var(--c-danger);  }
.toast-warn    { border-left: 3px solid var(--c-warn);    }
.toast-info    { border-left: 3px solid var(--c-accent);  }

/* ─── Tabs ─────────────────────────────────────────────────── */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--c-border); margin-bottom: 1.5rem; }
.tab-btn {
  padding: .6rem 1.1rem;
  font-size: .875rem;
  font-weight: 500;
  color: var(--c-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--c-text); }
.tab-btn.active { color: var(--c-accent-l); border-bottom-color: var(--c-accent); }
.tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--c-accent);
  color: #fff;
  font-size: .68rem;
  font-weight: 700;
  margin-left: .35rem;
  padding: 0 .3rem;
}

/* ─── Form controls ────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-label {
  display: block;
  font-size: .8rem;
  color: var(--c-muted);
  margin-bottom: .35rem;
  font-weight: 500;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  color: var(--c-text);
  padding: .45rem .75rem;
  border-radius: var(--radius);
  font-size: .875rem;
  font-family: var(--font);
  transition: border-color .15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--c-accent);
}
.form-textarea { resize: vertical; min-height: 80px; line-height: 1.5; }

/* ─── Diff viewer ──────────────────────────────────────────── */
.diff-viewer { font-family: monospace; font-size: .82rem; line-height: 1.6; }
.diff-added   { background: rgba(34,197,94,.12);  color: #4ade80; }
.diff-removed { background: rgba(239,68,68,.12);  color: #fca5a5; }

/* ─── Approval action buttons ──────────────────────────────── */
.btn-approve { background: #166534; color: #4ade80; border-color: #166534; }
.btn-approve:hover { background: #15803d; }
.btn-reject  { background: #7f1d1d; color: #fca5a5; border-color: #7f1d1d; }
.btn-reject:hover  { background: #991b1b; }
.btn-execute { background: #1e3a5f; color: #60a5fa; border-color: #1e3a5f; }
.btn-execute:hover { background: #1e40af; }
.btn-danger  { background: var(--c-danger); color: #fff; }
.btn-danger:hover { opacity: .85; }
.btn-success { background: var(--c-success); color: #fff; }
.btn-success:hover { opacity: .85; }

/* ─── Timeline Phase 2 (vertical approval steps) ──────────── */
.approval-timeline { list-style: none; padding: 0; }
.approval-timeline li {
  display: flex;
  gap: 1rem;
  padding: .65rem 0;
  position: relative;
}
.approval-timeline li + li::before {
  content: '';
  position: absolute;
  left: 8px; top: -8px;
  width: 2px; height: 8px;
  background: var(--c-border);
}
.at-dot {
  width: 18px; height: 18px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: .2rem;
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem;
}
.at-dot-created  { background: var(--c-border);   color: var(--c-muted); }
.at-dot-submit   { background: #2d200a;            color: var(--c-warn);  }
.at-dot-approve  { background: #1c3728;            color: var(--c-success); }
.at-dot-reject   { background: #450a0a;            color: var(--c-danger);  }
.at-dot-execute  { background: #0f2d1c;            color: #34d399; }
.at-dot-expire   { background: #1a1d27;            color: var(--c-muted); }
.at-dot-fail     { background: #450a0a;            color: var(--c-danger); }
.at-content { flex: 1; }
.at-action  { font-weight: 600; font-size: .85rem; }
.at-meta    { font-size: .78rem; color: var(--c-muted); margin-top: .15rem; }

/* =============================================================================
   Phase AA4 — Interactive AI Coach + Simulation Mode
   ============================================================================= */

/* ── Coach: spotlight overlay + highlighted target ──────────────────────── */
.coach-dim {
  position: fixed; inset: 0; z-index: 1400; display: none;
  background: rgba(6, 8, 15, 0.55); pointer-events: none;  /* never blocks the real click */
}
.coach-highlight {
  position: relative; z-index: 1450 !important;
  outline: 3px solid var(--c-accent-l, #818cf8) !important;
  outline-offset: 3px; border-radius: 6px;
  box-shadow: 0 0 0 3px rgba(129, 140, 248, .35), 0 0 22px 6px rgba(99, 102, 241, .55) !important;
  animation: coach-pulse 1.4s ease-in-out infinite;
}
@keyframes coach-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(129, 140, 248, .35), 0 0 18px 4px rgba(99, 102, 241, .45); }
  50%      { box-shadow: 0 0 0 4px rgba(129, 140, 248, .55), 0 0 30px 10px rgba(99, 102, 241, .7); }
}

/* ── Coach: guidance panel (bottom-left, above everything) ───────────────── */
.coach-panel {
  position: fixed; left: 1.25rem; bottom: 1.25rem; z-index: 1500;
  width: 360px; max-width: calc(100vw - 2.5rem); max-height: 78vh; overflow-y: auto;
  background: var(--c-surface, #1a1d27); color: var(--c-text, #e2e8f0);
  border: 1px solid var(--c-border, #2a2d3a); border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .55); font-size: .88rem;
}
.coach-head { display: flex; align-items: center; gap: .5rem; padding: .7rem .9rem; border-bottom: 1px solid var(--c-border, #2a2d3a); }
.coach-badge { background: var(--c-accent, #6366f1); color: #fff; font-size: .62rem; font-weight: 700; letter-spacing: .08em; padding: .15rem .4rem; border-radius: 4px; }
.coach-x { margin-left: auto; background: transparent; border: none; color: var(--c-muted, #8892a4); cursor: pointer; font-size: 1rem; }
.coach-progress { height: 6px; background: #11141d; border-radius: 3px; overflow: hidden; }
.coach-progress-bar { height: 100%; background: var(--c-accent, #6366f1); transition: width .3s ease; }
.coach-meta { padding: .4rem .9rem; color: var(--c-muted, #8892a4); font-size: .78rem; }
.coach-step { padding: 0 .9rem .8rem; }
.coach-step-title { font-weight: 700; margin-bottom: .3rem; }
.coach-step-body { line-height: 1.45; }
.coach-why, .coach-expect { margin-top: .5rem; font-size: .82rem; color: var(--c-muted, #8892a4); }
.coach-warn { margin-top: .5rem; font-size: .82rem; }
.coach-warn ul { margin: .2rem 0 0 1.1rem; }
.coach-ph { margin-top: .5rem; padding: .4rem; border: 1px dashed var(--c-border, #2a2d3a); border-radius: 6px; color: var(--c-muted, #8892a4); font-size: .75rem; }
.coach-wait { margin-top: .6rem; font-size: .8rem; color: var(--c-accent-l, #818cf8); }
.coach-recovery { margin-top: .6rem; padding: .5rem; border-left: 3px solid var(--c-warn, #f59e0b); background: rgba(245, 158, 11, .08); border-radius: 4px; font-size: .8rem; }
.coach-recovery-how { margin-top: .3rem; color: var(--c-muted, #8892a4); }
.coach-actions { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; padding: .6rem .9rem; border-top: 1px solid var(--c-border, #2a2d3a); }
.coach-link { font-size: .8rem; color: var(--c-accent-l, #818cf8); }
.coach-btn { margin-left: auto; background: var(--c-accent, #6366f1); color: #fff; border: none; border-radius: 8px; padding: .4rem .8rem; cursor: pointer; font-size: .82rem; }
.coach-btn-ghost { background: transparent; color: var(--c-text, #e2e8f0); border: 1px solid var(--c-border, #2a2d3a); border-radius: 8px; padding: .35rem .7rem; cursor: pointer; font-size: .8rem; }

/* ── Simulation Mode: banner, badge, sandbox theme ──────────────────────── */
#sim-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1300;
  background: repeating-linear-gradient(45deg, #0e7490, #0e7490 12px, #0c6478 12px, #0c6478 24px);
  color: #ecfeff; text-align: center; font-size: .82rem; padding: .4rem 1rem; letter-spacing: .01em;
}
#sim-banner a { color: #fff; text-decoration: underline; font-weight: 600; }
body.sim-active { padding-top: 2rem; }               /* make room for the banner */
body.sim-active .sidebar-logo::after {
  content: "SIM"; margin-left: .4rem; background: #0e7490; color: #ecfeff;
  font-size: .55rem; font-weight: 700; padding: .1rem .3rem; border-radius: 3px; letter-spacing: .06em;
}
.sim-chip {
  background: #0e7490; color: #ecfeff; font-size: .62rem; font-weight: 700; letter-spacing: .08em;
  padding: .18rem .45rem; border-radius: 4px;
}
.sim-explainer {
  background: rgba(14, 116, 144, .12); border: 1px solid #0e7490; border-radius: 8px;
  padding: .7rem .9rem; margin-bottom: 1rem; font-size: .86rem; line-height: 1.45;
}

/* Light-theme fallbacks (the app is dark by default; keep AA4 legible either way) */
@media (prefers-color-scheme: light) {
  .coach-dim { background: rgba(15, 23, 42, .28); }
}

/* ─── DESIGN-07.1 — filtre par prospect des opérations agents ──────────────
   `.main-content` est un élément flex (`flex: 1`) : son `min-width: auto`
   implicite le fait grandir jusqu'à la largeur intrinsèque de son contenu,
   si bien qu'un `overflow-x: auto` intérieur ne contient rien et que la page
   entière défile horizontalement. La règle est portée par `:has()` pour ne
   viser QUE l'écran filtré : corriger `.main-content` globalement toucherait
   les quarante-sept écrans hérités, ce que cette phase n'autorise pas. */
.main-content:has(#aoc-prospect-tasks) { min-width: 0; }
