:root, [data-theme="jardin"] {
  --bg: #F3EEE3;
  --surface: #FBF8F1;
  --border: #E3DCCB;
  --text: #26302A;
  --muted: #5C6658;
  --primary: #3F6B4C;
  --primary-hover: #335740;
  --on-primary: #FFFFFF;
  --accent: #C8452D;
  --on-accent: #FFFFFF;
  --chip: #EFE9DA;
  --danger: #C92A2A;
  --danger-bg: #FFF5F5;
  --danger-border: #FFC9C9;
  color-scheme: light;
  --add: #2f9e44;
  --replace: #f08c00;
  --skip: #868e96;
  --radius: 14px;
}

/* ---- Thèmes (choisis dans l'onglet Réglages) ---- */
[data-theme="lagon"] {
  --bg: #E6F0EF;
  --surface: #F6FAF9;
  --border: #C9DCD9;
  --text: #1F2E2E;
  --muted: #48605F;
  --primary: #1E6B73;
  --primary-hover: #17565D;
  --on-primary: #FFFFFF;
  --accent: #F0A030;
  --on-accent: #2B2108;
  --chip: #D9E9E7;
  --danger: #C92A2A;
  --danger-bg: #FFF5F5;
  --danger-border: #FFC9C9;
  color-scheme: light;
}
[data-theme="lavande"] {
  --bg: #EFEBF6;
  --surface: #F9F7FD;
  --border: #D9D2EA;
  --text: #2A2540;
  --muted: #565071;
  --primary: #5B4B9A;
  --primary-hover: #4A3C82;
  --on-primary: #FFFFFF;
  --accent: #F08A5D;
  --on-accent: #3A1A0C;
  --chip: #E7E1F4;
  --danger: #C92A2A;
  --danger-bg: #FFF5F5;
  --danger-border: #FFC9C9;
  color-scheme: light;
}
[data-theme="cerise"] {
  --bg: #F6ECEE;
  --surface: #FDF8F9;
  --border: #E8D4D8;
  --text: #2E2024;
  --muted: #675459;
  --primary: #A8325A;
  --primary-hover: #8C274A;
  --on-primary: #FFFFFF;
  --accent: #1F7A70;
  --on-accent: #FFFFFF;
  --chip: #F2E1E5;
  --danger: #C92A2A;
  --danger-bg: #FFF5F5;
  --danger-border: #FFC9C9;
  color-scheme: light;
}
[data-theme="aube"] {
  --bg: #F6F5FB;
  --surface: #FFFFFF;
  --border: #E4E1F3;
  --text: #1E2033;
  --muted: #565B78;
  --primary: #5B5BD6;
  --primary-hover: #4A4AC0;
  --on-primary: #FFFFFF;
  --accent: #7C3AED;
  --on-accent: #FFFFFF;
  --chip: #EDEAFB;
  --danger: #C92A2A;
  --danger-bg: #FFF5F5;
  --danger-border: #FFC9C9;
  color-scheme: light;
}
[data-theme="ocean"] {
  --bg: #E8F0F8;
  --surface: #F7FAFD;
  --border: #CBDAEA;
  --text: #12263A;
  --muted: #4A6078;
  --primary: #1D4E89;
  --primary-hover: #163D6D;
  --on-primary: #FFFFFF;
  --accent: #F26B4F;
  --on-accent: #2A0F08;
  --chip: #DCE7F3;
  --danger: #C92A2A;
  --danger-bg: #FFF5F5;
  --danger-border: #FFC9C9;
  color-scheme: light;
}
[data-theme="mangue"] {
  --bg: #FBF1DC;
  --surface: #FFFBF1;
  --border: #EBD9B0;
  --text: #3B2A12;
  --muted: #6B5733;
  --primary: #B45309;
  --primary-hover: #92400E;
  --on-primary: #FFFFFF;
  --accent: #3F7D2E;
  --on-accent: #FFFFFF;
  --chip: #F6E7C4;
  --danger: #C92A2A;
  --danger-bg: #FFF5F5;
  --danger-border: #FFC9C9;
  color-scheme: light;
}
[data-theme="terre"] {
  --bg: #F2E8E1;
  --surface: #FAF5F1;
  --border: #E0CFC3;
  --text: #33261F;
  --muted: #65524A;
  --primary: #9A4A2F;
  --primary-hover: #7E3B24;
  --on-primary: #FFFFFF;
  --accent: #5E6B3A;
  --on-accent: #FFFFFF;
  --chip: #EADBD0;
  --danger: #C92A2A;
  --danger-bg: #FFF5F5;
  --danger-border: #FFC9C9;
  color-scheme: light;
}
[data-theme="nuit"] {
  --bg: #0D1520;
  --surface: #152233;
  --border: #26384D;
  --text: #E6EEF5;
  --muted: #9DB0C2;
  --primary: #2DD4BF;
  --primary-hover: #5EEAD4;
  --on-primary: #062521;
  --accent: #F59E0B;
  --on-accent: #1F1400;
  --chip: #1C2E43;
  --danger: #FF8787;
  --danger-bg: #3A1D22;
  --danger-border: #6B2E36;
  color-scheme: dark;
}
[data-theme="crepuscule"] {
  --bg: #1A1426;
  --surface: #251C36;
  --border: #3A2D52;
  --text: #EFE9F8;
  --muted: #B3A6CC;
  --primary: #C4A8FF;
  --primary-hover: #D6C2FF;
  --on-primary: #1E0F3D;
  --accent: #FF8FB1;
  --on-accent: #35101D;
  --chip: #2F2445;
  --danger: #FF8787;
  --danger-bg: #3F1D2A;
  --danger-border: #7A3045;
  color-scheme: dark;
}

* { box-sizing: border-box; }

input, textarea, select {
  background: var(--surface);
  color: var(--text);
}

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  flex: none;
  padding: 0.9rem 2rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
}

.brand { display: flex; align-items: center; gap: 0.7rem; }
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: var(--primary);
  color: var(--on-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  transform: rotate(-6deg);
}

header h1 {
  font-size: 1.3rem;
  margin: 0;
  white-space: nowrap;
  letter-spacing: -0.02em;
  font-weight: 800;
}

nav { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }

.nav-menu { position: relative; }
.nav-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 220px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  padding: 0.4rem;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.14);
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 30;
}
.nav-dropdown.right { left: auto; right: 0; padding: 0.8rem; gap: 0.6rem; align-items: stretch; }
.nav-dropdown > button {
  background: none;
  color: var(--text);
  text-align: left;
  padding: 0.55rem 0.8rem;
  border-radius: 10px;
  font-size: 0.92rem;
}
.nav-dropdown > button:hover { background: var(--chip); }
.nav-dropdown.right > button { border: 1px solid var(--border); text-align: center; }
.caret { font-size: 0.7em; }

.avatar {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.avatar:hover { background: var(--accent); filter: brightness(0.92); }

.tab-btn {
  background: none;
  border: none;
  font-weight: 600;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--text);
}

.tab-btn:hover { background: var(--chip); }

.tab-btn.active {
  background: var(--primary);
  color: var(--on-primary);
}

main {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0.5rem 2rem 1.5rem;
  overflow-y: auto;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.muted { color: var(--muted); font-size: 0.9rem; }
.hidden { display: none !important; }

/* ---- Chat ---- */

.chat-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.chat-toolbar select {
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.chat-toolbar .secondary-btn {
  margin-left: auto;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.chat-toolbar .secondary-btn:hover:not(:disabled) { background: var(--bg); }

.gmail-accounts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.gmail-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--text);
}
.gmail-chip-remove {
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  font-size: 0.75rem;
  line-height: 1;
}
.gmail-chip-remove:hover { color: var(--text); }

.chat-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 1.5rem;
  height: 100%;
  min-height: 520px;
}
#tab-chat.active { display: block; height: 100%; }

.chat-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 28px;
  overflow: hidden;
}
.chat-main { display: flex; flex-direction: column; gap: 1rem; min-height: 0; min-width: 0; }
.chat-card { flex: 1; }
.chat-options-card {
  flex: none;
  background: var(--primary);
  color: var(--on-primary);
  border-radius: 24px;
  padding: 0.8rem 1.25rem;
}
.chat-options-card .muted { color: inherit; }
.chat-options-card select {
  background: rgba(255, 255, 255, 0.16);
  color: inherit;
  border: none;
  border-radius: 12px;
}
.chat-options-card select option { background: var(--surface); color: var(--text); }
.chat-options-card .gmail-chip {
  background: rgba(255, 255, 255, 0.16);
  color: inherit;
  border: none;
}
.chat-options-card .gmail-chip-remove { color: inherit; }
.chat-options-card .chat-toolbar .secondary-btn {
  background: rgba(255, 255, 255, 0.16);
  color: inherit;
  border: none;
}
.chat-options-card .chat-toolbar .secondary-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.28); }
.chat-options-card .chat-toolbar { margin: 0; flex-wrap: wrap; }
.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1.5rem 1.75rem 1rem;
}
.chat-card .attachment-chips { padding: 0 1.5rem; }

.side-panels { display: flex; flex-direction: column; gap: 1rem; min-height: 0; overflow-y: auto; }
.today-card {
  padding: 1.25rem;
  border-radius: 24px;
  background: var(--primary);
  color: var(--on-primary);
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.today-card h2, .todo-card h2 { margin: 0; font-size: 1.3rem; font-weight: 700; }
.today-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
.today-head span { font-size: 0.8rem; }
.today-event {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0.7rem 0.8rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.16);
  font-size: 0.9rem;
}
.today-event b { font-size: 0.95rem; white-space: nowrap; }
.today-empty { margin: 0; font-size: 0.9rem; }
.todo-card {
  flex: none;
  padding: 1.25rem;
  border-radius: 24px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 160px;
}
.side-todo { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.7rem; font-size: 0.9rem; }
.side-todo li { display: flex; align-items: flex-start; gap: 0.7rem; }
.side-todo li > span:not(.rank) { white-space: pre-wrap; overflow-wrap: anywhere; min-width: 0; padding-top: 0.1rem; }
.side-todo .rank {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  border-radius: 8px;
  background: var(--chip);
  color: var(--text);
  font-weight: 700;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.side-todo li:first-child .rank { background: var(--accent); color: var(--on-accent); }
.dashed-btn {
  margin-top: auto;
  background: transparent;
  color: var(--text);
  border: 1.5px dashed var(--border);
  border-radius: 14px;
  padding: 0.7rem;
  font-weight: 600;
}
.dashed-btn:hover { background: var(--chip); }

.todo-add-form .mic-btn, .kb-toolbar .mic-btn { background: var(--chip); color: var(--text); }
.msg { max-width: 80%; padding: 0.7rem 1rem; border-radius: 20px 20px 6px 20px; line-height: 1.4; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--on-accent); }
.msg.assistant {
  align-self: flex-start;
  position: relative;
  margin-left: 48px;
  background: var(--surface);
  border-radius: 6px 20px 20px 20px;
  border: 1.5px solid var(--border);
  padding: 0.9rem 1.1rem;
  line-height: 1.6;
}
.msg.assistant::before {
  content: "";
  position: absolute;
  left: -48px;
  top: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
}
.msg.assistant::after {
  content: "";
  position: absolute;
  left: -48px;
  top: 0;
  width: 36px;
  height: 36px;
  background: var(--on-primary);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2.5l2 6.2 6.2 2-6.2 2-2 6.2-2-6.2-6.2-2 6.2-2z'/%3E%3C/svg%3E") center / 18px no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2.5l2 6.2 6.2 2-6.2 2-2 6.2-2-6.2-6.2-2 6.2-2z'/%3E%3C/svg%3E") center / 18px no-repeat;
}

.msg.error { align-self: center; background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger-border); }
.msg-attachments { margin-top: 0.4rem; font-size: 0.8rem; opacity: 0.85; }

.attachment-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.attachment-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.5rem 0.25rem 0.75rem;
  font-size: 0.85rem;
}
.attachment-chip.error { border-color: var(--danger); color: var(--danger); }
.attachment-chip button {
  background: none;
  color: var(--muted);
  border: none;
  padding: 0 0.3rem;
  font-size: 0.9rem;
  line-height: 1;
}
.attachment-chip button:hover { color: var(--danger); }

.chat-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 1.25rem 1.25rem;
  padding: 0.5rem 0.5rem 0.5rem 1.25rem;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 999px;
}
.chat-form textarea {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0;
  border: none;
  outline: none;
  background: transparent;
  font-size: 1rem;
  font-family: inherit;
  resize: none;
  line-height: 1.4;
  field-sizing: content;
  max-height: 9rem;
}
.chat-form-actions { display: flex; align-items: center; gap: 0.4rem; }
.icon-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  background: var(--chip);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--border); }
.send-btn {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stop-btn { background: var(--danger); color: white; }
.stop-btn:hover { filter: brightness(0.92); }

.mic-btn.listening {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
  animation: mic-pulse 1.2s infinite;
}
.mic-btn.unsupported { display: none; }

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(224, 49, 49, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(224, 49, 49, 0); }
}

button {
  background: var(--primary);
  color: var(--on-primary);
  border: none;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.95rem;
}
button:hover { background: var(--primary-hover); }
button:disabled { background: var(--border); color: var(--muted); cursor: not-allowed; }

/* ---- KB ---- */

.kb-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; gap: 1rem; }
.kb-toolbar .secondary-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.kb-toolbar .secondary-btn:hover:not(:disabled) { background: var(--bg); }
.kb-toolbar input {
  flex: 1;
  padding: 0.5rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.kb-add {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}
.kb-add summary { cursor: pointer; font-weight: 600; }
.kb-add form { margin-top: 0.75rem; display: flex; flex-direction: column; gap: 0.5rem; }
.kb-add textarea { padding: 0.5rem; border: 1px solid var(--border); border-radius: var(--radius); min-height: 60px; font-family: inherit; }
.kb-add .row { display: flex; gap: 0.5rem; }
.kb-add select { flex: 1; padding: 0.5rem; border: 1px solid var(--border); border-radius: var(--radius); }

.kb-table-scroll { overflow-x: auto; border-radius: var(--radius); }
.kb-table { width: 100%; min-width: 560px; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); }
.kb-table th, .kb-table td { text-align: left; padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--border); font-size: 0.9rem; vertical-align: top; }
.kb-table th { background: var(--bg); font-weight: 600; }
.kb-table td.actions { text-align: right; }
.kb-table .badge { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.78rem; background: var(--bg); color: var(--muted); white-space: nowrap; }
.kb-table .delete-btn { background: none; color: var(--danger); padding: 0.2rem 0.5rem; font-size: 0.85rem; }
.kb-table .delete-btn:hover { background: var(--danger-bg); }

#document-viewer {
  margin-top: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.document-viewer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.document-viewer-header > div { display: flex; gap: 0.5rem; }
#document-viewer-content {
  margin: 0;
  padding: 1rem;
  max-height: 60vh;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: 0.9rem;
}

.todo-add-form { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.todo-add-form input {
  flex: 1;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.todo-add-form textarea {
  flex: 1;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  line-height: 1.4;
  color: inherit;
  background: var(--surface);
  min-height: 2.4rem;
  max-height: 40vh;
  resize: vertical;
}
.todo-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.todo-list li {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.5rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.todo-rank { font-weight: 700; color: var(--muted); min-width: 1.5rem; }
.todo-text { flex: 1; cursor: text; white-space: pre-wrap; overflow-wrap: anywhere; }
.todo-text:hover { text-decoration: underline dotted; text-underline-offset: 3px; }
.todo-edit-input {
  flex: 1;
  min-height: 3.2rem;
  resize: vertical;
  line-height: 1.4;
  padding: 0.15rem 0.4rem;
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  font: inherit;
  color: inherit;
  background: var(--surface);
}
.todo-actions { display: flex; gap: 0.25rem; flex-wrap: wrap; justify-content: flex-end; }
.todo-actions button {
  background: none;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.2rem 0.4rem;
  font-size: 0.85rem;
  cursor: pointer;
}
.todo-actions .todo-delete { color: var(--danger); }

/* ---- Agenda ---- */

.calendar-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin: 1rem 0;
}
.calendar-toolbar .secondary-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.calendar-toolbar .secondary-btn:hover:not(:disabled) { background: var(--bg); }
#calendar-month-label { font-weight: 700; min-width: 11rem; text-align: center; text-transform: capitalize; }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.calendar-day-header {
  text-align: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  padding: 0.3rem 0;
}
.calendar-day {
  min-height: 90px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.3rem;
  font-size: 0.78rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}
.calendar-day.other-month { opacity: 0.4; }
.calendar-day.today { border-color: var(--primary); border-width: 2px; }
.calendar-day-number { font-weight: 600; margin-bottom: 2px; }
.calendar-event-chip {
  background: var(--primary);
  color: var(--on-primary);
  border: none;
  border-radius: 4px;
  padding: 1px 4px;
  font-size: 0.7rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
  cursor: pointer;
}
.calendar-event-more {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.7rem;
  text-align: left;
  cursor: pointer;
  padding: 0;
}

#calendar-event-viewer {
  margin-top: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
#calendar-event-details { padding: 1rem; font-size: 0.9rem; line-height: 1.6; }
#calendar-event-details div { margin-bottom: 0.3rem; }
#calendar-event-delete { margin: 0 1rem 1rem; background: var(--danger); }

.calendar-event-edit-form {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.calendar-event-edit-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.calendar-event-edit-form label.calendar-edit-allday {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}
.calendar-event-edit-form input[type="text"],
.calendar-event-edit-form input[type="datetime-local"],
.calendar-event-edit-form input[type="date"],
.calendar-event-edit-form textarea {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
}
.calendar-event-edit-form textarea { min-height: 60px; resize: vertical; }
.calendar-event-edit-form .row { display: flex; gap: 0.5rem; }

.calendar-view-switch { display: flex; justify-content: center; gap: 0.4rem; margin-bottom: 1rem; }
.calendar-view-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.35rem 0.9rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
}
.calendar-view-btn.active { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.calendar-view-btn:hover:not(.active) { background: var(--bg); }

/* Vue semaine : mêmes 7 colonnes que la vue mois, mais cellules plus hautes et
   événements affichés en entier (pas de troncature ni de "+X de plus"). */
.calendar-day-week { min-height: 220px; }
.calendar-event-chip-week {
  white-space: normal;
  text-align: left;
  padding: 3px 5px;
}
.calendar-event-time { font-weight: 700; }

/* Vue jour : simple liste chronologique plutôt qu'une grille. */
.calendar-grid-day { display: flex; flex-direction: column; gap: 0.4rem; }
.calendar-day-event-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.6rem 0.9rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: left;
  cursor: pointer;
  font-size: 0.9rem;
  width: 100%;
}
.calendar-day-event-row .calendar-event-time { color: var(--primary); min-width: 8rem; }
.calendar-day-event-summary { flex: 1; }

/* ---- Import Claude ---- */

.import-form { display: flex; gap: 0.5rem; align-items: center; margin: 1rem 0; }

#import-loading {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 1rem 0;
}

.conv-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.conv-card h3 { margin: 0 0 0.75rem; font-size: 1rem; }
.conv-card .conv-date { color: var(--muted); font-weight: 400; font-size: 0.85rem; }

.fact-row {
  display: flex;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-top: 1px solid var(--border);
  align-items: flex-start;
}
.fact-row:first-of-type { border-top: none; }
.fact-row input[type="checkbox"] { margin-top: 0.35rem; }
.fact-body { flex: 1; display: flex; flex-direction: column; gap: 0.35rem; }
.fact-body textarea { width: 100%; padding: 0.4rem; border: 1px solid var(--border); border-radius: 6px; font-family: inherit; font-size: 0.92rem; resize: vertical; }
.fact-meta { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.fact-meta select { padding: 0.2rem 0.4rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.82rem; }
.decision-badge { padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.78rem; color: white; white-space: nowrap; }
.decision-badge.add { background: var(--add); }
.decision-badge.replace { background: var(--replace); }
.decision-badge.skip { background: var(--skip); }
.fact-reason { font-size: 0.8rem; color: var(--muted); font-style: italic; }
.fact-similar { font-size: 0.78rem; color: var(--muted); }

#import-apply-bar { display: flex; align-items: center; gap: 1rem; margin-top: 1rem; position: sticky; bottom: 0; background: var(--bg); padding: 1rem 0; }

/* ---- Réglages / thèmes ---- */

.settings-section { margin-bottom: 2rem; }
.settings-section h2 { margin: 0 0 0.25rem; font-size: 1.15rem; }
.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 0.9rem;
  margin-top: 1rem;
}
.theme-card {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.7rem;
  text-align: left;
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: 18px;
}
.theme-card:hover { background: var(--surface); border-color: var(--primary); }
.theme-card[aria-pressed="true"] { border-color: var(--primary); box-shadow: 0 0 0 3px var(--chip); }
.theme-preview {
  height: 84px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.theme-preview .tp-nav { display: flex; gap: 4px; }
.theme-preview .tp-nav i { height: 8px; width: 22px; border-radius: 999px; background: var(--chip); }
.theme-preview .tp-nav i:first-child { background: var(--primary); }
.theme-preview .tp-body { flex: 1; display: flex; gap: 6px; }
.theme-preview .tp-chat { flex: 1; background: var(--surface); border-radius: 8px; padding: 5px; display: flex; flex-direction: column; gap: 4px; }
.theme-preview .tp-chat i { height: 8px; border-radius: 6px; width: 60%; }
.theme-preview .tp-chat i.u { align-self: flex-end; background: var(--accent); }
.theme-preview .tp-chat i.a { background: var(--chip); width: 75%; }
.theme-preview .tp-side { width: 28%; background: var(--primary); border-radius: 8px; }
.theme-name { display: flex; justify-content: space-between; align-items: center; font-weight: 600; font-size: 0.95rem; }
.theme-tag { font-weight: 400; font-size: 0.75rem; color: var(--muted); }

/* ---- Compte, connexion, clés API ---- */

.account-bar { margin-left: auto; display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.account-bar .secondary-btn,
.overlay-header .secondary-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
}
.account-bar .secondary-btn:hover,
.overlay-header .secondary-btn:hover { background: var(--bg); }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(31, 36, 48, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem;
  overflow-y: auto;
}
.overlay-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 560px;
  width: 100%;
  line-height: 1.55;
}
.overlay-card h2 { margin-top: 0; }
.overlay-card h3 { margin: 1.2rem 0 0.4rem; font-size: 1rem; }
.overlay-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.overlay-header h2 { margin: 0; }

.login-btn {
  display: inline-block;
  background: var(--primary);
  color: var(--on-primary);
  text-decoration: none;
  padding: 0.7rem 1.2rem;
  border-radius: var(--radius);
  font-weight: 600;
  margin: 0.5rem 0 1rem;
}
.login-btn:hover { background: var(--primary-hover); }

.keys-alert {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger-border);
  border-radius: var(--radius);
  padding: 0.6rem 0.8rem;
  margin: 1rem 0 0;
  font-size: 0.9rem;
}
.keys-steps { padding-left: 1.2rem; margin: 0.4rem 0 0.8rem; }
.keys-steps li { margin-bottom: 0.4rem; }
.keys-card code { background: var(--bg); padding: 0.05rem 0.35rem; border-radius: 4px; }
.keys-list { list-style: none; padding: 0; margin: 0 0 0.8rem; display: flex; flex-direction: column; gap: 0.4rem; }
.keys-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.45rem 0.7rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.85rem;
}
.keys-list li button {
  background: none;
  color: var(--danger);
  border: 1px solid var(--border);
  padding: 0.15rem 0.5rem;
  font-size: 0.8rem;
}
.keys-form { display: flex; gap: 0.5rem; }
.keys-form input {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  color: var(--text);
  background: var(--surface);
}


.import-guide {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 1rem 1.25rem;
  margin: 0.75rem 0;
  line-height: 1.6;
}
.import-guide ol { margin: 0.4rem 0 0.4rem 1.2rem; padding: 0; }
.import-guide p { margin: 0.4rem 0; }
.import-prompt {
  white-space: pre-wrap;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.7rem 0.9rem;
  font-family: inherit;
  font-size: 0.9rem;
  margin: 0.5rem 0;
}
#import-paste-form { margin-top: 0.75rem; display: flex; flex-direction: column; gap: 0.5rem; }
#import-paste-form textarea { padding: 0.6rem; border: 1px solid var(--border); border-radius: 12px; font-family: inherit; }

@media (max-width: 960px) {
  #tab-chat.active { height: auto; }
  .chat-layout { grid-template-columns: 1fr; height: auto; }
  #tab-chat .chat-card { height: 70vh; min-height: 460px; flex: none; }
  .side-panels { overflow: visible; }
  header { padding: 0.75rem 1rem; }
  main { padding: 0.5rem 1rem 1.5rem; }
}

@media (max-width: 600px) {
  /* Téléphone : la page d'accueil ne garde que le chat (agenda et tâches restent dans leurs onglets) */
  .side-panels { display: none; }
  .account-bar { margin-left: 0; width: 100%; }
  .overlay { padding: 1rem 0.5rem; }
  .keys-form { flex-wrap: wrap; }
  .keys-form button { width: 100%; }
  header { padding: 0.75rem 1rem; }
  header h1 { font-size: 1rem; }
  nav { width: 100%; gap: 0.35rem; }
  .tab-btn { padding: 0.45rem 0.7rem; font-size: 0.85rem; text-align: center; }
  .brand-mark { width: 36px; height: 36px; }
  .chat-form { margin: 0 0.6rem 0.8rem; padding-left: 0.9rem; }
  .chat-messages { padding: 1rem; }

  main { padding: 1rem; }

  .chat-toolbar { flex-wrap: wrap; row-gap: 0.5rem; }
  .chat-toolbar .secondary-btn { margin-left: 0; flex-basis: 100%; }

  .chat-messages { max-height: 55vh; }
  .msg { max-width: 90%; }

  .import-form { flex-wrap: wrap; }

  .calendar-day { min-height: 60px; padding: 0.2rem; font-size: 0.68rem; }
  .calendar-event-chip, .calendar-event-more { font-size: 0.62rem; }
  #calendar-month-label { min-width: 8rem; font-size: 0.9rem; }
  .calendar-day-week { min-height: 120px; }
  .calendar-day-event-row { flex-wrap: wrap; }
  .calendar-day-event-row .calendar-event-time { min-width: auto; }
  .import-form input[type="file"] { flex-basis: 100%; }

  .kb-toolbar { flex-wrap: wrap; }
  .kb-toolbar input { flex-basis: 100%; }

  #import-apply-bar { flex-wrap: wrap; }
}

/* Mise en valeur du texte des tâches : barre B / I / rouge à droite du champ, rendu dans les listes */
.todo-field { position: relative; flex: 1; display: flex; min-width: 0; }
.todo-field textarea, .todo-field .todo-edit-input { width: 100%; padding-right: 6.3rem; }
.fmt-bar { position: absolute; top: 0.3rem; right: 0.35rem; display: flex; gap: 0.15rem; }
.fmt-btn { width: 1.75rem; height: 1.75rem; padding: 0; display: grid; place-items: center; line-height: 1; font-size: 0.95rem; border-radius: 6px; border: 1px solid var(--border); background: var(--chip, var(--surface)); color: var(--text, inherit); cursor: pointer; }
.fmt-btn:hover { border-color: var(--primary, currentColor); }
.fmt-red { color: #e5383b; font-weight: 800; line-height: 1; padding: 0 1px; border-bottom: 3px solid #e5383b; }
.rt-red { color: #e5383b; }
.todo-text strong, .side-todo strong { font-weight: 800; }
/* Modification d'une tâche : la barre passe au-dessus du texte pour laisser toute la largeur à la saisie */
.todo-field-edit { flex-direction: column; gap: 0.25rem; }
.todo-field-edit .fmt-bar { position: static; align-self: flex-end; order: -1; }
.todo-field-edit .todo-edit-input { padding-right: 0.4rem; flex: none; } /* flex: none : en colonne, « flex: 1 » ignorerait la hauteur calculée et ne montrerait que 2 lignes */

/* ---- Images jointes aux tâches : miniatures + fenêtre d'agrandissement ---- */
.todo-main { flex: 1; min-width: 0; }
.todo-imgs { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.4rem; }
.todo-imgs-pending { margin: -0.4rem 0 1rem; }
.todo-thumb-wrap { position: relative; display: inline-block; }
.todo-thumb { display: block; padding: 0; line-height: 0; overflow: hidden; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: zoom-in; }
span.todo-thumb { cursor: default; }
.todo-thumb:hover, .todo-thumb:focus-visible { border-color: var(--primary); }
.todo-thumb img { display: block; height: 56px; width: auto; max-width: 110px; object-fit: cover; }
.todo-thumb-del { position: absolute; top: -7px; right: -7px; width: 20px; height: 20px; padding: 0; border: 1px solid var(--border); border-radius: 50%; background: var(--surface); color: var(--danger); font-size: 0.65rem; line-height: 1; cursor: pointer; }
.todo-thumb-del:hover { background: var(--danger-bg); }
.todo-actions .todo-img-add:disabled { opacity: 0.4; cursor: not-allowed; }
.side-main { min-width: 0; }
.side-main > span { display: block; white-space: pre-wrap; overflow-wrap: anywhere; padding-top: 0.1rem; }
.side-todo .todo-thumb img { height: 40px; max-width: 80px; }
.side-todo .todo-imgs { margin-top: 0.3rem; }

.img-lightbox { position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center; background: rgba(15, 18, 26, 0.88); padding: 1rem; }
.img-lightbox .lb-img { max-width: min(92vw, 1600px); max-height: 88vh; object-fit: contain; border-radius: 6px; background: #fff; box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5); }
.img-lightbox .lb-close, .img-lightbox .lb-nav { position: absolute; display: flex; align-items: center; justify-content: center; border: 0; border-radius: 50%; background: rgba(255, 255, 255, 0.16); color: #fff; cursor: pointer; line-height: 1; }
.img-lightbox .lb-close:hover, .img-lightbox .lb-nav:hover { background: rgba(255, 255, 255, 0.3); }
.img-lightbox .lb-close { top: 0.8rem; right: 0.8rem; width: 2.6rem; height: 2.6rem; font-size: 1.2rem; }
.img-lightbox .lb-nav { top: 50%; transform: translateY(-50%); width: 2.8rem; height: 2.8rem; font-size: 2rem; padding-bottom: 0.2rem; }
.img-lightbox .lb-prev { left: 0.8rem; }
.img-lightbox .lb-next { right: 0.8rem; }
.img-lightbox .lb-count { position: absolute; bottom: 0.8rem; left: 50%; transform: translateX(-50%); color: #fff; font-size: 0.9rem; background: rgba(0, 0, 0, 0.4); padding: 0.15rem 0.7rem; border-radius: 999px; }
@media (max-width: 600px) {
  .img-lightbox .lb-nav { top: auto; bottom: 0.8rem; transform: none; }
  .img-lightbox .lb-prev { left: 1rem; }
  .img-lightbox .lb-next { right: 1rem; }
}
@media (max-width: 600px) {
  /* Téléphone : le champ « Nouvelle tâche » prend toute la largeur, les boutons (image, micro, Ajouter) passent dessous */
  #todo-add-form { flex-wrap: wrap; }
  #todo-add-form .todo-field { flex: 1 1 100%; }
  #todo-add-form button[type="submit"] { margin-left: auto; }
}

/* Mon nom et la dictée vocale (Réglages) */
.vn-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0.8rem 1rem; margin-top: 0.9rem; max-width: 760px; }
.vn-row { display: flex; flex-direction: column; gap: 0.25rem; font-weight: 600; }
.vn-row input { font-weight: 400; }
.vn-row small { font-weight: 400; }
.vn-check { display: flex; align-items: flex-start; gap: 0.6rem; margin-top: 1rem; max-width: 760px; }
.vn-check input { margin-top: 0.2rem; flex: none; }
.vn-status { min-height: 1.2em; margin: 0.5rem 0 0; }

/* ---- Glisser-déposer des tâches ---- */
.todo-grip { flex: none; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; padding: 0.1rem 0.35rem; margin: -0.05rem 0 0 -0.3rem; font-size: 1.25rem; line-height: 1.2; color: var(--muted); border-radius: 6px; }
.todo-grip:hover { background: var(--border); color: var(--text); }
.todo-list li { transition: transform 0.14s ease; }
.todo-list li.dragging { position: relative; z-index: 20; transition: none; cursor: grabbing; box-shadow: 0 8px 22px rgba(0, 0, 0, 0.25); border-color: var(--primary); }
.todo-list li.dragging .todo-grip { cursor: grabbing; }
.todo-list.drag-active { user-select: none; -webkit-user-select: none; }
@media (max-width: 600px) { .todo-grip { font-size: 1.5rem; padding: 0.2rem 0.5rem; } }
