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

:root {
  --bg: #f4f5f7;
  --panel-bg: #ffffff;
  --border: #e0e0e0;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #ede9fe;
  --text: #1f2937;
  --muted: #6b7280;
  --tag-f: #fce7f3;
  --tag-f-text: #be185d;
  --tag-m: #dbeafe;
  --tag-m-text: #1d4ed8;
  --radius: 8px;
  --sidebar-w: 72px;
  --mobile-nav-h: 60px;
  --mobile-user-bar-h: 40px;
}

html, body { height: 100%; font-family: system-ui, sans-serif; background: var(--bg); color: var(--text); }

/* ─── Layout commun ───────────────────────────────────────────────────────── */
.layout {
  display: flex;
  height: 100vh;
}

.content-area {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel-bg);
  overflow: hidden;
}

.panel-hidden { display: none; }

.panel-title {
  padding: 16px 20px;
  font-weight: 700;
  font-size: 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* ─── Sidebar nav (desktop) ──────────────────────────────────────────────── */
.app-nav {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  gap: 4px;
  border-right: 1px solid var(--border);
  background: var(--panel-bg);
  z-index: 10;
}

.app-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 56px;
  padding: 10px 6px;
  border: none;
  border-radius: var(--radius);
  background: none;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.app-nav-btn .nav-icon  { font-size: 1.3rem; line-height: 1; }
.app-nav-btn .nav-label { font-size: 0.6rem; font-weight: 600; }
.app-nav-btn:hover  { background: var(--bg); color: var(--text); }
.app-nav-btn.active { background: var(--primary-light); color: var(--primary); }

/* ─── Mobile (≤ 768px) — nav en bas ──────────────────────────────────────── */
@media (max-width: 768px) {
  body { padding-bottom: calc(var(--mobile-nav-h) + var(--mobile-user-bar-h)); }

  .layout {
    flex-direction: column;
    height: calc(100dvh - var(--mobile-nav-h) - var(--mobile-user-bar-h));
  }

  .app-nav {
    width: auto;
    flex-direction: row;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--mobile-nav-h);
    padding: 0;
    gap: 0;
    border-right: none;
    border-top: 1px solid var(--border);
  }

  .app-nav-btn {
    flex: 1;
    width: auto;
    border-radius: 0;
    padding: 5px 2px;
    gap: 1px;
  }
  .app-nav-btn .nav-icon  { font-size: 1.2rem; }
  .app-nav-btn.active { background: none; color: var(--primary); }

  .content-area { flex: 1; }
}

/* ─── Tabs (masqués — nav gère la navigation) ────────────────────────────── */
.tabs { display: none; }
.tab-content { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
.tab-content.hidden { display: none; }

/* ─── Conversation bar ───────────────────────────────────────────────────── */
.conv-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
}
.conv-title {
  flex: 1;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}
.conv-bar-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  cursor: pointer;
  font-size: 0.95rem;
  flex-shrink: 0;
  transition: background 0.1s;
}
.conv-bar-btn:hover { background: #f3f4f6; }

.conv-list {
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  max-height: 220px;
  overflow-y: auto;
  background: var(--bg);
}
.conv-list.hidden { display: none; }

.conv-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.conv-item:last-child { border-bottom: none; }
.conv-item:hover { background: #f3f4f6; }
.conv-item.active { background: var(--primary-light); }
.conv-item-title {
  flex: 1;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-item-date { font-size: 0.72rem; color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.conv-delete {
  background: none; border: none;
  color: var(--muted); cursor: pointer;
  padding: 2px 5px; border-radius: 4px; font-size: 0.85rem; flex-shrink: 0;
}
.conv-delete:hover { background: #fee2e2; color: #e11d48; }

/* ─── Chat ───────────────────────────────────────────────────────────────── */
.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  line-height: 1.5;
  word-break: break-word;
}
.msg-user      { background: var(--primary); color: #fff; align-self: flex-end; }
.msg-assistant { background: #f3f4f6; color: var(--text); align-self: flex-start; }

.msg-has-results {
  cursor: pointer;
  position: relative;
  padding-right: 36px;
  transition: background 0.15s;
}
.msg-has-results:hover { background: #e5e7eb; }
.msg-results-badge {
  position: absolute;
  top: 6px; right: 8px;
  background: var(--primary); color: #fff;
  font-size: 0.65rem; font-weight: 700;
  padding: 1px 5px; border-radius: 999px;
  min-width: 18px; text-align: center; line-height: 16px;
}

.chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-input-area input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  outline: none;
}
.chat-input-area input:focus { border-color: var(--primary); }
.chat-input-area button {
  padding: 10px 16px;
  background: var(--primary); color: #fff;
  border: none; border-radius: var(--radius);
  cursor: pointer; font-size: 0.9rem; font-weight: 600;
  white-space: nowrap;
}
.chat-input-area button:hover    { background: var(--primary-hover); }
.chat-input-area button:disabled { opacity: 0.6; cursor: default; }

.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid #ccc;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Search tab ─────────────────────────────────────────────────────────── */
.search-box { padding: 12px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.search-input-wrap { position: relative; display: flex; align-items: center; }
.search-input-wrap input {
  width: 100%; padding: 11px 40px 11px 14px;
  border: 1.5px solid var(--border); border-radius: var(--radius);
  font-size: 16px; outline: none; transition: border-color 0.15s;
}
.search-input-wrap input:focus { border-color: var(--primary); }
.search-clear {
  position: absolute; right: 10px;
  background: none; border: none; color: var(--muted);
  font-size: 0.9rem; cursor: pointer; padding: 4px; display: none;
}
.search-clear.visible { display: block; }
.search-clear:hover { color: var(--text); }

/* ─── Browse ─────────────────────────────────────────────────────────────── */
.browse-controls { padding: 10px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.letter-bar { display: flex; flex-wrap: wrap; gap: 3px; margin-bottom: 8px; }
.letter-btn {
  padding: 5px 7px; border: 1px solid var(--border); border-radius: 4px;
  background: none; font-size: 0.8rem; font-weight: 600; cursor: pointer;
  color: var(--text); min-width: 30px; text-align: center; transition: background 0.1s;
}
.letter-btn:hover  { background: #f3f4f6; }
.letter-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.browse-filters { display: flex; gap: 14px; font-size: 0.85rem; }
.browse-filters label { cursor: pointer; display: flex; align-items: center; gap: 4px; }
.browse-stats { font-size: 0.75rem; color: var(--muted); margin-top: 6px; }
.browse-pagination {
  display: flex; gap: 6px; padding: 8px 12px;
  border-top: 1px solid var(--border); flex-shrink: 0; flex-wrap: wrap;
}
.page-btn {
  padding: 6px 12px; border: 1px solid var(--border); border-radius: 4px;
  background: none; font-size: 0.8rem; cursor: pointer; min-width: 36px; text-align: center;
}
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn:hover:not(.active) { background: #f3f4f6; }

/* ─── Favoris ────────────────────────────────────────────────────────────── */
.heart-btn {
  margin-left: auto; background: none; border: none;
  font-size: 1.1rem; cursor: pointer; color: var(--border);
  padding: 2px 4px; line-height: 1;
  transition: color 0.15s, transform 0.1s; flex-shrink: 0;
}
.heart-btn:hover  { color: #e11d48; }
.heart-btn.active { color: #e11d48; }
.heart-btn.active:hover { transform: scale(1.2); }

.detail-heart {
  display: inline-flex; align-items: center; gap: 6px;
  margin-bottom: 16px; background: none;
  border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 7px 14px; cursor: pointer; font-size: 0.9rem; color: var(--muted);
  transition: border-color 0.15s, color 0.15s;
}
.detail-heart:hover  { border-color: #e11d48; color: #e11d48; }
.detail-heart.active { border-color: #e11d48; color: #e11d48; background: #fff1f2; }
.detail-heart .heart-icon { font-size: 1.1rem; }

.favoris-actions { padding: 12px 16px; border-top: 1px solid var(--border); flex-shrink: 0; }
.btn-similaires {
  width: 100%; padding: 11px;
  background: var(--primary); color: #fff;
  border: none; border-radius: var(--radius);
  font-size: 0.9rem; font-weight: 600; cursor: pointer; transition: background 0.15s;
}
.btn-similaires:hover { background: var(--primary-hover); }

.favori-item {
  display: flex; align-items: center; gap: 10px; padding: 12px;
  border-radius: var(--radius); cursor: pointer; border: 1px solid transparent;
  transition: background 0.1s;
}
.favori-item:hover { background: #f9fafb; border-color: var(--border); }
.favori-remove {
  margin-left: auto; background: none; border: none;
  color: var(--muted); font-size: 1rem; cursor: pointer;
  padding: 2px 6px; border-radius: 4px; flex-shrink: 0;
}
.favori-remove:hover { background: #fee2e2; color: #e11d48; }

/* ─── Results ────────────────────────────────────────────────────────────── */
.results-list { flex: 1; overflow-y: auto; padding: 8px; }
.result-item {
  display: flex; align-items: center; gap: 10px; padding: 12px;
  border-radius: var(--radius); cursor: pointer; border: 1px solid transparent;
  transition: background 0.1s;
}
.result-item:hover  { background: #f9fafb; border-color: var(--border); }
.result-item.active { background: var(--primary-light); border-color: var(--primary); }
.result-name { font-weight: 600; font-size: 0.95rem; }
.result-meta { font-size: 0.75rem; color: var(--muted); margin-left: auto; }

.gender-tag { font-size: 0.75rem; font-weight: 700; padding: 2px 7px; border-radius: 999px; }
.gender-tag.F { background: var(--tag-f); color: var(--tag-f-text); }
.gender-tag.M { background: var(--tag-m); color: var(--tag-m-text); }

.hint { color: var(--muted); font-size: 0.875rem; padding: 12px; }

/* ─── Source selector (VIP/admin) ────────────────────────────────────────── */
.source-selector {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 10px 0 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.source-tab {
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--text);
  font-size: 0.78rem;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.source-tab:hover:not(.disabled) { background: var(--primary-light); border-color: var(--primary); }
.source-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.source-tab.disabled { opacity: .4; cursor: not-allowed; }

/* ─── Detail ─────────────────────────────────────────────────────────────── */
.detail-content { flex: 1; overflow-y: auto; padding: 20px; }
.detail-content h2 { font-size: 1.5rem; color: var(--primary); margin-bottom: 4px; }
.detail-meta { font-size: 0.85rem; color: var(--muted); margin-bottom: 16px; }
.detail-section { margin-bottom: 14px; }
.detail-section h3 {
  font-size: 0.8rem; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted); margin-bottom: 4px;
}
.detail-section p { font-size: 0.9rem; line-height: 1.6; }
.detail-link {
  display: inline-block; margin-top: 16px;
  font-size: 0.8rem; color: var(--primary); text-decoration: none;
}
.detail-link:hover { text-decoration: underline; }

/* ─── Nouvelles sections fiche détail ────────────────────────────────────── */
.detail-stats {
  font-size: 0.8rem; color: var(--muted); margin-bottom: 14px;
}

.detail-portrait {
  background: var(--primary-light); border-left: 3px solid var(--primary);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 14px 16px; margin-bottom: 16px;
}
.detail-portrait p { font-size: 0.92rem; line-height: 1.65; color: var(--text); }
.detail-portrait p + p { margin-top: 8px; }

.detail-tags {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px;
}
.tag-pill {
  display: inline-block; padding: 3px 10px;
  background: var(--primary-light); color: var(--primary);
  border-radius: 20px; font-size: 0.78rem; font-weight: 600;
  letter-spacing: 0.02em;
}

.symbolic-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  margin-bottom: 16px;
}
.symbolic-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.symbolic-icon { font-size: 1.4rem; flex-shrink: 0; }
.symbolic-label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.symbolic-value { font-size: 0.88rem; font-weight: 600; color: var(--text); margin-top: 2px; }

.popularity-chart-section .popularity-chart {
  max-width: 100%; height: 220px; margin-top: 10px;
}
.popularity-chart-section .popularity-chart canvas { max-height: 220px; }

.detail-wiki-image {
  float: right; margin: 0 0 12px 16px;
  max-width: 120px; border-radius: var(--radius); overflow: hidden;
}
.detail-wiki-image img { width: 100%; display: block; }
.ipa-badge {
  display: inline-block; margin-bottom: 4px;
  font-family: monospace; font-size: .85rem;
  color: var(--muted); background: var(--bg);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 1px 6px; letter-spacing: 0.04em;
}
.detail-forme-orig {
  font-size: .82rem; color: var(--muted);
  margin-bottom: 12px; font-style: italic;
}
.detail-variantes { border: 1px solid var(--border); border-radius: var(--radius); }
.detail-variantes summary { padding: 8px 12px; cursor: pointer; }
.variantes-table { width: 100%; border-collapse: collapse; font-size: .82rem; padding: 8px 12px; }
.variantes-table td { padding: 3px 8px; }
.variantes-table td.var-lang { font-weight: 600; color: var(--muted); width: 120px; }
.variantes-table tr:nth-child(even) { background: var(--bg); }

.detail-sources {
  margin-top: 16px; font-size: 0.78rem; color: var(--muted);
}
.detail-sources a { color: var(--primary); text-decoration: none; }
.detail-sources a:hover { text-decoration: underline; }

@media (max-width: 768px) {
  .symbolic-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ─── Nav user zone ──────────────────────────────────────────────────────── */
.nav-spacer { flex: 1; }
.nav-user {
  display: flex; flex-direction: column; align-items: center;
  gap: 4px; padding: 10px 6px; border-top: 1px solid var(--border);
  width: 100%;
}
.nav-user-name {
  font-size: 0.62rem; font-weight: 600; color: var(--text);
  text-align: center; width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 0 4px;
}
.nav-budget {
  font-size: 0.58rem; color: var(--muted); text-align: center;
}
.nav-admin-link {
  font-size: 0.62rem; color: var(--primary); text-decoration: none;
  padding: 3px 6px; border: 1px solid var(--primary-light);
  border-radius: 4px; font-weight: 600;
}
.nav-admin-link:hover { background: var(--primary-light); }
.nav-admin-link.hidden { display: none; }
.nav-logout {
  width: 100%; padding: 6px 8px;
  background: none; border: 1px solid var(--border); border-radius: 6px;
  color: var(--muted); cursor: pointer; font-size: .7rem; font-weight: 600;
  transition: background .15s, color .15s, border-color .15s;
}
.nav-logout:hover { background: #fee2e2; color: #e11d48; border-color: #fca5a5; }

/* Mobile — show only the logout button, hide extra info */
@media (max-width: 768px) {
  .nav-user {
    flex-direction: row; justify-content: space-between; align-items: center;
    position: fixed; bottom: var(--mobile-nav-h); left: 0; right: 0;
    height: var(--mobile-user-bar-h);
    background: var(--panel-bg); border-top: 1px solid var(--border);
    padding: 0 12px; z-index: 11;
  }
  .nav-user-name { font-size: .75rem; font-weight: 600; }
  .nav-budget, .nav-admin-link { display: none; }
  .nav-logout {
    width: auto; padding: 5px 12px; font-size: .75rem;
  }
}
