/* Agenda : thème sombre uniquement */

:root {
  color-scheme: dark;
  --bg: #131314;
  --surface: #1b1c1d;
  --surface-2: #232426;
  --surface-3: #2d2f31;
  --line: #2a2c2e;
  --line-strong: #3c3f41;
  --grid: #45484c; /* séparation entre les jours */
  --text: #e3e3e3;
  --text-2: #c4c7c5;
  --muted: #8e918f;
  --accent: #a8c7fa;
  --accent-hover: #c2d7fb;
  --on-accent: #062e6f;
  --accent-soft: rgba(168, 199, 250, 0.14);
  --danger: #f2b8b5;
  --danger-strong: #e46962;
  --now: #ea4335;
  --radius: 8px;
  --topbar-h: 64px;
  --gutter: 56px;
  --font: 'Segoe UI Variable Text', 'Segoe UI', system-ui, -apple-system, Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }
.i { flex: none; display: block; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

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

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 16px; border-radius: 18px;
  border: 1px solid transparent; background: none;
  font-weight: 500; white-space: nowrap;
  transition: background-color .15s, border-color .15s;
}
.btn-sm { height: 30px; padding: 0 12px; font-size: 13px; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-outline { border-color: var(--line-strong); }
.btn-outline:hover { background: var(--surface-3); }
.btn-ghost { color: var(--accent); }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-danger { background: var(--danger-strong); color: #fff; }
.btn-danger:hover { background: #ef7d77; }
.btn-danger-ghost { color: var(--danger); }
.btn-danger-ghost:hover { background: rgba(242, 184, 181, .12); }
.link-btn { background: none; border: 0; color: var(--accent); font-size: 12px; font-weight: 500; padding: 0; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: none; color: var(--text-2);
  text-decoration: none; flex: none;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.sm { width: 28px; height: 28px; }
.mini-btn {
  display: inline-grid; place-items: center; width: 26px; height: 26px;
  border-radius: 50%; border: 0; background: none; color: var(--muted);
}
.mini-btn:hover { background: var(--surface-3); color: var(--text); }

#btn-sync.spinning .i { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Structure --------------------------------------------------------- */

.app { display: flex; flex-direction: column; height: 100dvh; }

.topbar {
  display: flex; align-items: center; gap: 8px;
  height: var(--topbar-h); padding: 0 12px 0 16px; flex: none;
  padding-left: max(16px, env(safe-area-inset-left));
}
.brand { display: flex; align-items: center; gap: 10px; width: 228px; font-size: 20px; color: var(--text-2); }
.brand img { border-radius: 6px; }
.nav-arrows { display: flex; }
.period { font-size: 20px; font-weight: 400; margin: 0 0 0 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.views { display: flex; border: 1px solid var(--line-strong); border-radius: 18px; overflow: hidden; margin-left: 4px; }
.views button { border: 0; background: none; height: 34px; padding: 0 14px; font-weight: 500; color: var(--text-2); }
.views button + button { border-left: 1px solid var(--line-strong); }
.views button[aria-selected='true'] { background: var(--accent-soft); color: var(--accent); }
.views button:hover:not([aria-selected='true']) { background: var(--surface-3); }
.views-select { display: none; }
.only-mobile { display: none; }

.banner {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  margin: 0 16px 8px; padding: 10px 16px; border-radius: var(--radius);
  background: #3b2f12; color: #fdd663;
}
.banner span { flex: 1; min-width: 200px; }

.layout { flex: 1; display: grid; grid-template-columns: 256px 1fr; min-height: 0; }
.main {
  min-width: 0; min-height: 0; overflow: hidden;
  background: var(--surface); border-radius: 16px 0 0 0;
  display: flex; flex-direction: column;
}

/* --- Barre latérale ---------------------------------------------------- */

.sidebar { overflow-y: auto; padding: 4px 12px 24px 12px; }
.btn-create {
  height: 56px; padding: 0 22px 0 16px; border-radius: 16px; gap: 12px;
  background: var(--surface-3); color: var(--text); font-size: 15px;
  box-shadow: 0 1px 3px rgba(0,0,0,.4); margin: 4px 0 16px 4px;
}
.btn-create:hover { background: #37393b; }
.create-icon { color: var(--accent); display: grid; }

.mini { padding: 0 4px; margin-bottom: 16px; }
.mini-head { display: flex; align-items: center; gap: 2px; padding-left: 6px; margin-bottom: 4px; }
.mini-head span { flex: 1; font-weight: 500; font-size: 13px; }
.mini-grid { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; row-gap: 2px; }
.mini-grid > span { font-size: 11px; color: var(--muted); height: 24px; line-height: 24px; }
.mini-grid button {
  border: 0; background: none; width: 28px; height: 28px; margin: 0 auto;
  border-radius: 50%; font-size: 12px; color: var(--text-2);
}
.mini-grid button:hover { background: var(--surface-3); }
.mini-grid button.other { color: #6b6e70; }
.mini-grid button.in-range { background: var(--accent-soft); color: var(--accent); }
.mini-grid button.today { background: var(--accent); color: var(--on-accent); font-weight: 600; }

.side-section { margin: 8px 0 16px; }
.side-section h2 {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 14px; font-weight: 500; margin: 0 8px 6px;
}
.section-toggle {
  display: flex; align-items: center; gap: 4px; flex: 1; min-width: 0;
  margin: -4px 0 -4px -6px; padding: 4px 6px; border: 0; border-radius: 6px;
  background: none; font-size: 14px; font-weight: 500; text-align: left;
}
.section-toggle:hover { background: var(--surface-2); }
.chevron { display: grid; color: var(--muted); transition: transform .15s; }
.side-section.collapsed .chevron { transform: rotate(-90deg); }
.side-section.collapsed .cal-list { display: none; }
.side-section.collapsed h2 { margin-bottom: 0; }
.cal-list { list-style: none; margin: 0; padding: 0; }
.cal-list li { display: flex; align-items: center; }
.check {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px;
  padding: 5px 8px; border-radius: 6px; cursor: pointer;
}
.check:hover { background: var(--surface-2); }
.check input { position: absolute; opacity: 0; pointer-events: none; }
.check .box {
  width: 18px; height: 18px; border-radius: 3px; flex: none;
  border: 2px solid var(--c); display: grid; place-items: center;
}
.check input:checked + .box { background: var(--c); }
.check input:checked + .box::after {
  content: ''; width: 5px; height: 10px; margin-top: -2px;
  border: solid #131314; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.check input:focus-visible + .box { outline: 2px solid var(--accent); outline-offset: 2px; }
.check .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-row .mini-btn { opacity: 0; }
.person-row:hover .mini-btn, .person-row .mini-btn:focus-visible { opacity: 1; }
@media (hover: none) { .person-row .mini-btn { opacity: 1; } }

.add-person { display: flex; align-items: center; gap: 4px; flex: 1; padding: 4px 0 0 8px; }
.add-person input {
  flex: 1; min-width: 0; height: 30px; padding: 0 10px; border-radius: 6px;
  border: 1px solid var(--line-strong); background: transparent;
}
.add-person input:focus { border-color: var(--accent); outline: none; }

.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--c); color: #131314; font-size: 10px; font-weight: 700; letter-spacing: -.3px;
}

.source { border-top: 1px solid var(--line); padding: 14px 8px 0; margin-top: 8px; }
.source-line { display: flex; align-items: center; gap: 8px; font-weight: 500; margin-bottom: 4px; }
.source-line.ok { color: #81c995; }
.source-line.warn { color: #fdd663; }
.source-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }

.side-settings { display: none; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 30; }

/* --- Barres d'événements longs (bandeau) -------------------------------- */

.bar {
  position: absolute; display: flex; align-items: center; gap: 4px;
  padding: 0 6px; border: 0; border-radius: 4px; overflow: hidden;
  background: var(--c); color: var(--fg); font-size: 12px; text-align: left;
  white-space: nowrap; z-index: 1;
}
.bar, .ev, .rail, .mv-item { cursor: pointer; }
.bar:hover { filter: brightness(1.08); z-index: 2; }
.bar.cont-l { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.bar.cont-r { border-top-right-radius: 0; border-bottom-right-radius: 0; }
/* Début et fin marqués d'un trait vertical : l'heure exacte se lit d'un coup d'œil */
.bar.timed:not(.cont-l) { box-shadow: inset 3px 0 0 rgba(0,0,0,.35); padding-left: 8px; }
.bar-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.bar-label b { font-weight: 600; }
.bar-end { font-size: 11px; opacity: .8; flex: none; }

.chips { display: inline-flex; flex: none; }
.chips .avatar { box-shadow: 0 0 0 1.5px var(--c-ring, rgba(0,0,0,.35)); }
.chips .avatar + .avatar { margin-left: -4px; }
.chips.sm .avatar { width: 16px; height: 16px; font-size: 8px; }

/* --- Vue jour / semaine ------------------------------------------------ */

.tg { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.tg-head, .tg-band {
  display: grid; grid-template-columns: var(--gutter) 1fr;
  overflow: hidden; scrollbar-gutter: stable; flex: none;
}
.tg-gutter { border-right: 1px solid transparent; }
.tg-gutter.tz { font-size: 10px; color: var(--muted); align-self: end; text-align: right; padding: 0 8px 6px 0; }
.tg-days { display: grid; grid-template-columns: repeat(var(--n), 1fr); }
.tg-dayhead {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 0 6px; border: 0; background: none; color: var(--text-2);
  border-left: 1px solid transparent;
}
.tg-dayhead .dow { font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: .5px; }
.tg-dayhead .num {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  font-size: 24px; color: var(--text);
}
.tg-dayhead:hover .num { background: var(--surface-3); }
.tg-dayhead.today .dow { color: var(--accent); }
.tg-dayhead.today .num { background: var(--accent); color: var(--on-accent); }

.tg-band { border-bottom: 1px solid var(--line-strong); }
.band-area { position: relative; margin-bottom: 2px; }
.band-cells { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(var(--n), 1fr); }
.band-cell { border-left: 1px solid var(--grid); cursor: pointer; }
.band-cell:hover { background: rgba(255,255,255,.02); }

.tg-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; scrollbar-gutter: stable; min-height: 0; }
.tg-body { display: grid; grid-template-columns: var(--gutter) 1fr; height: calc(var(--hour) * 24); }
.tg-hours { position: relative; }
.tg-hours span {
  position: absolute; right: 8px; transform: translateY(-50%);
  font-size: 10px; color: var(--muted);
}
.tg-cols {
  display: grid; grid-template-columns: repeat(var(--n), 1fr);
  background-image: repeating-linear-gradient(to bottom, var(--line) 0 1px, transparent 1px var(--hour));
}
.col { position: relative; border-left: 1px solid var(--grid); cursor: default; user-select: none; }
.col.weekend { background: rgba(255,255,255,.02); }
.col.is-today { background: rgba(168, 199, 250, .05); }

.rail {
  position: absolute; width: 4px; padding: 0; border: 0; border-radius: 2px;
  background: var(--c); opacity: .85; z-index: 1;
}
.rail:hover { opacity: 1; width: 6px; }

.ev {
  position: absolute; display: flex; flex-direction: column; align-items: flex-start;
  padding: 3px 6px; border: 0; border-radius: 6px; overflow: hidden;
  background: var(--c); color: var(--fg); text-align: left; font-size: 12px; line-height: 1.25;
  box-shadow: 0 0 0 1px var(--surface); z-index: 2;
}
.ev:hover { filter: brightness(1.08); z-index: 3; }
.ev.past { filter: saturate(.55) brightness(.8); }
.ev.past:hover { filter: saturate(.7) brightness(.9); }
.ev > * { flex: none; }
.ev-title { font-weight: 500; width: 100%; overflow: hidden; text-overflow: ellipsis; }
.ev-time { opacity: .85; font-weight: 400; }
.ev.compact { flex-direction: row; align-items: center; padding: 0 6px; gap: 4px; }
.ev.compact .ev-title { white-space: nowrap; flex: 1 1 auto; min-width: 0; }
.ev .chips { margin-top: 3px; }
.ev.compact .chips { margin-top: 0; }

.now { position: absolute; left: -1px; right: 0; height: 2px; background: var(--now); z-index: 4; pointer-events: none; }
.now::before { content: ''; position: absolute; left: -6px; top: -5px; width: 12px; height: 12px; border-radius: 50%; background: var(--now); }

.ghost {
  position: absolute; left: 2px; right: 6px; z-index: 5; pointer-events: none;
  border-radius: 6px; background: var(--accent); color: var(--on-accent);
  padding: 2px 6px; font-size: 12px; font-weight: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,.5);
}

/* --- Glisser-déposer --------------------------------------------------- */

body.dragging, body.dragging * { cursor: grabbing !important; user-select: none; }
.drag-src { opacity: .35; }
.drag-ghost {
  position: absolute; left: 2px; right: 6px; z-index: 6; pointer-events: none;
  border-radius: 6px; background: var(--c); color: var(--fg);
  padding: 2px 6px; font-size: 12px; font-weight: 600;
  box-shadow: 0 6px 18px rgba(0,0,0,.55), 0 0 0 2px var(--text);
}
.drop-target { background: var(--accent-soft) !important; box-shadow: inset 0 0 0 1px var(--accent); }
.drag-label {
  position: fixed; z-index: 70; pointer-events: none; white-space: nowrap;
  padding: 6px 10px; border-radius: 8px; background: var(--text); color: #1f1f1f;
  font-size: 12px; font-weight: 500; box-shadow: 0 4px 14px rgba(0,0,0,.5);
}

/* --- Vue mois ---------------------------------------------------------- */

.mv { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.mv-head { display: grid; grid-template-columns: repeat(7, 1fr); flex: none; }
.mv-head div {
  text-align: center; font-size: 11px; font-weight: 500; text-transform: uppercase;
  letter-spacing: .5px; color: var(--muted); padding: 8px 0 4px; border-left: 1px solid var(--grid);
}
.mv-head div:first-child { border-left-color: transparent; }
.mv-rows { flex: 1; display: grid; grid-template-rows: repeat(var(--rows), minmax(92px, 1fr)); overflow-y: auto; min-height: 0; }
.mv-week { position: relative; border-top: 1px solid var(--grid); min-height: 0; }
.mv-cells { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(7, 1fr); }
.mv-cell {
  display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden;
  border-left: 1px solid var(--grid); cursor: pointer;
}
.mv-cell:first-child { border-left-color: transparent; }
.mv-cell.weekend { background: rgba(255,255,255,.02); }
.mv-cell.other { background: var(--bg); }
.mv-cell.today { background: rgba(168, 199, 250, .07); }
.mv-cell:hover { box-shadow: inset 0 0 0 1px var(--line-strong); }
.mv-num {
  align-self: center; margin: 4px 0 2px; height: 24px; min-width: 24px; padding: 0 6px;
  border: 0; border-radius: 12px; background: none; font-size: 12px; font-weight: 500; color: var(--text);
  flex: none;
}
.mv-num:hover { background: var(--surface-3); }
.mv-cell.other .mv-num { color: #6b6e70; }
.mv-cell.today .mv-num { background: var(--accent); color: var(--on-accent); }
.mv-band { position: absolute; left: 0; right: 0; top: 30px; pointer-events: none; }
.mv-band .bar { pointer-events: auto; }
.mv-items { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; padding: 0 2px 2px; }
.mv-item {
  display: flex; align-items: center; gap: 5px; flex: none;
  height: 20px; padding: 0 4px; border: 0; border-radius: 4px; background: none;
  font-size: 12px; text-align: left; white-space: nowrap; overflow: hidden;
}
.mv-item:hover { background: var(--surface-3); }
.mv-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }
.mv-t { color: var(--text-2); flex: none; }
.mv-ttl { overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.mv-more {
  flex: none; height: 20px; border: 0; background: none; border-radius: 4px;
  padding: 0 6px; font-size: 12px; font-weight: 500; text-align: left; color: var(--text-2);
}
.mv-more:hover { background: var(--surface-3); }

/* --- Popover de détail ------------------------------------------------- */

.popover {
  position: fixed; z-index: 40; width: 380px; max-width: calc(100vw - 16px);
  max-height: calc(100dvh - 16px); overflow-y: auto;
  background: var(--surface-2); border-radius: 16px; padding: 8px 16px 18px;
  box-shadow: 0 8px 28px rgba(0,0,0,.6), 0 0 0 1px var(--line-strong);
}
.pop-actions { display: flex; justify-content: flex-end; gap: 2px; margin-right: -8px; }
.pop-title { display: flex; gap: 14px; align-items: flex-start; margin: 2px 0 10px; }
.pop-title .sq { width: 16px; height: 16px; border-radius: 4px; background: var(--c); margin-top: 6px; flex: none; }
.pop-title h3 { margin: 0; font-size: 20px; font-weight: 400; line-height: 1.35; overflow-wrap: anywhere; }
.pop-row { display: flex; gap: 14px; align-items: flex-start; padding: 6px 0; color: var(--text-2); }
.pop-row .i { color: var(--muted); margin-top: 1px; }
.pop-desc { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 180px; overflow-y: auto; }
.pop-people { display: flex; flex-wrap: wrap; gap: 6px; }
.person-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px 2px 2px;
  border-radius: 14px; background: var(--surface-3); font-size: 13px;
}
.pop-files { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.pop-files a { color: var(--accent); overflow-wrap: anywhere; }

/* --- Images ------------------------------------------------------------ */

.thumbs { display: flex; flex-wrap: wrap; gap: 6px; }
.thumb {
  display: grid; place-items: center; width: 72px; height: 72px; padding: 0; overflow: hidden;
  border: 0; border-radius: 8px; background: var(--surface-3); color: var(--muted);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb:hover img { opacity: .85; }
.thumb:empty::after {
  content: ''; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--line-strong); border-top-color: var(--muted); animation: spin .8s linear infinite;
}
.thumb-wrap { position: relative; }
.thumb-del {
  position: absolute; top: -6px; right: -6px; display: grid; place-items: center;
  width: 22px; height: 22px; padding: 0; border-radius: 50%;
  border: 2px solid var(--surface-2); background: var(--surface-3); color: var(--text);
}
.thumb-del:hover { background: var(--danger-strong); color: #fff; }
.images-field { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding-top: 4px; }
.images-field .thumbs { padding-top: 6px; }
#ed-img-note.bad { color: var(--danger); font-weight: 500; }

.viewer-dialog {
  width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  background: rgba(0,0,0,.92); color: var(--text);
  flex-direction: column;
}
.viewer-dialog[open] { display: flex; }
.viewer-dialog::backdrop { background: transparent; }
.viewer-bar { display: flex; align-items: center; gap: 4px; padding: 8px 8px 8px 20px; }
.viewer-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-title .muted { margin-left: 8px; }
.viewer-stage { flex: 1; min-height: 0; display: flex; align-items: center; gap: 8px; padding: 0 8px 16px; }
.viewer-img { flex: 1; min-width: 0; height: 100%; display: grid; place-items: center; }
.viewer-img img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; }
.viewer-img:empty::after {
  content: ''; width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid var(--line-strong); border-top-color: var(--text-2); animation: spin .8s linear infinite;
}
.viewer-nav { width: 48px; height: 48px; flex: none; }
@media (max-width: 760px) {
  .viewer-stage { position: relative; padding: 0 0 12px; }
  .viewer-nav { position: absolute; top: 50%; transform: translateY(-50%); z-index: 1; background: rgba(0,0,0,.45); }
  .viewer-nav[data-viewer="-1"] { left: 6px; }
  .viewer-nav[data-viewer="1"] { right: 6px; }
}

/* --- Dialogues --------------------------------------------------------- */

.dialog {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  padding: 0; border: 0; border-radius: 20px;
  background: var(--surface-2); color: var(--text);
  box-shadow: 0 12px 40px rgba(0,0,0,.6);
}
.dialog-small { width: min(420px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgba(0,0,0,.55); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.dlg-head h2 { margin: 0; font-size: 18px; font-weight: 500; }
.dlg-foot { display: flex; align-items: center; gap: 8px; margin-top: 20px; flex-wrap: wrap; }

.editor, .settings, .confirm { padding: 18px 22px 20px; }
.confirm h2 { margin: 0 0 8px; font-size: 18px; font-weight: 500; }
.confirm p { margin: 0; color: var(--text-2); }

.editor input:not([type]), .editor input[type='date'],
.editor select, .editor textarea, .settings input, .settings select {
  height: 38px; padding: 0 10px; border-radius: 6px;
  border: 1px solid var(--line-strong); background: var(--surface);
  min-width: 0;
}
.editor textarea { height: auto; padding: 8px 10px; resize: vertical; width: 100%; }
.editor input:focus, .editor select:focus, .editor textarea:focus, .settings input:focus, .settings select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent);
}
.editor select:disabled { opacity: .5; }
input[type='date']::-webkit-calendar-picker-indicator { filter: invert(.8); cursor: pointer; }
.editor input.time { font-variant-numeric: tabular-nums; }

.title-input {
  width: 100%; height: 48px !important; font-size: 20px; margin: 4px 0 12px;
  border: 0 !important; border-bottom: 1px solid var(--line-strong) !important;
  border-radius: 6px 6px 0 0 !important; background: var(--surface) !important;
}
.title-input:focus { box-shadow: none !important; border-bottom: 2px solid var(--accent) !important; }

.scope {
  display: flex; gap: 6px; margin: 0 0 12px; padding: 4px; border-radius: 10px; background: var(--surface);
}
.scope label { flex: 1; text-align: center; padding: 6px; border-radius: 7px; cursor: pointer; color: var(--text-2); font-weight: 500; }
.scope input { position: absolute; opacity: 0; }
.scope label:has(input:checked) { background: var(--accent-soft); color: var(--accent); }
.scope label:has(input:focus-visible) { outline: 2px solid var(--accent); }

.field-row { display: flex; gap: 14px; align-items: flex-start; padding: 7px 0; }
.field-row > .i { color: var(--muted); margin-top: 9px; }
.field-row > input, .field-row > select, .field-row > textarea, .field-row > div { flex: 1; min-width: 0; }

.when { display: flex; flex-direction: column; gap: 8px; }
.when-grid { display: grid; grid-template-columns: auto 1fr auto; gap: 6px 8px; align-items: center; }
.when-grid .lbl { color: var(--muted); font-size: 13px; }
.editor.all-day .time { visibility: hidden; }
.recur { align-self: flex-start; max-width: 100%; }

.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; margin-top: 6px; }
.toggle input { position: absolute; opacity: 0; }
.toggle span {
  width: 34px; height: 20px; border-radius: 10px; background: var(--line-strong); position: relative; transition: background .15s;
}
.toggle span::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--text-2); transition: transform .15s, background .15s;
}
.toggle input:checked + span { background: var(--accent); }
.toggle input:checked + span::after { transform: translateX(14px); background: var(--on-accent); }
.toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.people-picker { display: flex; flex-direction: column; gap: 8px; padding-top: 4px; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px 0 5px;
  border-radius: 15px; border: 1px solid var(--line-strong); background: none; color: var(--text-2);
}
.chip:hover { background: var(--surface-3); }
.chip.on { background: color-mix(in srgb, var(--c) 22%, transparent); border-color: var(--c); color: var(--text); }
.chip:not(.on) .avatar { opacity: .55; }
.add-inline { display: flex; gap: 6px; }
.add-inline input { flex: 1; height: 32px !important; }

.swatches { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 6px; }
.swatch { position: relative; cursor: pointer; }
.swatch input { position: absolute; opacity: 0; }
.swatch span { display: block; width: 24px; height: 24px; border-radius: 50%; background: var(--c); }
.swatch.default span { background: conic-gradient(var(--c) 0 50%, transparent 50%); box-shadow: inset 0 0 0 2px var(--c); }
.swatch input:checked + span { box-shadow: 0 0 0 2px var(--surface-2), 0 0 0 4px var(--text); }
.swatch.default input:checked + span { box-shadow: inset 0 0 0 2px var(--c), 0 0 0 2px var(--surface-2), 0 0 0 4px var(--text); }
.swatch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 3px; }

#ed-duration.bad { color: var(--danger); font-weight: 500; }
.form-error {
  margin-top: 12px; padding: 10px 12px; border-radius: 8px;
  background: rgba(228, 105, 98, .15); color: var(--danger);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}

.settings h3 { font-size: 13px; font-weight: 600; color: var(--accent); margin: 18px 0 8px; text-transform: uppercase; letter-spacing: .5px; }
.settings .field { display: flex; flex-direction: column; gap: 6px; }
.settings .field.inline { flex-direction: row; align-items: center; justify-content: space-between; }
.settings .field input { width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.settings p { margin: 8px 0; }
code.copy {
  font-family: ui-monospace, Consolas, monospace; background: var(--surface); padding: 2px 6px;
  border-radius: 4px; color: var(--text); cursor: copy; border: 1px solid var(--line-strong);
}

/* --- Notifications ----------------------------------------------------- */

.toasts {
  position: fixed; left: 24px; bottom: 24px; z-index: 60;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  background: #e3e3e3; color: #1f1f1f; padding: 12px 18px; border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.5); max-width: min(480px, calc(100vw - 32px));
  animation: toast-in .2s ease-out; transition: opacity .4s, transform .4s;
}
.toast.error { background: #f2b8b5; color: #601410; }
.toast.out { opacity: 0; transform: translateY(8px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* --- Écrans étroits ---------------------------------------------------- */

@media (max-width: 1100px) {
  .brand { width: auto; }
  .brand span { display: none; }
}

@media (max-width: 760px) {
  :root { --topbar-h: 56px; --gutter: 44px; }
  .topbar { gap: 2px; padding: 0 6px; }
  .only-mobile { display: inline-grid; }
  .brand, .nav-arrows, .views { display: none; }
  .period { font-size: 18px; margin-left: 4px; flex: 1; }
  #btn-today { height: 32px; padding: 0 10px; font-size: 13px; order: 2; }
  .topbar .spacer { display: none; }
  .views-select {
    display: block; order: 3; height: 32px; padding: 0 6px; border-radius: 16px;
    border: 1px solid var(--line-strong); background: var(--bg); margin-left: 4px;
  }
  #btn-sync { order: 4; }
  #btn-settings { display: none; }
  .side-settings { display: inline-flex; margin-top: 8px; }

  .layout { grid-template-columns: 1fr; }
  .main { border-radius: 0; }
  .sidebar {
    position: fixed; z-index: 35; left: 0; top: 0; bottom: 0; width: min(300px, 85vw);
    background: var(--surface-2); padding-top: 16px;
    transform: translateX(-100%); transition: transform .2s ease-out;
    box-shadow: 4px 0 24px rgba(0,0,0,.5);
  }
  .sidebar.open { transform: none; }

  .tg-dayhead .num { width: 36px; height: 36px; font-size: 18px; }
  .tg-gutter.tz { font-size: 0; }
  .tg-hours span { right: 4px; }
  .ev { padding: 2px 4px; font-size: 11px; }
  .bar { font-size: 11px; padding: 0 4px; }
  .mv-rows { grid-template-rows: repeat(var(--rows), minmax(84px, 1fr)); }
  .mv-item { gap: 3px; padding: 0 2px; font-size: 11px; }
  .mv-t, .mv-item .chips { display: none; }

  .popover {
    left: 0 !important; right: 0; bottom: 0; top: auto !important; width: 100%; max-width: none;
    border-radius: 20px 20px 0 0; padding-bottom: max(18px, env(safe-area-inset-bottom));
    max-height: 75dvh;
  }
  .dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; margin: 0; }
  .dialog-small { height: auto; border-radius: 20px; margin: auto; width: calc(100vw - 32px); }
  .editor, .settings { padding: 14px 16px calc(20px + env(safe-area-inset-bottom)); }
  .when-grid { grid-template-columns: auto 1fr; }
  .when-grid .time { grid-column: 2; }
  .editor.all-day .time { display: none; }
  .toasts { left: 16px; right: 16px; bottom: 16px; }
}
