
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eceef1;
  --border: #dfe2e8;
  --text: #1b1f27;
  --muted: #667085;
  --accent: #4653e8;
  --accent-hover: #3a46d1;
  --accent-soft: #eef0fe;
  --on-accent: #ffffff;
  --danger: #d92d20;
  --danger-soft: #fee4e2;
  --ok-soft: #d1fadf;
  --ok-text: #067647;
  --shadow: 0 1px 2px rgb(16 24 40 / .06), 0 1px 3px rgb(16 24 40 / .1);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101318;
    --surface: #181c23;
    --surface-2: #21262f;
    --border: #2c323d;
    --text: #e6e9ef;
    --muted: #8b94a3;
    --accent: #6473ff;
    --accent-hover: #7c89ff;
    --accent-soft: #232848;
    --on-accent: #ffffff;
    --danger: #f97066;
    --danger-soft: #3a1f1d;
    --ok-soft: #123527;
    --ok-text: #75e0a7;
    --shadow: 0 1px 2px rgb(0 0 0 / .4);
  }
}
* { box-sizing: border-box; margin: 0; }
html { height: 100%; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
svg.ic { width: 16px; height: 16px; flex: none; vertical-align: -3px; }

/* ---- app shell ---- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 236px; flex: none; padding: 16px 12px;
  display: flex; flex-direction: column; gap: 4px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.wordmark {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 16px; letter-spacing: .2px;
  padding: 4px 8px 14px;
}
.wordmark svg { width: 22px; height: 22px; color: var(--accent); }
.side-compose {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: var(--on-accent);
  border-radius: var(--radius); padding: 9px 12px; font-weight: 600;
  margin: 0 4px 14px; box-shadow: var(--shadow);
}
.side-compose:hover { background: var(--accent-hover); text-decoration: none; }
.side-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--muted); padding: 10px 10px 4px; font-weight: 600;
}
.side-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 8px; color: var(--text);
  font-weight: 500;
}
.side-item:hover { background: var(--surface-2); text-decoration: none; }
.side-item.active { background: var(--accent-soft); color: var(--accent); }
.side-item svg { color: var(--muted); }
.side-item.active svg { color: var(--accent); }
.side-item .grow { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  background: var(--accent); color: var(--on-accent);
  font-size: 11px; font-weight: 700; line-height: 1;
  border-radius: 99px; padding: 3px 7px;
}
.side-item.active .badge { background: var(--accent); }
.side-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
.side-user { display: flex; align-items: center; gap: 10px; padding: 6px 10px; }
.side-user .who { flex: 1; overflow: hidden; }
.side-user .who b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user .who span { font-size: 12px; color: var(--muted); }

/* ---- main column ---- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 24px; border-bottom: 1px solid var(--border);
  background: var(--surface); position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 16px; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .sub { color: var(--muted); font-weight: 500; font-size: 13px; }
.content { padding: 20px 24px 48px; max-width: 1060px; width: 100%; }
.content.narrow { max-width: 760px; }

/* ---- notices ---- */
.notice { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px; font-weight: 500; }
.notice.ok { background: var(--ok-soft); color: var(--ok-text); }
.notice.err { background: var(--danger-soft); color: var(--danger); }

/* ---- message list ---- */
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.msg-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 16px; border-bottom: 1px solid var(--border);
  color: var(--text);
}
.msg-row:last-child { border-bottom: none; }
.msg-row:hover { background: var(--surface-2); text-decoration: none; }
.msg-row .dot { width: 7px; height: 7px; border-radius: 99px; flex: none; background: transparent; }
.msg-row.unread .dot { background: var(--accent); }
.avatar {
  width: 34px; height: 34px; border-radius: 99px; flex: none;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 14px;
}
.msg-row .m-mid { flex: 1; min-width: 0; }
.msg-row .m-top { display: flex; gap: 8px; align-items: baseline; }
.msg-row .m-from { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
.msg-row.unread .m-from, .msg-row.unread .m-subj { font-weight: 700; }
.msg-row .m-rcpt { font-size: 12px; color: var(--muted); white-space: nowrap; }
.msg-row .m-line { display: flex; gap: 6px; min-width: 0; }
.msg-row .m-subj { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-row .m-prev { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.msg-row .m-side { flex: none; text-align: right; color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 8px; }
.msg-row .star { color: #eab308; }
.empty {
  padding: 56px 24px; text-align: center; color: var(--muted);
}
.empty svg { width: 40px; height: 40px; margin-bottom: 12px; opacity: .5; }
.pager { display: flex; justify-content: center; padding: 16px; }

/* ---- message view ---- */
.msg-head { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.msg-head .mh-top { padding: 18px 20px 8px; }
.msg-head h2 { font-size: 18px; margin-bottom: 12px; }
.mh-meta { display: flex; gap: 12px; align-items: flex-start; }
.mh-meta .who { flex: 1; min-width: 0; }
.mh-meta .who .name { font-weight: 600; }
.mh-meta .who .detail { color: var(--muted); font-size: 13px; }
.mh-meta .when { color: var(--muted); font-size: 13px; flex: none; }
.mh-actions { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 20px 16px; border-bottom: 1px solid var(--border); }
.msg-body-frame { width: 100%; height: 70vh; border: none; display: block; background: #fff; border-radius: 0 0 var(--radius) var(--radius); }
.msg-body-text { padding: 20px; white-space: pre-wrap; word-wrap: break-word; font-size: 14px; }
.att-strip { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.att-chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px;
  font-size: 13px; color: var(--text); background: var(--surface-2);
}
.att-chip:hover { border-color: var(--accent); text-decoration: none; }
.att-chip .sz { color: var(--muted); font-size: 12px; }

/* ---- buttons & forms ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
  padding: 7px 12px; font: inherit; font-weight: 500; cursor: pointer;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
form.inline { display: inline-flex; gap: 6px; align-items: center; }
input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type=file] { padding: 6px; }
select { width: auto; }
label.fl { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 5px; color: var(--muted); }
.form-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.form-row { display: flex; gap: 12px; }
.form-row > div { flex: 1; }
textarea.body { min-height: 260px; resize: vertical; }
.form-foot { display: flex; gap: 10px; margin-top: 18px; align-items: center; }

/* ---- admin ---- */
.cards { display: grid; gap: 20px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card > h3 { padding: 14px 18px; border-bottom: 1px solid var(--border); font-size: 14px; display: flex; align-items: center; gap: 8px; }
.card .pad { padding: 16px 18px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; padding: 10px 18px; border-bottom: 1px solid var(--border); }
.tbl td { padding: 10px 18px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl .muted { color: var(--muted); }
.pill { font-size: 11.5px; font-weight: 600; border-radius: 99px; padding: 3px 9px; }
.pill.admin { background: var(--accent-soft); color: var(--accent); }
.pill.on { background: var(--ok-soft); color: var(--ok-text); }
.pill.off { background: var(--danger-soft); color: var(--danger); }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat b { display: block; font-size: 22px; font-weight: 700; }
.stat span { color: var(--muted); font-size: 12.5px; }

/* ---- login ---- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 20% -10%, var(--accent-soft), transparent), var(--bg);
  padding: 24px;
}
.login-card {
  width: 380px; max-width: 100%;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px; box-shadow: var(--shadow);
}
.login-card .wordmark { justify-content: center; padding-bottom: 6px; font-size: 20px; }
.login-card .tag { text-align: center; color: var(--muted); margin-bottom: 18px; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 18px; padding: 10px; }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .side-foot { margin: 0; border: none; padding: 0; margin-left: auto; }
  .side-label { display: none; }
  .msg-row .m-prev { display: none; }
  .content { padding: 14px; }
}
