/* ============================================================
   BPA Dashboard - Thème sombre
   Arnaud Avril - bon-plan-auto.fr
   ============================================================ */

:root {
  --bg-primary:    #0d1117;
  --bg-secondary:  #161b22;
  --bg-tertiary:   #21262d;
  --bg-hover:      #30363d;
  --accent:        #22d3ee;
  --accent-dim:    #0e7490;
  --accent-glow:   rgba(34, 211, 238, 0.15);
  --text-primary:  #e6edf3;
  --text-secondary:#8b949e;
  --text-muted:    #484f58;
  --border:        #30363d;
  --border-subtle: #21262d;
  --success:       #3fb950;
  --warning:       #d29922;
  --danger:        #f85149;
  --info:          #58a6ff;
  --radius:        8px;
  --radius-sm:     4px;
  --shadow:        0 8px 24px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

/* ── Écran de connexion ───────────────────────────────────── */
#login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-primary);
  z-index: 1000;
}
#login-screen.hidden { display: none; }

.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 340px;
  box-shadow: var(--shadow);
}
.login-card h1 {
  font-size: 1.4rem;
  margin-bottom: 6px;
  color: var(--accent);
}
.login-card p { color: var(--text-secondary); margin-bottom: 24px; font-size: 13px; }
.login-card input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  margin-bottom: 12px;
  outline: none;
  transition: border-color 0.2s;
}
.login-card input:focus { border-color: var(--accent); }
.login-error { color: var(--danger); font-size: 12px; margin-bottom: 8px; min-height: 16px; }

/* ── Layout principal ─────────────────────────────────────── */
#app {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: 48px 1fr;
  height: 100vh;
}
#app.hidden { display: none; }

/* ── Header ───────────────────────────────────────────────── */
header {
  grid-column: 1 / -1;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  z-index: 10;
}
.header-logo {
  font-weight: 700;
  font-size: 15px;
  color: var(--accent);
  letter-spacing: -0.3px;
}
.header-logo span { color: var(--text-secondary); font-weight: 400; }
.header-spacer { flex: 1; }
.header-model-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.header-token-info {
  font-size: 11px;
  color: var(--text-muted);
}
.header-token-info span { color: var(--accent); }

/* ── Sidebar ───────────────────────────────────────────────── */
aside {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-section {
  padding: 12px;
  border-bottom: 1px solid var(--border-subtle);
}
.sidebar-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 8px;
  padding: 0 4px;
}

/* Navigation des vues */
.nav-tabs { display: flex; flex-direction: column; gap: 2px; }
.nav-tab {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
  border: none; background: none; width: 100%; text-align: left;
}
.nav-tab:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-tab.active { background: var(--accent-glow); color: var(--accent); }
.nav-tab .icon { font-size: 15px; width: 18px; text-align: center; }

/* Liste des repos */
.repo-list { display: flex; flex-direction: column; gap: 1px; flex: 1; overflow-y: auto; }
.repo-item {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
}
.repo-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.repo-item.active { background: var(--accent-glow); color: var(--accent); }
.repo-icon { font-size: 13px; }
.repo-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.repo-badge {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--bg-tertiary);
  color: var(--text-muted);
}

/* Actions rapides */
.quick-actions { display: flex; flex-direction: column; gap: 4px; }
.quick-action-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  width: 100%;
  text-align: left;
}
.quick-action-btn:hover { border-color: var(--accent-dim); color: var(--text-primary); background: var(--bg-hover); }
.quick-action-btn:active { transform: scale(0.98); }
.quick-action-btn.loading { opacity: 0.7; cursor: wait; pointer-events: none; }
.quick-action-btn.loading span:first-child { display: inline-block; animation: qa-spin 0.8s linear infinite; }

/* ── Zone principale ───────────────────────────────────────── */
main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
}

/* ── Vues ──────────────────────────────────────────────────── */
.view { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.view.active { display: flex; }

/* ── Vue Chat ──────────────────────────────────────────────── */
#view-chat {
  display: none;
  flex-direction: column;
}
#view-chat.active { display: flex; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }
@keyframes qa-spin { to { transform: rotate(360deg); } }

.chat-message.user { align-self: flex-end; }
.chat-message.assistant { align-self: flex-start; }

.message-bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13.5px;
  line-height: 1.6;
  word-break: break-word;
}
.chat-message.user .message-bubble {
  background: var(--accent-dim);
  color: #fff;
  border-bottom-right-radius: 2px;
}
.chat-message.assistant .message-bubble {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 2px;
}

.message-meta {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 3px;
  padding: 0 2px;
}
.chat-message.user .message-meta { text-align: right; }

/* Rendu markdown dans les messages */
.message-bubble pre {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 12px;
}
.message-bubble code {
  background: var(--bg-primary);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
}
.message-bubble pre code { background: none; padding: 0; }
.message-bubble p { margin: 6px 0; }
.message-bubble ul, .message-bubble ol { padding-left: 18px; margin: 6px 0; }
.message-bubble h1,.message-bubble h2,.message-bubble h3 { margin: 10px 0 4px; }
.message-bubble strong { color: var(--accent); }

/* Indicateur de frappe */
.typing-indicator { display: flex; align-items: center; gap: 4px; padding: 10px 14px; }
.typing-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingDot 1.2s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingDot {
  0%, 60%, 100% { transform: scale(1); opacity: 0.4; }
  30% { transform: scale(1.3); opacity: 1; }
}

/* Zone de saisie */
.chat-input-area {
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-textarea {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 13.5px;
  padding: 9px 12px;
  resize: none;
  min-height: 40px;
  max-height: 140px;
  outline: none;
  font-family: inherit;
  line-height: 1.5;
  transition: border-color 0.2s;
}
.chat-textarea:focus { border-color: var(--accent); }
.chat-textarea::placeholder { color: var(--text-muted); }

.chat-controls {
  display: flex; gap: 4px; align-items: flex-end;
}

.btn-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--accent-dim); }
.btn-icon.active { background: var(--accent-glow); color: var(--accent); border-color: var(--accent); }
.btn-icon.primary {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
  color: #fff;
}
.btn-icon.primary:hover { background: var(--accent); border-color: var(--accent); }

.chat-footer-info {
  display: flex;
  gap: 12px;
  font-size: 11px;
  color: var(--text-muted);
}
.model-selector { display: flex; gap: 4px; }
.model-btn {
  padding: 2px 8px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: none;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}
.model-btn.active { background: var(--accent-glow); border-color: var(--accent); color: var(--accent); }

/* ── Vue Dashboard ─────────────────────────────────────────── */
#view-dashboard {
  overflow-y: auto;
  padding: 16px;
}
#view-dashboard.active { display: block; }

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.widget {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.widget-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.widget-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-secondary);
}
.widget-status {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--success);
}
.widget-status.loading { background: var(--warning); animation: pulse 1.5s ease-in-out infinite; }
.widget-status.error { background: var(--danger); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

.stat-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 13px;
}
.stat-row:last-child { border-bottom: none; }
.stat-label { color: var(--text-secondary); }
.stat-value { font-weight: 600; color: var(--text-primary); }
.stat-value.accent { color: var(--accent); }
.stat-value.success { color: var(--success); }
.stat-value.warning { color: var(--warning); }
.stat-value.danger { color: var(--danger); }

/* Barre de progression budget */
.progress-bar {
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
  margin: 8px 0;
}
.progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
  background: var(--success);
}
.progress-fill.warning { background: var(--warning); }
.progress-fill.danger { background: var(--danger); }

/* Commits */
.commit-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--border-subtle);
}
.commit-item:last-child { border-bottom: none; }
.commit-repo { font-size: 12px; font-weight: 600; color: var(--info); }
.commit-msg { font-size: 12px; color: var(--text-secondary); margin: 2px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.commit-meta { font-size: 11px; color: var(--text-muted); }
.commit-dot {
  display: inline-block; width: 7px; height: 7px;
  border-radius: 50%; margin-right: 5px; vertical-align: middle;
}

/* ── Vue Fichiers ───────────────────────────────────────────── */
#view-files { display: none; flex-direction: column; }
#view-files.active { display: flex; }

.file-browser-header {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-secondary);
  font-size: 13px;
}
.breadcrumb-item {
  color: var(--text-secondary);
  cursor: pointer;
}
.breadcrumb-item:hover { color: var(--accent); }
.breadcrumb-sep { color: var(--text-muted); }
.branch-select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  font-size: 12px;
  outline: none;
  margin-left: auto;
}

.file-browser-content { display: flex; flex: 1; overflow: hidden; }

.file-list {
  width: 260px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
}
.file-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
  transition: background 0.1s;
}
.file-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.file-item.active { background: var(--accent-glow); color: var(--accent); }
.file-item-icon { font-size: 14px; }
.file-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.file-editor-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.file-editor-toolbar {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  display: flex; gap: 8px; align-items: center;
  background: var(--bg-secondary);
}
.file-name-display { font-size: 12px; color: var(--text-secondary); flex: 1; }
.file-name-display span { color: var(--text-primary); font-weight: 500; }

.file-content-view {
  flex: 1;
  overflow: auto;
  padding: 16px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-primary);
}

.file-editor {
  flex: 1;
  background: var(--bg-primary);
  border: none;
  color: var(--text-primary);
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  padding: 16px;
  resize: none;
  outline: none;
  line-height: 1.6;
}

.commit-form {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  display: flex; gap: 8px;
}
.commit-input {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 12px;
  padding: 7px 10px;
  outline: none;
}
.commit-input:focus { border-color: var(--accent); }

/* ── Boutons communs ───────────────────────────────────────── */
.btn {
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex; align-items: center; gap: 5px;
  font-family: inherit;
}
.btn-primary {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
  color: #fff;
}
.btn-primary:hover { background: var(--accent); border-color: var(--accent); }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-secondary); }
.btn-secondary:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Toast notifications ───────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 9999;
}
.toast {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: slideIn 0.25s ease;
  max-width: 320px;
}
.toast.success { border-color: var(--success); color: var(--success); }
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.info { border-color: var(--info); color: var(--info); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; } }

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── État vide ─────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  flex: 1; gap: 8px; color: var(--text-muted); padding: 32px;
}
.empty-state .icon { font-size: 32px; }
.empty-state p { font-size: 13px; text-align: center; }

/* ── Mobile (iPhone) ───────────────────────────────────────── */
@media (max-width: 768px) {
  html, body { overflow: hidden; }

  #app {
    grid-template-columns: 1fr;
    grid-template-rows: 48px 1fr 52px;
  }

  aside {
    display: none;
    position: fixed;
    top: 48px; left: 0; bottom: 52px;
    width: 260px;
    z-index: 100;
    box-shadow: 4px 0 20px rgba(0,0,0,0.5);
  }
  aside.open { display: flex; }

  .mobile-nav {
    grid-column: 1;
    grid-row: 3;
    display: flex;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
  }

  .mobile-nav-btn {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px;
    font-size: 10px;
    color: var(--text-muted);
    border: none; background: none;
    padding: 8px 4px;
    cursor: pointer;
    transition: color 0.15s;
  }
  .mobile-nav-btn .icon { font-size: 18px; }
  .mobile-nav-btn.active { color: var(--accent); }

  .chat-message { max-width: 94%; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .file-browser-content { flex-direction: column; }
  .file-list { width: 100%; height: 180px; border-right: none; border-bottom: 1px solid var(--border); }
  .chat-textarea { font-size: 16px; }
}

@media (min-width: 769px) {
  .mobile-nav { display: none; }
}
