:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #667085;
  --line: #dde3ed;
  --canvas: #f2f5f9;
  --surface: #ffffff;
  --navy: #101b35;
  --blue: #1d5fd1;
  --blue-soft: #eaf1ff;
  --orange: #d96b20;
  --red: #b42318;
  --green: #17805c;
  --shadow: 0 12px 35px rgba(21, 35, 62, .08);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--ink); font-size: 16px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

.app-shell { min-height: 100vh; }
.topbar { height: 72px; display: flex; align-items: center; justify-content: space-between; padding: 0 28px; color: white; background: var(--navy); border-bottom: 3px solid #2e70df; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 11px; background: linear-gradient(145deg, #3883ef, #164aab); font-weight: 800; letter-spacing: -.04em; }
.brand h1 { margin: 0; font-size: 1.2rem; line-height: 1.1; }
.brand p { margin: 4px 0 0; color: #aebbd4; font-size: .82rem; }
.service-state { display: flex; align-items: center; gap: 9px; color: #d4dded; font-size: .88rem; }
.service-state > span { width: 9px; height: 9px; border-radius: 50%; background: #43d19e; box-shadow: 0 0 0 5px rgba(67, 209, 158, .13); }
.service-state > div { display: grid; gap: 2px; }
.service-state strong { color: inherit; font-size: .875rem; font-weight: 600; }
.service-state small { color: #a9bad8; font-size: .75rem; }
.service-state small .integration-ok { color: #63ddb2; }
.account-menu { position: relative; margin-left: 10px; }
.account-menu summary { list-style: none; cursor: pointer; border: 1px solid rgba(255,255,255,.22); border-radius: 8px; padding: 7px 10px; color: #dce6f7; background: rgba(255,255,255,.07); font-size: .76rem; }
.account-menu summary::-webkit-details-marker { display: none; }
.account-menu[open] summary { background: rgba(255,255,255,.13); }
.account-popover { position: absolute; z-index: 20; top: calc(100% + 10px); right: 0; width: 280px; border: 1px solid var(--line); border-radius: 12px; padding: 12px; color: var(--ink); background: white; box-shadow: var(--shadow); }
.account-popover > p { margin: 2px 4px 10px; color: var(--muted); font-size: .75rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.account-popover ul { list-style: none; margin: 0; padding: 0; }
.account-popover li { display: grid; gap: 2px; border-radius: 8px; padding: 9px 10px; }
.account-popover li.current { background: var(--blue-soft); }
.account-popover li strong { font-size: .84rem; }
.account-popover li span { color: var(--muted); font-size: .75rem; }
.logout-form { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.logout-button { border: 1px solid rgba(255,255,255,.22); border-radius: 8px; padding: 7px 10px; color: #dce6f7; background: rgba(255,255,255,.07); font-size: .76rem; }
.logout-button:hover { background: rgba(255,255,255,.13); }
.account-popover .logout-button { width: 100%; border-color: var(--line); color: var(--ink); background: #f3f5f8; }
.account-popover .logout-button:hover { background: #e9edf4; }

.login-page { min-height: 100vh; background: linear-gradient(145deg, #0d1830 0 42%, #eef3fa 42% 100%); }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(440px, 100%); border: 1px solid var(--line); border-radius: 18px; padding: 30px; background: white; box-shadow: 0 24px 70px rgba(8, 19, 42, .22); }
.login-brand { padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.login-brand h1 { color: var(--ink); }
.login-brand p { color: var(--muted); }
.login-copy { margin: 24px 0; }
.login-copy h2 { margin-bottom: 8px; }
.login-copy > p:last-child { color: var(--muted); line-height: 1.5; }
.login-form { display: grid; gap: 16px; }
.login-form .field span { display: block; margin-bottom: 7px; color: var(--muted); font-size: .8rem; font-weight: 700; }
.login-form input { width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 11px 12px; }
.login-form .button { margin-top: 4px; }
.login-error { margin-bottom: 16px; border-radius: 9px; padding: 11px 12px; color: var(--red); background: #feeceb; font-size: .86rem; }

main { padding: 22px 28px 30px; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 14px; max-width: 1480px; margin: 0 auto 18px; }
.metrics article { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 15px 18px; display: flex; align-items: center; justify-content: space-between; box-shadow: 0 3px 12px rgba(21,35,62,.035); }
.metrics span { color: var(--muted); font-size: .9rem; }
.metrics strong { font-size: 1.65rem; letter-spacing: -.04em; }

.workspace { max-width: 1480px; min-height: calc(100vh - 160px); margin: 0 auto; display: grid; grid-template-columns: minmax(360px, 39%) 1fr; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); }
.queue-panel { border-right: 1px solid var(--line); min-width: 0; }
.queue-heading { padding: 22px 22px 14px; display: flex; align-items: center; justify-content: space-between; }
.eyebrow { margin: 0 0 4px; color: var(--blue); text-transform: uppercase; letter-spacing: .1em; font-size: .72rem; font-weight: 800; }
h2 { margin: 0; font-size: 1.3rem; }
.count { min-width: 32px; height: 32px; padding: 0 9px; display: grid; place-items: center; border-radius: 16px; background: var(--blue-soft); color: var(--blue); font-weight: 800; }
.search { display: block; padding: 0 22px 14px; }
.search input { width: 100%; height: 42px; border: 1px solid var(--line); border-radius: 10px; padding: 0 13px; background: #f9fafc; color: var(--ink); outline: none; }
.search input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(29,95,209,.12); background: white; }
.filters { display: flex; gap: 7px; padding: 0 22px 14px; overflow-x: auto; scrollbar-width: thin; }
.filter { white-space: nowrap; border: 1px solid var(--line); border-radius: 18px; padding: 7px 11px; background: white; color: #49556c; font-size: .8rem; }
.filter.active { color: white; background: var(--navy); border-color: var(--navy); }
.ticket-list { border-top: 1px solid var(--line); max-height: calc(100vh - 314px); overflow-y: auto; }
.ticket-card { width: 100%; display: block; text-align: left; padding: 17px 21px; border: 0; border-bottom: 1px solid #e8ecf2; background: white; color: inherit; }
.ticket-card.unread { background: #f7faff; box-shadow: inset 4px 0 #2e70df; }
.ticket-card.read .sender, .ticket-card.read h3 { font-weight: 500; color: #4e5a70; }
.ticket-card.read .unread-dot { visibility: hidden; }
.ticket-card:hover { background: #f7f9fd; }
.ticket-card.selected { background: var(--blue-soft); box-shadow: inset 4px 0 var(--blue); }
.ticket-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sender-line { min-width: 0; display: flex; align-items: center; gap: 9px; }
.unread-dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 3px rgba(29,95,209,.12); }
.ticket-card h3 { margin: 7px 0 6px; font-size: .98rem; line-height: 1.35; }
.ticket-card p { margin: 0; color: var(--muted); font-size: .84rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sender { font-size: .82rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.date { color: var(--muted); font-size: .75rem; white-space: nowrap; }
.badges { display: flex; gap: 7px; margin-top: 11px; flex-wrap: wrap; }
.badge { display: inline-flex; align-items: center; padding: 4px 8px; border-radius: 6px; font-size: .72rem; font-weight: 750; background: #eef1f6; color: #596579; }
.badge.intervention { color: #1556b3; background: #e4efff; }
.badge.haute, .badge.urgente { color: var(--red); background: #feeceb; }
.badge.a_verifier { color: #96520d; background: #fff0d9; }
.badge.assigned { color: #116044; background: #e4f6ee; }
.badge.mailbox { text-transform: uppercase; letter-spacing: .03em; }
.badge.mailbox.test { color: #596579; background: #eef1f6; }
.badge.mailbox.hotline { color: #116044; background: #dff5eb; }

.detail-panel { min-width: 0; background: #fbfcfe; }
.empty-state { min-height: 580px; display: grid; place-content: center; text-align: center; padding: 30px; color: var(--muted); }
.empty-state h2 { color: var(--ink); margin-top: 14px; }
.empty-state p { max-width: 420px; line-height: 1.55; }
.empty-icon { width: 54px; height: 54px; margin: auto; display: grid; place-items: center; border-radius: 16px; background: var(--blue-soft); color: var(--blue); font-size: 1.6rem; }
.detail { padding: 26px 30px 42px; }
.detail-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); padding-bottom: 22px; }
.detail-header h2 { max-width: 760px; font-size: 1.45rem; line-height: 1.35; }
.detail-header p { margin: 8px 0 0; color: var(--muted); }
.confidence { min-width: 92px; text-align: center; border-radius: 12px; padding: 10px; color: #1556b3; background: var(--blue-soft); font-size: .78rem; font-weight: 700; }
.confidence strong { display: block; font-size: 1.35rem; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 20px 0; }
.info-card { border: 1px solid var(--line); border-radius: 12px; padding: 15px 16px; background: white; }
.info-card span { display: block; margin-bottom: 6px; color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }
.info-card strong { font-size: .94rem; line-height: 1.4; }
.section { margin-top: 24px; }
.section h3 { margin: 0 0 10px; font-size: .92rem; text-transform: uppercase; letter-spacing: .055em; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.section-heading h3 { margin-bottom: 5px; }
.section-heading p { margin: 0; color: var(--muted); font-size: .84rem; line-height: 1.45; }
.intervention-builder { padding: 18px; border: 1px solid #cbdaf5; border-radius: 12px; background: #f7faff; }
.preview-state { white-space: nowrap; padding: 5px 9px; border-radius: 8px; color: #96520d; background: #fff0d9; font-size: .74rem; font-weight: 750; }
.preview-state.saved { color: #116044; background: #e4f6ee; }
.actions.compact { margin-top: 16px; padding-top: 16px; }
.inline-control { display: flex; gap: 9px; }
.inline-control input { flex: 1; }
.planning-assistant { border: 1px solid #cbdaf5; border-radius: 11px; padding: 14px; background: white; }
.planning-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.planning-heading > div { display: grid; gap: 3px; }
.planning-heading strong { font-size: .9rem; }
.planning-heading span, .planning-assistant > small { color: var(--muted); font-size: .76rem; }
.planning-suggestions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 12px 0; }
.planning-slot { display: grid; gap: 4px; text-align: left; border: 1px solid var(--line); border-radius: 9px; padding: 10px; color: var(--ink); background: #f9fafc; }
.planning-slot:hover, .planning-slot.selected { border-color: var(--blue); background: var(--blue-soft); }
.planning-slot strong { font-size: .82rem; }
.planning-slot span { color: #33405a; font-size: .78rem; }
.planning-slot small { color: var(--muted); font-size: .7rem; line-height: 1.35; }
.selected-planning-slot { margin-top: 10px; border-radius: 8px; padding: 9px 10px; color: #116044; background: #e4f6ee; font-size: .8rem; font-weight: 750; }
.planning-empty { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: .82rem; }
.content-box { padding: 17px 18px; border: 1px solid var(--line); border-radius: 12px; background: white; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.mail-body { max-height: 260px; overflow-y: auto; color: #39445a; }
.reply-box { border-left: 4px solid var(--blue); background: #f5f8ff; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 24px; padding-top: 22px; border-top: 1px solid var(--line); }
.field label { display: block; margin-bottom: 7px; color: var(--muted); font-size: .8rem; font-weight: 700; }
.field select, .field input, .field textarea { width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 10px 11px; background: white; color: var(--ink); }
.field textarea { min-height: 94px; resize: vertical; }
.field.full { grid-column: 1 / -1; }
.action-row { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 10px; }
.button { border: 0; border-radius: 9px; padding: 10px 16px; font-weight: 750; }
.button.primary { background: var(--blue); color: white; }
.button.secondary { background: #e9edf4; color: #33405a; }
.attachment { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); font-size: .88rem; }
.attachment:last-child { border-bottom: 0; }
.toast { position: fixed; right: 24px; bottom: 24px; opacity: 0; transform: translateY(10px); pointer-events: none; background: var(--navy); color: white; border-radius: 10px; padding: 12px 16px; box-shadow: var(--shadow); transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 900px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .workspace { grid-template-columns: 1fr; }
  .queue-panel { border-right: 0; }
  .ticket-list { max-height: 420px; }
  .detail-panel { border-top: 1px solid var(--line); }
}

@media (max-width: 560px) {
  .topbar { height: auto; padding: 14px 16px; align-items: flex-start; }
  .service-state { max-width: 160px; text-align: right; }
  main { padding: 14px; }
  .metrics { gap: 9px; }
  .metrics article { display: block; padding: 12px; }
  .metrics strong { display: block; margin-top: 5px; }
  .workspace { border-radius: 12px; }
  .detail { padding: 21px 18px 34px; }
  .detail-header, .detail-grid, .actions { display: grid; grid-template-columns: 1fr; }
  .confidence { width: 100%; }
  .planning-heading { align-items: stretch; flex-direction: column; }
  .planning-suggestions { grid-template-columns: 1fr; }
}
.audit-list {
  display: grid;
  gap: 0;
  padding: 0;
}

.audit-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.25rem 1rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
}

.audit-entry:last-child { border-bottom: 0; }
.audit-entry div { display: flex; gap: 0.5rem; align-items: baseline; flex-wrap: wrap; }
.audit-entry div span, .audit-entry time, .audit-entry p { color: var(--muted); font-size: 0.85rem; }
.audit-entry p { grid-column: 1 / -1; margin: 0; white-space: pre-wrap; }
