:root {
  color-scheme: light;
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-muted: #fafafa;
  --text: #202124;
  --text-secondary: #5f6368;
  --text-muted: #80868b;
  --border: #e1e3e6;
  --border-strong: #c9ccd1;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff4ff;
  --success: #18794e;
  --success-soft: #edf8f2;
  --warning: #9a6700;
  --warning-soft: #fff8e6;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --radius: 8px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  --mono: "SFMono-Regular", "Cascadia Code", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
}

button,
summary {
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100;
  padding: 8px 12px;
  color: #fff;
  background: var(--text);
  border-radius: 4px;
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

.container {
  width: min(960px, calc(100% - 40px));
  margin: 0 auto;
}

.site-header {
  height: 56px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.site-header__inner {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  color: var(--text);
  text-decoration: none;
  font-size: 15px;
  font-weight: 650;
}

.internal-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  color: var(--text-secondary);
  background: #f1f2f3;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.text-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 550;
}

.text-link:hover {
  color: var(--primary);
}

.page-main {
  padding: 32px 0 56px;
}

.page-heading {
  margin-bottom: 20px;
}

.page-heading--row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.page-heading h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 650;
  line-height: 1.3;
  letter-spacing: -0.02em;
}

.page-heading p {
  margin: 6px 0 0;
  color: var(--text-secondary);
}

.stack {
  display: grid;
  gap: 20px;
}

.lookup-form {
  padding-bottom: 2px;
}

.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.panel__body {
  padding: 20px;
}

.panel__header {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

.panel__header h2,
.section-heading h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
}

.panel__meta {
  color: var(--text-muted);
  font-size: 12px;
}

.field-label {
  display: block;
  margin-bottom: 7px;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
}

.form-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 148px;
  gap: 12px;
}

.text-input,
.number-input,
.code-editor {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  color: var(--text);
  background: var(--surface);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.text-input,
.number-input {
  min-height: 42px;
  padding: 9px 12px;
}

.text-input::placeholder,
.number-input::placeholder {
  color: #9aa0a6;
}

.text-input:focus,
.number-input:focus,
.code-editor:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.text-input:disabled,
.number-input:disabled,
.code-editor:disabled {
  color: var(--text-muted);
  background: #f4f5f6;
  cursor: not-allowed;
}

.btn {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.btn:hover:not(:disabled) {
  background: #f5f6f7;
}

.btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

.btn--primary {
  color: #fff;
  border-color: var(--primary);
  background: var(--primary);
}

.btn--primary:hover:not(:disabled) {
  border-color: var(--primary-hover);
  background: var(--primary-hover);
}

.btn--danger {
  color: var(--danger);
  border-color: #efc7c2;
  background: var(--surface);
}

.btn--small {
  min-height: 36px;
  padding: 7px 12px;
}

.btn.is-loading::before {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.btn:focus-visible,
.text-link:focus-visible,
.brand:focus-visible,
.copy-value:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.field-help {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 12px;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  color: var(--text-secondary);
  font-size: 12px;
}

.status-line__dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--success);
}

.status-line.is-warning {
  color: var(--warning);
}

.status-line.is-warning .status-line__dot {
  background: var(--warning);
}

.status-line.is-idle .status-line__dot {
  background: var(--text-muted);
}

.empty-state {
  padding: 54px 20px;
  color: var(--text-muted);
  text-align: center;
}

.empty-state strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
}

.message-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.message-item {
  padding: 17px 20px;
  border-bottom: 1px solid var(--border);
}

.message-item:last-child {
  border-bottom: 0;
}

.message-item__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.message-item h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 620;
  overflow-wrap: anywhere;
}

.message-item__date {
  flex: 0 0 auto;
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}

.message-item__from {
  margin: 3px 0 0;
  color: var(--text-secondary);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.message-item__preview {
  display: -webkit-box;
  overflow: hidden;
  margin: 10px 0 0;
  color: var(--text-secondary);
  font-size: 13px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  white-space: pre-line;
}

.message-item__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 11px;
}

.matched-values {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.copy-value {
  padding: 3px 7px;
  border: 1px solid #cad7f5;
  border-radius: 4px;
  color: #1e4fbf;
  background: var(--primary-soft);
  cursor: pointer;
  font: 600 11px/1.4 var(--mono);
}

.message-details {
  min-width: 88px;
  color: var(--text-secondary);
  font-size: 12px;
}

.message-details summary {
  width: fit-content;
  margin-left: auto;
  color: var(--primary);
  cursor: pointer;
  font-weight: 600;
}

.message-details[open] {
  width: 100%;
  flex: 0 0 100%;
}

.mail-body {
  max-height: min(50vh, 420px);
  overflow: auto;
  margin: 12px 0 0;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: #34373b;
  background: var(--surface-muted);
  font: 12px/1.6 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.mail-frame {
  width: 100%;
  height: 320px;
  display: block;
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}

.truncate-note {
  margin: 7px 0 0;
  color: var(--warning);
  font-size: 11px;
}

.error-block,
.info-block {
  margin: 20px;
  padding: 12px 14px;
  border-radius: 6px;
  font-size: 13px;
}

.error-block {
  color: var(--danger);
  border: 1px solid #efc7c2;
  background: var(--danger-soft);
}

.info-block {
  color: var(--text-secondary);
  border: 1px solid var(--border);
  background: var(--surface-muted);
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 50;
  padding: 9px 12px;
  color: #fff;
  background: #303134;
  border-radius: 6px;
  font-size: 12px;
}

/* Settings */
.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.6fr);
  gap: 16px;
}

.settings-grid .panel--wide {
  grid-column: 1 / -1;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.section-heading p {
  margin: 4px 0 0;
  color: var(--text-secondary);
  font-size: 12px;
}

.source-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  gap: 12px;
}

.input-suffix {
  position: relative;
}

.input-suffix input {
  padding-right: 42px;
}

.input-suffix span {
  position: absolute;
  top: 50%;
  right: 11px;
  color: var(--text-muted);
  transform: translateY(-50%);
  font-size: 11px;
  pointer-events: none;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.form-message {
  min-height: 18px;
  margin: 10px 0 0;
  color: var(--text-secondary);
  font-size: 12px;
}

.field-hint {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 11px;
}

.form-message:empty {
  min-height: 0;
  margin-top: 0;
}

.form-message.is-success {
  color: var(--success);
}

.form-message.is-error {
  color: var(--danger);
}

.source-status {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-bottom: 14px;
  padding: 11px;
  border: 1px solid #cce6d8;
  border-radius: 6px;
  background: var(--success-soft);
}

.source-status.is-error {
  border-color: #efc7c2;
  background: var(--danger-soft);
}

.source-status__dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--success);
}

.source-status.is-error .source-status__dot {
  background: var(--danger);
}

.source-status strong,
.source-status span {
  display: block;
}

.source-status strong {
  font-size: 13px;
}

.source-status span {
  margin-top: 2px;
  color: var(--text-secondary);
  font-size: 11px;
}

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
}

.metric {
  min-width: 0;
  padding: 10px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.metric--wide {
  grid-column: 1 / -1;
}

.metric__label,
.metric__value {
  display: block;
}

.metric__label {
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}

.metric__value {
  margin-top: 3px;
  font-size: 12px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.status-details {
  margin-top: 12px;
}

.status-details summary {
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12px;
}

.status-raw {
  max-height: 260px;
  overflow: auto;
  margin: 8px 0 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-muted);
  font: 11px/1.5 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.editor-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.editor-header .actions {
  flex: 0 0 auto;
  margin-top: 0;
}

.code-editor {
  min-height: 500px;
  resize: vertical;
  padding: 13px;
  background: #fcfcfd;
  font: 12px/1.6 var(--mono);
  tab-size: 2;
}

.editor-note {
  margin: 9px 0 0;
  color: var(--text-muted);
  font-size: 11px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 760px) {
  .container {
    width: min(100% - 24px, 960px);
  }

  .page-main {
    padding-top: 24px;
  }

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

  .settings-grid .panel--wide {
    grid-column: auto;
  }

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

  .message-item__top {
    display: block;
  }

  .message-item__date {
    display: block;
    margin-top: 4px;
  }

  .message-item__footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .message-details,
  .message-details[open] {
    width: 100%;
  }

  .message-details summary {
    margin-left: 0;
  }

  .editor-header {
    flex-direction: column;
  }

  .editor-header .actions {
    width: 100%;
  }
}

@media (max-width: 520px) {
  .container {
    width: min(100% - 16px, 960px);
  }

  .site-header {
    height: 52px;
  }

  .page-heading h1 {
    font-size: 23px;
  }

  .panel__body,
  .message-item {
    padding: 16px;
  }

  .panel__header {
    padding: 13px 16px;
  }

  .panel__meta {
    display: none;
  }

  .form-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .form-row .btn,
  .actions .btn {
    width: 100%;
  }

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

  .metric--wide {
    grid-column: auto;
  }

  .editor-header .actions {
    display: grid;
  }

  .code-editor {
    min-height: 420px;
    font-size: 11px;
  }
}

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