:root {
  --paper: #f7f8fa;
  --surface: #ffffff;
  --ink: #172033;
  --graphite: #5a6577;
  --line: #dfe3e8;
  --line-strong: #c6ccd5;
  --action: #0a66c2;
  --success: #167c5a;
  --amber: #a85d00;
  --danger: #b42318;
  --ui: "Avenir Next", Avenir, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --subject: "Iowan Old Style", Georgia, serif;
  --mono: "SFMono-Regular", SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 14px;
  line-height: 1.45;
}

button, select { font: inherit; }
textarea { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-gate[hidden], #app-shell[hidden] { display: none !important; }

.auth-panel {
  width: min(390px, 100%);
  padding: 26px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.auth-panel h1 { margin: 0 0 6px; font-size: 24px; letter-spacing: 0; }
.auth-panel p { margin: 0 0 20px; color: var(--graphite); }

.app-shell { min-height: 100vh; }

.app-header {
  height: 58px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(220px, 1fr);
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand-lockup, .account-controls, .queue-heading-actions, .sender-line,
.mail-actions, .composer-tools, .composer-actions, .recommendation-row {
  display: flex;
  align-items: center;
}

.brand-lockup { gap: 10px; min-width: 0; }
.brand-lockup > div { display: flex; align-items: baseline; gap: 8px; min-width: 0; }

.brand-mark {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background: var(--action);
  border-radius: 5px;
  color: #fff;
  font-family: var(--subject);
  font-size: 18px;
  font-weight: 700;
  text-decoration: none;
}

.product-name { font-weight: 750; white-space: nowrap; }
.mailbox-label { color: var(--graphite); font: 11px/1 var(--mono); white-space: nowrap; }
.account-controls { justify-content: flex-end; gap: 10px; min-width: 0; }
.auth-account { overflow: hidden; color: var(--graphite); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }

.view-switcher {
  display: flex;
  height: 34px;
  padding: 2px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 7px;
}

.view-tab {
  min-width: 76px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.view-tab.is-active { background: var(--surface); color: var(--action); box-shadow: 0 1px 2px rgba(23, 32, 51, 0.12); }
.view-tab span { font-family: var(--mono); font-size: 10px; }

.pulse-workspace {
  height: calc(100vh - 58px);
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  overflow: hidden;
}

.queue-pane {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.pane-heading, .rules-heading {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.pane-heading h1, .rules-heading h1 { margin: 1px 0 0; font-size: 22px; line-height: 1.15; letter-spacing: 0; }
.utility-label { margin: 0; color: var(--graphite); font: 10px/1.2 var(--mono); text-transform: uppercase; }
.queue-heading-actions { gap: 7px; }
.queue-count { min-width: 24px; color: var(--graphite); font: 11px/1 var(--mono); text-align: right; }

.icon-button {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
}

.icon-button:hover:not(:disabled), .button:hover:not(:disabled), .text-button:hover:not(:disabled) { border-color: var(--action); color: var(--action); }
.icon-button:disabled, .button:disabled { cursor: not-allowed; opacity: 0.45; }

.button {
  min-height: 34px;
  padding: 7px 12px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.button-primary { background: var(--action); border-color: var(--action); color: #fff; }
.button-primary:hover:not(:disabled) { color: #fff; filter: brightness(0.94); }

.text-button { padding: 3px 0; background: transparent; border: 0; color: var(--action); cursor: pointer; font-size: 12px; font-weight: 700; }

.thread-list { min-height: 0; flex: 1 1 auto; overflow-y: auto; }

.queue-action-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: #eef7f3;
  border-bottom: 1px solid #c6e2d7;
  color: var(--success);
  font-size: 12px;
  font-weight: 700;
}

.load-more-wrap { flex: 0 0 auto; padding: 10px 16px; border-top: 1px solid var(--line); text-align: center; }
.load-more-wrap .button { width: 100%; }

.thread-row {
  width: 100%;
  min-height: 88px;
  display: grid;
  grid-template-columns: 4px minmax(0, 1fr);
  gap: 11px;
  padding: 0 14px 0 0;
  background: var(--surface);
  border: 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  text-align: left;
}

.thread-row:hover { background: #f2f5f8; }
.thread-row[aria-selected="true"] { background: #edf4fb; }
.thread-rail { align-self: stretch; background: var(--action); }
.thread-row[data-state="actioned"] .thread-rail { background: var(--success); }
.thread-row[data-state="waiting"] .thread-rail { background: var(--amber); }

.thread-copy { min-width: 0; padding: 12px 0; }
.thread-topline { display: flex; justify-content: space-between; gap: 8px; }
.thread-sender, .thread-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-sender { font-size: 13px; font-weight: 750; }
.thread-time { color: var(--graphite); font: 10px/1.4 var(--mono); white-space: nowrap; }
.thread-subject { display: block; margin: 3px 0 2px; font-family: var(--subject); font-size: 15px; font-weight: 600; }
.thread-snippet { display: block; margin: 0; overflow: hidden; color: var(--graphite); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }

.queue-state { padding: 16px; }
.queue-skeleton span, .analysis-line {
  display: block;
  height: 11px;
  margin-bottom: 10px;
  background: #e7eaee;
  border-radius: 3px;
  animation: pulse-fade 1.4s ease-in-out infinite;
}
.queue-skeleton span:nth-child(2), .queue-skeleton span:nth-child(4) { width: 68%; margin-bottom: 24px; }

.state-message { color: var(--graphite); }
.state-message strong { display: block; margin-bottom: 5px; color: var(--ink); }

.detail-pane { min-width: 0; overflow-y: auto; background: var(--paper); }
.detail-mobile-toolbar { display: none; }
.detail-state { min-height: 100%; display: grid; align-content: center; justify-items: center; padding: 32px; color: var(--graphite); }
.detail-loading { width: min(560px, calc(100% - 40px)); margin: 0 auto; justify-items: stretch; }
.analysis-line.short { width: 62%; }
.detail-loading p { text-align: center; }
.empty-pulse { width: 4px; height: 52px; background: var(--line-strong); }

.detail-content { min-height: 100%; background: var(--surface); }
.detail-toolbar {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 22px;
  border-bottom: 1px solid var(--line);
}
.mail-actions { gap: 6px; }
.command-button { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.message-position { color: var(--graphite); font: 10px/1 var(--mono); }
.mobile-back { display: none; }

.email-header { padding: 28px 30px 22px; border-bottom: 1px solid var(--line); }
.sender-line { gap: 10px; }
.sender-avatar { width: 32px; height: 32px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; background: #e8edf3; color: var(--ink); font-size: 12px; font-weight: 800; }
.sender-line > div { min-width: 0; display: flex; flex-direction: column; }
.sender-line strong, .sender-line span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sender-line span { color: var(--graphite); font-size: 11px; }
.sender-line time { margin-left: auto; color: var(--graphite); font: 10px/1 var(--mono); white-space: nowrap; }
.email-header h2 { margin: 20px 0 0; font-family: var(--subject); font-size: clamp(24px, 3vw, 38px); font-weight: 600; line-height: 1.12; letter-spacing: 0; }

.analysis-section { display: grid; grid-template-columns: 5px minmax(0, 1fr); border-bottom: 1px solid var(--line); }
.pulse-rail { min-height: 164px; background: var(--action); }
.pulse-rail[data-state="actioned"] { background: var(--success); }
.pulse-rail[data-state="waiting"] { background: var(--amber); }
.analysis-copy { padding: 24px 30px 26px; }
.summary { max-width: 760px; margin: 8px 0 19px; font-size: 17px; line-height: 1.55; }
.recommendation-row { max-width: 760px; flex-wrap: wrap; gap: 7px 10px; padding-top: 13px; border-top: 1px solid var(--line); }
.recommendation-label { color: var(--graphite); font: 10px/1 var(--mono); text-transform: uppercase; }
.recommendation-row strong { color: var(--action); }
.recommendation-row > span:last-child { color: var(--graphite); }
.recommendation-command { margin-left: auto; }

.email-preview { border-bottom: 1px solid var(--line); }
.email-preview summary { padding: 14px 30px; cursor: pointer; color: var(--graphite); font-size: 12px; font-weight: 700; }
.email-preview > div { max-width: 820px; padding: 0 30px 26px; color: #293348; white-space: pre-wrap; }

.next-step-panel {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr);
  gap: 18px;
  max-width: 900px;
  padding: 24px 30px;
  border-bottom: 1px solid var(--line);
  background: #f7fbff;
}
.decision-marker { width: 52px; height: 52px; display: grid; place-items: center; border: 1px solid #a9c9e8; border-radius: 50%; color: var(--action); font: 10px/1 var(--mono); text-transform: uppercase; }
.next-step-copy h3 { margin: 5px 0 6px; font-size: 18px; }
.next-step-copy > p:not(.utility-label) { max-width: 760px; margin: 0; color: var(--graphite); }
.next-step-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.next-step-correction { max-width: 760px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.next-step-correction label { display: block; margin-bottom: 6px; font-size: 12px; font-weight: 700; }
.next-step-correction textarea { width: 100%; resize: vertical; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: 6px; color: var(--ink); background: var(--surface); line-height: 1.45; }
.task-result, .automation-proposal { max-width: 760px; margin-top: 16px; padding: 12px 14px; border: 1px solid #c6e2d7; border-radius: 6px; background: #eef7f3; color: var(--success); }
.task-result a { color: inherit; font-weight: 800; }
.automation-proposal { border-color: #e6cda9; background: #fff8ed; color: var(--amber); }
.automation-proposal p { margin: 4px 0; color: inherit; }

.composer { margin: 22px 30px; border: 1px solid var(--line-strong); border-radius: 8px; }
.composer-heading-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.composer-heading-row h3 { margin: 2px 0 0; font-size: 15px; }
.composer-tools { gap: 6px; }
.reply-editor { min-height: 170px; padding: 16px; outline: 0; white-space: pre-wrap; }
.reply-editor:empty::before { content: "Write or dictate a reply"; color: #8791a0; }
.reply-editor[contenteditable="false"] { background: var(--paper); color: var(--graphite); }
.composer-status, .send-state, .action-status { min-height: 18px; margin: 0; color: var(--graphite); font: 11px/1.5 var(--mono); }
.composer-status { padding: 0 16px; }
.composer-actions { justify-content: flex-end; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line); }
.send-state { padding: 0 14px 12px; text-align: right; }
.action-status { padding: 0 30px 24px; }

.rules-panel { grid-column: 1 / -1; min-width: 0; overflow-y: auto; background: var(--paper); }
.rules-heading { position: sticky; top: 0; z-index: 1; background: var(--surface); }
.rules-heading select { min-height: 34px; padding: 6px 28px 6px 9px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); color: var(--ink); }
.rules-list { max-width: 980px; margin: 0 auto; background: var(--surface); border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.rule-row { display: grid; grid-template-columns: 5px minmax(0, 1fr) auto; gap: 16px; border-bottom: 1px solid var(--line); }
.rule-state { background: var(--amber); }
.rule-row[data-status="approved"] .rule-state { background: var(--success); }
.rule-row[data-status="rejected"] .rule-state { background: var(--danger); }
.rule-row[data-status="paused"] .rule-state { background: var(--graphite); }
.rule-copy { min-width: 0; padding: 18px 0; }
.rule-copy h2 { margin: 0 0 4px; font-size: 15px; }
.rule-copy p { margin: 0 0 6px; color: var(--graphite); }
.rule-copy span { color: var(--graphite); font: 10px/1.4 var(--mono); }
.rule-copy .rule-error { display: flex; align-items: baseline; gap: 8px; margin: 9px 0 0; color: var(--danger); }
.rule-copy .rule-error [data-rule-error] { color: inherit; font: inherit; }
.rule-actions { display: flex; align-items: center; gap: 6px; padding: 14px 16px 14px 0; }

:focus-visible { outline: 3px solid rgba(10, 102, 194, 0.32); outline-offset: 2px; }

@keyframes pulse-fade { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }

@media (max-width: 820px) {
  .app-header { grid-template-columns: minmax(0, 1fr) auto; padding: 0 12px; }
  .view-switcher { grid-column: 2; grid-row: 1; }
  .account-controls { display: none; }
  .mailbox-label { display: none; }
  .pulse-workspace { display: block; height: calc(100vh - 58px); }
  .queue-pane, .detail-pane { width: 100%; height: 100%; border: 0; }
  .detail-pane { display: none; }
  .pulse-workspace.is-detail-open .queue-pane { display: none; }
  .pulse-workspace.is-detail-open .detail-pane { display: block; }
  .detail-mobile-toolbar { position: sticky; top: 0; z-index: 3; display: flex; min-height: 52px; align-items: center; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--line); }
  .detail-state { min-height: calc(100% - 52px); }
  .mobile-back { display: inline-grid; }
  .detail-toolbar { position: sticky; top: 52px; z-index: 2; padding: 8px 12px; background: var(--surface); }
  .email-header { padding: 22px 18px 18px; }
  .email-header h2 { font-size: 27px; }
  .analysis-copy { padding: 20px 18px 22px; }
  .summary { font-size: 15px; }
  .email-preview summary { padding: 14px 18px; }
  .email-preview > div { padding: 0 18px 22px; }
  .next-step-panel { grid-template-columns: 1fr; gap: 10px; padding: 20px 18px; }
  .decision-marker { width: 44px; height: 44px; }
  .composer { margin: 16px 12px 78px; }
  .composer-actions { position: sticky; bottom: 0; background: var(--surface); }
  .action-status { padding: 0 18px 20px; }
  .rules-panel { height: 100%; }
  .rule-row { grid-template-columns: 5px minmax(0, 1fr); }
  .rule-actions { grid-column: 2; padding: 0 12px 14px 0; flex-wrap: wrap; }
  .rule-copy { padding-right: 12px; }
  .recommendation-command { width: 100%; margin-left: 0; }
}

@media (max-width: 480px) {
  .product-name { font-size: 13px; }
  .view-tab { min-width: 64px; }
  .mail-actions { gap: 4px; }
  .mail-actions .command-button { min-height: 32px; padding: 6px 8px; font-size: 11px; }
  .mail-actions .command-button > span:first-child { display: none; }
  .message-position { display: none; }
  .sender-line time { display: none; }
  .composer-heading-row { align-items: flex-start; }
  .composer-tools { flex-wrap: wrap; justify-content: flex-end; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
