:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-soft: #fafbfc;
  --ink: #171a20;
  --muted: #6b7280;
  --line: #e4e7ec;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-soft: #eff4ff;
  --danger: #b42318;
  --ok: #067647;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 8px 24px rgb(16 24 40 / 4%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #161a21;
    --panel-soft: #1b2028;
    --ink: #e8ebf0;
    --muted: #98a2b3;
    --line: #262c36;
    --accent: #5b8cff;
    --accent-ink: #0b1020;
    --accent-soft: #1b2740;
    --danger: #ff7b72;
    --ok: #3ccb7f;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

a {
  color: var(--accent);
  text-decoration: none;
}

code {
  font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
}

/* ------------------------------- top bar -------------------------------- */

.topbar {
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  font-weight: 650;
  letter-spacing: -0.01em;
  font-size: 15px;
}

.brand-mark {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: var(--accent);
  position: relative;
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 6px 4px;
  border: 1.6px solid var(--accent-ink);
  border-radius: 2px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.domain {
  color: var(--muted);
  font-size: 12.5px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
}

/* -------------------------------- layout -------------------------------- */

.layout {
  display: flex;
  height: calc(100vh - 54px);
  min-height: 0;
}

.sidebar {
  width: 285px;
  flex: 0 0 285px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 10px;
}

.sidebar-head h2 {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.inbox-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.inbox-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--ink);
  border: 1px solid transparent;
}

.inbox-item:hover {
  background: var(--panel-soft);
}

.inbox-item.active {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 25%, transparent);
}

.inbox-address {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inbox-meta {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: none;
}

.badge {
  min-width: 19px;
  height: 19px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

.tag {
  font-size: 10.5px;
  letter-spacing: 0.02em;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 6px;
}

.sidebar-foot {
  border-top: 1px solid var(--line);
  padding: 12px 14px;
  font-size: 12.5px;
  color: var(--muted);
}

.sidebar-foot p {
  margin: 0 0 8px;
}

.empty {
  color: var(--muted);
  font-size: 13px;
  padding: 14px 10px;
  margin: 0;
}

/* --------------------------------- pane --------------------------------- */

.pane {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
}

.pane-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 28px 64px;
}

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

.inbox-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.inbox-title h1,
.pane h1 {
  margin: 0 0 4px;
  font-size: 20px;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}

.pane h1 {
  font-size: 22px;
}

.muted {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
}

.head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ------------------------------- buttons -------------------------------- */

button,
.button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 550;
  line-height: 1.2;
  transition:
    background 0.12s ease,
    border-color 0.12s ease;
}

button:hover:not(:disabled) {
  background: var(--panel-soft);
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

button.primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent) 88%, black);
}

button.ghost {
  background: transparent;
}

button.danger {
  color: var(--danger);
}

button.small {
  padding: 5px 10px;
  font-size: 12.5px;
}

/* ------------------------------- messages ------------------------------- */

.messages {
  display: flex;
  flex-direction: column;
}

.message-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 13px 10px;
}

.message-row:hover {
  background: var(--panel-soft);
}

.message-row .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-top: 7px;
  flex: none;
  background: transparent;
}

.message-row.unread .dot {
  background: var(--accent);
}

.msg-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.msg-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.msg-from {
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-date {
  color: var(--muted);
  font-size: 12px;
  flex: none;
}

.msg-subject {
  font-size: 13.5px;
}

.message-row.unread .msg-subject {
  font-weight: 650;
}

.msg-snippet {
  color: var(--muted);
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.direction-tag {
  font-size: 10.5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 6px;
  color: var(--muted);
  margin-left: 6px;
  vertical-align: 1px;
}

.notice {
  margin: 12px 0;
  padding: 9px 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--ok) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--ok) 30%, transparent);
  color: var(--ok);
  font-size: 13px;
}

/* --------------------------------- detail -------------------------------- */

.message-meta {
  margin: 14px 0 18px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  gap: 6px;
}

.message-meta div {
  display: grid;
  grid-template-columns: 62px 1fr;
  gap: 10px;
}

.message-meta dt {
  color: var(--muted);
  font-size: 12.5px;
}

.message-meta dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.tab {
  padding: 4px 10px;
  font-size: 12.5px;
  border-radius: 999px;
}

.tab.active {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
  color: var(--accent);
}

.html-frame {
  width: 100%;
  height: 62vh;
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.text-body {
  margin: 0;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 13px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.attachments {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attachment {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 8px 11px;
  font-size: 12.5px;
}

.attachment small {
  color: var(--muted);
}

.raw-headers {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  color: var(--muted);
  font-size: 12.5px;
}

.raw-headers summary {
  cursor: pointer;
  user-select: none;
}

.raw-headers pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 12px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

/* -------------------------------- compose -------------------------------- */

.compose-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.compose-form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12.5px;
  color: var(--muted);
}

.compose-form input,
.compose-form textarea,
dialog input {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--ink);
  font-size: 13.5px;
}

.compose-form textarea {
  resize: vertical;
  min-height: 200px;
  font: 13.5px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.compose-form input:focus,
.compose-form textarea:focus,
dialog input:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.compose-from {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.compose-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.status {
  font-size: 12.5px;
  color: var(--muted);
  flex: 1;
}

.status.error {
  color: var(--danger);
}

/* -------------------------------- welcome -------------------------------- */

.welcome {
  max-width: 620px;
  margin: 8vh auto 0;
  padding: 0 28px;
}

.welcome h1 {
  font-size: 26px;
  margin: 0 0 8px;
}

.welcome p {
  color: var(--muted);
  margin: 0 0 18px;
}

.welcome ol {
  margin: 0 0 22px;
  padding-left: 20px;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 7px;
}

/* --------------------------------- dialogs ------------------------------- */

dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--ink);
  padding: 22px;
  width: min(420px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgb(10 14 20 / 45%);
}

dialog h3 {
  margin: 0 0 14px;
  font-size: 16px;
}

dialog label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 12px;
}

dialog label.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 13px;
}

dialog label.checkbox input {
  width: auto;
}

.hint {
  color: var(--muted);
  font-size: 12.5px;
  margin: 0 0 12px;
}

.error {
  color: var(--danger);
  font-size: 12.5px;
  margin: 0 0 12px;
}

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

/* -------------------------------- narrow -------------------------------- */

@media (max-width: 760px) {
  .layout {
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - 54px);
  }

  .sidebar {
    width: 100%;
    flex: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: 40vh;
  }

  .pane-inner {
    padding: 18px 16px 48px;
  }

  .inbox-head {
    flex-direction: column;
  }
}
