:root {
  --bg: #F6F7F9;
  --surface: #FFFFFF;
  --surface-2: #F1F3F6;
  --text: #111827;
  --muted: #6B7280;
  --border: #E2E5EA;
  --primary: #1E3A8A;
  --primary-text: #FFFFFF;
  --p1: #DC2626;
  --p2: #F59E0B;
  --p3: #64748B;
  --p4: #94A3B8;
  --focus: #2563EB;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1115; --surface: #171A21; --surface-2: #1F232C; --text: #E5E7EB; --muted: #9CA3AF;
    --border: #2A2F3A; --primary: #3B82F6; --primary-text: #FFFFFF; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0F1115; --surface: #171A21; --surface-2: #1F232C; --text: #E5E7EB; --muted: #9CA3AF;
  --border: #2A2F3A; --primary: #3B82F6; --primary-text: #FFFFFF; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 17px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 8px; }
.muted { color: var(--muted); }
code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; word-break: break-all; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Boutons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.icon-btn { border: 0; background: transparent; color: var(--text); font-size: 18px; cursor: pointer; padding: 6px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 9px;
}
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.inline { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }

/* Connexion */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 32px; text-align: center; max-width: 380px; }
.login-card h1 { margin: 12px 0 6px; font-size: 22px; }
.login-card p { color: var(--muted); margin: 0 0 20px; }

/* Structure */
.app { height: 100%; display: grid; grid-template-columns: 320px 1fr; grid-template-rows: auto 1fr; grid-template-areas: "top top" "side main"; }
.topbar { grid-area: top; display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.filter { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font: inherit; color: var(--text); }
.filter .dot { width: 10px; height: 10px; border-radius: 50%; }
.filter[aria-pressed="false"] { opacity: .45; }
.filter .warn { color: var(--p1); font-weight: 600; }
.top-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.pending { font-size: 12px; color: var(--muted); }
.sidebar { grid-area: side; background: var(--surface); border-right: 1px solid var(--border); overflow: auto; display: flex; flex-direction: column; }
.sidebar-head { padding: 14px 16px 8px; position: sticky; top: 0; background: var(--surface); z-index: 1; }
.counts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.count { font-size: 12px; padding: 2px 8px; border-radius: 999px; color: #fff; }
.queue { padding: 0 10px 16px; }
.qgroup h4 { margin: 14px 6px 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.qitem {
  display: block; width: 100%; text-align: left; border: 1px solid var(--border); border-left: 4px solid var(--acc, #999);
  background: var(--surface); color: var(--text); border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; cursor: pointer; font: inherit;
}
.qitem:hover { background: var(--surface-2); }
.qitem .subj { font-weight: 600; display: flex; gap: 6px; align-items: baseline; }
.qitem .subj span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qitem .meta { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.empty { color: var(--muted); padding: 24px 8px; text-align: center; }
.main { grid-area: main; padding: 12px; overflow: auto; min-width: 0; }
#calendar { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; min-height: calc(100% - 4px); }

/* Pastilles d'urgence */
/* Microsoft To Do */
.todo-item { display: flex; gap: 10px; align-items: flex-start; cursor: default; }
.todo-body { min-width: 0; flex: 1; display: grid; gap: 2px; }
.todo-check { flex: none; width: 20px; height: 20px; margin-top: 1px; border: 2px solid var(--acc, var(--muted)); border-radius: 50%; background: transparent; cursor: pointer; padding: 0; }
.todo-check:hover { background: var(--acc, var(--muted)); }
.todo-star { color: #D97706; flex: none; }
.late { color: var(--p1); font-weight: 600; }
.fc-event.todo-event { background: var(--surface) !important; border-style: dashed !important; border-width: 2px !important; color: var(--text) !important; }
.fc-event.todo-event .fc-event-main { color: var(--text); }
.todo-box { flex: none; }
.prio { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; color: #fff; flex: none; }
.prio.P1 { background: var(--p1); }
.prio.P2 { background: var(--p2); color: #111; }
.prio.P3 { background: var(--p3); }
.prio.P4 { background: var(--p4); color: #111; }
.prio.BRUIT { background: var(--border); color: var(--text); }

/* FullCalendar */
.fc { --fc-border-color: var(--border); --fc-page-bg-color: var(--surface); --fc-neutral-bg-color: var(--surface-2); --fc-today-bg-color: rgba(37, 99, 235, .06); }
.fc .fc-toolbar-title { font-size: 18px; }
.fc .fc-button-primary { background: var(--surface); color: var(--text); border-color: var(--border); }
.fc .fc-button-primary:not(:disabled).fc-button-active, .fc .fc-button-primary:not(:disabled):active { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.fc .fc-button-primary:hover { background: var(--surface-2); color: var(--text); }
.fc-event.task-event { background: var(--surface) !important; border-width: 2px !important; color: var(--text) !important; }
.fc-event.task-event .fc-event-main { color: var(--text); }
.fc-event.task-done { opacity: .5; text-decoration: line-through; }
.fc-event.cal-event .fc-event-main { color: #fff; }
.fc-event.cal-free { opacity: .55; }
.ev { display: flex; gap: 4px; align-items: baseline; overflow: hidden; font-size: 12px; }
.ev .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Dialogues */
dialog { border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(15, 23, 42, .45); backdrop-filter: blur(2px); }
.mail-dialog { width: min(1200px, 96vw); height: min(860px, 94vh); }
.mail-dialog[open] { display: flex; flex-direction: column; }
.mail-head { display: flex; justify-content: space-between; gap: 16px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.mail-meta { min-width: 0; }
.mail-meta h2 { margin: 6px 0 2px; }
.from { margin: 0; }
.mail-meta .muted { margin: 4px 0 0; }
.mail-tools { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; justify-content: flex-end; }
.chip { display: inline-block; font-size: 12px; font-weight: 600; color: #fff; padding: 2px 8px; border-radius: 999px; }
.mail-split { flex: 1; display: grid; grid-template-columns: 1fr 1fr; min-height: 0; }
.pane { display: flex; flex-direction: column; padding: 14px 18px; min-height: 0; gap: 8px; }
.pane + .pane { border-left: 1px solid var(--border); }
.mail-body { flex: 1; overflow: auto; white-space: pre-wrap; word-wrap: break-word; background: var(--surface-2); border-radius: 8px; padding: 12px; }
#mDraft { flex: 1; min-height: 180px; resize: none; line-height: 1.5; }
.hint { margin: 0; font-size: 12px; color: var(--muted); }
.hint.ok { color: #16A34A; }
.regen { display: flex; gap: 6px; }
.regen input { flex: 1; }
.reviewed { font-weight: 600; }
.noreply { background: var(--surface-2); border-radius: 8px; padding: 12px; }
.noreply p { margin: 0 0 8px; }
.mail-actions { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; padding: 12px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.mail-actions .left, .mail-actions .right { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.wide-dialog { width: min(820px, 96vw); max-height: 92vh; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.settings-body { padding: 8px 18px 18px; }
.settings-body section { padding: 14px 0; border-bottom: 1px solid var(--border); }
.settings-body section:last-child { border-bottom: 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.accounts { display: grid; gap: 10px; margin-bottom: 12px; }
.account { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: start; border: 1px solid var(--border); border-radius: 10px; padding: 10px; }
.account input[type=color] { width: 40px; height: 34px; padding: 2px; }
.account .fields { display: grid; gap: 6px; }
.account textarea { min-height: 54px; }
.status-ok { color: #16A34A; }
.status-bad { color: var(--p1); }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; align-items: end; }
.rules, .noise-list { list-style: none; margin: 10px 0 0; padding: 0; }
.rules li, .noise-list li { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.noise-list { padding: 0 18px 18px; }
.noise-list .info { min-width: 0; }
.noise-list .info div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Notifications internes */
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 1000; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; max-width: 360px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }

/* Mobile */
.only-mobile { display: none; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; grid-template-areas: "top" "side" "main"; }
  .topbar { gap: 8px 10px; padding: 8px 12px; }
  .brand { flex: 1; }
  .filters { order: 3; flex-basis: 100%; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
  .filter { flex: none; }
  .only-mobile { display: inline-block; }
  .sidebar { display: none; border-right: 0; border-bottom: 1px solid var(--border); max-height: 55vh; }
  .sidebar.open { display: flex; }
  .main { padding: 8px; }
  .mail-split { grid-template-columns: 1fr; overflow: auto; }
  .pane + .pane { border-left: 0; border-top: 1px solid var(--border); }
  .mail-body { max-height: 40vh; }
  /* Lecteur de mail en plein écran, croix de fermeture toujours visible */
  .mail-dialog { width: 100vw; height: 100dvh; max-width: 100vw; max-height: 100dvh; margin: 0; border: 0; border-radius: 0; }
  .mail-head { flex-direction: column; gap: 8px; position: relative; padding: calc(12px + env(safe-area-inset-top)) 60px 12px 14px; }
  .mail-tools { justify-content: flex-start; }
  #mClose { position: absolute; top: calc(8px + env(safe-area-inset-top)); right: 8px; width: 44px; height: 44px; font-size: 22px; background: var(--surface-2); border-radius: 50%; }
  .mail-actions { padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); }
  .top-actions .btn { padding: 6px 8px; }
}

/* Éditeur de signature */
.sig-block { display: grid; gap: 6px; }
.sig-label { font-size: 13px; color: var(--muted); }
.sig-toolbar { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px 8px 0 0; }
.sig-toolbar select, .sig-toolbar input[type=number] { padding: 3px 6px; font-size: 13px; }
.sig-toolbar input[type=number] { width: 64px; }
.sig-toolbar input[type=color] { width: 32px; height: 28px; padding: 1px; }
.tb { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 6px; padding: 3px 8px; font: inherit; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.tb:hover { background: var(--bg); }
label.tb { flex-direction: row; color: var(--text); }
.tb.width { cursor: default; }
.sig-editor { min-height: 110px; max-height: 320px; overflow: auto; background: #fff; color: #111; border: 1px solid var(--border); border-top: 0; border-radius: 0 0 8px 8px; padding: 12px; margin-top: -6px; font-family: Arial, Helvetica, sans-serif; font-size: 10pt; }
.sig-editor:focus { outline: 2px solid var(--focus); outline-offset: -2px; }
.sig-editor img { max-width: 100%; cursor: pointer; }
.sig-editor img.sig-selected { outline: 2px dashed var(--focus); }
.sig-preview summary { cursor: pointer; font-size: 12px; color: var(--muted); }
.sig-preview iframe { width: 100%; height: 190px; border: 1px solid var(--border); border-radius: 8px; background: #fff; margin-top: 6px; }
.account { grid-template-columns: auto minmax(0, 1fr) auto; }

.sig-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sig-tabs { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.sig-tab { border: 0; background: var(--surface); color: var(--text); padding: 4px 10px; font: inherit; font-size: 12px; cursor: pointer; }
.sig-tab[aria-selected="true"] { background: var(--primary); color: var(--primary-text); }
.sig-html-pane, .sig-visual-pane { display: grid; gap: 6px; }
.account .sig-html { min-height: 200px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; line-height: 1.4; resize: vertical; }
.sig-live { width: 100%; height: 170px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }

.install-box { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); display: grid; gap: 8px; justify-items: center; }
.small { font-size: 13px; }
.todo-item .meta span:last-child { white-space: nowrap; }

/* Notes To Do */
.todo-item .todo-body { background: none; border: 0; padding: 0; text-align: left; color: inherit; font: inherit; cursor: pointer; }
.todo-note-btn { flex: none; background: none; border: 1px solid transparent; border-radius: 6px; padding: 2px 4px; cursor: pointer; opacity: .35; font-size: 14px; }
.todo-note-btn.has-note { opacity: 1; }
.todo-note-btn:hover { border-color: var(--border); opacity: 1; }
.todo-note-preview { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-dialog[open] { display: flex; flex-direction: column; height: min(640px, 90vh); }
.note-head { min-width: 0; }
.note-head h2 { margin: 6px 0 2px; font-size: 18px; }
.note-head p { margin: 0; }
.note-body { flex: 1; display: flex; flex-direction: column; gap: 6px; padding: 14px 18px; min-height: 0; }
#tNote { flex: 1; min-height: 200px; resize: none; line-height: 1.5; }
.note-conflict { border: 1px solid var(--p2); border-radius: 8px; padding: 10px; background: var(--surface-2); }
.note-conflict p { margin: 0 0 6px; }
.note-conflict pre { white-space: pre-wrap; max-height: 140px; overflow: auto; margin: 0 0 8px; font: inherit; font-size: 13px; }
@media (max-width: 900px) {
  .note-dialog { width: 100vw; height: 100dvh; max-width: 100vw; max-height: 100dvh; margin: 0; border: 0; border-radius: 0; }
  .note-dialog[open] { height: 100dvh; }
  .note-dialog .dialog-head { padding-top: calc(12px + env(safe-area-inset-top)); }
  .note-dialog #tClose { width: 44px; height: 44px; font-size: 22px; background: var(--surface-2); border-radius: 50%; }
}
