/* ══════════════════════════════════════════════
   GSA AI — Feuille de style principale
   ══════════════════════════════════════════════ */

/* ── Variables ── */
:root {
  --primary: #0078d4;
  --primary-dark: #005a9e;
  --secondary: #50e6ff;
  --bg: #0f1117;
  --bg2: #1a1d27;
  --bg3: #252836;
  --surface: #2d3148;
  --border: #3d4168;
  --text: #e8eaf6;
  --text-muted: #9ea3c0;
  --success: #13a10e;
  --error: #c50f1f;
  --warning: #f7630c;
  --radius: 10px;
  --shadow: 0 4px 20px rgba(0,0,0,0.4);
}

/* ── Reset ── */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
body.page-chat {
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

/* ── Header ── */
header {
  background: linear-gradient(135deg, #0046a8 0%, #0078d4 60%, #50e6ff33 100%);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow);
}
header .logo {
  width: 42px; height: 42px;
  background: white;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.15s ease;
}
header .logo:hover {
  transform: scale(1.1);
}
header h1 { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.01em; }
header p { font-size: 0.82rem; color: rgba(255,255,255,0.75); }

.badge {
  margin-left: auto;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 20px;
  padding: 0.25rem 0.8rem;
  font-size: 0.75rem;
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.header-actions .badge { margin-left: 0; }

.user-info {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.8);
}
.logout-btn {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 6px;
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  color: rgba(255,255,255,0.85);
  cursor: pointer;
  transition: background 0.2s;
}
.logout-btn:hover {
  background: rgba(255,255,255,0.25);
}

/* ── Layout ── */
.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── Panel gauche ── */
.sidebar {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  flex: 1;
  padding: 0.75rem 0.5rem;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  transition: all .2s;
}
.tab-btn.active {
  color: var(--secondary);
  border-bottom-color: var(--secondary);
}
.tab-content { display: none; flex: 1; overflow-y: auto; padding: 1rem; }
.tab-content.active { display: flex; flex-direction: column; gap: 0.75rem; }

/* ── Formulaires ── */
label { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 2px; display: block; }
input, select, textarea {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.55rem 0.75rem;
  font-size: 0.88rem;
  outline: none;
  transition: border-color .2s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 80px; font-family: inherit; }
select option { background: var(--bg3); }
.form-row { display: flex; gap: 0.5rem; }
.form-row > * { flex: 1; }

/* ── Boutons ── */
btn, .btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all .2s;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--error); color: white; }
.btn-danger:hover { opacity: 0.85; }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { opacity: 0.85; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.78rem; }
.btn-full { width: 100%; justify-content: center; }

/* ── Agent cards ── */
.agent-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  cursor: pointer;
  transition: all .2s;
}
.agent-card:hover { border-color: var(--primary); }
.agent-card.selected { border-color: var(--secondary); background: var(--surface); }
.agent-card h3 { font-size: 0.9rem; margin-bottom: 2px; }
.agent-card .meta { font-size: 0.75rem; color: var(--text-muted); }
.agent-card .actions { display: flex; gap: 0.4rem; margin-top: 0.5rem; }

.status-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 4px;
}
.status-created { background: var(--text-muted); }
.status-running { background: var(--warning); animation: pulse 1s infinite; }
.status-completed { background: var(--success); }
.status-failed { background: var(--error); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

/* ── File list ── */
.file-item {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.file-icon { font-size: 1.2rem; }
.file-info { flex: 1; }
.file-info .name { font-size: 0.85rem; word-break: break-all; }
.file-info .size { font-size: 0.72rem; color: var(--text-muted); }

/* ── Zone de chat ── */
.chat-area {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
  min-height: 0;
}
.chat-header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chat-header h2 { font-size: 1rem; }
.chat-header .meta { font-size: 0.8rem; color: var(--text-muted); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  color: var(--text-muted);
  text-align: center;
}
.empty-state .icon { font-size: 4rem; opacity: 0.3; }

.message {
  max-width: 80%;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.message.user { align-self: flex-end; align-items: flex-end; }
.message.assistant { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 0.75rem 1rem;
  border-radius: 16px;
  line-height: 1.55;
  font-size: 0.9rem;
  word-break: break-word;
}
.message.user .bubble {
  white-space: pre-wrap;
  background: var(--primary);
  border-bottom-right-radius: 4px;
}
.message.assistant .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* ── Markdown inside bubbles ── */
.bubble p { margin: 0 0 0.5em; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 0.3em 0 0.5em 1.2em; padding: 0; }
.bubble li { margin-bottom: 0.2em; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 {
  margin: 0.6em 0 0.3em;
  line-height: 1.3;
}
.bubble h1 { font-size: 1.2em; }
.bubble h2 { font-size: 1.1em; }
.bubble h3 { font-size: 1.0em; }
.bubble code {
  background: rgba(0,0,0,0.25);
  padding: 0.15em 0.35em;
  border-radius: 4px;
  font-size: 0.85em;
  font-family: 'Cascadia Code', 'Fira Code', monospace;
}
.bubble pre {
  background: rgba(0,0,0,0.3);
  border-radius: 8px;
  padding: 0.8em 1em;
  overflow-x: auto;
  margin: 0.5em 0;
}
.bubble pre code {
  background: none;
  padding: 0;
  font-size: 0.82em;
  line-height: 1.5;
}
.bubble blockquote {
  border-left: 3px solid var(--primary);
  margin: 0.5em 0;
  padding: 0.3em 0.8em;
  color: var(--text-muted);
}
.bubble table {
  border-collapse: collapse;
  margin: 0.5em 0;
  width: 100%;
  font-size: 0.85em;
}
.bubble th, .bubble td {
  border: 1px solid var(--border);
  padding: 0.4em 0.6em;
  text-align: left;
}
.bubble th { background: rgba(0,0,0,0.2); font-weight: 600; }
.bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.8em 0;
}
.bubble a { color: var(--secondary); text-decoration: underline; }
.bubble strong { font-weight: 600; }
.bubble img { max-width: 100%; border-radius: 6px; }

.message .time { font-size: 0.7rem; color: var(--text-muted); }
.message-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}
.usage-badge {
  font-size: 0.7rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.15rem 0.6rem;
  color: var(--text-muted);
}
.context-badge {
  background: rgba(0,120,212,0.15);
  border-color: rgba(0,120,212,0.3);
  color: var(--secondary);
}

/* ── Create agent file selector ── */
.create-files-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  max-height: 150px;
  overflow-y: auto;
  padding: 0.3rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  margin-bottom: 0.5rem;
}
.create-file-check {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s;
}
.create-file-check:hover { background: var(--bg3); }
.create-file-check input[type="checkbox"] {
  accent-color: var(--primary);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}
.create-file-icon { font-size: 1rem; }
.create-file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.create-file-size { font-size: 0.72rem; color: var(--text-muted); flex-shrink: 0; }

/* ── Input zone ── */
.input-area {
  border-top: 1px solid var(--border);
  padding: 1rem 1.5rem;
  background: var(--bg2);
}
.input-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
}
.input-row textarea {
  flex: 1;
  min-height: 56px;
  max-height: 200px;
}

/* ── Upload zone ── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--primary);
  background: rgba(0,120,212,0.05);
}
.upload-zone .icon { font-size: 2rem; margin-bottom: 0.5rem; }
.upload-zone p { font-size: 0.82rem; color: var(--text-muted); }

/* ── Notifications ── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 600;
  z-index: 9999;
  box-shadow: var(--shadow);
  animation: slidein .3s ease;
}
@keyframes slidein { from{transform:translateX(100%);opacity:0} to{transform:none;opacity:1} }
.toast.success { background: var(--success); color: white; }
.toast.error { background: var(--error); color: white; }
.toast.info { background: var(--primary); color: white; }

/* ── Loader ── */
.loading-bubble {
  display: flex;
  gap: 5px;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}
.dot { width:8px;height:8px;border-radius:50%;background:var(--text-muted);animation:bounce 1.2s infinite; }
.dot:nth-child(2){animation-delay:.2s}
.dot:nth-child(3){animation-delay:.4s}
@keyframes bounce{0%,60%,100%{transform:none}30%{transform:translateY(-8px)}}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Section titles ── */
.section-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

/* ── Divider ── */
hr { border: none; border-top: 1px solid var(--border); }

/* ── Attached files chips ── */
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.2rem 0.65rem;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.chip-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1;
  padding: 0;
}
.chip-remove:hover { color: var(--error); }

/* ── Utilitaires ── */
.hidden { display: none !important; }

.text-muted-center {
  color: var(--text-muted);
  font-size: 0.82rem;
  text-align: center;
}
.text-muted-center--padded-2 { padding: 2rem 0; }
.text-muted-center--padded-1 { padding: 1rem 0; }

.text-muted-sm {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.upload-hint { margin-top: 4px; }
.upload-status { font-size: 0.82rem; color: var(--text-muted); }
.upload-progress-bar {
  margin-top: 0.4rem;
  height: 4px;
  background: var(--bg3);
  border-radius: 2px;
  overflow: hidden;
}
.upload-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: 2px;
  transition: width 0.3s ease;
}
.section-title--spaced { margin-top: 0.5rem; }

/* ── Chat actions ── */
.chat-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* ── Attached files bar ── */
.attached-bar {
  display: flex;
  padding: 0.5rem 1.5rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.attached-bar-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-right: 0.5rem;
}

/* ── File item actions ── */
.file-actions {
  display: flex;
  gap: 4px;
  margin-left: auto;
  align-items: center;
}
.file-download-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 1rem;
  cursor: pointer;
}
.file-view-link {
  color: var(--primary);
  text-decoration: none;
  font-size: 1rem;
  cursor: pointer;
}
.file-view-link:hover { opacity: 0.8; }
.file-rename-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 2px;
}
.file-rename-btn:hover { color: var(--primary); }
.rename-input {
  width: 100%;
  padding: 2px 4px;
  font-size: 0.85rem;
  border: 1px solid var(--primary);
  border-radius: 4px;
  background: var(--bg-secondary);
  color: var(--text-main);
  outline: none;
}
.rename-confirm-btn,
.rename-cancel-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 2px;
}
.file-delete-btn {
  background: none;
  border: none;
  color: var(--error);
  cursor: pointer;
  font-size: 1rem;
  padding: 2px;
}

/* ── Empty state title ── */
.empty-state h3 { font-size: 1.1rem; }

/* ── Modals ── */
.modal-overlay {
  display: flex;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}
.modal-box--sm { min-width: 380px; max-width: 500px; }
.modal-box--md { min-width: 420px; max-width: 540px; }
.modal-title { margin-bottom: 1rem; }
.modal-files-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 300px;
  overflow-y: auto;
}
.modal-footer {
  margin-top: 1rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* ── Form groups (edit modal) ── */
.form-group { margin-bottom: 0.75rem; }
.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  display: block;
  margin-bottom: 0.25rem;
}
.form-control {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
}
textarea.form-control { resize: vertical; }
.form-row-pair {
  display: flex;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.form-row-pair > div { flex: 1; }
