:root {
  color-scheme: dark;
  --navy: #f2f6fc;
  --blue: #58a6ff;
  --blue-dark: #318ce7;
  --cyan: #43c8dc;
  --paper: #121c2b;
  --canvas: #08111e;
  --surface-muted: #182538;
  --line: #27384d;
  --text: #e6edf7;
  --muted: #9cabc0;
  --success: #49d3a3;
  --danger: #ff766d;
  --warning: #f4b454;
  --shadow: 0 16px 42px rgba(0, 0, 0, 0.3);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

a {
  color: var(--blue);
}

* {
  scrollbar-color: #3d536f var(--canvas);
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 76px;
  padding: 12px clamp(20px, 4vw, 64px);
  background: rgba(8, 17, 30, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--navy);
  text-decoration: none;
}

.brand-mark,
.login-logo {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: linear-gradient(145deg, var(--blue), var(--cyan));
  color: white;
  font-size: 17px;
  font-weight: 850;
  box-shadow: 0 8px 22px rgba(23, 105, 224, 0.24);
}

.brand span:last-child {
  display: grid;
  gap: 1px;
}

.brand small {
  color: var(--muted);
}

.shell {
  width: min(1440px, calc(100% - 40px));
  margin: 0 auto;
  padding: 44px 0 70px;
}

.page-heading,
.detail-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 30px;
  margin-bottom: 28px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  color: var(--navy);
  font-size: clamp(30px, 4vw, 46px);
  line-height: 1.05;
  letter-spacing: -0.035em;
}

h2 {
  margin-bottom: 8px;
  color: var(--navy);
}

.eyebrow {
  margin-bottom: 8px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.muted {
  margin-bottom: 0;
  color: var(--muted);
}

.filter {
  display: grid;
  min-width: min(310px, 100%);
  gap: 7px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--navy);
  font-size: 13px;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #354963;
  border-radius: 11px;
  background: #0d1725;
  color: var(--text);
  outline: none;
  transition: border 0.2s, box-shadow 0.2s;
}

input,
select {
  min-height: 46px;
  padding: 10px 13px;
}

textarea {
  min-height: 390px;
  padding: 15px;
  line-height: 1.55;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(23, 105, 224, 0.12);
}

.email-list {
  display: grid;
  gap: 13px;
}

.email-card {
  position: relative;
  display: grid;
  grid-template-columns: 5px minmax(0, 1fr) auto;
  gap: 20px;
  overflow: hidden;
  padding: 22px 24px 22px 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--paper);
  color: var(--text);
  text-decoration: none;
  box-shadow: 0 7px 20px rgba(0, 0, 0, 0.16);
  transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s;
}

.email-card:hover {
  transform: translateY(-2px);
  border-color: #426183;
  box-shadow: var(--shadow);
}

.priority {
  align-self: stretch;
  border-radius: 0 6px 6px 0;
  background: #a9b3c2;
}

.priority-urgent {
  background: #d6453d;
}

.priority-high {
  background: #ef8a24;
}

.priority-medium {
  background: #e0b323;
}

.priority-low {
  background: #2d9b72;
}

.email-main {
  min-width: 0;
}

.email-main h2 {
  margin-bottom: 6px;
  overflow: hidden;
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-main > p {
  display: -webkit-box;
  overflow: hidden;
  margin-bottom: 13px;
  color: var(--muted);
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.email-meta {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 13px;
}

.email-meta strong {
  overflow: hidden;
  color: var(--navy);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip,
.status,
.confidence {
  display: inline-flex;
  align-items: center;
  min-height: 27px;
  padding: 4px 9px;
  border-radius: 999px;
  background: #1b2a3d;
  color: #b8c6d9;
  font-size: 12px;
  font-weight: 700;
}

.chip-priority {
  background: #3b2a11;
  color: #f4c46d;
}

.chevron {
  align-self: center;
  color: #71849e;
  font-size: 34px;
}

.detail-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.detail-nav a {
  font-weight: 750;
  text-decoration: none;
}

.status-pending_review {
  background: #3b2d13;
  color: #f5c76e;
}

.detail-heading {
  display: block;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 24px;
  color: var(--muted);
  font-size: 14px;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 20px;
  align-items: start;
}

.panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 24px;
  border-bottom: 1px solid var(--line);
}

.panel-heading h2 {
  margin: 0;
  font-size: 21px;
}

.message-body {
  max-height: 720px;
  overflow: auto;
  padding: 24px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.62;
}

.ai-note {
  margin: 18px 22px 0;
  padding: 14px 16px;
  border-left: 4px solid var(--cyan);
  border-radius: 8px;
  background: #102b35;
  color: #c0e6ec;
  font-size: 13px;
  line-height: 1.45;
}

.ai-note p:last-child {
  margin-bottom: 0;
}

.reply-form {
  display: grid;
  gap: 16px;
  padding: 22px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
  transition: transform 0.15s, background 0.15s, border-color 0.15s;
}

.button:hover {
  transform: translateY(-1px);
}

.button-primary {
  background: var(--blue);
  color: white;
}

.button-primary:hover {
  background: var(--blue-dark);
}

.button-secondary {
  border-color: #405572;
  background: #182538;
  color: var(--text);
}

.button-danger {
  border-color: #713b3c;
  background: #341b20;
  color: var(--danger);
}

.button-quiet {
  border-color: var(--line);
  background: #121c2b;
  color: var(--navy);
}

.button-wide {
  width: 100%;
}

.flash-stack {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.flash {
  padding: 12px 15px;
  border-radius: 10px;
  font-weight: 650;
}

.flash-success {
  border: 1px solid #245b4c;
  background: #12362d;
  color: #83e6c2;
}

.flash-error {
  border: 1px solid #713b3c;
  background: #351b20;
  color: #ffaca5;
}

.empty-state,
.locked-state {
  padding: 60px 24px;
  border: 1px dashed #40526b;
  border-radius: 18px;
  background: var(--paper);
  text-align: center;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  margin: 0 auto 18px;
  border-radius: 50%;
  background: #14382f;
  color: var(--success);
  font-size: 28px;
  font-weight: 900;
}

.locked-state {
  margin: 22px;
  padding: 30px 20px;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(67, 200, 220, 0.16), transparent 36%),
    radial-gradient(circle at 82% 76%, rgba(88, 166, 255, 0.14), transparent 34%),
    var(--canvas);
}

.login-card {
  width: min(440px, 100%);
  padding: 38px;
  border: 1px solid #2f425a;
  border-radius: 22px;
  background: rgba(18, 28, 43, 0.98);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.46);
}

.login-logo {
  width: 58px;
  height: 58px;
  margin-bottom: 28px;
  font-size: 20px;
}

.login-card h1 {
  font-size: 38px;
}

.form-stack {
  display: grid;
  gap: 16px;
  margin-top: 28px;
}

@media (max-width: 900px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }

  .page-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .filter {
    min-width: 0;
  }
}

@media (max-width: 600px) {
  .shell {
    width: min(100% - 24px, 1440px);
    padding-top: 28px;
  }

  .topbar {
    min-height: 68px;
    padding: 10px 14px;
  }

  .brand small {
    display: none;
  }

  .email-card {
    grid-template-columns: 4px minmax(0, 1fr);
    gap: 14px;
    padding-right: 16px;
  }

  .chevron {
    display: none;
  }

  .email-meta {
    display: grid;
    gap: 4px;
  }

  .actions {
    display: grid;
  }

  .button {
    width: 100%;
  }

  .panel-heading,
  .message-body,
  .reply-form {
    padding: 18px;
  }

  .login-card {
    padding: 28px 22px;
  }
}

/* Mise à jour interface simplifiée — logo, filtres et actions rapides */
.brand-logo {
  display: block;
  width: 54px;
  height: 54px;
  flex: 0 0 54px;
  border: 1px solid #33465e;
  border-radius: 50%;
  background: #0a0a0a;
  object-fit: contain;
  box-shadow: 0 9px 24px rgba(0, 0, 0, 0.32);
}

.login-logo {
  display: block;
  width: 92px;
  height: 92px;
  margin: 0 auto 28px;
  border: 1px solid #3b4d63;
  border-radius: 50%;
  background: #0a0a0a;
  object-fit: contain;
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.36);
}

.empty-logo {
  display: block;
  width: 72px;
  height: 72px;
  margin: 0 auto 20px;
  border: 1px solid #354963;
  border-radius: 50%;
  background: #0a0a0a;
  object-fit: contain;
}

.page-heading {
  align-items: flex-start;
}

.priority-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 15px;
  margin-top: 13px;
  color: var(--muted);
  font-size: 13px;
}

.priority-summary span {
  white-space: nowrap;
}

.priority-summary strong {
  color: var(--text);
}

.filters {
  display: grid;
  grid-template-columns: minmax(220px, 1.5fr) minmax(185px, 1fr) minmax(160px, 0.8fr);
  align-items: end;
  width: min(850px, 100%);
  gap: 12px;
}

.filter-actions {
  display: flex;
  grid-column: 1 / -1;
  justify-content: flex-end;
  gap: 9px;
}

.email-list {
  gap: 11px;
}

.email-card {
  grid-template-columns: 5px minmax(0, 1fr) auto;
  gap: 0;
  padding: 0;
}

.email-main {
  display: block;
  min-width: 0;
  padding: 17px 20px;
  color: var(--text);
  text-decoration: none;
}

.email-main:focus-visible {
  outline: 3px solid rgba(88, 166, 255, 0.5);
  outline-offset: -4px;
  border-radius: 12px;
}

.email-main h2 {
  font-size: 17px;
}

.email-main > p {
  margin-bottom: 11px;
  -webkit-line-clamp: 1;
}

.email-actions {
  display: flex;
  align-items: center;
  align-self: stretch;
  gap: 8px;
  padding: 16px 18px 16px 0;
}

.email-actions form {
  margin: 0;
}

.button-compact {
  min-height: 38px;
  padding: 8px 13px;
  white-space: nowrap;
}

.button[disabled] {
  cursor: wait;
  opacity: 0.65;
  transform: none;
}

.flash {
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.flash-hide {
  opacity: 0;
  transform: translateY(-5px);
  pointer-events: none;
}

@media (max-width: 1050px) {
  .page-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .filters {
    width: 100%;
  }
}

@media (max-width: 760px) {
  .filters {
    grid-template-columns: 1fr 1fr;
  }

  .filters label:first-child {
    grid-column: 1 / -1;
  }

  .email-card {
    grid-template-columns: 4px minmax(0, 1fr);
  }

  .email-main {
    padding: 16px 14px;
  }

  .email-actions {
    grid-column: 2;
    justify-content: flex-end;
    padding: 0 14px 14px;
  }
}

@media (max-width: 600px) {
  .brand-logo {
    width: 46px;
    height: 46px;
    flex-basis: 46px;
  }

  .filters {
    grid-template-columns: 1fr;
  }

  .filters label:first-child,
  .filter-actions {
    grid-column: auto;
  }

  .filter-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .email-card {
    gap: 0;
    padding-right: 0;
  }

  .email-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .email-actions form,
  .email-actions .button {
    width: 100%;
  }

  .email-meta {
    display: grid;
    gap: 3px;
  }

  .email-main h2 {
    white-space: normal;
  }
}

/* Gestion Spam et expéditeurs ignorés */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-actions form {
  margin: 0 0 0 4px;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.nav-link:hover,
.nav-link-active {
  background: var(--surface-muted);
  color: var(--text);
}

.button-warning {
  border-color: #72582a;
  background: #342912;
  color: #f4c66e;
}

.button-spam {
  border-color: #84443c;
  background: #421f1c;
  color: #ff9a8d;
}

.button-warning:hover {
  background: #463719;
}

.button-spam:hover {
  background: #572824;
}

.email-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 520px;
}

.actions-review {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.rules-heading {
  align-items: center;
}

.rules-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.rules-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 840px;
}

.rules-table th,
.rules-table td {
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.rules-table th {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.rules-table tr:last-child td {
  border-bottom: 0;
}

.rules-table td {
  color: var(--muted);
  font-size: 14px;
}

.rules-table td strong {
  color: var(--text);
}

.rule-badge {
  display: inline-flex;
  align-items: center;
  min-height: 27px;
  padding: 4px 9px;
  border-radius: 999px;
  background: #3b2d13;
  color: #f5c76e;
  font-size: 12px;
  font-weight: 800;
}

.rule-badge-spam {
  background: #421f1c;
  color: #ff9a8d;
}

.rule-actions {
  width: 1%;
  white-space: nowrap;
}

.rule-actions form {
  margin: 0;
}

.rules-note {
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 980px) {
  .topbar {
    align-items: flex-start;
  }

  .topbar-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .email-actions {
    max-width: 390px;
  }
}

@media (max-width: 760px) {
  .email-actions {
    max-width: none;
    grid-template-columns: 1fr 1fr;
  }

  .email-actions form,
  .email-actions > .button {
    width: 100%;
  }

  .topbar-actions .nav-link {
    display: none;
  }
}

@media (max-width: 600px) {
  .email-actions {
    grid-template-columns: 1fr 1fr;
  }

  .actions-review {
    display: grid;
    grid-template-columns: 1fr;
  }

  .rules-heading {
    align-items: stretch;
  }
}
