:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --line: #e2e0da;
  --accent: #1a7f4b;
  --accent-text: #ffffff;
  --warn: #b5530b;
  --danger: #b42318;
  --selected: #e7f3ec;
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151614;
    --surface: #1e1f1c;
    --text: #ecebe6;
    --muted: #9b9a93;
    --line: #34352f;
    --accent: #3ccf7f;
    --accent-text: #0d1a12;
    --warn: #f0a050;
    --danger: #ff7b6e;
    --selected: #22342a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 1.4rem; margin: .2rem 0; }
h2 { font-size: 1.1rem; margin: .4rem 0; }
code { background: var(--bg); padding: 0 .3em; border-radius: 4px; word-break: break-all; }

button, .button, input, select, textarea {
  font: inherit;
  color: inherit;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: .4rem .7rem;
}
button, .button { cursor: pointer; text-decoration: none; display: inline-block; }
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
button.primary, .button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; padding: .2rem .4rem; color: var(--muted); }
textarea { width: 100%; resize: vertical; }

.row { display: flex; align-items: center; }
.between { justify-content: space-between; }
.gap { gap: .5rem; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: .6rem; }
.stack label { display: grid; gap: .2rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); }
.narrow { max-width: 760px; margin: 1.5rem auto; padding: 0 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem 1.4rem; }
.checks { list-style: none; padding: 0; }
.checks .ok { color: var(--accent); }
.checks .ko { color: var(--danger); }
.steps li { margin-bottom: .4rem; }
.htmx-indicator { display: none; }
.htmx-request.htmx-indicator, .htmx-request .htmx-indicator { display: block; }
button.htmx-request { opacity: .6; }

.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: .5rem 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar .brand { font-weight: 600; color: var(--text); text-decoration: none; margin-right: auto; }
.topbar form { margin: 0; }

.playlists { list-style: none; padding: 0; }
.playlists li { padding: .6rem 0; border-bottom: 1px solid var(--line); display: flex; gap: .6rem; align-items: baseline; flex-wrap: wrap; }

/* ---- Espace de travail ---------------------------------------------- */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 400px);
  grid-template-areas: "search search" "board panel";
  gap: 0 1rem;
  padding: .8rem 16px;
  max-width: 1300px;
  margin: 0 auto;
}
.searchbar { grid-area: search; margin-bottom: .8rem; }
.searchbar input { width: 100%; }
.board { grid-area: board; min-width: 0; }
.panel {
  grid-area: panel;
  align-self: start;
  position: sticky; top: .8rem;
  max-height: calc(100vh - 1.6rem); overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .8rem 1rem;
}
.panel-inner { display: grid; gap: .7rem; }
.board-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem; }
.total { font-weight: 600; }
.dirty { color: var(--warn); font-size: .9rem; }
.toolbar { margin: .6rem 0; }
.toolbar form { margin: 0; }
.flash { display: none; }

/* ---- Arbre ------------------------------------------------------------ */
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul.children { padding-left: 1.4rem; min-height: .5rem; }
.node > .line {
  display: flex; align-items: center; gap: .4rem;
  padding: .3rem .4rem; border-radius: 6px; cursor: pointer;
}
.node > .line:hover { background: var(--surface); }
.node.selected > .line { background: var(--selected); }
.node-section { margin-top: .4rem; }
.node-section > .line { font-weight: 600; border-bottom: 1px solid var(--line); border-radius: 0; }
.node-block > .line { font-weight: 500; }
.node .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node .dur, .node .clock { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .85rem; }
.node .clock { min-width: 3em; }
.node .icon { color: var(--muted); width: 1.1em; text-align: center; }
.node .has-note { color: var(--muted); font-size: .8rem; }
.node .handle { cursor: grab; color: var(--muted); padding: 0 .2rem; user-select: none; }
.node .toggle { border: 0; background: none; padding: 0 .2rem; color: var(--muted); font-size: .7rem; transition: transform .15s; }
.node.collapsed > .line .toggle { transform: rotate(-90deg); }
.node.collapsed > ul.children { display: none; }
.node-block > ul.children { border-left: 2px solid var(--line); margin-left: .6rem; padding-left: .8rem; }
.node-block.locked > ul.children { border-left-color: var(--warn); }
.node.inbox > .line { color: var(--muted); font-style: italic; }
.node.unavailable > .line { opacity: .45; }
.sortable-ghost { opacity: .35; }

/* ---- Panneau ---------------------------------------------------------- */
.track-head { display: flex; gap: .8rem; align-items: flex-start; }
.track-head img { border-radius: 4px; flex: none; }
.track-head p { margin: .2rem 0; }
.note-body p, .note-body ul { margin: .3rem 0; }
.note-body button.ts {
  padding: 0 .3em; border-radius: 4px; font-variant-numeric: tabular-nums;
  color: var(--accent); border-color: currentColor; font-size: .9em;
}
.actions summary { cursor: pointer; color: var(--muted); }
.actions[open] { display: grid; gap: .5rem; }
.actions form { margin: 0; }
.results { list-style: none; padding: 0; margin: 0; display: grid; gap: .4rem; }
.results img { border-radius: 3px; flex: none; }

#toast {
  position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%) translateY(150%);
  background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: var(--radius);
  max-width: calc(100vw - 32px); transition: transform .2s; z-index: 20;
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--danger); color: #fff; }

/* ---- Téléphone : une colonne, panneau par-dessus, pas de glisser-déposer ---- */
@media (max-width: 760px) {
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-areas: "search" "board"; }
  .panel {
    display: none; position: fixed; inset: auto 0 0 0; top: 20vh; max-height: none;
    border-radius: 14px 14px 0 0; z-index: 10; box-shadow: 0 -8px 30px rgba(0, 0, 0, .25);
  }
  body.panel-open .panel { display: block; }
  .node .handle { display: none; }
  .tree ul.children { padding-left: .9rem; }
}
