:root {
  --bg: #0d0f14;
  --bg-2: #141821;
  --bg-3: #1a1f2b;
  --bg-4: #222836;
  --line: #262d3b;
  --text: #e8ebf2;
  --muted: #8b95ab;
  --accent: #5b9cff;
  --accent-2: #7fb4ff;
  --accent-dim: #1d3559;
  --good: #38d39f;
  --warn: #ffb454;
  --bad: #ff6b6b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
code { background: var(--bg-4); padding: 1px 6px; border-radius: 4px; font-size: 12px; }

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--text);
  padding: 8px 13px;
  border-radius: 8px;
  transition: background .12s, border-color .12s;
}
button:hover:not(:disabled) { border-color: #3b4a63; background: var(--bg-4); }
button:disabled { opacity: .45; cursor: default; }
button.ghost { background: transparent; }
button.mini { padding: 5px 10px; font-size: 12px; }
button.icon { padding: 6px 10px; font-size: 15px; line-height: 1; }
button.primary { background: var(--accent); border-color: var(--accent); color: #06121f; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent-2); border-color: var(--accent-2); }
button.danger:hover:not(:disabled) { border-color: var(--bad); color: var(--bad); }

input, select {
  font: inherit;
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 8px;
  min-width: 0;
  width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
input::placeholder { color: #5d6779; }

/* ---------------------------------------------------------------- login --- */

.login { position: fixed; inset: 0; display: grid; place-items: center;
         background: radial-gradient(circle at 50% 25%, #18203180, #0d0f14 65%); z-index: 50; }
.login-card { width: min(360px, 92vw); background: var(--bg-2); border: 1px solid var(--line);
              border-radius: 16px; padding: 32px 28px; text-align: center; display: grid; gap: 12px; }
.login-logo { font-size: 42px; }
.login-card h1 { margin: 0; font-size: 20px; }
.login-card p { margin: 0; font-size: 13px; }
.login-card button { background: var(--accent); border-color: var(--accent); color: #06121f; font-weight: 600; }
.login-error { color: var(--bad); font-size: 13px; min-height: 18px; }

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

.app { display: flex; flex-direction: column; height: 100%; }

.topbar { display: flex; align-items: center; gap: 14px; padding: 10px 16px;
          border-bottom: 1px solid var(--line); background: var(--bg-2); flex: none; }
.brand { font-weight: 600; white-space: nowrap; }
.topbar #search { flex: 1; max-width: 420px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.stat { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* ------------------------------------------------------------------ hero --- */

.hero { flex: none; padding: 16px 18px; border-bottom: 1px solid var(--line);
        background: linear-gradient(180deg, #171d29, var(--bg-2)); }
.hero-inner { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.hero-main { flex: 1; min-width: 260px; }
.hero-cap { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.hero-addr { display: flex; align-items: center; gap: 12px; margin-top: 4px; flex-wrap: wrap; }
.hero-addr .addr {
  font-size: 24px; font-weight: 700; letter-spacing: -.01em; word-break: break-all;
  color: #fff; cursor: pointer;
}
.hero-addr .addr:hover { color: var(--accent-2); }
.hero-purpose { margin-top: 7px; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hero-purpose .tag {
  background: var(--accent-dim); border: 1px solid #2f4d7d; color: var(--accent-2);
  padding: 2px 10px; border-radius: 20px; font-size: 12px;
}
.hero-purpose .tag.none { background: #33240f; border-color: #6b4a15; color: var(--warn); }
.hero-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.hero-actions button { white-space: nowrap; }
.copy-btn { min-width: 108px; }
.copy-btn.done { background: var(--good); border-color: var(--good); color: #04281c; }

.panes { flex: 1; display: grid; grid-template-columns: 270px 350px 1fr; min-height: 0; }
.pane { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.pane-read { border-right: none; }

.pane-head { display: flex; align-items: center; justify-content: space-between; gap: 8px;
             padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 12px;
             text-transform: uppercase; letter-spacing: .06em; color: var(--muted); flex: none; }
.pane-foot { border-top: 1px solid var(--line); padding: 8px; flex: none; }
.pane-foot button { width: 100%; }
.auto { display: flex; align-items: center; gap: 6px; text-transform: none; letter-spacing: 0; cursor: pointer; }
.auto input { width: auto; }

/* ------------------------------------------------------------ mailboxes --- */

.boxlist { overflow-y: auto; flex: 1; }
.box { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer;
       display: grid; grid-template-columns: 1fr auto; gap: 3px 8px; align-items: center; }
.box:hover { background: var(--bg-2); }
.box.active { background: var(--accent-dim); border-left: 3px solid var(--accent); padding-left: 9px; }
.box-purpose { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.box-purpose.none { color: var(--warn); font-weight: 500; font-style: italic; }
.box-addr { grid-column: 1 / -1; font-size: 12px; color: var(--muted); word-break: break-all; }
.box-meta { grid-column: 1 / -1; font-size: 11px; color: #6b7488; }
.badge { background: var(--accent); color: #06121f; font-size: 11px; font-weight: 700;
         border-radius: 20px; padding: 1px 7px; }

/* -------------------------------------------------------------- msglist --- */

.msglist { overflow-y: auto; flex: 1; }
.msg { padding: 11px 12px; border-bottom: 1px solid var(--line); cursor: pointer;
       display: grid; grid-template-columns: 34px 1fr; gap: 2px 10px; }
.msg:hover { background: var(--bg-2); }
.msg.active { background: var(--accent-dim); }
.msg.unread .msg-subject { font-weight: 700; color: #fff; }
.avatar { grid-row: 1 / 4; width: 34px; height: 34px; border-radius: 50%; display: grid;
          place-items: center; font-weight: 700; font-size: 14px; color: #06121f; align-self: start; }
.msg-top { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.msg-from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; color: var(--text); }
.msg-time { flex: none; }
.msg-subject { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-preview { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-to { font-size: 11px; color: var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-flags { display: flex; align-items: center; gap: 6px; margin-top: 3px; flex-wrap: wrap; }
.otp-chip { background: #2a1f0b; border: 1px solid var(--warn); color: var(--warn); font-weight: 700;
            letter-spacing: .12em; border-radius: 6px; padding: 1px 8px; font-size: 12px; }
.clip { font-size: 11px; color: var(--muted); }

/* ------------------------------------------------------- waiting / empty --- */

.waiting { padding: 40px 22px; text-align: center; color: var(--muted); }
.waiting .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent);
                margin: 0 auto 14px; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { transform: scale(1);   box-shadow: 0 0 0 0 rgba(91,156,255,.55); }
  50%      { transform: scale(1.1); box-shadow: 0 0 0 12px rgba(91,156,255,0); }
}
.waiting h3 { margin: 0 0 6px; font-size: 15px; color: var(--text); font-weight: 600; }
.waiting p { margin: 4px 0; font-size: 13px; }
.waiting .addr-inline { color: var(--accent-2); word-break: break-all; }

.empty { display: grid; place-items: center; height: 100%; text-align: center; color: var(--muted); padding: 24px; }
.empty-icon { font-size: 44px; margin-bottom: 8px; }

/* --------------------------------------------------------------- reader --- */

.pane-read { overflow: hidden; }
#reader { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.reader-empty { display: block; }

.rd-head { padding: 15px 18px; border-bottom: 1px solid var(--line); flex: none; }
.rd-subject { font-size: 17px; font-weight: 600; margin: 0 0 8px; }
.rd-line { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; }
.rd-line b { color: var(--text); font-weight: 500; }
.rd-otp { margin: 14px 0 4px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.rd-otp .code { font-size: 26px; font-weight: 700; letter-spacing: .2em; color: var(--warn);
                background: #2a1f0b; border: 1px solid var(--warn); border-radius: 8px; padding: 4px 16px; }
.rd-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 13px; }

.rd-att { padding: 10px 18px; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px; flex: none; }
.att { background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px;
       font-size: 12px; text-decoration: none; color: var(--text); }
.att:hover { border-color: var(--accent); }

.rd-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.rd-body iframe { flex: 1; width: 100%; border: 0; background: #fff; }
.rd-body pre { flex: 1; margin: 0; padding: 18px; overflow: auto; white-space: pre-wrap;
               word-break: break-word; font: 13px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; }

.tabs { display: flex; gap: 6px; padding: 8px 18px; border-bottom: 1px solid var(--line); flex: none; align-items: center; }
.tab { font-size: 12px; padding: 5px 11px; }
.tab.active { background: var(--accent-dim); border-color: var(--accent); }

/* ---------------------------------------------------------------- modal --- */

.modal { position: fixed; inset: 0; background: #05070bcc; display: grid; place-items: center; z-index: 55; padding: 20px; }
.modal-card { width: min(480px, 100%); background: var(--bg-2); border: 1px solid var(--line);
              border-radius: 14px; padding: 24px; display: grid; gap: 16px; }
.modal-card h2 { margin: 0; font-size: 18px; }
.field { display: grid; gap: 6px; }
.field-label { font-size: 13px; font-weight: 600; }
.field-hint { font-size: 12px; color: var(--muted); }
.req { color: var(--bad); }
.addr-row { display: grid; grid-template-columns: 1fr 150px; gap: 8px; }
.modal-error { color: var(--bad); font-size: 13px; min-height: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------------------------------------------------------------- toast --- */

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
         background: var(--bg-4); border: 1px solid var(--accent); color: var(--text);
         padding: 10px 18px; border-radius: 24px; opacity: 0; pointer-events: none;
         transition: opacity .2s, transform .2s; z-index: 60; font-size: 13px; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.loading { padding: 24px; text-align: center; color: var(--muted); font-size: 13px; }

@media (max-width: 1040px) {
  .panes { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; }
  .pane { border-right: none; border-bottom: 1px solid var(--line); }
  .pane-boxes { max-height: 30vh; }
  .pane-list { max-height: 38vh; }
  .hero-addr .addr { font-size: 19px; }
  .topbar #search { max-width: none; }
}
