:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-solid: #ffffff;
  --text: #101828;
  --muted: #667085;
  --subtle: #98a2b3;
  --line: rgba(16, 24, 40, 0.10);
  --soft: rgba(255, 255, 255, 0.64);
  --black: #101828;
  --blue: #2563eb;
  --cyan: #06b6d4;
  --purple: #7c3aed;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #f59e0b;
  --shadow: 0 24px 80px rgba(15, 23, 42, 0.10);
  --shadow-soft: 0 14px 40px rgba(15, 23, 42, 0.07);
  --radius: 28px;
}

body.dark {
  color-scheme: dark;
  --bg: #0c1018;
  --panel: rgba(20, 25, 36, 0.78);
  --panel-solid: #151b27;
  --text: #f8fafc;
  --muted: #a7b0c0;
  --subtle: #798397;
  --line: rgba(255, 255, 255, 0.11);
  --soft: rgba(255, 255, 255, 0.06);
  --black: #f8fafc;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
  --shadow-soft: 0 14px 40px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 6%, rgba(37, 99, 235, 0.20), transparent 34vw),
    radial-gradient(circle at 88% 12%, rgba(124, 58, 237, 0.18), transparent 30vw),
    linear-gradient(135deg, #f8fbff 0%, var(--bg) 48%, #eef5ff 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}
body.dark {
  background:
    radial-gradient(circle at 14% 4%, rgba(37, 99, 235, 0.24), transparent 34vw),
    radial-gradient(circle at 85% 12%, rgba(124, 58, 237, 0.22), transparent 30vw),
    linear-gradient(135deg, #090d14 0%, var(--bg) 58%, #111827 100%);
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .58; }

.ambient { position: fixed; z-index: -1; border-radius: 999px; filter: blur(18px); opacity: .42; }
.ambient-a { width: 260px; height: 260px; left: -70px; top: 130px; background: #60a5fa; }
.ambient-b { width: 320px; height: 320px; right: -120px; bottom: 60px; background: #c084fc; }

.mail-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(260px, auto) minmax(220px, 1fr);
  align-items: center;
  gap: 18px;
  min-height: 82px;
  padding: 16px clamp(16px, 3vw, 34px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(22px);
}
body.dark .mail-topbar { background: rgba(12, 16, 24, 0.72); }
.brand { display: inline-flex; align-items: center; gap: 14px; color: inherit; text-decoration: none; min-width: 0; }
.brand-mark {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 18px;
  color: #fff;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  box-shadow: 0 16px 34px rgba(37, 99, 235, .28);
  font-size: 22px;
  font-weight: 900;
}
.brand strong { display: block; font-size: 22px; line-height: 1.1; font-weight: 950; letter-spacing: -0.03em; }
.brand small { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.current-pill {
  justify-self: center;
  max-width: min(520px, 42vw);
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 22px;
  color: var(--text);
  background: var(--soft);
  font-size: 14px;
  font-weight: 950;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.top-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; }
.soft-button, .theme-button, .primary-button, .secondary-button, .black-button, .quick-pill {
  border: 1px solid transparent;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 999px;
  padding: 0 18px;
  font-weight: 950;
  white-space: nowrap;
}
.soft-button, .theme-button, .secondary-button {
  color: var(--text);
  background: var(--soft);
  border-color: var(--line);
}
.theme-button span { width: 20px; height: 20px; border-radius: 50%; background: linear-gradient(135deg, #111827 50%, #f8fafc 50%); box-shadow: inset 0 0 0 1px var(--line); }
.primary-button { color: #fff; background: linear-gradient(135deg, var(--blue), var(--purple)); box-shadow: 0 16px 30px rgba(37, 99, 235, .22); }
.black-button { color: #fff; background: #101828; box-shadow: 0 16px 30px rgba(16, 24, 40, .20); }
body.dark .black-button { color: #101828; background: #f8fafc; }
.secondary-button:hover, .soft-button:hover, .theme-button:hover { transform: translateY(-1px); }

.mail-shell {
  width: min(1780px, calc(100vw - 32px));
  height: calc(100vh - 114px);
  margin: 16px auto;
  display: grid;
  grid-template-columns: minmax(340px, 430px) minmax(390px, 0.86fr) minmax(430px, 1fr);
  gap: 18px;
  align-items: stretch;
}
.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  overflow: hidden;
  height: 100%;
  min-height: 0;
}
.input-panel { padding: 22px; display: flex; flex-direction: column; min-height: 0; }
.inbox-panel { padding: 0; display: flex; flex-direction: column; min-height: 0; }
.detail-panel { padding: 22px; display: flex; flex-direction: column; min-height: 0; }
.panel-title { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 18px; }
.compact-title { align-items: center; padding: 22px 22px 16px; margin: 0; border-bottom: 1px solid var(--line); }
.compact-title .black-button { margin-left: auto; padding: 0 20px; }
.step-badge {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 15px;
  color: var(--blue);
  background: rgba(37, 99, 235, .10);
  font-weight: 950;
}
.panel h1, .panel h2 { margin: 0; letter-spacing: -0.04em; }
.panel h1 { font-size: clamp(26px, 2.3vw, 38px); line-height: 1.04; }
.panel h2 { font-size: 25px; line-height: 1.08; }
.panel p { margin: 7px 0 0; color: var(--muted); font-size: 13px; font-weight: 750; line-height: 1.45; }
.field { display: grid; gap: 9px; }
.field > span { color: var(--muted); font-size: 13px; font-weight: 950; }
textarea, input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 18px;
  color: var(--text);
  background: rgba(255,255,255,.72);
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}
body.dark textarea, body.dark input, body.dark select { background: rgba(255,255,255,.05); }
textarea { min-height: 150px; resize: vertical; padding: 16px; line-height: 1.55; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
input, select { height: 48px; padding: 0 14px; font-weight: 850; }
textarea:focus, input:focus, select:focus { border-color: rgba(37, 99, 235, .52); box-shadow: 0 0 0 4px rgba(37, 99, 235, .11); background: var(--panel-solid); }
.action-grid { display: grid; grid-template-columns: 1.4fr .8fr; gap: 12px; margin: 14px 0 12px; }
.action-grid button { border-radius: 18px; min-height: 50px; }
.format-box { border: 1px solid var(--line); border-radius: 18px; padding: 0; background: var(--soft); }
.format-box summary { padding: 13px 14px; color: var(--muted); cursor: pointer; font-size: 13px; font-weight: 950; }
.format-list { display: grid; gap: 8px; padding: 0 14px 14px; }
.format-list code { display: block; padding: 10px 12px; border-radius: 12px; background: rgba(15, 23, 42, .06); color: var(--text); font-size: 11px; white-space: nowrap; overflow: auto; }
body.dark .format-list code { background: rgba(255,255,255,.07); }
.provider-strip { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 10px; }
.provider-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 11px;
  color: var(--muted);
  background: var(--soft);
  font-size: 12px;
  font-weight: 950;
}
.provider-chip.active { color: #fff; background: linear-gradient(135deg, var(--blue), var(--purple)); border-color: transparent; }
.notice, .status-line {
  border-radius: 16px;
  padding: 12px 14px;
  color: var(--muted);
  background: rgba(255,255,255,.52);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 850;
  line-height: 1.45;
}
body.dark .notice, body.dark .status-line { background: rgba(255,255,255,.05); }
.notice.success, .status-line.success { color: var(--green); border-color: rgba(22, 163, 74, .24); background: rgba(22, 163, 74, .08); }
.notice.error, .status-line.error { color: var(--red); border-color: rgba(220, 38, 38, .22); background: rgba(220, 38, 38, .08); }
.mailbox-list { display: grid; align-content: start; gap: 10px; margin-top: 12px; flex: 1; min-height: 0; overflow: auto; padding-right: 3px; }
.mailbox-card {
  width: 100%;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px;
  color: var(--text);
  background: rgba(255,255,255,.58);
  text-align: left;
}
body.dark .mailbox-card { background: rgba(255,255,255,.05); }
.mailbox-card.active { border-color: rgba(37, 99, 235, .62); box-shadow: inset 0 0 0 2px rgba(37, 99, 235, .16); }
.avatar { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 16px; color:#fff; background: linear-gradient(135deg, var(--blue), var(--purple)); font-weight: 950; }
.avatar.icloud { background: linear-gradient(135deg, #38bdf8, #8b5cf6); }
.avatar.gmail { background: linear-gradient(135deg, #ef4444, #f59e0b); }
.avatar.outlook, .avatar.hotmail { background: linear-gradient(135deg, #111827, #2563eb); }
.mailbox-email { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 950; }
.mailbox-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; color: var(--muted); font-size: 11px; font-weight: 900; }
.badge { border-radius: 999px; padding: 4px 8px; background: rgba(37, 99, 235, .10); color: var(--blue); }
.badge.warn { color: var(--amber); background: rgba(245,158,11,.12); }
.badge.ok { color: var(--green); background: rgba(22,163,74,.10); }

.toolbar { display: grid; grid-template-columns: 1.1fr .7fr 1.5fr; gap: 10px; padding: 16px 22px 12px; }
.quick-row { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; padding: 0 22px 14px; }
.quick-pill { min-height: 38px; color: var(--muted); background: var(--soft); border-color: var(--line); padding: 0 14px; }
.quick-pill.active { color: #fff; background: #101828; }
body.dark .quick-pill.active { color: #101828; background: #f8fafc; }
.count-pill { margin-left: auto; border-radius: 999px; padding: 9px 12px; color: var(--muted); background: var(--soft); font-size: 12px; font-weight: 950; }
.inbox-panel .status-line { margin: 0 22px 14px; }
.message-list { display: grid; align-content: start; gap: 12px; flex: 1; min-height: 0; overflow: auto; padding: 0 22px 22px; }
.message-card {
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 16px;
  color: var(--text);
  background: rgba(255,255,255,.62);
  text-align: left;
  box-shadow: var(--shadow-soft);
}
body.dark .message-card { background: rgba(255,255,255,.05); }
.message-card.active { border-color: rgba(16, 24, 40, .78); box-shadow: inset 4px 0 0 var(--black), var(--shadow-soft); }
.message-card-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 12px; font-weight: 950; }
.message-from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.message-subject { display: block; margin: 12px 0 7px; font-size: 17px; line-height: 1.25; font-weight: 950; }
.message-snippet { display: -webkit-box; color: var(--muted); font-size: 13px; line-height: 1.45; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.message-labels { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 13px; }
.label-chip { border-radius: 999px; padding: 5px 9px; color: var(--blue); background: rgba(37,99,235,.10); font-size: 12px; font-weight: 950; }
.label-chip.code { color: var(--blue); background: #dbeafe; }
.label-chip.inbox { color: var(--green); background: rgba(22,163,74,.10); }
.label-chip.latest { color: #b45309; background: #fef3c7; }

.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.detail-head > div { display: flex; align-items: center; gap: 12px; min-width: 0; }
.detail-head .black-button { padding: 0 18px; min-height: 42px; }
.message-detail.empty { display: grid; place-items: center; align-content: center; flex: 1; min-height: 0; text-align: center; color: var(--muted); }
.empty-illustration { width: 120px; height: 120px; display: grid; place-items: center; margin-bottom: 18px; border-radius: 38px; background: linear-gradient(135deg, rgba(37,99,235,.12), rgba(124,58,237,.12)); font-size: 54px; }
.message-detail h2 { margin: 0 0 14px; font-size: clamp(28px, 3vw, 44px); line-height: 1.08; letter-spacing: -0.05em; }
.meta-grid { display: grid; grid-template-columns: 80px minmax(0, 1fr); gap: 13px 18px; margin: 24px 0 28px; font-size: 15px; }
.meta-grid span { color: var(--muted); font-weight: 900; }
.meta-grid strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 950; }
.code-card { margin: 0 0 22px; border: 1px solid rgba(37,99,235,.18); border-radius: 26px; padding: 26px; text-align: center; background: linear-gradient(135deg, rgba(37,99,235,.09), rgba(6,182,212,.08)); }
.code-title { color: var(--muted); font-size: 13px; font-weight: 950; }
.code-value { display: inline-block; margin-top: 12px; border-radius: 18px; padding: 8px 18px; color: #101828; background: #bfdbfe; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: clamp(40px, 6vw, 72px); letter-spacing: .22em; text-indent: .22em; line-height: 1.05; }
.body-card { border: 1px solid var(--line); border-radius: 24px; padding: 22px; flex: 1; min-height: 0; overflow: auto; background: rgba(255,255,255,.58); white-space: pre-wrap; color: var(--text); font-size: 14px; line-height: 1.7; }
body.dark .body-card { background: rgba(255,255,255,.05); }

@media (min-width: 1361px) {
  body { overflow: hidden; }
}
@media (max-width: 1360px) {
  .mail-shell { height: auto; min-height: 0; grid-template-columns: minmax(330px, 410px) minmax(420px, 1fr); align-items: start; }
  .detail-panel { grid-column: 1 / -1; min-height: auto; }
  .message-list { max-height: 620px; min-height: 320px; flex: none; }
  .message-detail.empty { min-height: 320px; }
}
@media (max-width: 940px) {
  .mail-topbar { grid-template-columns: 1fr; justify-items: stretch; gap: 12px; }
  .top-actions { justify-content: flex-start; }
  .current-pill { justify-self: stretch; max-width: none; }
  .mail-shell { width: min(100vw - 20px, 760px); height: auto; min-height: 0; grid-template-columns: 1fr; margin-top: 12px; gap: 12px; }
  .toolbar { grid-template-columns: 1fr; }
  .compact-title { align-items: flex-start; flex-wrap: wrap; }
  .compact-title .black-button { width: 100%; margin-left: 0; }
  .message-list { max-height: none; min-height: 240px; flex: none; }
  .detail-panel { padding: 18px; }
  .body-card { max-height: none; flex: none; }
}
@media (max-width: 520px) {
  .mail-topbar { padding: 12px; }
  .brand strong { font-size: 19px; }
  .brand small { white-space: normal; }
  .brand-mark { width: 42px; height: 42px; border-radius: 15px; }
  .input-panel, .detail-panel { padding: 14px; }
  .panel { border-radius: 22px; }
  .panel-title { gap: 10px; }
  .panel h1 { font-size: 26px; }
  .action-grid { grid-template-columns: 1fr; }
  .quick-row { align-items: stretch; }
  .quick-pill, .count-pill { width: 100%; justify-content: center; margin-left: 0; }
  .code-value { width: 100%; font-size: 40px; letter-spacing: .14em; text-indent: .14em; }
  .meta-grid { grid-template-columns: 1fr; gap: 5px; }
}
