:root {
  color-scheme: light;
  --bg: #0c2340;
  --bg-deep: #07182d;
  --panel: #ffffff;
  --panel-soft: #f7fafc;
  --line: #c4ced4;
  --line-strong: #8fa5b8;
  --text: #102238;
  --muted: #52657a;
  --accent: #003087;
  --accent-hover: #001f5c;
  --accent-soft: #edf4ff;
  --yankees-gray: #c4ced4;
  --warn: #6b4300;
  --warn-bg: #fff7df;
  --warn-line: #d59a16;
  --success: #146c43;
  --success-bg: #ecf8f0;
  --danger: #a4262c;
  --shadow: 0 18px 48px rgba(3, 17, 34, 0.22);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 260px),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.shell {
  display: grid;
  grid-template-columns: minmax(380px, 1fr) minmax(420px, 1fr);
  align-items: start;
  gap: 16px;
  min-height: 100vh;
  padding: 18px;
}

.pane {
  background: var(--panel);
  border: 1px solid rgba(196, 206, 212, 0.82);
  border-radius: 8px;
  padding: 14px;
  min-width: 0;
  box-shadow: var(--shadow);
}

.input-pane {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 36px);
}

.input-pane header,
.top-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.input-pane header {
  margin-bottom: 12px;
}

.top-actions {
  flex-wrap: nowrap;
  justify-content: flex-end;
  flex: 1 1 auto;
  min-width: 220px;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 28px;
  color: var(--bg);
  flex: 0 0 auto;
}

h2 {
  font-size: 19px;
  color: var(--bg);
}

p {
  color: var(--muted);
  line-height: 1.4;
}

textarea {
  display: block;
  width: 100%;
  height: calc(100vh - 190px);
  min-height: 420px;
  resize: vertical;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 12px;
  font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.hidden {
  display: none !important;
}

.thread-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.thread-panel-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  padding: 10px 12px;
}

.thread-panel-head h2 {
  color: #ffffff;
}

.thread-panel-head button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.thread-view {
  display: grid;
  align-content: start;
  gap: 10px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 12px;
}

.thread-view.empty {
  display: block;
  color: var(--muted);
}

.thread-raw {
  margin-top: 10px;
  height: 280px;
  min-height: 220px;
}

.email-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 12px;
  min-width: 0;
  box-shadow: 0 1px 0 rgba(12, 35, 64, 0.05);
}

.email-header {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  border-bottom: 1px solid #e1e7ec;
  padding-bottom: 9px;
  margin-bottom: 10px;
}

.email-avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--bg);
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
}

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

.email-meta-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.email-meta-top strong {
  overflow-wrap: anywhere;
}

.email-meta-top span,
.email-sub {
  color: var(--muted);
  font-size: 12px;
}

.email-meta-top span {
  flex: 0 0 auto;
  text-align: right;
}

.email-sub {
  margin-top: 2px;
  overflow-wrap: anywhere;
}

.email-body {
  color: var(--text);
  font-size: 13px;
  line-height: 1.48;
  overflow-wrap: anywhere;
}

.email-body.empty {
  color: var(--muted);
}

.email-body p {
  margin: 0 0 9px;
  color: var(--text);
}

.email-body p:last-child,
.email-body ul:last-child {
  margin-bottom: 0;
}

.email-body ul {
  margin: 0 0 9px;
  padding-left: 20px;
}

.source-highlight {
  position: relative;
  display: inline-block;
  border-radius: 4px;
  background: #fff176;
  color: inherit;
  padding: 0 2px;
  box-shadow: inset 0 -1px 0 #d6b900;
  cursor: help;
}

.source-highlight:hover {
  background: #ffe24d;
}

.source-highlight:hover::after,
.source-highlight:focus::after {
  content: attr(data-source-label);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 7px);
  z-index: 20;
  transform: translateX(-50%);
  width: max-content;
  max-width: 240px;
  border-radius: 6px;
  background: #111827;
  color: #ffffff;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
  white-space: normal;
  box-shadow: 0 8px 20px rgba(17, 24, 39, 0.22);
  pointer-events: none;
}

.source-highlight:hover::before,
.source-highlight:focus::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: calc(100% + 2px);
  z-index: 21;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #111827;
  pointer-events: none;
}

.actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}

button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  border-radius: 6px;
  min-height: 36px;
  padding: 0 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(12, 35, 64, 0.12);
}

button:hover:not(:disabled) {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
}

button.secondary {
  background: white;
  color: var(--accent);
  border-color: var(--accent);
}

button.secondary:hover:not(:disabled) {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

button.icon-button {
  width: 34px;
  min-height: 34px;
  padding: 0;
  border-color: var(--line-strong);
  background: white;
  color: var(--text);
}

button.small-button {
  min-height: 32px;
  padding: 0 9px;
  font-size: 12px;
  white-space: nowrap;
}

#reviewListBtn {
  background: #ffffff;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.status {
  min-height: 20px;
  margin: 0 0 6px;
  color: var(--muted);
  font-weight: 650;
  font-size: 13px;
}

.queue {
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 14px;
}

.queue-drawer {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  justify-content: flex-end;
  background: rgba(7, 24, 45, 0.62);
}

.queue-drawer.hidden {
  display: none;
}

.queue-drawer-card {
  width: min(480px, 100%);
  height: 100%;
  border-left: 1px solid var(--line);
  background: #ffffff;
  box-shadow: -18px 0 48px rgba(3, 17, 34, 0.32);
  padding: 16px;
  overflow: auto;
}

.queue-drawer-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.queue-drawer .queue-list {
  max-height: none;
}

.toast-host {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 1200;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 36px));
  pointer-events: none;
}

.toast {
  display: grid;
  gap: 3px;
  border: 1px solid var(--line-strong);
  border-left: 5px solid var(--accent);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  padding: 12px 14px;
  box-shadow: 0 16px 42px rgba(3, 17, 34, 0.26);
  animation: toast-in 180ms ease-out;
}

.toast-needs-action {
  border-left-color: var(--warn-line);
}

.toast strong {
  font-size: 14px;
}

.toast span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
}

.toast-exiting {
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 180ms ease, transform 180ms ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.queue-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.queue-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
}

.queue-list.empty {
  display: block;
  color: var(--muted);
}

.queue-item {
  display: block;
  width: 100%;
  min-height: 0;
  border-color: var(--line);
  background: white;
  color: var(--text);
  text-align: left;
  padding: 10px;
}

.queue-item:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.queue-title,
.queue-meta {
  display: block;
  overflow-wrap: anywhere;
}

.queue-title {
  font-weight: 800;
}

.queue-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.queue-item.status-needs_review {
  border-left: 4px solid var(--warn-line);
}

.queue-item.status-error {
  border-left: 4px solid var(--danger);
}

.queue-item.status-processed,
.queue-item.status-reviewed {
  border-left: 4px solid var(--success);
}

.job-history-list {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}

.job-history-list.empty {
  display: block;
  color: var(--muted);
}

.job-item {
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);
  border-radius: 6px;
  background: white;
  padding: 10px;
  min-width: 0;
}

.job-item.status-clean {
  border-left-color: var(--success);
}

.job-item.status-needs_review,
.job-item.status-running {
  border-left-color: var(--warn-line);
}

.job-item.status-error,
.job-item.status-failed {
  border-left-color: var(--danger);
}

.job-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

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

.job-title,
.job-meta {
  display: block;
  overflow-wrap: anywhere;
}

.job-title {
  font-weight: 800;
}

.job-meta,
.job-counts {
  color: var(--muted);
  font-size: 12px;
}

.job-badge {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  background: #f9fbfd;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.job-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.job-issues {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.job-issues ul {
  margin: 4px 0 0;
  padding-left: 18px;
}

.job-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.job-actions button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.job-details.hidden {
  display: none;
}

.review-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}

.review-head-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.review-head-actions #fillBtn {
  min-height: 32px;
  padding: 0 12px;
  white-space: nowrap;
}

.notification-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.notification-button::before {
  content: "🔔";
  font-size: 13px;
  line-height: 1;
}

.notification-log {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  min-height: 16px;
  text-align: right;
}

.notification-log.ok {
  color: #0a5c2f;
}

.notification-log.warn {
  color: #7a4b00;
}

.notification-log.error {
  color: #a4262c;
}

.notification-settings-card {
  max-width: 620px;
}

.settings-reason {
  margin: 0 0 14px;
  color: var(--text);
  font-size: 17px;
  line-height: 1.4;
}

.settings-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.settings-actions button {
  min-height: 42px;
}

.settings-help {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fbff;
  color: var(--text);
  font-size: 14px;
  line-height: 1.35;
}

.settings-help strong {
  display: block;
  margin-bottom: 8px;
  color: var(--navy);
}

.settings-help p {
  margin: 6px 0;
}

.settings-help span {
  color: var(--muted);
  font-weight: 800;
}

.badge {
  border-radius: 999px;
  background: var(--bg);
  color: #ffffff;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 5px;
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid #e1e7ec;
  border-radius: 8px;
  background: #ffffff;
}

.fields.empty {
  display: block;
  color: var(--muted);
}

.field {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  border: 0;
  border-radius: 0;
  padding: 3px 0;
  min-width: 0;
  background: #ffffff;
  box-shadow: none;
}

.field label {
  display: block;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 0;
  line-height: 1.2;
}

.field input {
  width: 100%;
  border: 1px solid #d8dde6;
  border-radius: 4px;
  outline: 0;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.3;
  min-height: 30px;
  background: #ffffff;
  padding: 5px 9px;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 48, 135, 0.12);
}

.required-mark {
  color: var(--warn);
}

.fillout-label::after {
  content: ":";
}

.radio-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding-top: 0;
}

.radio-option {
  display: flex !important;
  align-items: center;
  gap: 7px;
  width: max-content;
  min-height: 28px;
  margin: 0 !important;
  color: var(--text) !important;
  font-size: 14px !important;
  font-weight: 650 !important;
}

.radio-option input {
  width: 14px;
  min-height: 14px;
  height: 14px;
  margin: 0;
  padding: 0;
  box-shadow: none;
}

.datetime-review-field {
  align-items: start;
}

.review-datetime {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) 62px 76px 82px;
  gap: 8px;
  align-items: end;
}

.review-date-group {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  gap: 6px;
}

.compact-time-control {
  display: grid !important;
  gap: 3px;
  color: var(--muted) !important;
  font-size: 11px !important;
  font-weight: 800 !important;
  line-height: 1.1 !important;
}

.review-datetime input,
.review-datetime select {
  width: 100%;
  border: 1px solid #d8dde6;
  border-radius: 4px;
  min-height: 30px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  padding: 4px 7px;
}

.review-date-picker {
  padding: 0 3px !important;
}

.ready-notice {
  display: grid;
  gap: 4px;
  border: 1px solid var(--success);
  border-radius: 8px;
  background: #eef8f0;
  color: #173b1f;
  padding: 12px;
  margin-bottom: 12px;
}

.ready-notice.hidden {
  display: none;
}

.ready-notice.attention {
  border-color: var(--warn-line);
  background: #fff8e8;
  color: #5c3b00;
}

.ready-notice strong {
  font-size: 16px;
}

.ready-notice span {
  font-size: 14px;
}

.popup {
  margin-top: 8px;
  border: 1px solid var(--warn-line);
  background: var(--warn-bg);
  border-radius: 8px;
  padding: 10px 12px;
}

.popup.hidden {
  display: none;
}

.warnings {
  margin-bottom: 12px;
  border: 1px solid var(--warn-line);
  background: #fff8e8;
  border-radius: 8px;
  padding: 12px;
}

.warnings.hidden {
  display: none;
}

.warnings-title {
  font-weight: 800;
  font-size: 16px;
  margin-bottom: 6px;
}

.warnings ul {
  margin: 0;
  padding-left: 20px;
}

.warnings li + li {
  margin-top: 4px;
}

.submit-bar {
  display: none;
}

.submit-bar button {
  min-height: 34px;
  font-size: 13px;
}

.submit-bar #fillBtn {
  min-width: 180px;
}

.fillout-result {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f9fbfd;
}

.fillout-result.hidden {
  display: none;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.result-box {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: white;
  min-width: 0;
}

.result-box h3 {
  margin: 0 0 6px;
  font-size: 13px;
}

.result-box ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

.result-box li {
  margin: 2px 0;
}

.popup-title {
  font-weight: 800;
  color: var(--warn);
  margin-bottom: 5px;
  font-size: 15px;
}

.popup-body {
  white-space: pre-wrap;
  margin-bottom: 8px;
  font-size: 14px;
  line-height: 1.32;
}

.choice {
  display: block;
  margin: 6px 0;
  font-size: 14px;
}

.choice input {
  margin-right: 8px;
}

.datetime-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 64px 74px 84px;
  gap: 8px;
  margin: 7px 0 0 22px;
}

.datetime-field {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.datetime-row input,
.datetime-row select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 32px;
  padding: 0 8px;
  background: white;
  color: var(--text);
  font: inherit;
}

.date-group {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  gap: 6px;
}

.datetime-date-picker {
  padding: 0 4px;
}

.datetime-row input[type="number"] {
  appearance: textfield;
}

.datetime-row input[type="number"]::-webkit-outer-spin-button,
.datetime-row input[type="number"]::-webkit-inner-spin-button {
  opacity: 1;
}

.datetime-row select {
  appearance: auto;
  cursor: pointer;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(7, 24, 45, 0.68);
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(560px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  border: 1px solid var(--warn-line);
  border-radius: 8px;
  background: white;
  box-shadow: 0 22px 60px rgba(3, 17, 34, 0.34);
  padding: 16px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.modal-head h2 {
  font-size: 18px;
}

.modal-body {
  color: var(--text);
  line-height: 1.45;
  margin-bottom: 14px;
  white-space: pre-wrap;
}

.paste-thread-card {
  width: min(860px, calc(100vw - 32px));
  border-color: var(--line);
}

.paste-thread-card .modal-body {
  display: grid;
  gap: 10px;
  white-space: normal;
}

.modal-note {
  margin: 0;
  color: var(--muted);
  font-weight: 650;
}

.paste-thread-text {
  height: min(54vh, 520px);
  min-height: 300px;
  resize: vertical;
  border-color: var(--line-strong);
  background: #ffffff;
}

.modal-choices {
  display: grid;
  gap: 8px;
}

.modal-choice {
  display: block;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  cursor: pointer;
}

.modal-choice:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.modal-choice input {
  margin-right: 8px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

pre {
  max-height: 300px;
  overflow: auto;
  background: #101820;
  color: #e8eef5;
  border-radius: 8px;
  padding: 12px;
  font-size: 12px;
}

#jsonOut.hidden {
  display: none;
}

.login-body {
  min-height: 100vh;
  background: var(--navy);
  color: var(--ink);
}

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

.login-card {
  width: min(440px, 100%);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
  padding: 28px;
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 32px;
  line-height: 1.1;
  color: var(--navy);
}

.login-card p {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 16px;
}

.login-error {
  border: 1px solid #b94a48;
  background: #fff3f2;
  color: #8a2522;
  border-radius: 6px;
  padding: 10px 12px;
}

.login-form {
  display: grid;
  gap: 10px;
}

.login-form label {
  font-weight: 800;
  color: var(--navy);
}

.login-form input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  font: inherit;
}

.login-form input:focus {
  outline: 3px solid var(--accent-soft);
  border-color: var(--accent);
}

.login-form button {
  margin-top: 6px;
}

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

  textarea {
    height: 360px;
  }

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

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

  .submit-bar {
    justify-content: stretch;
  }

  .submit-bar button {
    width: 100%;
  }

  .datetime-row {
    grid-template-columns: 1fr 1fr;
    margin-left: 0;
  }

  .datetime-row .date-field {
    grid-column: 1 / -1;
  }
}
