:root {
  --ink: #172126;
  --muted: #68767c;
  --line: #dfe7e8;
  --surface: #ffffff;
  --canvas: #f3f7f7;
  --teal: #397f7b;
  --teal-dark: #256460;
  --teal-soft: #e4f1ef;
  --navy: #172c35;
  --red: #c33b3b;
  --red-soft: #fff0ef;
  --amber: #c77b18;
  --amber-soft: #fff6df;
  --green: #20825c;
  --shadow: 0 18px 45px rgba(28, 55, 58, .09);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 250px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--navy); color: white; padding: 28px 20px; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 30px; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 13px; background: #77b8b3; color: #10282d; font: 800 14px/1 ui-sans-serif, system-ui, sans-serif; box-shadow: inset 0 0 0 1px rgba(255,255,255,.2); }
.brand strong { display: block; font: 700 17px/1.2 ui-sans-serif, system-ui, sans-serif; }
.brand span { display: block; margin-top: 4px; color: #a7bdc2; font-size: 12px; }
nav { display: grid; gap: 7px; }
.nav-item { border: 0; border-radius: 12px; padding: 12px 13px; display: grid; grid-template-columns: 23px 1fr auto; align-items: center; gap: 8px; text-align: left; color: #b9cace; background: transparent; transition: .18s ease; }
.nav-item:hover, .nav-item.active { color: white; background: rgba(119, 184, 179, .15); }
.nav-item b { min-width: 23px; padding: 3px 7px; border-radius: 99px; background: rgba(255,255,255,.09); font-size: 11px; text-align: center; }
.sidebar-status { margin-top: auto; padding: 16px 10px 12px; border-top: 1px solid rgba(255,255,255,.1); color: #dce9e8; font-size: 12px; }
.sidebar-status div { display: flex; align-items: center; gap: 8px; }
.sidebar-status small { display: block; color: #829ba1; margin: 8px 0 0 16px; line-height: 1.5; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #9aa7aa; box-shadow: 0 0 0 4px rgba(154,167,170,.12); }
.status-dot.ok { background: #5fd09b; box-shadow: 0 0 0 4px rgba(95,208,155,.12); }
.status-dot.error { background: #ff7474; box-shadow: 0 0 0 4px rgba(255,116,116,.12); }
.text-button { border: 0; background: none; color: #8fa6ab; text-align: left; padding: 8px 10px; font-size: 12px; }

main { min-width: 0; padding: 34px clamp(22px, 4vw, 58px) 70px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.eyebrow { margin: 0 0 7px; color: var(--teal); font-size: 11px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase; }
h1, h2, h3 { font-family: ui-sans-serif, system-ui, sans-serif; margin: 0; }
.topbar h1 { font-size: clamp(27px, 3vw, 38px); letter-spacing: -.035em; }
.top-actions { display: flex; gap: 10px; }
button.primary, button.secondary { border-radius: 11px; padding: 10px 15px; font-weight: 700; border: 1px solid transparent; }
button.primary { background: var(--teal); color: white; box-shadow: 0 8px 20px rgba(57,127,123,.16); }
button.primary:hover { background: var(--teal-dark); }
button.secondary { color: var(--ink); border-color: var(--line); background: var(--surface); }
button.secondary:hover { border-color: #b9cccc; background: #fbfdfd; }
.download-button { border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; color: var(--ink); background: white; text-decoration: none; font-size: 11px; font-weight: 700; }
button:disabled { opacity: .5; cursor: wait; }
.full { width: 100%; }

.alert { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 15px; background: var(--red-soft); border: 1px solid #efc7c4; border-left: 4px solid var(--red); padding: 15px 16px; border-radius: 13px; margin-bottom: 20px; }
.alert-icon { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; color: white; background: var(--red); font-weight: 800; }
.alert p { margin: 3px 0 0; color: #7e4743; font-size: 13px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 13px; margin-bottom: 34px; }
.stats article { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 17px 18px; box-shadow: 0 5px 20px rgba(40,70,75,.04); }
.stats span, .stats small { display: block; color: var(--muted); font-size: 12px; }
.stats strong { display: block; font: 700 29px/1.15 ui-sans-serif, system-ui, sans-serif; margin: 5px 0 4px; }
.stats .danger-stat strong { color: var(--red); }

.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 16px; }
.section-heading h2 { font-size: 20px; }
.section-heading p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.legend { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; }
.legend .amber { margin-left: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.green { background: var(--green); }.dot.amber { background: var(--amber); }
.message-list { display: grid; gap: 12px; }
.message-card { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 15px; overflow: hidden; box-shadow: 0 7px 25px rgba(39,72,77,.04); }
.message-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--green); }
.message-card.review::before { background: var(--amber); }
.message-card.error::before { background: var(--red); }
.message-main { display: grid; grid-template-columns: minmax(250px, 1.2fr) minmax(250px, 1fr) auto; gap: 22px; padding: 18px 20px 15px 22px; align-items: start; }
.sender-line { display: flex; gap: 10px; align-items: center; min-width: 0; }
.sender-avatar { flex: 0 0 auto; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--teal-soft); color: var(--teal-dark); font-weight: 800; font-size: 12px; }
.sender-line strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sender-line span { display: block; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.message-copy h3 { margin-top: 12px; font: 700 15px/1.35 ui-sans-serif, system-ui, sans-serif; }
.message-copy > p { margin: 6px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.mail-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip { padding: 5px 8px; border-radius: 7px; background: #f0f4f4; color: #54656a; font-size: 10px; font-weight: 600; }
.chip.priority-high { background: var(--amber-soft); color: #8d5b18; }
.chip.spam { background: var(--red-soft); color: var(--red); }
.route-label { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.route { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; margin: 8px 0 12px; }
.route span { padding: 6px 8px; background: #f1f5f5; border-radius: 7px; font-size: 11px; }
.route i { color: #94a5a8; font-style: normal; font-size: 11px; }
.route span.final { background: var(--teal-soft); color: var(--teal-dark); font-weight: 700; }
.reason { margin: 0; color: #536267; font-size: 12px; line-height: 1.55; }
.confidence { min-width: 78px; text-align: right; }
.confidence strong { display: block; font: 700 20px/1 ui-sans-serif, system-ui, sans-serif; }
.confidence small { color: var(--muted); font-size: 10px; }
.confidence-meter { height: 4px; margin-top: 8px; background: #e7eeee; border-radius: 4px; overflow: hidden; }
.confidence-meter i { display: block; height: 100%; background: var(--green); }
.review .confidence-meter i { background: var(--amber); }
.message-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 11px 20px 13px 22px; background: #fbfdfd; border-top: 1px solid #edf1f1; }
.message-actions button { padding: 8px 11px; border-radius: 9px; border: 1px solid var(--line); background: white; color: #4e5d62; font-weight: 700; font-size: 11px; }
.message-actions .approve { border-color: var(--teal); background: var(--teal); color: white; }
.message-actions .feedback { margin-right: auto; border: 0; background: transparent; color: var(--muted); }
.empty { text-align: center; padding: 70px 20px; color: var(--muted); }
.empty div { margin: auto; width: 48px; height: 48px; display: grid; place-items: center; border-radius: 50%; background: var(--teal-soft); color: var(--teal); font-size: 24px; }
.empty h3 { color: var(--ink); margin-top: 14px; }
.empty p { margin: 6px 0; font-size: 13px; }

.process-list, .audit-list { display: grid; gap: 10px; }
.process-row { display: grid; grid-template-columns: 12px minmax(200px, 1fr) auto; align-items: center; gap: 14px; padding: 15px 17px; border: 1px solid var(--line); border-radius: 12px; background: white; }
.process-row.overdue { border-color: #e7aaa6; background: var(--red-soft); }
.process-row h3 { font: 700 13px/1.4 ui-sans-serif, system-ui, sans-serif; }
.process-row p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.process-row time { color: var(--muted); font-size: 11px; }
.audit-row { display: grid; grid-template-columns: 145px 185px 1fr; gap: 18px; padding: 12px 15px; border-bottom: 1px solid var(--line); font-size: 12px; }
.audit-row time, .audit-row span { color: var(--muted); }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 25px; background: radial-gradient(circle at 70% 15%, #dcefed, transparent 30%), var(--canvas); }
.login-card { width: min(420px, 100%); background: white; padding: 35px; border-radius: 20px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.login-card .brand-mark { margin-bottom: 25px; }
.login-card h1 { font-size: 30px; }
.login-card .muted { color: var(--muted); font-size: 13px; line-height: 1.6; margin-bottom: 25px; }
label { display: grid; gap: 7px; margin: 14px 0; color: #46565b; font-size: 12px; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid #cfdadb; border-radius: 10px; background: white; padding: 11px 12px; color: var(--ink); outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(57,127,123,.1); }
.form-error { min-height: 18px; color: var(--red); font-size: 12px; }

dialog { width: min(520px, calc(100vw - 28px)); border: 0; border-radius: 17px; padding: 0; box-shadow: 0 30px 90px rgba(17,39,45,.25); }
dialog::backdrop { background: rgba(15,31,36,.52); backdrop-filter: blur(3px); }
dialog form { padding: 22px; }
.dialog-head { display: flex; justify-content: space-between; align-items: start; }
.icon-button { width: 34px; height: 34px; border-radius: 50%; border: 0; background: #eef3f3; font-size: 20px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.toast { position: fixed; right: 22px; bottom: 22px; max-width: 380px; padding: 12px 15px; border-radius: 10px; color: white; background: var(--navy); box-shadow: var(--shadow); transform: translateY(25px); opacity: 0; pointer-events: none; transition: .2s ease; font-size: 12px; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: #8f3232; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 78px minmax(0,1fr); }
  .sidebar { padding-inline: 12px; }
  .brand > div:last-child, .nav-item:not(.active) b, .nav-item { font-size: 0; }
  .brand { padding-inline: 5px; }.nav-item { grid-template-columns: 1fr; place-items: center; }.nav-item span { font-size: 18px; }
  .sidebar-status span:last-child, .sidebar-status small, .text-button { display: none; }
  .message-main { grid-template-columns: 1fr auto; }.route-block { grid-column: 1 / -1; grid-row: 2; }
}
@media (max-width: 720px) {
  .app-shell { display: block; }.sidebar { position: static; height: auto; padding: 10px 15px; flex-direction: row; align-items: center; gap: 10px; }
  .brand { padding: 0; margin-right: auto; }.brand-mark { width: 36px; height: 36px; }.sidebar nav { display: flex; }.sidebar-status, .text-button { display: none; }
  main { padding: 22px 14px 55px; }.topbar { align-items: flex-start; }.top-actions { display: grid; }.top-actions button { padding: 8px 10px; font-size: 11px; }
  .stats { grid-template-columns: repeat(2, 1fr); }.alert { grid-template-columns: auto 1fr; }.alert button { grid-column: 1/-1; }
  .message-main { display: block; }.confidence { position: absolute; top: 20px; right: 18px; }.message-copy { padding-right: 75px; }.route-block { margin-top: 16px; }
  .message-actions { flex-wrap: wrap; }.message-actions .feedback { width: 100%; margin: 0; text-align: left; }.audit-row { grid-template-columns: 1fr; gap: 3px; }
}
