@font-face {
  font-family: "Inter";
  src: url("/static/fonts/inter-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #0b0d10;
  --sidebar: #101318;
  --surface: #151920;
  --surface-2: #1a1f27;
  --border: #252b34;
  --border-strong: #333b47;
  --text: #f1f3f5;
  --text-dim: #929aa6;
  --text-faint: #6d7583;
  --accent: #7c8cf8;
  --accent-hover: #93a1fa;
  --accent-soft: rgba(124, 140, 248, 0.12);
  --danger: #f0736a;
  --danger-soft: rgba(240, 115, 106, 0.1);
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-md: 15px;
  --fs-lg: 17px;
  --fs-xl: 21px;
  --tap: 44px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: var(--fs-md);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

h1,
h2,
p {
  margin: 0;
}

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

a:hover {
  text-decoration: underline;
}

svg {
  display: block;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.mono,
.addr,
.box-addr {
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.muted {
  color: var(--text-faint);
}

/* ---------- brand ---------- */

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-weight: 600;
  font-size: var(--fs-md);
  letter-spacing: -0.01em;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  width: 20px;
  height: 20px;
  color: var(--accent);
}

.brand-sm {
  font-size: var(--fs-sm);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

.btn svg {
  width: 15px;
  height: 15px;
}

.btn-primary {
  background: var(--accent);
  color: #0a0c10;
  font-weight: 600;
}

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

.btn-subtle {
  background: var(--surface-2);
  border-color: var(--border);
}

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

.btn-ghost {
  color: var(--text-dim);
}

.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  height: 32px;
  padding: 0 10px;
  font-size: var(--fs-sm);
}

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

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.icon-btn svg {
  width: 16px;
  height: 16px;
}

/* ---------- auth ---------- */

.auth {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.auth-head {
  padding: 20px 20px 0;
}

.auth-main {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px 20px calc(32px + env(safe-area-inset-bottom));
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
}

.auth-panel {
  width: 100%;
  max-width: 384px;
  padding: 26px 24px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.auth-panel h1 {
  font-size: var(--fs-xl);
  font-weight: 600;
  letter-spacing: -0.015em;
}

.lede {
  margin-top: 6px;
  color: var(--text-dim);
  font-size: var(--fs-sm);
  line-height: 1.55;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.label {
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--text-dim);
}

.field input {
  height: 42px;
  padding: 0 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-md);
  transition: border-color 0.15s ease;
}

.field input:hover {
  border-color: var(--border-strong);
}

.field input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.hint {
  font-size: var(--fs-xs);
  color: var(--text-faint);
}

.alert {
  margin-top: 18px;
  padding: 10px 12px;
  background: var(--danger-soft);
  border: 1px solid rgba(240, 115, 106, 0.28);
  border-radius: var(--radius);
  color: #f7a9a3;
  font-size: var(--fs-sm);
}

.auth-switch {
  color: var(--text-dim);
  font-size: var(--fs-sm);
}

.auth-note {
  color: var(--text-faint);
  font-size: var(--fs-xs);
  text-align: center;
}

/* ---------- app shell ---------- */

.app {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  min-height: 100dvh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100dvh;
  padding: 14px 12px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
}

.sidebar-head {
  padding: 4px 8px 2px;
}

.sidebar-new {
  width: 100%;
}

.box-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  margin: 0 -2px;
  padding: 0 2px;
}

.box-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 36px;
  padding: 7px 10px;
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: var(--fs-sm);
}

.box-item:hover {
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}

.box-item.is-active {
  background: var(--surface-2);
  color: var(--text);
}

.box-addr {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.box-count {
  flex: none;
  font-size: var(--fs-xs);
  color: var(--text-faint);
}

.sidebar-foot {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: auto;
  padding: 6px 8px 4px;
}

.quota {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.quota-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: var(--fs-xs);
  color: var(--text-dim);
}

.quota-bar {
  height: 4px;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: 999px;
}

.quota-bar span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
}

.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.account-name {
  overflow: hidden;
  font-size: var(--fs-sm);
  color: var(--text-dim);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  min-height: 56px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
}

.addr-block {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.addr {
  overflow: hidden;
  font-size: var(--fs-md);
  font-weight: 500;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 56px 24px;
  text-align: center;
}

.empty-icon {
  width: 38px;
  height: 38px;
  margin-bottom: 4px;
  color: var(--text-faint);
}

.empty h2 {
  font-size: var(--fs-lg);
  font-weight: 600;
}

.empty p {
  max-width: 34ch;
  color: var(--text-dim);
  font-size: var(--fs-sm);
  line-height: 1.6;
}

/* ---------- mobile ---------- */

.bottom-nav {
  display: none;
}

.bottom-form {
  margin: 0;
}

.toast {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: 50%;
  z-index: 40;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--fs-sm);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

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

@media (max-width: 820px) {
  .app {
    display: block;
  }

  .sidebar {
    display: none;
  }

  .main {
    min-height: 100dvh;
    padding-bottom: calc(58px + env(safe-area-inset-bottom));
  }

  .topbar {
    min-height: 52px;
    padding: 0 max(14px, env(safe-area-inset-left)) 0 max(14px, env(safe-area-inset-right));
  }

  .empty {
    padding: 40px 22px;
  }

  .bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 30;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(16, 19, 24, 0.94);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(12px);
  }

  .bottom-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    width: 100%;
    min-height: var(--tap);
    padding: 7px 0;
    border: 0;
    background: none;
    color: var(--text-faint);
    font: inherit;
    font-size: 11px;
    cursor: pointer;
  }

  .bottom-item svg {
    width: 18px;
    height: 18px;
  }

  .bottom-item.is-active {
    color: var(--accent);
  }

  .toast {
    bottom: calc(70px + env(safe-area-inset-bottom));
  }
}

/* ---------- message list ---------- */

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
}

.topbar-title {
  margin-left: 4px;
  color: var(--text-dim);
  font-size: var(--fs-sm);
}

.msg-list {
  width: 100%;
  max-width: 900px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.msg-list > li + li {
  border-top: 1px solid var(--border);
}

.msg-row {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  color: var(--text);
  min-height: 64px;
}

.msg-row:hover {
  background: var(--surface);
  text-decoration: none;
}

.msg-row.is-unread {
  background: rgba(124, 140, 248, 0.045);
}

.msg-dot {
  flex: none;
  width: 6px;
  height: 6px;
  margin-top: 8px;
  border-radius: 50%;
  background: transparent;
}

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

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

.msg-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.msg-from {
  overflow: hidden;
  font-size: var(--fs-sm);
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-time {
  flex: none;
  color: var(--text-faint);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}

.msg-subject {
  overflow: hidden;
  color: var(--text-dim);
  font-size: var(--fs-sm);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-row.is-unread .msg-subject {
  color: var(--text);
  font-weight: 600;
}

.msg-snippet {
  overflow: hidden;
  color: var(--text-faint);
  font-size: var(--fs-sm);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- message view ---------- */

.message {
  width: 100%;
  max-width: 900px;
  padding: 22px 16px 48px;
}

.msg-title {
  font-size: var(--fs-xl);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.msg-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin-top: 14px;
}

.msg-sender {
  font-size: var(--fs-sm);
  font-weight: 600;
}

.msg-meta .msg-addr {
  color: var(--text-dim);
  font-size: var(--fs-sm);
  overflow-wrap: anywhere;
}

.msg-submeta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  color: var(--text-faint);
  font-size: var(--fs-xs);
}

.dot-sep {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--border-strong);
}

.expiry {
  color: var(--text-dim);
}

.msg-frame {
  display: block;
  width: 100%;
  height: min(70vh, 720px);
  margin-top: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #ffffff;
}

.msg-plain {
  margin: 20px 0 0;
  padding: 16px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: var(--fs-sm);
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.attachments {
  margin-top: 20px;
}

.attachments-title {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.attachment-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.attachment {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: var(--fs-sm);
}

.attachment:hover {
  background: var(--surface-2);
  text-decoration: none;
}

.attachment svg {
  width: 16px;
  height: 16px;
  flex: none;
  color: var(--text-faint);
}

.attachment-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-size {
  flex: none;
  color: var(--text-faint);
  font-size: var(--fs-xs);
}

/* ---------- quota fill ---------- */

.quota-fill.q0 { width: 0; }
.quota-fill.q5 { width: 5%; }
.quota-fill.q10 { width: 10%; }
.quota-fill.q15 { width: 15%; }
.quota-fill.q20 { width: 20%; }
.quota-fill.q25 { width: 25%; }
.quota-fill.q30 { width: 30%; }
.quota-fill.q35 { width: 35%; }
.quota-fill.q40 { width: 40%; }
.quota-fill.q45 { width: 45%; }
.quota-fill.q50 { width: 50%; }
.quota-fill.q55 { width: 55%; }
.quota-fill.q60 { width: 60%; }
.quota-fill.q65 { width: 65%; }
.quota-fill.q70 { width: 70%; }
.quota-fill.q75 { width: 75%; }
.quota-fill.q80 { width: 80%; }
.quota-fill.q85 { width: 85%; }
.quota-fill.q90 { width: 90%; }
.quota-fill.q95 { width: 95%; }
.quota-fill.q100 { width: 100%; }

.box-count.has-unread {
  color: var(--text);
  font-weight: 600;
}

@media (max-width: 820px) {
  .msg-row {
    padding: 12px 14px;
  }

  .message {
    padding: 18px max(16px, env(safe-area-inset-left)) 40px max(16px, env(safe-area-inset-right));
  }

  .msg-title {
    font-size: 19px;
  }

  .msg-frame {
    height: 62vh;
  }
}

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