:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1d2129;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --unseen: #eef4ff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Layout ---- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; flex: 0 0 240px; background: var(--panel);
  border-right: 1px solid var(--line); padding: 16px 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.brand a { font-weight: 700; font-size: 18px; color: var(--ink); }
.compose-btn {
  display: block; text-align: center; background: var(--accent); color: var(--accent-ink);
  padding: 9px; border-radius: 6px; font-weight: 600; margin: 8px 0;
}
.compose-btn:hover { text-decoration: none; opacity: .92; }
.mailbox-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.mbox {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border-radius: 6px; color: var(--ink); font-size: 13px;
}
.mbox:hover { background: var(--bg); text-decoration: none; }
.mbox.active { background: var(--unseen); font-weight: 600; }
.mbox .dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 10px; }
.mbox-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.unread {
  background: var(--accent); color: #fff; border-radius: 10px;
  font-size: 11px; padding: 1px 7px; font-weight: 600;
}
.logout button {
  width: 100%; background: none; border: 1px solid var(--line); color: var(--muted);
  padding: 7px; border-radius: 6px; cursor: pointer;
}
.logout button:hover { background: var(--bg); }

.content { flex: 1; padding: 24px 28px; min-width: 0; }
.content-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 16px; }
.content-head h1 { font-size: 20px; margin: 0; }
.count { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); }

/* ---- Message list ---- */
.msg-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line);
  border-radius: 8px; overflow: hidden; background: var(--panel); }
.msg-row + .msg-row { border-top: 1px solid var(--line); }
.msg-row a {
  display: grid; grid-template-columns: auto 180px 1fr auto; gap: 12px;
  align-items: center; padding: 10px 14px; color: var(--ink);
}
.msg-row a:hover { background: var(--bg); text-decoration: none; }
.msg-row.unseen { background: var(--unseen); }
.msg-row.unseen .subject { font-weight: 700; }
.from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.badge {
  color: #fff; font-size: 11px; padding: 2px 8px; border-radius: 10px;
  white-space: nowrap; font-weight: 600;
}

/* ---- Message view ---- */
.msg-view { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 20px; }
.msg-toolbar { display: flex; justify-content: space-between; margin-bottom: 12px; }
.reply-btn { background: var(--accent); color: #fff; padding: 6px 14px; border-radius: 6px; font-weight: 600; }
.reply-btn:hover { text-decoration: none; opacity: .92; }
.msg-subject { font-size: 20px; margin: 6px 0 14px; }
.msg-meta { border-collapse: collapse; margin-bottom: 14px; font-size: 13px; }
.msg-meta th { text-align: left; color: var(--muted); font-weight: 500; padding: 2px 14px 2px 0; vertical-align: top; }
.attachments { border: 1px solid var(--line); border-radius: 6px; padding: 10px 14px; margin-bottom: 14px; background: var(--bg); }
.attachments ul { margin: 6px 0 0; padding-left: 18px; }
.att-meta { color: var(--muted); font-size: 12px; }
.msg-body { margin-top: 8px; }
.text-body { white-space: pre-wrap; word-wrap: break-word; font: 14px/1.55 inherit; margin: 0; }
.html-body { width: 100%; min-height: 60vh; border: 1px solid var(--line); border-radius: 6px; background: #fff; }

/* ---- Compose ---- */
.compose-view { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 20px; max-width: 780px; }
.compose-form { display: flex; flex-direction: column; gap: 4px; }
.compose-form label { font-size: 12px; color: var(--muted); margin-top: 8px; }
.compose-form input, .compose-form select, .compose-form textarea {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; width: 100%;
}
.compose-form input.readonly { background: var(--bg); color: var(--muted); }
.compose-form textarea { resize: vertical; }
.compose-actions { margin-top: 14px; display: flex; align-items: center; gap: 14px; }
.compose-actions button { background: var(--accent); color: #fff; border: 0; padding: 9px 22px; border-radius: 6px; font-weight: 600; cursor: pointer; }
.cancel { color: var(--muted); }

/* ---- Login ---- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 30px; width: 320px; display: flex; flex-direction: column; gap: 8px; box-shadow: 0 4px 24px rgba(0,0,0,.06); }
.login-card h1 { margin: 0 0 10px; font-size: 22px; text-align: center; }
.login-card label { font-size: 12px; color: var(--muted); }
.login-card input { padding: 9px 11px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.login-card button { margin-top: 10px; background: var(--accent); color: #fff; border: 0; padding: 10px; border-radius: 6px; font-weight: 600; cursor: pointer; }
.error { color: #b91c1c; background: #fee2e2; padding: 8px 10px; border-radius: 6px; font-size: 13px; margin: 0; }
.notice { color: #92400e; background: #fef3c7; padding: 8px 10px; border-radius: 6px; font-size: 13px; margin: 0; }
code { background: var(--bg); padding: 1px 5px; border-radius: 4px; }

/* ---- Admin ---- */
.admin-link {
  display: block; text-align: center; padding: 8px; border-radius: 6px;
  color: var(--ink); border: 1px solid var(--line); font-size: 13px;
}
.admin-link:hover { background: var(--bg); text-decoration: none; }
.admin-link.active { background: var(--unseen); font-weight: 600; }
.admin-cards { display: flex; gap: 16px; flex-wrap: wrap; }
.admin-card {
  flex: 1 1 260px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 18px 20px; color: var(--ink);
}
.admin-card:hover { background: var(--bg); text-decoration: none; }
.admin-card h2 { margin: 0 0 6px; font-size: 16px; }
.admin-card p { margin: 0; color: var(--muted); font-size: 13px; }
.admin-form { background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 20px; max-width: 640px; display: flex; flex-direction: column; gap: 4px; }
.admin-form label { font-size: 12px; color: var(--muted); margin-top: 10px; }
.admin-form input, .admin-form select {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; }
.addr-row { display: flex; align-items: center; gap: 6px; }
.addr-row input { flex: 1; }
.addr-row .at { color: var(--muted); }
.addr-row select { flex: 1; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.notice-ok { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0;
  padding: 14px 16px; border-radius: 8px; margin-bottom: 14px; }
.notice-ok table { margin-top: 8px; }
.sub { font-size: 15px; margin: 18px 0 8px; }
.plan-table { border-collapse: collapse; width: 100%; max-width: 900px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; overflow: hidden; font-size: 13px; }
.plan-table th, .plan-table td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.plan-table .val { word-break: break-all; }
.plan-table .old { color: #b91c1c; }
.plan-table .new { color: #166534; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 10px; color: #fff; }
.tag-create { background: #16a34a; }
.tag-replace { background: #d97706; }
.tag-delete { background: #dc2626; }
.tag-skip { background: #9ca3af; }
.row-delete { background: #fef2f2; }
.row-replace { background: #fffbeb; }
.confirm-form { margin-top: 16px; }
button.danger { background: #dc2626; }

@media (max-width: 720px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .msg-row a { grid-template-columns: 1fr auto; }
  .from, .badge { display: none; }
}
