/* golem-web — thème « Golem » : glaise/pierre sombre, accent terracotta. */

:root {
  --bg: #16130f;
  --bg-elevated: #1f1a14;
  --card: #241f18;
  --card-border: #362e23;
  --text: #f3ede2;
  --text-dim: #b3a798;
  --text-faint: #7d7264;
  --accent: #cd8348;
  --accent-strong: #e0996a;
  --accent-contrast: #1a1108;
  --success: #7cb98a;
  --success-bg: #1c2a1f;
  --error: #e2695a;
  --error-bg: #2c1a17;
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --space-1: 6px;
  --space-2: 10px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 32px;
}

* {
  box-sizing: border-box;
}

/* L'attribut [hidden] doit toujours l'emporter sur les règles de display
   des composants (.app-section, .overlay, etc. sont en flex) — sinon les
   sections/overlays masqués via `el.hidden = true` restent visibles. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
}

a {
  color: var(--accent-strong);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- Coque app + navigation --- */

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding-bottom: calc(64px + env(safe-area-inset-bottom, 0));
}

.nav {
  order: 2;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: stretch;
  background: var(--bg-elevated);
  border-top: 1px solid var(--card-border);
  padding: 4px env(safe-area-inset-right, 0) calc(4px + env(safe-area-inset-bottom, 0)) env(safe-area-inset-left, 0);
  z-index: 30;
}

.nav-brand {
  display: none;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: transparent;
  border: none;
  color: var(--text-faint);
  font-family: inherit;
  font-size: 0.66rem;
  font-weight: 600;
  padding: 8px 4px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color 0.15s ease;
}

.nav-item .nav-icon {
  font-size: 1.3rem;
  line-height: 1;
}

.nav-item[aria-current="page"] {
  color: var(--accent-strong);
}

@media (min-width: 900px) {
  .app-shell {
    flex-direction: row;
  }

  .app-main {
    padding-bottom: 0;
  }

  .nav {
    order: 0;
    position: sticky;
    top: 0;
    bottom: auto;
    left: auto;
    right: auto;
    height: 100vh;
    flex-direction: column;
    align-items: stretch;
    width: 232px;
    flex-shrink: 0;
    border-top: none;
    border-right: 1px solid var(--card-border);
    padding: var(--space-4) var(--space-2);
    gap: var(--space-1);
  }

  .nav-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 1.15rem;
    padding: 0 var(--space-2) var(--space-4);
  }

  .nav-item {
    flex-direction: row;
    justify-content: flex-start;
    gap: var(--space-2);
    font-size: 0.94rem;
    padding: 11px 14px;
  }

  .nav-item .nav-icon {
    font-size: 1.1rem;
  }
}

/* --- En-tête --- */

.topbar {
  padding: var(--space-5) var(--space-4) var(--space-4);
  background: linear-gradient(180deg, var(--bg-elevated), var(--bg));
  border-bottom: 1px solid var(--card-border);
}

.topbar h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: var(--space-1) 0 0;
  color: var(--text-dim);
  font-size: 0.92rem;
}

/* --- Contenu --- */

.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: var(--space-4);
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  min-height: 0;
}

.app-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.section-hint {
  margin: 0 0 var(--space-3);
  color: var(--text-dim);
  font-size: 0.88rem;
}

.field-label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin: 0 0 var(--space-1);
}

.input,
.select {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

.input::placeholder {
  color: var(--text-faint);
}

.select {
  appearance: none;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%),
    linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position: calc(100% - 20px) center, calc(100% - 15px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 40px;
}

.badge {
  display: inline-flex;
  align-items: center;
  background: var(--bg-elevated);
  border: 1px solid var(--card-border);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: var(--space-5) var(--space-3);
}

.empty-state-hint {
  color: var(--text-faint);
  font-size: 0.88rem;
}

.mailbox-list {
  list-style: none;
  margin: 0 0 var(--space-4);
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* --- Carte boîte mail --- */

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.card-main {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
}

.card-status {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
  background: var(--text-faint);
}

.card-status.status-ok {
  background: var(--success);
  box-shadow: 0 0 0 4px var(--success-bg);
}

.card-status.status-error {
  background: var(--error);
  box-shadow: 0 0 0 4px var(--error-bg);
}

.card-info {
  min-width: 0;
}

.card-email {
  margin: 0;
  font-weight: 600;
  font-size: 1.02rem;
  word-break: break-word;
}

.card-host {
  margin: var(--space-1) 0 0;
  color: var(--text-dim);
  font-size: 0.86rem;
}

.card-meta {
  margin: var(--space-1) 0 0;
  color: var(--text-faint);
  font-size: 0.8rem;
}

.card-actions {
  display: flex;
  gap: var(--space-2);
}

.card-feedback {
  font-size: 0.86rem;
  min-height: 1em;
}

.card-feedback.ok {
  color: var(--success);
}

.card-feedback.error {
  color: var(--error);
}

/* --- Boutons --- */

.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.08s ease, opacity 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
}

.btn-primary:hover {
  background: var(--accent-strong);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--card-border);
  flex: 1;
}

.btn-danger {
  background: transparent;
  color: var(--error);
  border: 1px solid var(--error-bg);
}

.btn-block {
  width: 100%;
  margin-top: var(--space-3);
  padding: 14px;
}

.btn-add {
  width: 100%;
  padding: 15px;
  font-size: 1rem;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 1.1rem;
  cursor: pointer;
  padding: var(--space-1) var(--space-2);
}

.btn:focus-visible,
.btn-icon:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

/* --- Formulaire (bottom sheet) --- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 6, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 40;
}

.sheet {
  background: var(--bg-elevated);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: var(--space-4);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding-bottom: calc(var(--space-5) + env(safe-area-inset-bottom, 0));
}

@media (min-width: 640px) {
  .overlay {
    align-items: center;
  }

  .sheet {
    border-radius: var(--radius-lg);
  }
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.sheet-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

#mailbox-form label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin: var(--space-3) 0 var(--space-1);
}

#mailbox-form input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

#mailbox-form input::placeholder {
  color: var(--text-faint);
}

.help {
  margin-top: var(--space-3);
  color: var(--text-dim);
  font-size: 0.85rem;
}

.help summary {
  cursor: pointer;
  color: var(--accent-strong);
  font-weight: 600;
}

.help ol {
  margin: var(--space-2) 0 0;
  padding-left: 1.2em;
  line-height: 1.6;
}

.feedback {
  margin-top: var(--space-3);
  font-size: 0.88rem;
  min-height: 1.2em;
}

.feedback.ok {
  color: var(--success);
}

.feedback.error {
  color: var(--error);
}

/* --- Spinner --- */

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(0, 0, 0, 0.25);
  border-top-color: var(--accent-contrast);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* --- 💬 Chat --- */

.chat-toolbar {
  margin-bottom: var(--space-3);
}

#chat-competence-select {
  max-width: 320px;
}

.chat-messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  overflow-y: auto;
  padding: var(--space-1) 0 var(--space-3);
  min-height: 0;
}

.chat-hint {
  color: var(--text-faint);
  font-size: 0.9rem;
  text-align: center;
  padding: var(--space-5) var(--space-3);
}

.bubble {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  line-height: 1.5;
  font-size: 0.95rem;
}

.bubble-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble-user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-contrast);
  border-bottom-right-radius: 4px;
}

.bubble-assistant {
  align-self: flex-start;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-bottom-left-radius: 4px;
}

.bubble-error {
  border-color: var(--error-bg);
  color: var(--error);
}

.bubble-typing {
  padding: 16px;
}

.typing-dots {
  display: inline-flex;
  gap: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: typing-bounce 1s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typing-bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.sources {
  margin-top: var(--space-2);
  font-size: 0.8rem;
  color: var(--text-dim);
}

.sources summary {
  cursor: pointer;
  color: var(--accent-strong);
  font-weight: 600;
}

.sources ul {
  margin: var(--space-2) 0 0;
  padding-left: 1.1em;
  line-height: 1.5;
}

.chat-form {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  background: var(--bg);
  padding-top: var(--space-2);
}

.chat-input {
  flex: 1;
  resize: none;
  background: var(--bg-elevated);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  max-height: 140px;
}

.chat-input:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

.btn-round {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  flex-shrink: 0;
  font-size: 1.1rem;
}

/* --- 🧠 Mémoire --- */

.search-bar {
  margin-bottom: var(--space-3);
}

.memory-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.memory-card {
  gap: var(--space-2);
}

.memory-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.memory-date {
  color: var(--text-faint);
  font-size: 0.78rem;
}

.memory-content {
  margin: 0;
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.5;
  word-break: break-word;
}

/* --- 🎓 Compétences --- */

.competences-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
}

@media (min-width: 640px) {
  .competences-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.competence-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-1);
  text-align: left;
  background: var(--card);
  border: 2px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.08s ease;
}

.competence-card:active {
  transform: scale(0.98);
}

.competence-card.active {
  border-color: var(--accent);
}

.competence-emoji {
  font-size: 1.8rem;
}

.competence-name {
  font-weight: 700;
  font-size: 1.02rem;
}

.competence-description {
  color: var(--text-dim);
  font-size: 0.86rem;
  line-height: 1.45;
}

.competence-active-tag {
  display: none;
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 700;
}

.competence-card.active .competence-active-tag {
  display: inline;
}

/* --- ⚙️ Réglages --- */

.settings-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  max-width: 420px;
}

.settings-card label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin: 0 0 var(--space-2);
}

.settings-card .select {
  margin-bottom: var(--space-2);
}
