:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1d232b;
  --muted: #677180;
  --line: #dde1e7;
  --accent: #1f5fbf;
  --accent-ink: #ffffff;
  --accent-soft: #e6eefb;
  --ok: #1e7b45;
  --ok-soft: #e3f4ea;
  --warn: #9a5b00;
  --warn-soft: #fff3db;
  --bad: #b3261e;
  --bad-soft: #fde8e6;
  --chip: #eef0f3;
  --top: 56px;
  font-size: 15px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --panel: #1c2027;
    --ink: #e6e9ee;
    --muted: #98a2b0;
    --line: #2e343d;
    --accent: #6ea2ff;
    --accent-ink: #0d1726;
    --accent-soft: #1d2b42;
    --ok: #63c98e;
    --ok-soft: #173325;
    --warn: #f0b45a;
    --warn-soft: #3a2c12;
    --bad: #ff8a80;
    --bad-soft: #3d1c1a;
    --chip: #262b33;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; line-height: 1.45; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pad { padding: 8px 12px; }

.btn, button.btn, label.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 7px 12px; border-radius: 8px; font: inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
button.link { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 0; }
.mini {
  border: 1px solid var(--line); background: transparent; color: var(--muted);
  border-radius: 6px; font-size: .75rem; padding: 1px 6px; margin-left: 4px; cursor: pointer; text-decoration: none;
}
.mini:hover { color: var(--accent); border-color: var(--accent); }
.mini.danger:hover { color: var(--bad); border-color: var(--bad); }
.count:empty { display: none; }
.count { background: var(--accent); color: var(--accent-ink); border-radius: 10px; padding: 0 7px; font-size: .8rem; }

/* BARRE DU HAUT */
.top {
  position: sticky; top: 0; z-index: 20; height: var(--top);
  display: flex; align-items: center; gap: 14px; padding: 0 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .2px; }
.clock { color: var(--muted); font-size: .9rem; white-space: nowrap; }
.clock b { color: var(--ink); }
.state { margin-left: 6px; padding: 1px 8px; border-radius: 10px; font-size: .78rem; }
.state.open { background: var(--ok-soft); color: var(--ok); }
.state.lunch { background: var(--warn-soft); color: var(--warn); }
.state.closed { background: var(--chip); color: var(--muted); }
.search { position: relative; flex: 1; min-width: 160px; max-width: 460px; }
.search input { width: 100%; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit; }
.results {
  position: absolute; top: 42px; left: 0; right: 0; max-height: 60vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.15);
}
.results button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--ink); padding: 8px 12px; font: inherit; cursor: pointer; }
.results button:hover { background: var(--accent-soft); }
.results .muted { display: block; font-size: .8rem; }
.top-actions { display: flex; gap: 8px; margin-left: auto; }
button.side-toggle { display: none; }
.warn { background: var(--bad-soft); color: var(--bad); padding: 8px 16px; font-weight: 600; }

/* MISE EN PAGE */
.layout {
  display: grid; grid-template-columns: 290px minmax(0, 1fr) 380px;
  gap: 16px; padding: 16px; align-items: start;
}
#side, #form {
  position: sticky; top: calc(var(--top) + 16px);
  max-height: calc(100vh - var(--top) - 32px); overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
}
.side-tools { position: sticky; top: 0; background: var(--panel); padding: 10px; display: grid; gap: 6px; border-bottom: 1px solid var(--line); z-index: 1; }
.side-tools select { width: 100%; padding: 6px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit; }
.group { font-size: .8rem; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 12px 12px 4px; display: flex; justify-content: space-between; }
.group button.link { font-size: .8rem; text-transform: uppercase; letter-spacing: .5px; display: flex; gap: 6px; }
.item {
  display: grid; grid-template-columns: 1fr auto; gap: 0 8px; width: 100%; text-align: left;
  background: none; border: 0; border-left: 3px solid transparent; padding: 7px 12px; color: var(--ink); font: inherit; cursor: pointer;
}
.item:hover { background: var(--accent-soft); }
.item.active { background: var(--accent-soft); border-left-color: var(--accent); }
.item.done .t { text-decoration: line-through; color: var(--muted); }
.item .t { font-weight: 600; font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .s { grid-column: 1; font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .m { grid-column: 2; grid-row: 1 / 3; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-size: .75rem; }
.item .where { color: var(--muted); }

/* BADGES */
.b { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: .78rem; background: var(--chip); color: var(--ink); white-space: nowrap; }
.b.ok { background: var(--ok-soft); color: var(--ok); }
.b.late { background: var(--bad-soft); color: var(--bad); }
.b.due { background: var(--warn-soft); color: var(--warn); }
.b.prio-A { background: var(--accent); color: var(--accent-ink); }
.b.prio-B { background: var(--accent-soft); color: var(--accent); }
.b.fam-nouveau { background: var(--accent-soft); color: var(--accent); }
.b.fam-suivi { background: var(--warn-soft); color: var(--warn); }
.b.fam-transmis { background: var(--ok-soft); color: var(--ok); }
.b.fam-clos, .b.fam-doublon, .b.fam-attente { background: var(--chip); color: var(--muted); }

/* FICHE */
#card { min-width: 0; }
.nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.pos { color: var(--muted); font-size: .9rem; }
.card-head { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 14px; }
.crumbs { color: var(--muted); font-size: .82rem; margin-bottom: 4px; overflow-wrap: anywhere; }
.card-head h1 { font-size: 1.5rem; margin-bottom: 8px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.alerts { margin: 10px 0 0; padding: 8px 12px; background: var(--warn-soft); color: var(--warn); border-radius: 8px; font-size: .92rem; }
.alerts ul { margin: 4px 0 0; padding-left: 18px; }
.alerts li { margin: 2px 0; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; min-width: 0; }
.box h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-bottom: 8px; }
.box.todo { grid-column: 1 / -1; border-left: 4px solid var(--accent); }
.box.history, .box.pitch, .box.linked { grid-column: 1 / -1; }
.next { font-size: 1.12rem; font-weight: 600; margin: 0 0 10px; }
dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 12px; margin: 0; }
dt { color: var(--muted); font-size: .85rem; }
dd { margin: 0; overflow-wrap: anywhere; }
a.tel { font-weight: 600; font-size: 1.05rem; text-decoration: none; }
.notes { max-height: 340px; overflow: auto; padding-right: 6px; }
.notes p { margin: 0 0 10px; }
.notes p.mine { background: var(--ok-soft); border-radius: 8px; padding: 8px 10px; }
.lk { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; width: 100%; text-align: left; background: none; border: 0; border-top: 1px solid var(--line); padding: 7px 0; color: var(--ink); font: inherit; cursor: pointer; }
.lk:hover { background: var(--accent-soft); }
.lk .muted { grid-column: 1; font-size: .8rem; }
.lk .st { grid-column: 1 / -1; font-size: .8rem; color: var(--muted); }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tab { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 16px; padding: 3px 12px; font: inherit; font-size: .85rem; cursor: pointer; }
.tab.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.script { font-size: 1.02rem; margin: 0 0 8px; }
.tip { color: var(--muted); font-size: .88rem; margin: 0; }
details.mail { border-top: 1px solid var(--line); padding: 6px 0; }
details.mail summary { cursor: pointer; font-weight: 600; }
details.mail pre { white-space: pre-wrap; font: inherit; background: var(--bg); padding: 10px; border-radius: 8px; }
.empty { background: var(--panel); border: 1px dashed var(--line); border-radius: 12px; padding: 40px 24px; text-align: center; }
.empty h2 { margin-bottom: 10px; }

/* FORMULAIRE */
#form { padding: 14px 16px; }
#form h2 { font-size: 1rem; margin-bottom: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { border: 1px solid var(--line); background: var(--chip); color: var(--ink); border-radius: 16px; padding: 5px 11px; font: inherit; font-size: .88rem; cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chips.small .chip { font-size: .8rem; padding: 3px 9px; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-bottom: 10px; font-size: .9rem; }
.field { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 8px; }
.field input, .field textarea, .entry textarea, .entry input, .entry select, select[data-jday], select[data-eday] {
  display: block; width: 100%; margin-top: 3px; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit; font-size: .95rem;
}
.field textarea { resize: vertical; min-height: 120px; }
details.fix { margin: 4px 0 10px; font-size: .9rem; }
details.fix summary { cursor: pointer; color: var(--muted); }
.err { color: var(--bad); font-weight: 600; margin: 6px 0; }
.mailbox { border: 1px dashed var(--line); border-radius: 10px; padding: 8px 10px; margin: 2px 0 10px; font-size: .88rem; color: var(--muted); }
.mailbox b { color: var(--ink); }
.mailbox.wanted { border-style: solid; border-color: var(--accent); background: var(--accent-soft); }
.mailbox .actions { margin: 6px 0 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }

/* FENÊTRES */
dialog {
  width: min(860px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow: auto;
  border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--ink); padding: 20px 24px;
}
dialog::backdrop { background: rgba(10, 14, 20, .45); }
dialog .close { float: right; }
dialog h2 { margin-bottom: 12px; }
dialog section { margin-bottom: 16px; }
dialog h3 { font-size: 1rem; margin-bottom: 6px; }
dialog table { border-collapse: collapse; width: 100%; font-size: .9rem; }
dialog td, dialog th { border-top: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }
.entry { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.entry header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; margin-bottom: 6px; }
.entry header .danger { margin-left: auto; }
.entry .row2 { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 6px; }
.entry .row2 select, .entry .row2 input[type=date] { width: auto; margin: 0; }
.entry textarea { margin-bottom: 6px; }
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 10px 0 14px; }
.stats div { background: var(--bg); border-radius: 10px; padding: 10px; text-align: center; font-size: .82rem; color: var(--muted); }
.stats b { display: block; font-size: 1.6rem; color: var(--ink); }
.how li { margin-bottom: 8px; }
.warnline { background: var(--warn-soft); color: var(--warn); padding: 6px 10px; border-radius: 8px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 10px; z-index: 50; }
.dropzone { display: none; }
body.dragging .dropzone {
  display: flex; position: fixed; inset: 12px; z-index: 60; align-items: center; justify-content: center;
  border: 3px dashed var(--accent); border-radius: 16px; background: rgba(31, 95, 191, .12); font-size: 1.5rem; font-weight: 700; color: var(--accent);
}

/* ÉCRANS PLUS ÉTROITS */
@media (max-width: 1280px) {
  .layout { grid-template-columns: 270px minmax(0, 1fr); }
  #form { grid-column: 2; position: static; max-height: none; }
}
@media (max-width: 900px) {
  :root { --top: auto; }
  .top { height: auto; flex-wrap: wrap; padding: 10px 16px; position: static; }
  button.side-toggle { display: inline-flex; }
  .search { order: 5; flex-basis: 100%; max-width: none; }
  .top-actions { flex-wrap: wrap; margin-left: 0; }
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px 16px; }
  #side { display: none; position: static; max-height: 60vh; }
  body.show-side #side { display: block; }
  #form { grid-column: 1; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
