:root {
  color-scheme: light;
  --surface: #fcfcfb;
  --page: #f9f9f7;
  --ink: #0b0b0b;
  --ink-secondary: #52514e;
  --muted: #898781;
  --gridline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --accent-strong: #1c5cab;
  --danger: #e34948;

  --c-reve: #2a78d6;
  --c-reflexion: #eb6834;
  --c-idee: #1baf7a;
  --c-sortie_de_corps: #4a3aa7;
  --c-autre: #898781;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-8: 3rem;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;

  --shadow-sm: 0 1px 2px rgba(11, 11, 11, 0.06), 0 1px 1px rgba(11, 11, 11, 0.04);
  --shadow-md: 0 8px 24px rgba(11, 11, 11, 0.08), 0 2px 6px rgba(11, 11, 11, 0.05);
  --shadow-focus: 0 0 0 3px rgba(42, 120, 214, 0.25);

  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface: #1a1a19;
    --page: #0d0d0d;
    --ink: #ffffff;
    --ink-secondary: #c3c2b7;
    --muted: #898781;
    --gridline: #2c2c2a;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --accent-strong: #6da7ec;
    --danger: #e66767;

    --c-reve: #3987e5;
    --c-reflexion: #d95926;
    --c-idee: #199e70;
    --c-sortie_de_corps: #9085e9;
    --c-autre: #898781;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35), 0 1px 1px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 12px 28px rgba(0, 0, 0, 0.45), 0 2px 8px rgba(0, 0, 0, 0.35);
    --shadow-focus: 0 0 0 3px rgba(57, 135, 229, 0.3);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background:
    radial-gradient(1200px 600px at 15% -10%, color-mix(in srgb, var(--accent) 6%, transparent), transparent),
    var(--page);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

body { animation: fade-in 0.35s var(--ease); }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

h1, h2 { letter-spacing: -0.01em; }

a {
  color: var(--accent);
  transition: color 0.15s var(--ease);
}
a:hover { color: var(--accent-strong); }

::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }

/* Nav */
.nav {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  padding: var(--space-3) var(--space-5);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.nav .brand {
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.01em;
}
.nav nav { display: flex; gap: var(--space-5); flex: 1; }
.nav nav a {
  text-decoration: none;
  color: var(--ink-secondary);
  font-size: 0.92rem;
  position: relative;
  padding-bottom: 2px;
}
.nav nav a::after {
  content: '';
  position: absolute;
  left: 0; right: 100%; bottom: -3px;
  height: 2px;
  background: var(--accent);
  border-radius: 2px;
  transition: right 0.2s var(--ease);
}
.nav nav a:hover { color: var(--ink); }
.nav nav a:hover::after { right: 0; }
.logout-form { display: flex; align-items: center; gap: var(--space-3); }
.logout-form .who { color: var(--muted); font-size: 0.88rem; }
.logout-form button {
  background: none; border: 1px solid var(--border); color: var(--ink-secondary);
  padding: 0.35rem 0.8rem; border-radius: var(--radius-sm); cursor: pointer;
  transition: border-color 0.15s var(--ease), color 0.15s var(--ease), background 0.15s var(--ease);
}
.logout-form button:hover { color: var(--ink); border-color: var(--ink-secondary); background: color-mix(in srgb, var(--ink) 4%, transparent); }

/* Login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--space-6); width: 340px;
  box-shadow: var(--shadow-md);
  animation: rise-in 0.4s var(--ease);
}
@keyframes rise-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.login-card h1 { font-size: 1.35rem; margin-top: 0; margin-bottom: var(--space-5); }
.login-card form { display: flex; flex-direction: column; gap: var(--space-4); }
.login-card label { display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.88rem; color: var(--ink-secondary); }
.error { color: var(--danger); font-size: 0.88rem; margin-top: -0.5rem; }

input[type="text"], input[type="password"], select, textarea {
  font: inherit;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--ink);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
input[type="text"]:focus, input[type="password"]:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--shadow-focus);
}

button {
  font: inherit;
  cursor: pointer;
}
button[type="submit"] {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s var(--ease), box-shadow 0.12s var(--ease), background 0.12s var(--ease);
}
button[type="submit"]:hover { background: var(--accent-strong); transform: translateY(-1px); box-shadow: var(--shadow-md); }
button[type="submit"]:active { transform: translateY(0); }
button.danger {
  background: var(--danger); color: #fff; border: none; padding: 0.6rem 1.2rem; border-radius: var(--radius-sm);
  font-weight: 600; transition: transform 0.12s var(--ease), box-shadow 0.12s var(--ease);
}
button.danger:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Graph page */
.graph-page {
  position: relative;
  height: calc(100vh - 61px);
  background-image: radial-gradient(var(--gridline) 1px, transparent 1px);
  background-size: 22px 22px;
}
.graph-canvas { width: 100%; height: 100%; }
.legend {
  position: absolute; top: var(--space-4); right: var(--space-4);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4); font-size: 0.85rem; color: var(--ink-secondary);
  box-shadow: var(--shadow-md);
}
.legend .legend-item { display: flex; align-items: center; gap: var(--space-2); margin: 0.35rem 0; }
.legend .swatch { width: 11px; height: 11px; border-radius: 50%; display: inline-block; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 12%, transparent); }
.empty-hint {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  color: var(--muted); text-align: center;
}

/* Content cards (form / view / admin pages) */
.note-form-page, .note-view-page, .admin-page {
  max-width: 720px; margin: var(--space-6) auto var(--space-8);
  padding: var(--space-6);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  animation: rise-in 0.3s var(--ease);
}
.admin-page { max-width: 800px; }

#note-form { display: flex; flex-direction: column; gap: var(--space-5); }
#note-form label { display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.88rem; color: var(--ink-secondary); }
#editor { background: var(--page); color: var(--ink); min-height: 200px; border: 1px solid var(--border); border-radius: 0 0 var(--radius-sm) var(--radius-sm); }
.ql-toolbar.ql-snow { border-radius: var(--radius-sm) var(--radius-sm) 0 0; border-color: var(--border) !important; }
.link-picker { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--space-3); }
.link-picker legend { padding: 0 var(--space-2); color: var(--ink-secondary); font-size: 0.85rem; font-weight: 600; }
.link-list { max-height: 200px; overflow-y: auto; display: flex; flex-direction: column; gap: 0.35rem; margin-top: var(--space-2); }
.link-item {
  flex-direction: row !important; align-items: center; gap: var(--space-2) !important; font-size: 0.9rem;
  padding: 0.3rem 0.4rem; border-radius: 6px; transition: background 0.12s var(--ease);
}
.link-item:hover { background: color-mix(in srgb, var(--ink) 4%, transparent); }
.form-actions { display: flex; align-items: center; gap: var(--space-4); }
.form-actions .cancel { color: var(--muted); text-decoration: none; transition: color 0.15s var(--ease); }
.form-actions .cancel:hover { color: var(--ink); }
.delete-form { margin-top: var(--space-6); border-top: 1px solid var(--border); padding-top: var(--space-4); }
.muted { color: var(--muted); }

/* Note view */
.note-header { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.note-header h1 { margin: 0; flex: 1; font-size: 1.6rem; min-width: 200px; }
.edit-link {
  text-decoration: none; font-size: 0.88rem; font-weight: 600;
  border: 1px solid var(--border); padding: 0.3rem 0.75rem; border-radius: var(--radius-sm);
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}
.edit-link:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.type-badge {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.01em; padding: 0.25rem 0.7rem; border-radius: 999px; color: #fff;
  box-shadow: var(--shadow-sm);
}
.type-reve { background: var(--c-reve); }
.type-reflexion { background: var(--c-reflexion); }
.type-idee { background: var(--c-idee); }
.type-sortie_de_corps { background: var(--c-sortie_de_corps); }
.type-autre { background: var(--c-autre); }

.tags { margin: var(--space-4) 0; display: flex; flex-wrap: wrap; gap: 0.4rem; }
.tag {
  color: var(--ink-secondary); font-size: 0.8rem;
  background: color-mix(in srgb, var(--ink) 5%, transparent);
  border: 1px solid var(--border);
  padding: 0.15rem 0.6rem; border-radius: 999px;
}
.note-content { padding: 0; line-height: 1.6; }
.linked-notes { margin-top: var(--space-6); border-top: 1px solid var(--border); padding-top: var(--space-4); }
.linked-notes h2 { font-size: 1rem; }
.linked-notes ul { list-style: none; padding: 0; }
.linked-notes li { padding: 0.35rem 0; }

/* Admin - IPs bloquees */
.blocked-table { width: 100%; border-collapse: collapse; margin-top: var(--space-4); font-size: 0.9rem; }
.blocked-table th {
  text-align: left; padding: 0.5rem 0.6rem; color: var(--muted); font-size: 0.78rem;
  text-transform: uppercase; letter-spacing: 0.03em; border-bottom: 1px solid var(--border);
}
.blocked-table td { text-align: left; padding: 0.6rem; border-bottom: 1px solid var(--border); }
.blocked-table tr:hover td { background: color-mix(in srgb, var(--ink) 3%, transparent); }
.blocked-table button {
  background: none; border: 1px solid var(--border); color: var(--ink-secondary); padding: 0.35rem 0.8rem; border-radius: var(--radius-sm);
  transition: border-color 0.15s var(--ease), color 0.15s var(--ease);
}
.blocked-table button:hover { border-color: var(--danger); color: var(--danger); }
.manual-block { margin-top: var(--space-6); border-top: 1px solid var(--border); padding-top: var(--space-4); }
.manual-block-form { display: flex; gap: var(--space-3); flex-wrap: wrap; }
.manual-block-form input { flex: 1; min-width: 160px; }
