:root {
  --bg: #0f1419;
  --panel: #171d25;
  --line: #2a3441;
  --text: #e8eef6;
  --muted: #8b9bb0;
  --accent: #3d9bfd;
  --danger: #ff6b6b;
  --unread: #1a2838;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 10% -10%, #1b2a3d 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #152033 0%, transparent 50%),
    var(--bg);
  color: var(--text);
}

.brand {
  margin: 0;
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
}

.muted { color: var(--muted); margin: 0.25rem 0 0; }
.error { color: var(--danger); }

.auth-page {
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 1.5rem;
}
.auth-card {
  width: min(400px, 100%);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 2rem;
  backdrop-filter: blur(8px);
}
.auth-card h1 {
  margin: 0.35rem 0 0.15rem;
  font-size: 2rem;
  font-weight: 650;
}
.auth-card form {
  display: grid;
  gap: 0.9rem;
  margin-top: 1.4rem;
}
.auth-card label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
}
.auth-card input,
.top-actions input,
.top-actions select {
  width: 100%;
  border: 1px solid var(--line);
  background: #0c1117;
  color: var(--text);
  border-radius: 10px;
  padding: 0.75rem 0.85rem;
  font-size: 16px;
}
.auth-card button,
.ghost {
  border: 1px solid var(--line);
  background: var(--accent);
  color: #041018;
  font-weight: 650;
  border-radius: 10px;
  padding: 0.75rem 1rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ghost {
  background: transparent;
  color: var(--text);
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 80%, transparent);
  position: sticky;
  top: 0;
  z-index: 5;
}
.top-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}
.top-actions input { width: min(220px, 40vw); }
.top-actions select { width: auto; }

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 420px) 1fr;
  min-height: calc(100vh - 74px);
}
.list-pane {
  border-right: 1px solid var(--line);
  overflow: auto;
  max-height: calc(100vh - 74px);
}
#msgList { list-style: none; margin: 0; padding: 0; }
.msg-item {
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.msg-item:hover { background: #121820; }
.msg-item.active { background: #1a2430; outline: 1px solid #2f4d6e; }
.msg-item.unread { background: var(--unread); }
.msg-item .row1 {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: baseline;
}
.msg-item .subj { margin-top: 0.2rem; font-weight: 600; }
.msg-item .prev, .msg-item .meta {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 0.2rem;
}
.box-tag {
  font-size: 0.72rem;
  color: var(--accent);
  border: 1px solid #2f4d6e;
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
  text-transform: lowercase;
}
.empty { color: var(--muted); padding: 2rem 1rem; text-align: center; }
.hidden { display: none; }

.detail-pane {
  overflow: auto;
  max-height: calc(100vh - 74px);
  padding: 1.25rem 1.5rem 2rem;
}
.detail-head h1 {
  margin: 0 0 0.75rem;
  font-size: 1.45rem;
  line-height: 1.25;
}
.detail-head p { margin: 0.25rem 0; color: var(--muted); }
.detail-head .label {
  display: inline-block;
  min-width: 4.5rem;
  color: #6f8299;
}
.detail-body { margin-top: 1.25rem; }
.mail-text {
  white-space: pre-wrap;
  word-break: break-word;
  background: #0c1117;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  font-family: var(--mono);
  font-size: 0.9rem;
}
.mail-frame {
  width: 100%;
  min-height: 60vh;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .list-pane { max-height: 42vh; }
  .detail-pane { max-height: none; }
  .top { flex-direction: column; align-items: stretch; }
  .top-actions input { width: 100%; }
}
