:root {
  --bg: #0a0e1a;
  --surface: #131a2b;
  --surface2: #1a2236;
  --border: #1e2d44;
  --border-hover: #2a3f5f;
  --text: #c9d1d9;
  --text2: #7d8590;
  --text3: #555f6d;
  --accent: #58a6ff;
  --accent2: #1f6feb;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

.app {
  width: min(960px, 100%);
  margin: 0 auto;
  padding: 24px 16px;
}

.header {
  padding: 18px 0 24px;
  text-align: center;
}

.header h1 {
  margin: 0;
  color: var(--text);
  font-size: 21px;
  font-weight: 650;
  line-height: 1.2;
}

.header h1 span {
  color: var(--accent);
}

.header p {
  margin: 5px 0 0;
  color: var(--text3);
  font-size: 12px;
}

.card {
  margin-bottom: 12px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

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

.card-title {
  margin: 0;
  color: var(--text2);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

textarea {
  width: 100%;
  min-height: 76px;
  resize: vertical;
  outline: none;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: "SF Mono", Consolas, "Cascadia Code", monospace;
  font-size: 12px;
  line-height: 1.5;
}

textarea:focus,
input[type="number"]:focus {
  border-color: var(--accent2);
}

textarea::placeholder {
  color: var(--text3);
}

.hint {
  margin-top: 7px;
  color: var(--text3);
  font-size: 11px;
  line-height: 1.5;
}

.hint code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--bg);
  color: var(--text2);
  font-size: 10px;
}

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

.toolbar label,
.check {
  color: var(--text2);
  font-size: 12px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 30px;
  padding: 0 2px;
}

.check input {
  width: 14px;
  height: 14px;
  accent-color: var(--accent2);
}

input[type="number"] {
  width: 58px;
  outline: none;
  padding: 6px 8px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  text-align: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  gap: 5px;
  padding: 6px 14px;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 6px;
  outline: none;
  font-size: 12px;
  font-weight: 600;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
}

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

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

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text2);
}

.btn-ghost:hover {
  background: var(--surface2);
  border-color: var(--border-hover);
  color: var(--text);
}

.btn-sm {
  min-height: 24px;
  padding: 3px 9px;
  font-size: 11px;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.status-text {
  min-height: 18px;
  color: var(--text2);
  font-size: 12px;
}

.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 1.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
}

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

.latest-code-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-color: rgba(88, 166, 255, 0.35);
}

.latest-code-layout {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.latest-code-main {
  min-width: 0;
}

.latest-code-value {
  color: var(--green);
  font-family: "SF Mono", Consolas, "Cascadia Code", monospace;
  font-size: 28px;
  font-weight: 750;
  line-height: 1;
}

.latest-code-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 8px;
  color: var(--text2);
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface2);
  color: var(--text2);
  font-size: 11px;
  font-weight: 600;
}

.badge-code {
  border-color: rgba(63, 185, 80, 0.45);
  color: var(--green);
}

.badge-muted:empty {
  display: none;
}

.mail-list {
  min-height: 220px;
  max-height: calc(100vh - 340px);
  overflow-y: auto;
}

.mail-list::-webkit-scrollbar,
.log-box::-webkit-scrollbar,
.mail-body-text::-webkit-scrollbar {
  width: 4px;
}

.mail-list::-webkit-scrollbar-thumb,
.log-box::-webkit-scrollbar-thumb,
.mail-body-text::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.mail {
  position: relative;
  margin-bottom: 5px;
  padding: 12px 14px;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 6px;
  transition: background-color 0.12s, border-color 0.12s;
}

.mail:hover,
.mail.expanded {
  background: var(--surface2);
  border-color: var(--border);
}

.mail-unread {
  padding-left: 20px;
}

.mail-unread::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 21px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
}

.mail-row1,
.mail-row2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.mail-row2 {
  margin-top: 4px;
}

.mail-from,
.mail-subject {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-from {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.mail-time {
  flex-shrink: 0;
  color: var(--text3);
  font-size: 11px;
}

.mail-subject {
  margin-top: 4px;
  color: var(--text2);
  font-size: 12.5px;
}

.mail-unread .mail-subject {
  color: var(--text);
}

.mail-preview {
  margin-top: 3px;
  overflow: hidden;
  color: var(--text3);
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  font-size: 11.5px;
  line-height: 1.4;
}

.mail-actions {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 6px;
}

.mail-body {
  display: none;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.mail.expanded .mail-body {
  display: block;
}

.mail.expanded .mail-preview {
  display: none;
}

.mail-body-frame {
  width: 100%;
  min-height: 180px;
  max-height: 520px;
  border: none;
  border-radius: 6px;
  background: #fff;
}

.mail-body-text {
  max-height: 520px;
  overflow-y: auto;
  padding: 14px;
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.log-box {
  min-height: 84px;
  max-height: 120px;
  overflow-y: auto;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text3);
  font-family: "SF Mono", Consolas, monospace;
  font-size: 10.5px;
  line-height: 1.6;
}

.log-error { color: var(--red); }
.log-success { color: var(--green); }
.log-info { color: var(--accent); }

.empty {
  padding: 48px 20px;
  color: var(--text3);
  font-size: 13px;
  text-align: center;
}

@media (max-width: 620px) {
  .app {
    padding: 16px 10px;
  }

  .card {
    padding: 14px;
  }

  .toolbar {
    align-items: stretch;
  }

  .toolbar .btn-primary {
    width: 100%;
  }

  .mail-row1,
  .mail-row2 {
    align-items: flex-start;
  }

  .mail-row2,
  .latest-code-layout {
    flex-direction: column;
  }

  .mail-actions,
  .latest-code-layout .btn {
    width: 100%;
  }

  .mail-actions .btn,
  .latest-code-layout .btn {
    flex: 1;
  }
}
