:root {
  --bg: #eef3f6;
  --sidebar: #10232a;
  --sidebar-2: #16343d;
  --accent: #0f766e;
  --accent-2: #14b8a6;
  --warn: #d97706;
  --danger: #e11d48;
  --text: #13202b;
  --muted: #5b6b75;
  --card: #ffffff;
  --line: #dbe4ea;
  --shadow: 0 12px 40px rgba(16, 35, 42, 0.08);
  --radius: 16px;
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1200px 500px at 10% -10%, #99f6e4 0%, transparent 50%),
    radial-gradient(900px 400px at 100% 0%, #bae6fd 0%, transparent 46%),
    var(--bg);
  padding: 24px;
}

.auth-card {
  width: min(440px, 100%);
  background: var(--card);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 36px 32px 28px;
  border: 1px solid #e8eef2;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 22px;
}
.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
}
.brand h1 { margin: 0; font-size: 20px; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #f8fbfc;
  border-radius: 12px;
  padding: 11px 12px;
  outline: none;
}
input[type="checkbox"] {
  width: auto;
  padding: 0;
  background: none;
  border: 0;
  box-shadow: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 4px rgba(20, 184, 166, 0.15);
  background: #fff;
}
input[type="checkbox"]:focus { box-shadow: none; }

.btn {
  border: 0;
  border-radius: 12px;
  padding: 11px 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn:hover { filter: brightness(1.05); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.secondary { background: #e8eef2; color: var(--text); }
.btn.ghost { background: transparent; color: #d1e4e4; }
.btn.danger { background: var(--danger); }
.btn.block { width: 100%; margin-top: 18px; }
.btn.small { padding: 7px 10px; border-radius: 10px; font-size: 13px; }

.hint, .error, .ok {
  font-size: 13px;
  margin-top: 10px;
  line-height: 1.5;
}
.error { color: var(--danger); }
.ok { color: var(--accent); }
.hint { color: var(--muted); }

.otp-input { letter-spacing: 0.4em; text-align: center; font-size: 22px; font-weight: 700; }
.qr-wrap { display: grid; place-items: center; margin: 12px 0; }
.qr-wrap img { width: 200px; height: 200px; border-radius: 12px; border: 1px solid var(--line); }
.secret {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #f1f5f9;
  padding: 8px 10px;
  border-radius: 8px;
  word-break: break-all;
  font-size: 12px;
}

.app {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: linear-gradient(180deg, var(--sidebar), #0c1c22);
  color: #d7e6e8;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.side-brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 18px; }
.side-brand strong { display: block; color: #fff; }
.side-brand span { color: #8aa3ab; font-size: 12px; }
.nav-btn {
  text-align: left;
  background: transparent;
  color: #c5d7db;
  border: 0;
  border-radius: 10px;
  padding: 10px 12px;
}
.nav-btn.active, .nav-btn:hover { background: var(--sidebar-2); color: #fff; }
.side-foot { margin-top: auto; padding: 12px 8px 0; font-size: 12px; color: #8aa3ab; }
.side-foot button { margin-top: 8px; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 16px 22px;
  background: rgba(255,255,255,0.86);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f4f8fa;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 12px;
}
.search input { border: 0; background: transparent; padding: 10px 0; }
.search input:focus { box-shadow: none; }
.filters { display: flex; gap: 8px; }
.filters select { width: auto; min-width: 140px; background: #fff; }
.sync-pill {
  font-size: 12px;
  background: #ecfdf5;
  color: #0f766e;
  border: 1px solid #99f6e4;
  border-radius: 999px;
  padding: 6px 10px;
  white-space: nowrap;
}
.sync-pill.busy { background: #fff7ed; color: #c2410c; border-color: #fed7aa; }

.content { padding: 18px 22px 40px; }
.mail-list { background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; }
.mail-row {
  display: grid;
  grid-template-columns: 210px 1fr 150px;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  align-items: center;
}
.mail-row:hover { background: #f8fbfc; }
.mail-row:last-child { border-bottom: 0; }
.mailbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  max-width: 100%;
}
.dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.mailbox span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subject { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.when { color: var(--muted); font-size: 12px; text-align: right; }
.kw {
  display: inline-block;
  margin-left: 6px;
  background: #fff7ed;
  color: #c2410c;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
}

.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; color: var(--muted); font-size: 13px; }
.empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--muted);
}
.empty h3 { color: var(--text); margin-bottom: 6px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 6px; font-size: 16px; overflow-wrap: anywhere; }
.card .muted { color: var(--muted); font-size: 13px; line-height: 1.5; }
.card .row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.err-line { color: var(--danger); font-size: 12px; margin-top: 8px; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 13px;
}
.chip.active { background: #0f766e; color: #fff; border-color: #0f766e; }
.chip .x { margin-left: 6px; opacity: 0.7; }

.drawer-bg {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  display: none;
  z-index: 20;
}
.drawer-bg.show { display: block; }
.drawer {
  position: absolute;
  right: 0;
  top: 0;
  height: 100%;
  width: min(720px, 100%);
  background: #fff;
  box-shadow: -20px 0 50px rgba(0,0,0,.12);
  display: flex;
  flex-direction: column;
}
.drawer header { padding: 18px 20px 10px; border-bottom: 1px solid var(--line); }
.drawer header h2 { margin: 8px 0 0; font-size: 18px; line-height: 1.4; }
.drawer .body { padding: 16px 20px; overflow: auto; flex: 1; }
.mail-iframe { width: 100%; min-height: 420px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
  line-height: 1.6;
}

.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  display: none;
  place-items: center;
  z-index: 30;
  padding: 20px;
}
.modal-bg.show { display: grid; }
.modal {
  width: min(560px, 100%);
  background: #fff;
  border-radius: 20px;
  padding: 22px;
  max-height: 90vh;
  overflow: auto;
}
.checks { display: flex; flex-wrap: wrap; gap: 10px 16px; margin: 8px 0 4px; }
.checks label { margin: 0; color: var(--text); display: flex; gap: 6px; align-items: center; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: #10232a;
  color: #fff;
  padding: 12px 14px;
  border-radius: 12px;
  z-index: 50;
  display: none;
  max-width: 360px;
}
.toast.show { display: block; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .side-foot { margin: 0 0 0 auto; }
  .mail-row { grid-template-columns: 1fr; gap: 4px; }
  .when { text-align: left; }
  .topbar { flex-wrap: wrap; }
  .filters { width: 100%; }
}
