:root {
  --primary: #3f7d8c;
  --primary-strong: #2f6473;
  --accent: #d99429;
  --bg: #f4f7f8;
  --panel: #ffffff;
  --panel-2: #f8fafb;
  --text: #1c2530;
  --muted: #6b7a88;
  --line: #e2e9ec;
  --danger: #c0492f;
  --ok: #2f8f6a;
  --radius: 14px;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #6fb3c2;
    --primary-strong: #8ac7d4;
    --bg: #0e1418;
    --panel: #151d23;
    --panel-2: #111a1f;
    --text: #e6edf2;
    --muted: #8ba0ad;
    --line: #23323a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; background: var(--panel-2); padding: 2px 6px; border-radius: 6px; }
h1 { font-size: 20px; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

/* ---- layout ---- */
.app { display: flex; min-height: 100vh; }

.side {
  width: 216px;
  flex: 0 0 216px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: -0.01em; }
.brand .logo {
  width: 26px; height: 26px; display: grid; place-items: center;
  border-radius: 8px; color: #fff; background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  font-size: 14px;
}

.side nav { display: flex; flex-direction: column; gap: 2px; }
.nav {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 9px; color: var(--text); font-size: 14px;
  transition: background 0.18s var(--ease);
}
.nav:hover { background: var(--panel-2); text-decoration: none; }
.nav.active { background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); font-weight: 600; }
.badge {
  margin-left: auto; background: var(--accent); color: #fff;
  font-size: 11px; min-width: 18px; height: 18px; border-radius: 9px;
  display: grid; place-items: center; padding: 0 5px;
}
.side-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; }

.main { flex: 1; min-width: 0; padding: 26px 30px 60px; max-width: 1080px; }

/* ---- controls ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-size: 13.5px; cursor: pointer;
  transition: transform 0.16s var(--ease), background 0.16s var(--ease);
  text-decoration: none;
}
.btn:hover { background: var(--panel-2); text-decoration: none; transform: translateY(-1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-strong); }
.btn.small { padding: 4px 9px; font-size: 12px; border-radius: 8px; }
.block { width: 100%; }

input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%; padding: 9px 11px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  font: inherit; font-size: 14px;
}
input:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 35%, transparent); border-color: var(--primary); }
textarea { resize: vertical; font-family: inherit; }
label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
label input, label textarea { margin-top: 5px; color: var(--text); }

.stack > * + * { margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.inline { display: inline; }
.inline-form { display: flex; gap: 8px; align-items: center; margin-top: 14px; }
.inline-form input { width: auto; flex: 1; }
.form-foot { display: flex; align-items: center; gap: 12px; padding-top: 6px; }

/* ---- blocks ---- */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(16, 32, 40, 0.03);
}

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.subject-title { font-size: 19px; }
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.search { display: flex; gap: 8px; }
.search input { width: 280px; }

.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; font-size: 13.5px; }
.flash.ok { background: color-mix(in srgb, var(--ok) 12%, transparent); color: var(--ok); }
.flash.error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }

/* ---- list ---- */
.list { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row {
  display: grid;
  grid-template-columns: 22px 160px 1fr auto auto 84px;
  gap: 10px; align-items: center;
  padding: 11px 16px; color: var(--text); border-bottom: 1px solid var(--line);
  transition: background 0.15s var(--ease);
}
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--panel-2); text-decoration: none; }
.row.unread .subject { font-weight: 600; }
.row .who, .row .subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .star { color: var(--accent); }
.row .time { color: var(--muted); font-size: 12px; text-align: right; }
.clip { font-size: 12px; color: var(--muted); }

.status { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; }
.status.s-bounced, .status.s-failed, .status.s-complained { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.status.s-delivered { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }

.empty { text-align: center; padding: 70px 20px; color: var(--muted); }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; padding: 18px 0; }

/* ---- message ---- */
.meta { font-size: 13.5px; line-height: 1.9; }
.meta .muted { display: inline-block; min-width: 58px; }
.chip {
  display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 7px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); margin-left: 4px;
}
.chip.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.chip.warn { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }

.mail-body {
  width: 100%; min-height: 420px; border: 1px solid var(--line); border-radius: var(--radius);
  background: #fff; margin-bottom: 16px;
}

.attachments ul, .thread { margin: 8px 0 0; padding-left: 18px; }
.attachments li, .thread li { margin: 4px 0; }
.thread li.current { font-weight: 600; }
.key-new code { display: block; margin: 8px 0; padding: 10px; background: var(--panel-2); }

/* ---- table ---- */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--muted); font-weight: 500; font-size: 12.5px; }
.table tr:last-child td { border-bottom: 0; }

/* ---- login ---- */
.login-body { display: grid; place-items: center; min-height: 100vh; background:
  radial-gradient(1200px 600px at 50% -10%, color-mix(in srgb, var(--primary) 16%, transparent), transparent 60%), var(--bg); }
.login-card {
  width: min(380px, 92vw); background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 28px 26px; box-shadow: 0 20px 50px rgba(16, 32, 40, 0.08);
}
.login-card .brand { justify-content: center; font-size: 17px; margin-bottom: 6px; }
.login-card form { margin-top: 18px; }

@media (max-width: 860px) {
  .app { flex-direction: column; }
  .side { width: auto; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .side nav { flex-direction: row; flex-wrap: wrap; }
  .main { padding: 18px 16px 40px; }
  .row { grid-template-columns: 22px 1fr auto; }
  .row .who, .row .status { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .search input { width: 100%; }
}
