:root {
  --bg: #0b0f14;
  --panel: #121820;
  --panel-2: #18202a;
  --line: #232c38;
  --text: #e6edf3;
  --muted: #8b98a8;
  --brand: #3fd47a;
  --danger: #f05d5d;
  --accent: #4c8dff;
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f5f8; --panel: #ffffff; --panel-2: #f6f8fa; --line: #dde3ea;
    --text: #1b2430; --muted: #5d6b7c; --brand: #18a957;
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }

/* ---------- Barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-weight: 700; letter-spacing: .04em; }
.brand img { width: 26px; height: 26px; }
.search-wrap { flex: 1; min-width: 0; }
#search {
  width: 100%; max-width: 520px; padding: 8px 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 9px; outline: none;
}
#search:focus { border-color: var(--brand); }
.actions { display: flex; gap: 6px; align-items: center; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 9px;
  background: var(--panel); border: 1px solid var(--line);
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #04140a; font-weight: 600; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.btn.icon { padding: 7px 11px; font-weight: 700; }
.btn[aria-pressed="true"] { border-color: var(--brand); color: var(--brand); }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 230px; z-index: 20;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px;
  box-shadow: 0 12px 30px rgba(0,0,0,.35);
}
.menu button { display: block; width: 100%; text-align: left; padding: 8px 10px; background: none; border: 0; border-radius: 7px; }
.menu button:hover { background: var(--panel-2); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 0; }

.banner { background: #6b4e00; color: #fff3cd; padding: 8px 16px; font-size: 14px; }

/* ---------- Tableau ---------- */
#board {
  display: grid; gap: 16px; padding: 16px;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  align-items: start;
  max-width: 1600px; margin: 0 auto;
}
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  border-top: 3px solid var(--accent);
  overflow: hidden;
}
.panel.dragging { opacity: .4; }
.panel.cat-before { box-shadow: -4px 0 0 var(--brand); }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px 8px; }
.editing .panel-head { cursor: grab; }
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 650; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-icon { font-size: 17px; }
.count { font-family: var(--mono); font-size: 12px; color: var(--muted); background: var(--panel-2); padding: 1px 7px; border-radius: 99px; }
.collapse { background: none; border: 0; color: var(--muted); padding: 0 2px; width: 18px; }

.links { list-style: none; margin: 0; padding: 0 6px 6px; min-height: 8px; }
.links.drop-into { outline: 2px dashed var(--brand); outline-offset: -4px; border-radius: 8px; }
.panel.drop-into { outline: 2px dashed var(--brand); }
.link { display: flex; align-items: center; gap: 4px; border-radius: 8px; position: relative; }
.link:hover { background: var(--panel-2); }
.link.dragging { opacity: .35; }
.link.drop-before::before, .link.drop-after::after {
  content: ""; position: absolute; left: 6px; right: 6px; height: 2px; background: var(--brand); border-radius: 2px;
}
.link.drop-before::before { top: -1px; }
.link.drop-after::after { bottom: -1px; }
.link.is-private .link-name { }
.grip { color: var(--muted); cursor: grab; padding-left: 4px; font-size: 12px; letter-spacing: -2px; user-select: none; }

.link-main {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px;
  padding: 7px 6px; color: inherit; text-decoration: none;
}
.fav {
  width: 26px; height: 26px; flex: none; border-radius: 6px; object-fit: contain;
  background: var(--panel-2);
}
.fav.letter, .fav.emoji { display: grid; place-items: center; font-size: 14px; font-weight: 700; }
.fav.letter { background: color-mix(in srgb, var(--accent) 22%, var(--panel-2)); color: var(--accent); font-family: var(--mono); }
.fav.emoji { font-size: 17px; background: none; }
.link-text { display: flex; flex-direction: column; min-width: 0; }
.link-name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 11px; margin-left: 6px; opacity: .75; }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; margin: 0 8px 0 4px; background: var(--line); }
.dot.up { background: var(--brand); box-shadow: 0 0 6px var(--brand); }
.dot.down { background: var(--danger); }
.dot.sleep { background: transparent; border: 1.5px solid #d29922; }

.row-tools { display: flex; gap: 2px; }
.mini {
  background: none; border: 1px solid transparent; border-radius: 6px;
  padding: 2px 6px; font-size: 13px; color: var(--muted);
}
.mini:hover { border-color: var(--line); color: var(--text); }
.mini.danger:hover { color: var(--danger); }
.mini.shared { color: var(--brand); }

.empty { color: var(--muted); font-size: 13px; padding: 10px; text-align: center; }
.add-here {
  display: block; width: calc(100% - 12px); margin: 0 6px 8px; padding: 7px;
  background: none; border: 1px dashed var(--line); border-radius: 8px; color: var(--muted);
}
.add-here:hover { color: var(--brand); border-color: var(--brand); }
.add-panel {
  min-height: 90px; border: 1px dashed var(--line); border-top: 1px dashed var(--line);
  background: transparent; color: var(--muted); font-size: 15px;
}
.add-panel:hover { color: var(--brand); border-color: var(--brand); }
.nothing { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 40px 0; }

/* ---------- Dialogues ---------- */
dialog {
  width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 24px);
  padding: 0; border: 1px solid var(--line); border-radius: 14px;
  background: var(--panel); color: var(--text);
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
}
dialog::backdrop { background: rgba(0,0,0,.55); backdrop-filter: blur(2px); }
dialog form { padding: 18px 18px 14px; display: flex; flex-direction: column; gap: 12px; }
dialog h2 { margin: 0 0 2px; font-size: 18px; }
dialog label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); flex: 1; min-width: 0; }
dialog input:not([type=checkbox]):not([type=color]), dialog select {
  width: 100%; padding: 8px 10px; background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; outline: none;
}
dialog input:focus, dialog select:focus { border-color: var(--brand); }
dialog input[type=color] { width: 52px; height: 37px; padding: 2px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
dialog .row { display: flex; gap: 10px; }
dialog .narrow { flex: 0 0 auto; width: 70px; }
dialog .grow { flex: 1; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
label.check input { width: 17px; height: 17px; accent-color: var(--brand); }
.share-box { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px 12px; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.share-box legend { color: var(--muted); font-size: 13px; padding: 0 4px; }
#share-url { font-family: var(--mono); font-size: 12px; }
.share-btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.hint { margin: 6px 0 0; color: var(--muted); font-size: 12.5px; }
.dlg-actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.spacer { flex: 1; }
#confirm-msg { margin: 4px 0; font-size: 15px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--brand);
  padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100vw - 32px);
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { border-left-color: var(--danger); }

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding-left: 12px; padding-right: 12px; }
  .search-wrap { order: 3; flex-basis: 100%; }
  #search { max-width: none; }
  .actions { margin-left: auto; }
  .lbl { display: none; }
  #board { padding: 12px; gap: 12px; grid-template-columns: 1fr; }
  .grip { display: none; }
  .link-main { padding: 9px 6px; }
  dialog .row { flex-direction: column; }
  dialog .narrow { width: auto; }
}

/* ---------- Pages login / partage ---------- */
.center-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 28px 24px; display: flex; flex-direction: column; gap: 14px; text-align: center;
}
.login-card img { width: 56px; height: 56px; margin: 0 auto; }
.login-card h1 { margin: 0; font-family: var(--mono); font-size: 22px; letter-spacing: .05em; }
.login-card p { margin: 0; color: var(--muted); font-size: 14px; }
.login-card input {
  padding: 11px 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 9px; outline: none; color: var(--text);
}
.login-card input:focus { border-color: var(--brand); }
.login-card .btn { justify-content: center; padding: 10px; }
.login-err { color: var(--danger) !important; min-height: 1.2em; }

.share-page { max-width: 640px; margin: 0 auto; padding: 24px 16px; }
.share-page .panel { margin-top: 12px; }
.share-page footer { color: var(--muted); font-size: 12.5px; text-align: center; margin-top: 18px; }
