:root {
  color-scheme: dark;
  --bg: #0e1014;
  --panel: #15181e;
  --panel-2: #1b1f27;
  --hover: #20252e;
  --line: #272c36;
  --text: #e4e7ec;
  --muted: #8a92a2;
  --accent: #7a96ff;
  --accent-strong: #5b7cf5;
  --accent-soft: rgba(122, 150, 255, 0.14);
  --danger: #ff7a7a;
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
::selection { background: rgba(122, 150, 255, 0.35); }
* { scrollbar-color: #343a46 transparent; }

/* ---------- Top bar ---------- */
.topbar {
  height: 56px; display: flex; align-items: center; gap: 16px;
  padding: 0 20px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; white-space: nowrap; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 7px; background: var(--accent-strong); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
}
.brand small { font-weight: 400; color: var(--muted); }
.search {
  flex: 1; max-width: 520px; margin-left: auto; padding: 8px 14px; border-radius: 20px;
  border: 1px solid var(--line); background: var(--bg); outline: none;
}
.search:focus { border-color: var(--accent); }
.search::placeholder { color: var(--muted); }

/* ---------- Inbox layout ---------- */
.inbox { display: grid; grid-template-columns: 210px 380px 1fr; height: calc(100% - 56px); }
.folders { padding: 16px 10px; border-right: 1px solid var(--line); overflow-y: auto; }
.folders h4 { margin: 18px 10px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.folder {
  display: flex; justify-content: space-between; width: 100%; padding: 7px 10px; border: 0;
  background: none; border-radius: 6px; cursor: pointer; text-align: left; font-size: 14px;
}
.folder:hover { background: var(--hover); }
.folder.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.folder .count { color: var(--muted); font-size: 12px; }

.list { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; }
.list-head { padding: 14px 16px; border-bottom: 1px solid var(--line); font-weight: 600; position: sticky; top: 0; background: var(--panel); z-index: 1; }
.item { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.item:hover { background: var(--hover); }
.item.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.item .row1 { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.item .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .who .n { color: var(--muted); font-weight: 400; margin-left: 4px; }
.item .date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.item .subj { font-size: 14px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .snip { font-size: 13px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

.reader { overflow-y: auto; padding: 28px 36px 60px; }
.reader h1 { font-size: 22px; margin: 0 0 6px; font-weight: 600; }
.thread-info { color: var(--muted); font-size: 13px; margin-bottom: 18px; display: flex; gap: 14px; align-items: center; }
.linkbtn { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; font-size: 13px; }

.msg { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; max-width: 860px; }
.msg-head { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; cursor: pointer; width: 100%; border: 0; background: none; text-align: left; }
.msg.open .msg-head { border-bottom: 1px solid var(--line); }
.avatar {
  flex: none; width: 38px; height: 38px; border-radius: 50%; color: #fff;
  display: grid; place-items: center; font-weight: 600; font-size: 14px;
}
.msg-head .lines { flex: 1; min-width: 0; font-size: 14px; line-height: 1.5; }
.msg-head .muted { color: var(--muted); }
.msg-head .preview { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-head .when { color: var(--muted); font-size: 13px; white-space: nowrap; }
.msg .recips { display: none; }
.msg.open .recips { display: block; }
.msg.open .preview { display: none; }
.msg .body { display: none; white-space: pre-wrap; line-height: 1.65; font-size: 15px; padding: 18px 16px 20px 66px; }
.msg.open .body { display: block; }
.back { display: none; }

@media (max-width: 900px) {
  .topbar { padding: 0 12px; gap: 10px; }
  .inbox { grid-template-columns: 1fr; }
  .folders { display: none; }
  .reader { display: none; padding: 16px 12px 40px; }
  .inbox.reading .list { display: none; }
  .inbox.reading .reader { display: block; }
  .back { display: inline-block; margin-bottom: 14px; border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; }
  .search { max-width: none; min-width: 0; }
  .brand small { display: none; }
  .msg-head { flex-wrap: wrap; }
  .msg-head .lines { overflow-wrap: anywhere; }
  .msg-head .when { flex-basis: 100%; padding-left: 50px; }
  .msg .body { padding-left: 16px; }
}

/* ---------- Admin ---------- */
.admin { max-width: 1150px; margin: 0 auto; padding: 24px 20px 60px; display: grid; gap: 24px; grid-template-columns: 1.15fr 1fr; align-items: start; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card.wide { grid-column: 1 / -1; }
.card h2 { margin: 0 0 14px; font-size: 17px; }
label, .label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 5px; }
.label .hint, label .hint { font-weight: 400; color: var(--muted); }
input[type=text], input[type=email], input[type=datetime-local], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg);
}
textarea { min-height: 220px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.picker { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); max-height: 150px; overflow-y: auto; }
.chip { border: 1px solid var(--line); background: var(--panel-2); border-radius: 14px; padding: 4px 11px; font-size: 13px; cursor: pointer; }
.chip:hover { border-color: #3a4150; }
.chip.on { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.chip.on::before { content: "✓ "; }
.picker .none { color: var(--muted); font-size: 13px; padding: 3px 4px; }

.actions { display: flex; gap: 8px; margin-top: 16px; align-items: center; flex-wrap: wrap; }
.btn { padding: 8px 16px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.danger { color: var(--danger); }
.status { font-size: 13px; color: var(--muted); }
.status.err { color: var(--danger); }
.replying { font-size: 13px; color: var(--accent); background: var(--accent-soft); padding: 8px 10px; border-radius: 6px; margin-bottom: 4px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
td.nowrap { white-space: nowrap; }
td .sub { color: var(--muted); font-size: 12px; }
.topbar a { color: var(--accent); text-decoration: none; font-size: 14px; margin-left: auto; }
@media (max-width: 860px) { .admin { grid-template-columns: 1fr; } }
