:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f242e;
  --border: #2a303d;
  --text: #eef1f6;
  --muted: #9aa4b5;
  --primary: #6c7cff;
  --primary-hover: #5a6bf5;
  --danger: #ef4444;
  --gmail: #ea4335;
  --instagram: #e1306c;
  --high: #f97316;
  --med: #eab308;
  --low: #22c55e;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a {
  color: #93a3ff;
}

code {
  background: #252b38;
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.85em;
}

.app {
  max-width: 1360px;
  margin: 0 auto;
  padding: 16px 20px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 100vh;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6c7cff, #e1306c);
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 700;
}

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-mvp {
  font-size: 0.7rem;
  background: #262e45;
  color: #a9b7ff;
  padding: 2px 7px;
  border-radius: 99px;
  font-weight: 600;
}

.subtitle {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.status-pills {
  display: flex;
  gap: 6px;
  margin-right: 4px;
}

.pill {
  font-size: 0.76rem;
  padding: 4px 10px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #556075;
}

.pill.ok {
  color: #dcfce7;
  border-color: #215137;
  background: #13281d;
}

.pill.ok .dot {
  background: #22c55e;
}

.btn {
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 8px 14px;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  transition: 0.15s ease;
  color: var(--text);
  background: var(--surface-2);
}

.btn:hover:not(:disabled) {
  filter: brightness(1.1);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-secondary {
  background: var(--surface-2);
  border-color: var(--border);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}

.btn-danger {
  background: #3a191d;
  border-color: #6b242c;
  color: #fca5a5;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.8rem;
}

.banner {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.88rem;
  border: 1px solid var(--border);
  background: #1b2235;
}

.banner.error {
  background: #33171b;
  border-color: #7f2530;
  color: #fecaca;
}

.banner.success {
  background: #12291d;
  border-color: #235c3d;
  color: #bbf7d0;
}

.hidden {
  display: none !important;
}

.brief-card {
  background: linear-gradient(135deg, rgba(108, 124, 255, 0.11), rgba(225, 48, 108, 0.06));
  border: 1px solid #303a57;
  border-radius: var(--radius);
  padding: 14px 18px;
}

.brief-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.brief-header span {
  margin-left: 8px;
  font-size: 0.8rem;
}

.brief-body {
  font-size: 0.9rem;
  white-space: pre-wrap;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.78rem;
}

.workspace {
  display: grid;
  grid-template-columns: 370px 1fr;
  gap: 14px;
  flex: 1;
  min-height: 540px;
}

.sidebar,
.detail-pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.filters {
  display: flex;
  gap: 6px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.filter-chip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  border-radius: 99px;
  padding: 5px 10px;
  font-size: 0.78rem;
  cursor: pointer;
}

.filter-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.thread-list {
  overflow-y: auto;
  flex: 1;
}

.thread-item {
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}

.thread-item:hover {
  background: #1c212b;
}

.thread-item.active {
  background: #232a3b;
  border-left: 3px solid var(--primary);
}

.thread-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.thread-meta-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.btn-delete-item {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0 4px;
  font-size: 0.85rem;
  line-height: 1;
  border-radius: 4px;
  opacity: 0.35;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}

.thread-item:hover .btn-delete-item {
  opacity: 0.75;
}

.btn-delete-item:hover {
  opacity: 1 !important;
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.2);
}

.sidebar-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px 4px;
}

.btn-clear-inbox {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 3px 7px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.btn-clear-inbox:hover {
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.3);
  background: rgba(239, 68, 68, 0.12);
}

.detail-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.btn-delete-detail {
  color: #fca5a5 !important;
  border-color: rgba(239, 68, 68, 0.3) !important;
}

.btn-delete-detail:hover {
  background: rgba(239, 68, 68, 0.18) !important;
  border-color: #ef4444 !important;
  color: #fff !important;
}

.thread-sender {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-time {
  font-size: 0.74rem;
  color: var(--muted);
  flex-shrink: 0;
}

.thread-subject {
  font-size: 0.83rem;
  color: #d4dae6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-snippet {
  font-size: 0.79rem;
  color: var(--muted);
  margin-top: 3px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tags-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 7px;
}

.tag {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
}

.tag-gmail {
  background: rgba(234, 67, 53, 0.16);
  color: #ff9c94;
}

.tag-instagram {
  background: rgba(225, 48, 108, 0.18);
  color: #ff9dc0;
}

.tag-cat {
  background: #252c3b;
  color: #c9d4ea;
}

.tag-prio-haute {
  background: rgba(249, 115, 22, 0.2);
  color: #fdba74;
}

.tag-prio-moyenne {
  background: rgba(234, 179, 8, 0.18);
  color: #fde047;
}

.tag-prio-basse {
  background: rgba(148, 163, 184, 0.16);
  color: #cbd5e1;
}

.tag-status-a_traiter {
  background: rgba(234, 179, 8, 0.18);
  color: #fde047;
  border: 1px solid rgba(234, 179, 8, 0.35);
}

.tag-status-en_attente {
  background: rgba(59, 130, 246, 0.18);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.35);
}

.tag-status-termine {
  background: rgba(34, 197, 94, 0.18);
  color: #86efac;
  border: 1px solid rgba(34, 197, 94, 0.35);
}

.status-select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: #e2e8f0;
  font-size: 0.8rem;
  padding: 5px 9px;
  border-radius: 6px;
  cursor: pointer;
  outline: none;
  font-family: inherit;
}

.status-select:focus {
  border-color: var(--primary);
}

.detail-pane {
  padding: 18px 22px;
  overflow-y: auto;
}

.empty-state {
  margin: auto;
  text-align: center;
  max-width: 460px;
  padding: 24px;
}

.empty-icon {
  font-size: 42px;
  margin-bottom: 10px;
}

.empty-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.detail-header h2 {
  margin: 0 0 4px;
  font-size: 1.15rem;
}

.ai-summary-box {
  margin: 14px 0;
  padding: 14px 16px;
  border-radius: 10px;
  background: #1b2133;
  border: 1px solid #323e60;
}

.ai-summary-box h3 {
  margin: 0 0 6px;
  font-size: 0.9rem;
  color: #b7c3ff;
}

.ai-next-step {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #2b3552;
  font-size: 0.85rem;
  color: #d6f5df;
}

.messages-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}

.msg-bubble {
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.msg-bubble.outbound {
  background: #1b2538;
  border-color: #2b3b5a;
}

.msg-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.msg-text {
  font-size: 0.9rem;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header,
.modal-footer {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.modal-footer {
  border-bottom: none;
  border-top: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1rem;
}

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.config-block {
  padding: 14px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.config-block h3 {
  margin: 0 0 8px;
  font-size: 0.92rem;
}

.block-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.help-text {
  margin: 0 0 10px;
  font-size: 0.81rem;
  color: var(--muted);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 8px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: #cbd5e1;
}

input,
select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #12151b;
  color: var(--text);
  font-size: 0.85rem;
}

.token-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.block-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.inline-badge {
  font-size: 0.74rem;
  color: #86efac;
  font-weight: 600;
}

.advanced-details {
  margin-top: 10px;
  font-size: 0.82rem;
  color: var(--muted);
}

.onboarding-steps-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 20px 0 24px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  text-align: left;
}

.step-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.step-num {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.8rem;
}

.filters-section {
  margin-bottom: 12px;
}

.filter-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
}

.filters-row {
  display: flex;
  gap: 8px;
}

.filter-select {
  flex: 1;
  padding: 6px 8px;
  font-size: 0.78rem;
  background: var(--surface-2);
  border-radius: 6px;
}

.badge-active {
  color: #86efac;
  background: rgba(34, 197, 94, 0.15);
  padding: 2px 8px;
  border-radius: 99px;
}

.ai-status-card {
  border-left: 3px solid var(--primary);
}

.ai-reply-box {
  background: #171d29;
  border: 1px solid #2f3b52;
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 14px;
}

.ai-reply-box h3 {
  margin: 0 0 10px 0;
  font-size: 0.92rem;
  color: #a5b4fc;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.reply-textarea {
  width: 100%;
  min-height: 110px;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #3b4559;
  background: #0d1017;
  color: var(--text);
  font-family: inherit;
  font-size: 0.88rem;
  line-height: 1.5;
  resize: vertical;
}

.reply-textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.reply-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 10px;
}

/* --- Animations & État de réflexion IA pour le photographe --- */
@keyframes pulseGlow {
  0% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.45); }
  70% { box-shadow: 0 0 0 10px rgba(99, 102, 241, 0); }
  100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0); }
}

@keyframes spinSlow {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes shimmerWave {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.ai-thinking-hud {
  margin: 14px 0 16px;
  padding: 14px 18px;
  background: linear-gradient(135deg, #181d2e 0%, #1a2238 100%);
  border: 1px solid #4f46e5;
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(79, 70, 229, 0.18);
  transition: all 0.3s ease;
}

.thinking-hud-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.thinking-hud-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.thinking-glow-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(99, 102, 241, 0.18);
  border: 1px solid rgba(129, 140, 248, 0.35);
  color: #c7d2fe;
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 0.78rem;
  font-weight: 600;
}

.thinking-pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #818cf8;
  animation: pulseGlow 1.6s infinite;
}

.thinking-hud-status {
  font-size: 0.88rem;
  color: #e2e8f0;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 24px;
}

.thinking-progress-track {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 99px;
  overflow: hidden;
  position: relative;
}

.thinking-progress-bar {
  height: 100%;
  width: 15%;
  background: linear-gradient(90deg, #6366f1, #a855f7, #ec4899);
  border-radius: 99px;
  transition: width 0.4s ease;
  background-size: 200% 100%;
  animation: shimmerWave 2s linear infinite;
}

/* Inline thinking indicator (cartes de détail, brief, réponses) */
.ai-thinking-inline,
.reply-thinking-box,
.brief-thinking-box {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: rgba(99, 102, 241, 0.08);
  border: 1px dashed rgba(129, 140, 248, 0.4);
  border-radius: var(--radius);
  margin: 10px 0;
}

.thinking-pulse-ring {
  width: 22px;
  height: 22px;
  border: 3px solid rgba(129, 140, 248, 0.25);
  border-top-color: #818cf8;
  border-radius: 50%;
  flex-shrink: 0;
  animation: spinSlow 0.85s linear infinite;
}

@media (max-width: 860px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .sidebar {
    max-height: 360px;
  }
  .form-row {
    grid-template-columns: 1fr;
  }
}
