:root {
  --bg: #f3f6fb;
  --panel: #ffffff;
  --border: #d8e0ea;
  --text: #1f2937;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #059669;
  --danger: #dc2626;
  --warning-bg: #fef3c7;
  --success-bg: #ecfdf5;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #eef4ff 0%, var(--bg) 220px, var(--bg) 100%);
}

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

.hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app-shell {
  width: min(980px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.top-bar,
.query-panel,
.result-panel,
.mail-card,
.code-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.channel-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #229ed9, #0088cc);
  color: #fff !important;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none !important;
  white-space: nowrap;
  cursor: pointer;
}

.channel-btn:hover {
  background: linear-gradient(135deg, #1d8ec7, #0077b3);
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 20px 24px;
  margin-bottom: 16px;
}

.top-bar h1,
.mail-card h2,
.code-card h2 {
  margin: 0 0 6px;
}

.top-bar p,
.hint,
.message-meta,
.message-preview {
  margin: 0;
  color: var(--muted);
}

.query-panel,
.result-panel {
  padding: 20px 24px;
}

.json-import-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 18px;
}

.json-import-header,
.panel-head,
.action-row,
.code-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.json-import-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

textarea,
input,
select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
}

textarea {
  resize: vertical;
  min-height: 140px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.field-grid label {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-grid .full-width {
  grid-column: 1 / -1;
}

.action-row {
  margin-top: 4px;
  justify-content: flex-end;
}

.primary-btn,
.ghost-btn {
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  cursor: pointer;
}

.primary-btn {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  font-weight: 700;
}

.ghost-btn {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.result-panel {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.code-card,
.mail-card {
  padding: 18px;
}

.code-value {
  margin-top: 14px;
  padding: 22px;
  border-radius: 14px;
  background: #f8fafc;
  border: 1px dashed var(--border);
  font-size: 42px;
  letter-spacing: 0.18em;
  text-align: center;
  font-weight: 800;
  color: var(--success);
}

.code-value.waiting {
  font-size: 20px;
  letter-spacing: normal;
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--warning-bg);
  color: #92400e;
  font-size: 13px;
  font-weight: 700;
}

.badge.matched {
  background: var(--success-bg);
  color: var(--success);
}

.mail-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 18px;
  margin: 16px 0;
}

.mail-meta dt {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
}

.mail-meta dd {
  margin: 0;
  word-break: break-word;
}

.mail-body-block h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.mail-body {
  margin: 0;
  padding: 14px;
  border-radius: 12px;
  background: #f8fafc;
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 260px;
  overflow: auto;
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}

.message-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  background: #f8fafc;
}

.message-subject {
  font-weight: 700;
  margin-bottom: 6px;
}

.message-code {
  margin-top: 10px;
  display: inline-block;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--success-bg);
  color: var(--success);
  font-weight: 700;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  box-shadow: var(--shadow);
}

@media (max-width: 760px) {
  .field-grid,
  .mail-meta {
    grid-template-columns: 1fr;
  }

  .top-bar,
  .json-import-header,
  .action-row,
  .code-card-head {
    flex-direction: column;
    align-items: stretch;
  }

  .top-bar-actions {
    width: 100%;
    justify-content: stretch;
  }

  .top-bar-actions .channel-btn,
  .top-bar-actions .ghost-btn {
    flex: 1;
    justify-content: center;
  }
}
