:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --border: #2a2f3a;
  --text: #e6e9ef;
  --muted: #9aa3b2;
  --accent: #4f8cff;
  --accent-2: #2f6fe0;
  --danger: #ff6b6b;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- login / single-card screens ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 14px; padding: 28px;
  display: flex; flex-direction: column; gap: 14px;
}
.brand { font-weight: 700; letter-spacing: .2px; }
.brand.big { font-size: 22px; }
.sub { color: var(--muted); margin: -6px 0 6px; }
.hint { color: var(--muted); font-size: 13px; margin: -4px 0; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input, textarea, select {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 10px 12px; font: inherit; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); border-color: transparent; }
input:disabled { color: var(--muted); }
button {
  background: var(--accent); color: #fff; border: 0; border-radius: 8px;
  padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer;
}
button:hover { background: var(--accent-2); }
.textlink { color: var(--muted); font-size: 13px; text-align: center; }
.error {
  background: rgba(255,107,107,.12); border: 1px solid var(--danger);
  color: #ffd5d5; padding: 10px 12px; border-radius: 8px; font-size: 14px;
}

/* ---- app shell ---- */
.layout { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--panel); border-right: 1px solid var(--border);
  padding: 18px 14px; display: flex; flex-direction: column; gap: 14px;
}
.compose-btn {
  background: var(--accent); color: #fff; text-align: center; padding: 10px;
  border-radius: 8px; font-weight: 600;
}
.compose-btn:hover { background: var(--accent-2); text-decoration: none; }
.search input { width: 100%; }
.folders { display: flex; flex-direction: column; gap: 2px; }
.folder {
  display: flex; justify-content: space-between; align-items: center;
  color: var(--text); padding: 9px 12px; border-radius: 8px;
}
.folder:hover { background: var(--panel-2); text-decoration: none; }
.folder.active { background: var(--panel-2); font-weight: 600; }
.badge { background: var(--accent); color: #fff; border-radius: 999px; padding: 1px 8px; font-size: 12px; }
.boxpick { margin-top: 4px; }
.account { margin-top: auto; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.account .addr { color: var(--text); overflow: hidden; text-overflow: ellipsis; }

.content { padding: 24px 28px; }
.content-head h1 { margin: 0 0 16px; font-size: 20px; }
.empty { color: var(--muted); }
.back { color: var(--muted); display: inline-block; margin-bottom: 14px; }

/* ---- message list ---- */
.msglist { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.msg { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-bottom: 1px solid var(--border); }
.msg:last-child { border-bottom: 0; }
.msg:hover { background: var(--panel); }
.msg.unread .subject, .msg.unread .from { font-weight: 700; }
.msg .flag, .msg .trash { background: none; color: var(--muted); padding: 4px 6px; font-size: 16px; }
.msg .flag:hover, .msg .trash:hover { color: var(--accent); background: none; }
.msg-link { flex: 1; display: grid; grid-template-columns: 200px 1fr auto; gap: 12px; align-items: center; color: var(--text); padding: 6px 4px; }
.msg-link:hover { text-decoration: none; }
.msg-link .from { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-link .subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-link .date { color: var(--muted); font-size: 13px; }

/* ---- outbox ---- */
.outbox .msg { gap: 10px; }
.status { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.status-queued { color: #ffd479; border-color: #6b5a2a; }
.status-sending { color: var(--accent); }
.status-failed { color: var(--danger); border-color: var(--danger); }
.status-canceled { color: var(--muted); }
.outbox-actions { display: flex; gap: 10px; }
.link-btn { background: none; color: var(--accent); padding: 4px 6px; font: inherit; font-weight: 500; }
.link-btn:hover { background: none; text-decoration: underline; }

/* ---- single message ---- */
.message h1 { margin: 0 0 12px; font-size: 22px; }
.message .meta { color: var(--muted); font-size: 14px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.message .meta .when { margin-top: 4px; }
.message .attachments { margin-top: 14px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.message .attachments .att-head { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.message .attachments ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.message .attachments li { display: flex; align-items: baseline; gap: 10px; }
.message .attachments .att-size { color: var(--muted); font-size: 12px; }
.message .thread { margin-top: 14px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.message .thread .thread-head { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.message .thread ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.message .thread li { display: flex; justify-content: space-between; gap: 12px; }
.message .thread li.current { font-weight: 600; }
.message .thread .thread-cur { color: var(--text); }
.message .thread .thread-date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.message .body { margin-top: 16px; }
.textbody { white-space: pre-wrap; word-break: break-word; font: inherit; margin: 0; }
.htmlbody { width: 100%; min-height: 60vh; border: 1px solid var(--border); border-radius: 10px; background: #fff; }

/* ---- compose ---- */
.compose { max-width: 720px; display: flex; flex-direction: column; gap: 12px; }
.compose .actions { display: flex; align-items: center; gap: 16px; }
.tpl-pick { max-width: 720px; margin-bottom: 16px; }

/* ---- settings ---- */
.card { max-width: 720px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; margin-bottom: 18px; }
.card h2 { margin: 0 0 6px; font-size: 16px; }
.card .stack { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.card .stack textarea, .card .stack input { width: 100%; }
.card .stack button { align-self: flex-start; }
.tpl-list { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.tpl-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 10px; background: var(--panel-2); border-radius: 8px; }
.tpl-meta { display: flex; flex-direction: column; }
.tpl-name { font-weight: 600; }
.tpl-subj { color: var(--muted); font-size: 13px; }
.tpl-new { border-top: 1px solid var(--border); padding-top: 14px; }
.checkbox { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.checkbox input { width: auto; }
.rule-row { display: flex; gap: 10px; flex-wrap: wrap; width: 100%; }
.rule-row label { flex: 1; min-width: 120px; }
