:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --line: #e2e8ef;
  --line-strong: #cfd8e3;
  --text: #15202b;
  --muted: #617485;
  --accent: #0e7c6b;
  --accent-hover: #0b6658;
  --on-accent: #ffffff;
  --soft: #e3f5f1;
  --warn: #0e7c6b;
  --warn-bg: #e3f5f1;
  --warn-line: #b7e4d8;
  --danger: #b42318;
  --ok: #0e7c6b;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sans: "Sora", "Segoe UI", sans-serif;
  --radius: 8px;
  --page: 1120px;
}

[data-theme="dark"] {
  --bg: #0c1116;
  --surface: #12181f;
  --surface-2: #171e26;
  --line: #243041;
  --line-strong: #354658;
  --text: #e8eef4;
  --muted: #8b9aab;
  --accent: #3dceb3;
  --accent-hover: #5ad9c2;
  --on-accent: #06241f;
  --soft: rgba(61, 206, 179, 0.12);
  --warn: #3dceb3;
  --warn-bg: rgba(61, 206, 179, 0.1);
  --warn-line: rgba(61, 206, 179, 0.28);
  --danger: #f07167;
  --ok: #3dceb3;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--sans);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* —— header —— */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  max-width: var(--page);
  margin: 0 auto;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: inherit;
}

.mark {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: var(--accent);
  color: var(--on-accent);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.mark svg {
  width: 18px;
  height: 18px;
  display: block;
}

.brand-name {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.brand-sub {
  margin: 0.1rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.nav-links a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.875rem;
  padding: 0.4rem 0.7rem;
  border-radius: 6px;
}

.nav-links a:hover {
  color: var(--text);
  background: var(--soft);
}

.nav-links a[aria-current="page"] {
  color: var(--accent);
  background: var(--soft);
}

.attrib {
  color: var(--muted);
  font-size: 0.78rem;
  font-family: var(--mono);
  padding: 0.3rem 0.55rem;
  border-radius: 6px;
  border: 1px solid var(--line);
}

.theme-toggle {
  appearance: none;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.theme-toggle:hover {
  background: var(--soft);
  border-color: var(--line-strong);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.theme-toggle svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-toggle .icon-sun,
[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

/* —— app shell —— */
.app,
.shell {
  width: 100%;
  max-width: var(--page);
  margin: 0 auto;
  padding: 1rem 1.25rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  flex: 1;
  min-height: 0;
}

/* —— toolbar (no card) —— */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--line);
}

.toolbar-main {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.address-block {
  flex: 1;
  min-width: min(100%, 280px);
}

.label {
  margin: 0 0 0.3rem;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
}

.address {
  margin: 0;
  font-family: var(--mono);
  font-size: clamp(0.95rem, 2.4vw, 1.2rem);
  font-weight: 500;
  letter-spacing: -0.01em;
  word-break: break-all;
  line-height: 1.35;
}

.address[data-empty="true"] {
  color: var(--muted);
  font-weight: 400;
  font-size: 1rem;
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.toolbar-sub {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem 1rem;
}

.history-inline {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex: 1;
  min-width: min(100%, 260px);
}

.history-inline .label {
  margin: 0;
  flex-shrink: 0;
}

.history-select {
  flex: 1;
  min-width: 0;
  max-width: 360px;
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.5rem 1.9rem 0.5rem 0.7rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text);
  background: var(--bg)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23737373' d='M1 1l5 5 5-5'/%3E%3C/svg%3E")
    right 0.65rem center / 12px no-repeat;
  cursor: pointer;
}

[data-theme="dark"] .history-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23a3a3a3' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
}

.history-select:focus {
  outline: 2px solid var(--text);
  outline-offset: 1px;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0.55rem 0.9rem;
  font-family: var(--sans);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.btn.primary {
  color: var(--on-accent);
  background: var(--accent);
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn.ghost {
  color: var(--text);
  background: var(--bg);
  border-color: var(--line);
}

.btn.ghost:hover:not(:disabled) {
  background: var(--soft);
  border-color: var(--line-strong);
}

.status {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  min-height: 1.2rem;
}

.status.error {
  color: var(--danger);
}

.status.ok {
  color: var(--ok);
}

.code-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  flex-wrap: wrap;
  padding: 0.7rem 0.9rem;
  border-radius: 6px;
  border: 1px solid var(--warn-line);
  background: var(--warn-bg);
}

.code-left {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.code-panel .label {
  margin: 0;
  color: var(--warn);
}

.code-value {
  margin: 0;
  font-family: var(--mono);
  font-size: 1.45rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  color: var(--warn);
}

/* —— workspace (one panel) —— */
.workspace,
.inbox,
.docs-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.workspace {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 480px;
  overflow: hidden;
}

.workspace-head,
.inbox-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
}

.workspace-head h2,
.inbox-head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.inbox-layout {
  display: grid;
  grid-template-columns: minmax(200px, 300px) 1fr;
  flex: 1;
  min-height: 0;
}

.message-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-right: 1px solid var(--line);
  overflow: auto;
  background: var(--surface);
  max-height: none;
  min-height: 360px;
}

.message-list:empty {
  display: none;
}

.message-item {
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: inherit;
  padding: 0.85rem 1rem;
  cursor: pointer;
  font-family: var(--sans);
}

.message-item:last-child {
  border-bottom: 0;
}

.message-item:hover,
.message-item:focus-visible,
.message-item.active {
  background: var(--soft);
  outline: none;
}

.message-item .subject {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.15rem;
}

.message-item .intro {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-view {
  padding: 1rem 1.15rem;
  background: var(--surface);
  overflow: auto;
  min-height: 360px;
  border: 0;
  border-radius: 0;
}

.msg-head {
  margin-bottom: 0.85rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--line);
}

.msg-head h3 {
  margin: 0 0 0.3rem;
  font-size: 1.05rem;
}

.msg-from,
.msg-date {
  margin: 0.1rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.msg-body {
  font-size: 0.9rem;
  word-break: break-word;
}

.msg-body pre {
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 0.82rem;
  margin: 0;
}

.msg-body a {
  color: var(--text);
  text-decoration: underline;
}

.empty {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  min-height: 360px;
  color: var(--muted);
  text-align: center;
  padding: 2rem;
  background: var(--surface);
}

.empty[hidden],
.message-view[hidden],
.code-panel[hidden] {
  display: none !important;
}

/* —— docs —— */
.docs-hero {
  padding: 1.35rem 1.35rem 1.2rem;
}

.docs-hero h1 {
  margin: 0 0 0.4rem;
  font-size: 1.4rem;
  letter-spacing: -0.03em;
}

.docs-hero p {
  margin: 0;
  color: var(--muted);
  max-width: 52ch;
}

.docs-hero code {
  font-family: var(--mono);
  font-size: 0.85em;
}

.docs-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 1rem;
}

.chip {
  display: inline-flex;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.75rem;
  font-family: var(--mono);
}

.docs-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.docs-toc a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.docs-toc a:hover {
  color: var(--text);
  background: var(--soft);
}

.endpoint {
  padding: 1.2rem 1.35rem 1.3rem;
  scroll-margin-top: 1rem;
}

.endpoint-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.7rem;
  margin-bottom: 0.6rem;
}

.method {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  color: var(--on-accent);
  background: var(--accent);
}

.method.get {
  background: #2563eb;
  color: #fff;
}

.method.post {
  background: #16a34a;
  color: #fff;
}

.method.delete {
  background: #dc2626;
  color: #fff;
}

.endpoint-path {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.9rem;
  word-break: break-all;
}

.endpoint h2 {
  margin: 0 0 0.4rem;
  font-size: 1rem;
}

.endpoint > p {
  margin: 0 0 0.8rem;
  color: var(--muted);
  font-size: 0.875rem;
}

.auth-note {
  margin: 0 0 0.8rem;
  padding: 0.6rem 0.75rem;
  border-radius: 6px;
  background: var(--soft);
  border: 1px solid var(--line);
  font-size: 0.84rem;
}

.auth-note code {
  font-family: var(--mono);
  font-size: 0.85em;
}

.param-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin: 0 0 0.85rem;
}

.param-table th,
.param-table td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.param-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.param-table code {
  font-family: var(--mono);
  font-size: 0.82rem;
}

.sample {
  margin: 0;
  padding: 0.85rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.docs-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 0.25rem 0 1rem;
}

.docs-footer code {
  font-family: var(--mono);
}

/* —— admin —— */
.admin-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
  margin-top: 1rem;
}

.admin-form .field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 220px;
}

.admin-form .field.grow {
  flex: 1;
}

.admin-form input[type="password"],
.admin-form input[type="text"] {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.65rem 0.8rem;
  font-family: var(--mono);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface-2);
}

.admin-form input:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 1px;
}

.admin-add .check {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.875rem;
  padding-bottom: 0.55rem;
}

.admin-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  flex-wrap: wrap;
}

.admin-head h2 {
  margin: 0 0 0.35rem;
}

.admin-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  max-width: 52ch;
}

.table-wrap {
  margin-top: 1rem;
  overflow: auto;
}

.row-actions {
  display: flex;
  gap: 0.4rem;
  justify-content: flex-end;
}

.row-actions .btn {
  padding: 0.4rem 0.7rem;
  font-size: 0.8rem;
}

.domain-pick {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.domain-pick[hidden] {
  display: none !important;
}

.domain-select {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.5rem 1.9rem 0.5rem 0.7rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text);
  background: var(--bg)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23617485' d='M1 1l5 5 5-5'/%3E%3C/svg%3E")
    right 0.65rem center / 12px no-repeat;
  cursor: pointer;
  min-width: 140px;
}

@media (max-width: 800px) {
  .inbox-layout {
    grid-template-columns: 1fr;
  }

  .message-list {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    min-height: 0;
    max-height: 220px;
  }

  .message-view,
  .empty {
    min-height: 280px;
  }

  .toolbar-main {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-actions {
    width: 100%;
  }

  .toolbar-actions .btn {
    flex: 1;
  }

  .top {
    flex-direction: column;
    align-items: flex-start;
    position: static;
  }

  .nav-links {
    width: 100%;
  }

  .history-inline {
    width: 100%;
  }

  .history-select {
    max-width: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}
