:root {
  --wine: #2b1620;
  --wine-panel: #3a2029;
  --wine-line: #5a3a45;
  --ivory: #f2e9de;
  --ivory-dim: #cbb9ac;
  --rose: #c97b84;
  --gold: #c9a66b;
  --font-display: Georgia, 'Iowan Old Style', 'Palatino Linotype', serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100vh;
  background: var(--wine);
  color: var(--ivory);
  font-family: var(--font-body);
}

button, input, textarea {
  font-family: inherit;
  color: inherit;
}

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

.btn-primary {
  background: var(--rose);
  color: var(--wine);
  border: none;
  padding: 0.6rem 1.1rem;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
}
.btn-primary:hover { background: #d68e96; }

.btn-ghost {
  background: none;
  border: 1px solid var(--wine-line);
  color: var(--ivory-dim);
  padding: 0.55rem 1rem;
  border-radius: 4px;
  font-size: 0.9rem;
  text-decoration: none;
  cursor: pointer;
}
.btn-ghost:hover { border-color: var(--rose); color: var(--ivory); }

/* ---------- Page de connexion ---------- */

.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-card {
  width: min(360px, 90vw);
  padding: 2.5rem 2rem;
  text-align: center;
}

.auth-mark {
  font-family: var(--font-display);
  font-size: 2rem;
  color: var(--gold);
  margin: 0 0 0.25rem;
}

.auth-card h1 {
  font-family: var(--font-display);
  font-size: 1.8rem;
  margin: 0 0 0.35rem;
  letter-spacing: 0.02em;
}

.auth-sub {
  color: var(--ivory-dim);
  margin: 0 0 1.75rem;
  font-size: 0.95rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  text-align: left;
}

.auth-form label {
  font-size: 0.8rem;
  color: var(--ivory-dim);
  margin-top: 0.6rem;
}

.auth-form input {
  background: var(--wine-panel);
  border: 1px solid var(--wine-line);
  border-radius: 4px;
  padding: 0.6rem 0.7rem;
  font-size: 0.95rem;
}
.auth-form input:focus { outline: 2px solid var(--rose); outline-offset: 1px; }

.auth-form button { margin-top: 1.3rem; }

.error {
  background: rgba(201, 123, 132, 0.15);
  border: 1px solid var(--rose);
  color: var(--rose);
  padding: 0.6rem 0.8rem;
  border-radius: 4px;
  font-size: 0.9rem;
}

/* ---------- App ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid var(--wine-line);
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.app-logo {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  object-fit: cover;
}

.app-header h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  margin: 0;
  letter-spacing: 0.02em;
}

.header-actions { display: flex; gap: 0.7rem; align-items: center; }

.app-body {
  display: grid;
  grid-template-columns: 64px 1fr;
}

.alphabet-rail {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--wine-line);
  padding: 0.75rem 0;
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
}

.rail-letter {
  background: none;
  border: none;
  padding: 0.4rem 0;
  font-family: var(--font-display);
  font-size: 0.95rem;
  color: var(--gold);
  cursor: pointer;
}
.rail-letter.is-empty { color: var(--wine-line); }
.rail-letter:hover { color: var(--rose); }

.content {
  padding: 1.5rem 2rem 4rem;
  max-width: 720px;
}

.letter-group {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 0 1.25rem;
  margin-bottom: 2.5rem;
}

.letter-title {
  grid-column: 1;
  align-self: start;
  position: sticky;
  top: 1.25rem;
  font-family: var(--font-display);
  font-size: 3.6rem;
  line-height: 1;
  color: var(--gold);
  margin: 0;
}

.entry-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.entry-card {
  position: relative;
  border-left: 3px solid var(--rose);
  background: var(--wine-panel);
  padding: 0.75rem 2.2rem 0.75rem 1rem;
  margin-bottom: 0.6rem;
  border-radius: 0 4px 4px 0;
}

.entry-main {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: baseline;
}

.entry-title { font-weight: 600; }

.entry-date {
  font-size: 0.85rem;
  color: var(--ivory-dim);
  white-space: nowrap;
}

.entry-desc {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
  color: var(--ivory-dim);
  line-height: 1.4;
}

.entry-delete {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  background: none;
  border: none;
  color: var(--wine-line);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.1rem 0.3rem;
}
.entry-delete:hover { color: var(--rose); }
.entry-delete:disabled { cursor: not-allowed; opacity: 0.6; }

/* ---------- Indicateur de chargement (bouton Enregistrer) ---------- */

.btn-primary:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.btn-spinner {
  display: inline-block;
  width: 0.9rem;
  height: 0.9rem;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: var(--wine);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.btn-spinner[hidden] { display: none; }

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

@media (prefers-reduced-motion: reduce) {
  .btn-spinner { animation-duration: 1.4s; }
}

.empty-state {
  color: var(--ivory-dim);
  font-style: italic;
  margin-top: 2rem;
}

/* ---------- Dialogue d'ajout ---------- */

.add-dialog {
  border: none;
  border-radius: 6px;
  padding: 1.75rem;
  width: min(420px, 92vw);
  background: var(--wine-panel);
  color: var(--ivory);
}
.add-dialog::backdrop { background: rgba(20, 10, 14, 0.6); }

.add-dialog h2 {
  font-family: var(--font-display);
  margin: 0 0 1rem;
  font-size: 1.3rem;
}

#add-form { display: flex; flex-direction: column; }

#add-form label {
  font-size: 0.8rem;
  color: var(--ivory-dim);
  margin-top: 0.8rem;
}

#add-form input,
#add-form textarea {
  background: var(--wine);
  border: 1px solid var(--wine-line);
  border-radius: 4px;
  padding: 0.55rem 0.65rem;
  font-size: 0.95rem;
  resize: vertical;
}
#add-form input:focus,
#add-form textarea:focus { outline: 2px solid var(--rose); outline-offset: 1px; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1.4rem;
}

/* ---------- Mobile ---------- */

@media (max-width: 640px) {
  .app-body { grid-template-columns: 44px 1fr; }
  .alphabet-rail { height: auto; position: static; }
  .content { padding: 1.2rem 1rem 3rem; }
  .app-header { padding: 1rem; }

  .letter-group { grid-template-columns: 52px 1fr; }
  .letter-title { font-size: 2.2rem; position: static; }

  .add-btn-label { display: none; }
  #add-btn {
    padding: 0.6rem 0.85rem;
    font-size: 1.1rem;
    line-height: 1;
  }
}