:root {
  color-scheme: dark;
  --bg: #08090d;
  --surface: #11131a;
  --surface-2: #171a22;
  --surface-3: #1d222b;
  --line: #2a3040;
  --line-strong: #3c465b;
  --text: #f4f6fb;
  --muted: #99a2b7;
  --soft: #707a92;
  --green: #29d391;
  --blue: #65a7ff;
  --amber: #f5b84b;
  --rose: #ff6b7a;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  background:
    linear-gradient(115deg, rgba(41, 211, 145, 0.08), transparent 28%),
    linear-gradient(245deg, rgba(101, 167, 255, 0.09), transparent 34%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
}

.shell {
  min-height: 100vh;
  padding: 28px;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
}

.auth-card {
  width: min(100%, 420px);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(17, 19, 26, 0.92);
  box-shadow: var(--shadow);
}

.auth-card h1 {
  font-size: clamp(28px, 5vw, 42px);
}

.auth-copy {
  margin: 14px 0 22px;
  color: var(--muted);
  line-height: 1.6;
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-error {
  margin: 14px 0 0;
  color: var(--rose);
  line-height: 1.5;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin: 0 auto 22px;
  max-width: 1500px;
}

.eyebrow {
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1 {
  margin: 4px 0 0;
  font-size: clamp(30px, 4vw, 54px);
  line-height: 1;
}

.server-state {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  padding: 8px 13px;
  white-space: nowrap;
}

.server-state.ok {
  color: var(--green);
  border-color: rgba(41, 211, 145, 0.36);
  background: rgba(41, 211, 145, 0.08);
}

.server-state.bad {
  color: var(--rose);
  border-color: rgba(255, 107, 122, 0.36);
  background: rgba(255, 107, 122, 0.08);
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: end;
  gap: 10px;
  flex-wrap: wrap;
}

.session-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 13px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
}

.logout-btn {
  min-height: 38px;
}

.workspace {
  display: grid;
  grid-template-columns: 340px minmax(360px, 1fr) minmax(360px, 520px);
  gap: 16px;
  align-items: start;
  max-width: 1500px;
  margin: 0 auto;
}

.compose-panel,
.inbox-panel,
.detail-panel {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(17, 19, 26, 0.88);
  box-shadow: var(--shadow);
}

.compose-panel {
  position: sticky;
  top: 20px;
  padding: 18px;
}

.inbox-panel,
.detail-panel {
  min-height: calc(100vh - 150px);
}

.section-head,
.inbox-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
}

.section-head span,
.muted {
  color: var(--soft);
  font-size: 12px;
}

.section-head strong,
.inbox-toolbar strong {
  display: block;
  margin-top: 2px;
  font-size: 17px;
  overflow-wrap: anywhere;
}

.type-list {
  display: grid;
  gap: 8px;
  margin: 18px 0;
}

.type-btn {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  width: 100%;
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface-2);
  text-align: left;
  cursor: pointer;
  max-width: 100%;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.type-btn:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
}

.type-btn.active {
  border-color: var(--accent);
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 13%, transparent), var(--surface-2) 56%);
}

.type-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 7px;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
  font-weight: 800;
}

.type-btn strong {
  display: block;
  margin-bottom: 2px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.type-btn span:last-child {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.create-form {
  display: grid;
  gap: 12px;
  padding-top: 4px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #0d0f15;
  color: var(--text);
  min-height: 42px;
  padding: 0 12px;
  outline: none;
  transition: border-color 0.16s ease, background 0.16s ease;
}

input:focus,
select:focus {
  border-color: var(--blue);
  background: #10131b;
}

.primary-btn,
.ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border-radius: 7px;
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease, opacity 0.16s ease;
}

.primary-btn {
  color: #08100d;
  background: var(--green);
  font-weight: 800;
}

.primary-btn:hover,
.ghost-btn:hover {
  transform: translateY(-1px);
}

.primary-btn:disabled,
.ghost-btn:disabled {
  opacity: 0.48;
  cursor: not-allowed;
  transform: none;
}

.ghost-btn {
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--surface-2);
  padding: 0 12px;
}

.mailbox-strip {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.mailbox-strip strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
  font-size: 15px;
}

.mailbox-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.toggle-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
}

.toggle-row em {
  color: var(--soft);
  font-style: normal;
  font-size: 12px;
}

.history-panel {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.history-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.history-empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 14px;
  text-align: center;
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.history-main {
  min-width: 0;
}

.history-main strong {
  display: block;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.history-meta {
  display: flex;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.history-actions {
  display: flex;
  gap: 6px;
}

.mini-btn {
  min-width: 56px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #10131b;
  color: var(--text);
  cursor: pointer;
}

.mini-btn:hover {
  border-color: var(--line-strong);
}

.inbox-panel {
  overflow: hidden;
}

.inbox-toolbar {
  min-height: 74px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

#lastRefresh {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.message-list {
  display: grid;
  align-content: start;
  max-height: calc(100vh - 224px);
  overflow: auto;
}

.message-item {
  display: grid;
  gap: 5px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.16s ease;
}

.message-item:hover,
.message-item.active {
  background: var(--surface-2);
}

.message-item strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.message-preview {
  color: var(--soft);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.45;
}

.empty-list {
  display: grid;
  place-items: center;
  min-height: 280px;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.detail-panel {
  overflow: hidden;
}

.detail-empty {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 150px);
  color: var(--muted);
  padding: 24px;
  text-align: center;
}

.message-detail {
  padding: 20px;
}

.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: 12px;
}

.detail-head span {
  overflow-wrap: anywhere;
}

.message-detail h2 {
  margin: 12px 0 8px;
  font-size: clamp(22px, 2.5vw, 34px);
  line-height: 1.1;
}

.detail-meta {
  color: var(--soft);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.html-frame,
.text-body {
  width: 100%;
  min-height: 380px;
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.text-body {
  max-height: 480px;
  overflow: auto;
  white-space: pre-wrap;
  color: var(--text);
  background: #0d0f15;
  padding: 14px;
}

.raw-details {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  color: var(--muted);
}

.raw-details pre {
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  color: var(--text);
  background: #0d0f15;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(17, 19, 26, 0.94);
  color: var(--text);
  padding: 10px 16px;
  box-shadow: var(--shadow);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.hidden {
  display: none !important;
}

.is-loading {
  cursor: progress;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 320px minmax(0, 1fr);
  }

  .detail-panel {
    grid-column: 1 / -1;
    min-height: 420px;
  }

  .detail-empty {
    min-height: 360px;
  }
}

@media (max-width: 780px) {
  .shell {
    padding: 18px;
    overflow: hidden;
  }

  .auth-shell {
    padding: 18px;
  }

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

  .topbar-actions {
    width: 100%;
    justify-content: start;
  }

  .workspace {
    grid-template-columns: 1fr;
    width: calc(100vw - 36px);
    max-width: calc(100vw - 36px);
  }

  .compose-panel {
    position: static;
  }

  .compose-panel,
  .inbox-panel,
  .detail-panel {
    width: calc(100vw - 36px);
    max-width: calc(100vw - 36px);
  }

  .section-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .inbox-panel,
  .detail-panel {
    min-height: auto;
  }

  .message-list {
    max-height: 520px;
  }
}

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