:root, [data-theme='dark'] {
  --bg: #0e1116; --bg2: #151a22; --card: #181e27; --card2: #1f2632; --border: #2a3240;
  --text: #e6e9ef; --muted: #8b95a7; --accent: #7c9cff; --accent2: #5b7cf0; --accent-soft: rgba(124,156,255,.14);
  --ok: #4ccf8a; --warn: #f2b84b; --danger: #ff6b6b; --shadow: 0 8px 30px rgba(0,0,0,.35);
  color-scheme: dark;
}
[data-theme='light'] {
  --bg: #f4f6fa; --bg2: #ffffff; --card: #ffffff; --card2: #f0f3f8; --border: #dfe4ec;
  --text: #18202c; --muted: #677285; --accent: #3f63e6; --accent2: #2f50c8; --accent-soft: rgba(63,99,230,.10);
  --ok: #1f9d5c; --warn: #b7791f; --danger: #d64545; --shadow: 0 8px 30px rgba(20,30,50,.10);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 26px; margin: 0; letter-spacing: -.02em; }
h3 { font-size: 15px; margin: 0 0 12px; }
code { background: var(--card2); padding: 1px 6px; border-radius: 5px; font-size: 13px; }
pre { background: var(--card2); padding: 12px; border-radius: 8px; overflow-x: auto; }
pre code { background: none; padding: 0; }

input, select, textarea {
  width: 100%; background: var(--bg2); color: var(--text); border: 1px solid var(--border); border-radius: 9px;
  padding: 9px 12px; font: inherit; outline: none; transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; }
input[type='checkbox'] { width: auto; }

.btn { background: var(--card2); color: var(--text); border: 1px solid var(--border); border-radius: 9px; padding: 8px 14px; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent2); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.icon-btn { background: none; border: none; color: var(--text); font-size: 18px; cursor: pointer; padding: 6px 8px; border-radius: 8px; position: relative; }
.icon-btn:hover { background: var(--card2); }
.link { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font: inherit; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pre-wrap { white-space: pre-wrap; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.error { color: var(--danger); font-size: 14px; }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--card2); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.pill.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.pill.accent { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }

/* Connexion */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(1000px 500px at 50% -10%, var(--accent-soft), transparent); }
.login-card { width: 100%; max-width: 340px; display: grid; gap: 14px; text-align: center; background: var(--card); padding: 36px 28px; border-radius: 18px; border: 1px solid var(--border); box-shadow: var(--shadow); }
.logo { color: var(--accent); font-size: 18px; }
.logo.big { font-size: 44px; line-height: 1; }

/* Layout */
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--bg2); border-right: 1px solid var(--border); padding: 18px 12px; }
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; padding: 0 10px 18px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; color: var(--text); margin-bottom: 2px; }
.nav-item:hover { background: var(--card2); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-icon { width: 22px; text-align: center; }
.nav-label { flex: 1; }
.nav-sep { height: 1px; background: var(--border); margin: 10px 6px; }
.badge { background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; border-radius: 99px; padding: 1px 7px; }
.topbar .badge { position: absolute; top: -2px; right: -4px; }
.main { min-width: 0; }
.topbar { display: none; }
.scrim { display: none; }
.page { padding: 28px 32px 60px; max-width: 1400px; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 18px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.card-head h3 { margin: 0; }
.widgets { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.widget.wide { grid-column: span 2; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 10px 2px; border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: none; }
.list.card > li { padding: 12px 6px; }
.clickable { cursor: pointer; }
.clickable:hover { background: var(--card2); }
.notif { border-left: 3px solid transparent; padding-left: 10px !important; }
.notif.lvl-important { border-left-color: var(--warn); }
.notif.lvl-urgent { border-left-color: var(--danger); }
.notif.read { opacity: .55; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.empty-icon { font-size: 30px; margin-bottom: 6px; }
.big-num { font-size: 28px; font-weight: 700; margin-bottom: 10px; }
.bar { height: 8px; background: var(--card2); border-radius: 99px; overflow: hidden; margin-bottom: 12px; }
.bar > div { height: 100%; background: var(--accent); }
.bar > div.warn { background: var(--danger); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 500; }

/* Paramètres */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 16px; align-items: start; }
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.help { font-size: 12px; color: var(--muted); margin-top: 4px; }
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--card2); border: 1px solid var(--border); border-radius: 99px; cursor: pointer; transition: .2s; }
.switch span::before { content: ''; position: absolute; width: 18px; height: 18px; left: 2px; top: 2px; background: var(--muted); border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::before { transform: translateX(18px); background: #fff; }

/* Modal & toasts */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--card); border: 1px solid var(--border); border-radius: 16px; width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; box-shadow: var(--shadow); }
.modal.wide { max-width: 860px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; }
.modal-body { padding: 18px; }
.toasts { position: fixed; bottom: 18px; right: 18px; display: grid; gap: 8px; z-index: 100; max-width: calc(100vw - 32px); }
.toast { background: var(--card2); border: 1px solid var(--border); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); animation: slide .2s ease; }
.toast.success { border-color: var(--ok); }
.toast.error { border-color: var(--danger); }
@keyframes slide { from { transform: translateY(10px); opacity: 0; } }

/* Chat */
.chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-log { flex: 1; overflow-y: auto; padding: 4px 2px 12px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 14px; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--card2); border-bottom-left-radius: 4px; }
.msg.tool { align-self: flex-start; font-size: 12px; color: var(--muted); background: none; padding: 0 6px; }
.md h3, .md h4 { margin: 8px 0 4px; }
.md ul, .md ol { margin: 4px 0; padding-left: 20px; }
.md a { text-decoration: underline; }
.chat-input { display: flex; gap: 8px; align-items: flex-end; padding-top: 10px; border-top: 1px solid var(--border); }
.chat-input textarea { min-height: 44px; max-height: 200px; }
.confirm-box { border: 1px solid var(--warn); background: color-mix(in srgb, var(--warn) 10%, transparent); border-radius: 12px; padding: 12px; }
.typing { color: var(--muted); font-size: 13px; padding: 0 6px; }
.split { display: grid; grid-template-columns: 260px 1fr; gap: 16px; height: calc(100vh - 140px); min-height: 480px; }
.split > .card { min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.side-list { overflow-y: auto; flex: 1; }
.side-list .item { padding: 8px 10px; border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; gap: 6px; }
.side-list .item:hover { background: var(--card2); }
.side-list .item.active { background: var(--accent-soft); color: var(--accent); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab { background: none; border: none; color: var(--muted); padding: 8px 14px; cursor: pointer; font: inherit; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Tâches */
.task { display: flex; gap: 10px; align-items: flex-start; }
.task input[type='checkbox'] { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.task.done .task-title { text-decoration: line-through; color: var(--muted); }
.task-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 3px; }
.prio-3 { color: var(--danger); } .prio-2 { color: var(--warn); }

/* Mobile */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; }
  .menu-open .sidebar { transform: none; }
  .menu-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 30; }
  .topbar { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--bg2); position: sticky; top: 0; z-index: 20; }
  .topbar .brand { padding: 0; }
  .page { padding: 18px 16px 50px; }
  .widgets, .settings-grid { grid-template-columns: 1fr; }
  .widget.wide { grid-column: auto; }
  .split { grid-template-columns: 1fr; height: auto; }
  .split > .card:first-child { max-height: 220px; }
  .split > .card:last-child { height: calc(100vh - 330px); min-height: 420px; }
  .msg { max-width: 92%; }
}

/* Icônes */
.icon { display: inline-block; vertical-align: -0.2em; flex-shrink: 0; }
.nav-icon { display: inline-flex; justify-content: center; color: var(--muted); }
.nav-item.active .nav-icon { color: var(--accent); }
.head-icon { display: flex; align-items: center; gap: 8px; }
.head-icon .icon, h1 .icon { color: var(--accent); }
h1 { display: flex; align-items: center; gap: 10px; }
.empty-icon { color: var(--muted); opacity: .7; }
.btn { display: inline-flex; align-items: center; gap: 6px; justify-content: center; }
.icon-btn { display: inline-flex; align-items: center; }
.pill { display: inline-flex; align-items: center; gap: 4px; }
.logo { display: inline-flex; }
.logo .icon { fill: var(--accent-soft); }
.meta-icons { display: inline-flex; align-items: center; gap: 4px; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-right: 6px; vertical-align: 1px; }
.msg.tool { display: inline-flex; align-items: center; gap: 4px; }
.login-card .logo, .login-card h1 { display: flex; justify-content: center; }

/* ===== Agenda ===== */
.cal-page { display: flex; height: 100vh; min-height: 0; }
.cal-side { width: 250px; flex-shrink: 0; border-right: 1px solid var(--border); padding: 16px 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; background: var(--bg2); }
.cal-side.hidden { display: none; }
.cal-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.cal-toolbar { display: flex; align-items: center; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.cal-title { font-size: 18px; margin: 0 6px; text-transform: capitalize; white-space: nowrap; }
.cal-select { width: auto; max-width: 230px; padding: 6px 10px; }
.cal-search { position: relative; }
.cal-search input { width: 220px; padding: 6px 10px 6px 32px; }
.cal-search-icon { position: absolute; left: 10px; top: 7px; color: var(--muted); }
.cal-results { position: absolute; top: 40px; left: 0; width: 340px; max-height: 420px; overflow-y: auto; z-index: 30; padding: 6px; box-shadow: var(--shadow); }
.cal-results .item { padding: 8px; border-radius: 8px; }
.cal-title-input { font-size: 18px; font-weight: 600; }

.mini-grid { display: grid; grid-template-columns: 22px repeat(7, 1fr); gap: 2px; margin-top: 8px; text-align: center; font-size: 12px; }
.mini-head { color: var(--muted); font-weight: 600; padding: 2px 0; }
.mini-week { color: var(--muted); font-size: 10px; align-self: center; }
.mini-day { background: none; border: none; color: var(--text); font: inherit; padding: 4px 0; border-radius: 6px; cursor: pointer; }
.mini-day:hover { background: var(--card2); }
.mini-day.other { color: var(--muted); opacity: .6; }
.mini-day.in-range { background: var(--accent-soft); }
.mini-day.today { background: var(--accent); color: #fff; font-weight: 700; }
.cal-item { display: flex; align-items: center; gap: 6px; padding: 4px 0; }
.cal-color { width: 22px; height: 22px; padding: 0; border: none; background: none; cursor: pointer; flex-shrink: 0; }
.cal-color::-webkit-color-swatch-wrapper { padding: 0; } .cal-color::-webkit-color-swatch { border: none; border-radius: 50%; }
.cal-help { margin-top: auto; } .cal-help div { margin-top: 6px; line-height: 1.6; }

/* Grille horaire */
.tg { flex: 1; min-height: 0; display: flex; flex-direction: column; user-select: none; }
.tg-head, .tg-allday, .tg-body { display: grid; }
.tg-head { border-bottom: 1px solid var(--border); padding-right: 10px; }
.tg-gutter { display: flex; align-items: flex-end; justify-content: center; padding: 4px; font-size: 10px; }
.tg-day { background: none; border: none; color: var(--muted); font: inherit; padding: 8px 4px; cursor: pointer; display: flex; gap: 6px; justify-content: center; align-items: baseline; text-transform: capitalize; }
.tg-day strong { color: var(--text); font-size: 17px; }
.tg-day.today strong { background: var(--accent); color: #fff; border-radius: 8px; padding: 0 7px; }
.tg-day:hover { color: var(--text); }
.tg-allday { border-bottom: 1px solid var(--border); padding-right: 10px; }
.tg-allday-cell { border-left: 1px solid var(--border); padding: 3px; min-height: 28px; display: grid; gap: 2px; align-content: start; }
.tg-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; }
.tg-body { position: relative; }
.tg-hours { position: relative; }
.tg-hours div { position: absolute; right: 8px; transform: translateY(-50%); font-size: 11px; color: var(--muted); }
.tg-col { position: relative; border-left: 1px solid var(--border); cursor: crosshair;
  background-image: linear-gradient(var(--border) 1px, transparent 1px), linear-gradient(color-mix(in srgb, var(--border) 45%, transparent) 1px, transparent 1px);
  background-size: 100% 48px, 100% 24px; }
.tg-col.today { background-color: color-mix(in srgb, var(--accent) 4%, transparent); }
.tg-now { position: absolute; left: -4px; right: 0; height: 2px; background: var(--danger); z-index: 5; pointer-events: none; }
.tg-now::before { content: ''; position: absolute; left: -2px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--danger); }

.cal-ev { position: absolute; border-radius: 6px; padding: 3px 7px; font-size: 12px; line-height: 1.3; overflow: hidden; cursor: pointer;
  background: color-mix(in srgb, var(--c) 22%, var(--card)); border-left: 3px solid var(--c); color: var(--text); z-index: 2; transition: box-shadow .15s; }
.cal-ev:hover { box-shadow: 0 2px 10px rgba(0,0,0,.25); z-index: 3; }
.cal-ev.editable { cursor: grab; }
.cal-ev.ghost { opacity: .75; outline: 2px dashed var(--c); z-index: 4; }
.cal-ev.flash { animation: flash 0.6s ease 3; }
@keyframes flash { 50% { box-shadow: 0 0 0 3px var(--c); } }
.cal-ev-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-ev-time { color: var(--muted); font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-ev-resize { position: absolute; left: 0; right: 0; bottom: 0; height: 7px; cursor: ns-resize; }
.tg-allday .cal-ev, .mg .cal-ev { position: relative; padding: 1px 6px; }

/* Vue mois */
.mg { flex: 1; display: flex; flex-direction: column; min-height: 0; user-select: none; }
.mg-head { display: grid; grid-template-columns: repeat(7, 1fr); border-bottom: 1px solid var(--border); }
.mg-head div { padding: 8px; text-align: center; color: var(--muted); font-size: 13px; }
.mg-body { flex: 1; display: grid; grid-template-columns: repeat(7, 1fr); grid-template-rows: repeat(6, 1fr); min-height: 0; }
.mg-cell { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 4px; display: flex; flex-direction: column; gap: 2px; overflow: hidden; min-height: 90px; }
.mg-cell.other { background: color-mix(in srgb, var(--bg) 60%, transparent); }
.mg-cell.other .mg-num { color: var(--muted); }
.mg-num { background: none; border: none; color: var(--text); font: inherit; font-size: 13px; text-align: left; padding: 2px 4px; cursor: pointer; align-self: flex-start; border-radius: 6px; }
.mg-cell.today .mg-num { background: var(--accent); color: #fff; font-weight: 700; }

/* Planning */
.agenda { padding: 16px; overflow-y: auto; }
.agenda-day { display: flex; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.agenda-date { width: 64px; display: flex; flex-direction: column; align-items: center; color: var(--muted); text-transform: capitalize; font-size: 12px; }
.agenda-date strong { font-size: 22px; color: var(--text); }
.agenda-date.today strong { color: var(--accent); }
.agenda-ev { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; color: var(--text); }
.agenda-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.agenda-time { width: 105px; color: var(--muted); font-size: 13px; flex-shrink: 0; }

@media (max-width: 860px) {
  .cal-page { height: calc(100vh - 53px); }
  .cal-side { position: fixed; z-index: 35; top: 53px; bottom: 0; left: 0; box-shadow: var(--shadow); }
  .cal-search input { width: 140px; }
  .cal-title { font-size: 15px; }
  .mg-cell { min-height: 64px; }
}
.cal-ev-badge { display: inline-flex; align-items: center; gap: 2px; margin-right: 4px; color: var(--muted); font-weight: 500; font-size: 10px; vertical-align: 0; }
.cal-ev-badge.ok { color: var(--ok); }
.rec-box { margin-top: 8px; padding: 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--card2); }
.day-toggle { width: 34px; padding: 4px 0; }
.scope-opt { padding: 8px 4px; cursor: pointer; } .scope-opt input { width: auto; }
.event-tasks .task { padding: 4px 0; }
