/* ----------------------------------------------------------------
   Notes IA — feuille de style
   Esthétique : carnet de notes éditorial, papier crème, encre.
   ---------------------------------------------------------------- */

:root {
  --paper: #f4ede0;
  --paper-light: #fbf6ec;
  --paper-dark: #ebe2d0;
  --ink: #1c1814;
  --ink-soft: #4a4138;
  --ink-faded: #8a7e6e;
  --rule: #d8cdb8;
  --accent: #b04a2f;
  --accent-soft: #d97a5e;
  --accent-bg: #f5d9cf;
  --success: #4a6b3f;
  --warn: #b07827;

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "DM Sans", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --radius: 4px;
  --radius-lg: 8px;
  --shadow-card: 0 1px 0 var(--paper-dark), 0 12px 28px -18px rgba(28, 24, 20, 0.25);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  background-image:
    radial-gradient(rgba(28, 24, 20, 0.025) 1px, transparent 1px),
    radial-gradient(rgba(28, 24, 20, 0.018) 1px, transparent 1px);
  background-size: 22px 22px, 7px 7px;
  background-position: 0 0, 11px 11px;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 36px 18px;
  border-bottom: 1px solid var(--rule);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.brand-mark {
  font-family: var(--font-display);
  font-size: 28px;
  color: var(--accent);
  line-height: 1;
}

.brand h1 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 22px;
  margin: 0;
  letter-spacing: -0.01em;
}

.brand h1 em {
  font-style: italic;
  color: var(--accent);
  font-weight: 400;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ---------- Boutons ---------- */

.btn-primary, .btn-ghost {
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary {
  background: var(--ink);
  color: var(--paper-light);
  border: 1px solid var(--ink);
}

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

.btn-primary span {
  font-size: 16px;
  line-height: 1;
}

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--rule);
}

.btn-ghost:hover {
  background: var(--paper-dark);
  color: var(--ink);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Layout principal ---------- */

.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 0;
  min-height: calc(100vh - 73px);
}

/* ---------- Sidebar ---------- */

.sidebar {
  border-right: 1px solid var(--rule);
  padding: 24px 16px;
  background: rgba(235, 226, 208, 0.25);
}

.sidebar-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0 8px 14px;
  border-bottom: 1px dashed var(--rule);
  margin-bottom: 10px;
}

.sidebar-label {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 14px;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
}

.sidebar-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faded);
}

.notes-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.note-item {
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: all 0.12s ease;
}

.note-item:hover { background: rgba(176, 74, 47, 0.06); }

.note-item.active {
  background: var(--paper-light);
  border-left-color: var(--accent);
}

.note-item-title {
  font-weight: 500;
  font-size: 14px;
  color: var(--ink);
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-item-preview {
  font-size: 12px;
  color: var(--ink-faded);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-item-badge {
  display: inline-block;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--accent);
  background: var(--accent-bg);
  padding: 0 5px;
  border-radius: 2px;
  margin-right: 4px;
}

.empty-list {
  padding: 16px 8px;
  font-style: italic;
  color: var(--ink-faded);
  font-size: 13px;
  text-align: center;
}

/* ---------- Éditeur ---------- */

.editor-wrap {
  padding: 32px 48px 48px;
  overflow-y: auto;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
}

.editor {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.empty-state {
  align-items: center;
  justify-content: center;
  min-height: 60vh;
}

.empty-msg {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 22px;
  color: var(--ink-faded);
  text-align: center;
  line-height: 1.5;
}

.empty-msg span {
  font-size: 14px;
  font-family: var(--font-body);
  font-style: normal;
  color: var(--ink-faded);
  display: block;
  margin-top: 8px;
}

.title-input {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 500;
  letter-spacing: -0.015em;
  color: var(--ink);
  background: transparent;
  border: none;
  outline: none;
  padding: 0;
  width: 100%;
}

.title-input::placeholder {
  color: var(--ink-faded);
  font-style: italic;
}

.note-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--ink-faded);
  padding-bottom: 14px;
  border-bottom: 1px solid var(--rule);
}

.note-meta-date {
  font-family: var(--font-mono);
}

.note-meta-source {
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-bg);
  padding: 2px 8px;
  border-radius: 2px;
  font-family: var(--font-mono);
}

.tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tag {
  background: var(--accent-bg);
  color: var(--accent);
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.note-textarea {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.75;
  color: var(--ink);
  background: transparent;
  border: none;
  outline: none;
  padding: 0;
  resize: none;
  width: 100%;
  min-height: 280px;
  background-image: linear-gradient(to bottom, transparent calc(1.75em - 1px), var(--rule) calc(1.75em - 1px), var(--rule) 1.75em, transparent 1.75em);
  background-size: 100% 1.75em;
  background-position: 0 0.3em;
  background-attachment: local;
}

.note-textarea::placeholder {
  color: var(--ink-faded);
  font-style: italic;
}

/* ---------- Panneau actions IA ---------- */

.ai-panel {
  margin-top: 8px;
  padding: 16px 18px;
  background: var(--paper-light);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

.ai-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.ai-panel-title {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 14px;
  color: var(--ink-soft);
}

.ai-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ai-btn {
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 6px 12px;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.ai-btn:hover {
  background: var(--accent);
  color: var(--paper-light);
  border-color: var(--accent);
}

.ai-btn-delete {
  margin-left: auto;
  color: var(--accent);
}

.ai-btn-delete:hover {
  background: var(--accent);
  color: var(--paper-light);
}

.ask-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.ask-row input {
  flex: 1;
  font-family: inherit;
  font-size: 13px;
  padding: 8px 12px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  outline: none;
  transition: border 0.15s;
}

.ask-row input:focus { border-color: var(--accent); }

.ask-row button {
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  background: var(--ink);
  color: var(--paper-light);
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  cursor: pointer;
}

.ask-row button:hover {
  background: var(--accent);
  border-color: var(--accent);
}

.ai-output {
  margin-top: 14px;
  padding: 14px 16px;
  border-left: 3px solid var(--accent);
  background: var(--paper);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink);
  white-space: pre-wrap;
  animation: slideIn 0.25s ease;
}

.ai-output-label {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 12px;
  color: var(--accent);
  letter-spacing: 0.03em;
  display: block;
  margin-bottom: 6px;
  text-transform: lowercase;
}

.ai-output.is-warn { border-color: var(--warn); }
.ai-output.is-warn .ai-output-label { color: var(--warn); }
.ai-output.is-success { border-color: var(--success); }
.ai-output.is-success .ai-output-label { color: var(--success); }

.ai-output .inline-action {
  display: inline-block;
  margin-top: 10px;
  font-size: 12px;
  font-weight: 500;
  padding: 5px 12px;
  background: var(--accent);
  color: var(--paper-light);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
}

.ai-output .inline-action:hover { background: var(--ink); }

.loader-dots::after {
  content: "...";
  animation: dots 1.2s steps(4, end) infinite;
}

@keyframes dots {
  0%, 20% { content: ""; }
  40%     { content: "."; }
  60%     { content: ".."; }
  80%, 100% { content: "..."; }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Modale ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(28, 24, 20, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}

.modal[hidden] { display: none; }

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background: var(--paper-light);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  max-width: 440px;
  width: 90%;
  box-shadow: 0 20px 60px -10px rgba(0, 0, 0, 0.35);
}

.modal-card h2 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 22px;
  margin: 0 0 8px;
}

.modal-intro {
  color: var(--ink-soft);
  font-size: 13px;
  margin: 0 0 16px;
}

.modal-intro a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

#api-key-input {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 10px 12px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  outline: none;
}

#api-key-input:focus { border-color: var(--accent); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

/* ---------- Drop overlay (drag & drop fichier) ---------- */

.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 24, 20, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
  animation: fadeIn 0.15s ease;
  pointer-events: none;
}

.drop-overlay[hidden] { display: none; }

.drop-overlay-inner {
  border: 2px dashed var(--paper);
  border-radius: var(--radius-lg);
  padding: 60px 80px;
  text-align: center;
  color: var(--paper);
  background: rgba(176, 74, 47, 0.1);
}

.drop-overlay-inner svg {
  margin-bottom: 18px;
  opacity: 0.9;
}

.drop-overlay-title {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 500;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}

.drop-overlay-sub {
  font-size: 13px;
  margin: 0;
  opacity: 0.7;
  letter-spacing: 0.02em;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper-light);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 200;
  animation: slideUp 0.2s ease;
}

.toast[hidden] { display: none; }
.toast.is-warn { background: var(--warn); }
.toast.is-success { background: var(--success); }

@keyframes slideUp {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- Responsive ---------- */

@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--rule); }
  .editor-wrap { padding: 24px 22px; }
  .title-input { font-size: 24px; }
  .topbar { flex-wrap: wrap; padding: 16px 22px; }
  .btn-ghost svg + span,
  .btn-ghost { font-size: 12px; }
}
