:root {
  --bg: #0f1115; --panel: #171a21; --panel2: #1e222b; --line: #2a2f3a;
  --fg: #e6e8ee; --muted: #8b93a5; --accent: #ee4d2d; --accent2: #ff7a59;
  --ok: #2ecc71; --warn: #f1c40f; --bad: #e74c3c; --radius: 12px;
}
@media (prefers-color-scheme: light) {
  :root { --bg: #f4f5f8; --panel: #fff; --panel2: #f7f8fb; --line: #e3e6ee; --fg: #1a1d24; --muted: #6b7384; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.45 system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--fg); }
a { color: var(--accent2); }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.top { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand small { color: var(--muted); font-weight: 400; font-size: 13px; }
.logo { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); display: inline-block; position: relative; }
.logo::after { content: ""; position: absolute; inset: 7px 5px; border: 2px solid #fff; border-radius: 3px; }
.status { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); }
.status.on .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(46,204,113,.2); }
.status.off .dot { background: var(--bad); }

.wrap { max-width: 1200px; margin: 0 auto; padding: 20px 16px 40px; display: flex; flex-direction: column; gap: 16px; }

.addrbox { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.lbl { display: block; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.addrrow { display: flex; gap: 8px; }
.addr { flex: 1; min-width: 0; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel2); font-size: 18px; font-weight: 600; letter-spacing: .2px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.openlbl { margin-top: 14px; }
.addr.open { font-weight: 500; font-size: 15px; }
.at { align-self: center; color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; margin: 12px 0 0; }

.btn { padding: 9px 14px; border-radius: 9px; border: 1px solid var(--line); background: var(--panel2); cursor: pointer; transition: .15s; white-space: nowrap; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--accent2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent2); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.danger-ghost { color: var(--bad); }
.btn.danger-ghost:hover { border-color: var(--bad); }
.pill { background: var(--accent); color: #fff; border-radius: 999px; padding: 0 7px; font-size: 12px; }

.mail { display: grid; grid-template-columns: 380px 1fr; gap: 16px; min-height: 520px; }
.list, .view { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.listhead { display: flex; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 600; }
.muted { color: var(--muted); font-weight: 400; font-size: 13px; }
.msgs { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.msgs li { padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; }
.msgs li:hover { background: var(--panel2); }
.msgs li.active { background: var(--panel2); box-shadow: inset 3px 0 0 var(--accent); }
.msgs .from { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msgs .time { color: var(--muted); font-size: 12px; }
.msgs .subj { grid-column: 1 / -1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msgs .intro { grid-column: 1 / -1; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msgs li.unread .from::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 6px; }
.msgs li.seen .from, .msgs li.seen .subj { font-weight: 400; }
.msgs .clip { color: var(--muted); font-size: 12px; }
.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); padding: 30px; text-align: center; }
.pulse { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); animation: pulse 1.4s infinite; margin-bottom: 14px; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(238,77,45,.5);} 100% { box-shadow: 0 0 0 18px rgba(238,77,45,0);} }

.viewempty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.viewbody { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.vhead { padding: 14px 18px; border-bottom: 1px solid var(--line); }
.vhead h2 { margin: 6px 0 8px; font-size: 18px; word-break: break-word; }
.meta { color: var(--muted); font-size: 13px; display: grid; gap: 2px; }
.meta b { color: var(--fg); font-weight: 600; }
.back { display: none; }
.vtools { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.tabs { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; margin-right: auto; }
.tab { padding: 6px 12px; border: 0; background: transparent; cursor: pointer; font-size: 13px; }
.tab.active { background: var(--accent); color: #fff; }
.codes { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 13px; color: var(--muted); }
.codes .code { font-family: ui-monospace, Consolas, monospace; font-size: 16px; font-weight: 700; letter-spacing: 2px; background: var(--panel2); border: 1px dashed var(--accent2); border-radius: 8px; padding: 4px 10px; cursor: pointer; color: var(--fg); }
.atts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.atts a { font-size: 13px; }
.frame { flex: 1; border: 0; background: #fff; min-height: 400px; width: 100%; }
.text { flex: 1; margin: 0; padding: 16px 18px; overflow: auto; white-space: pre-wrap; word-break: break-word; font-size: 14px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; width: 100%; max-width: 480px; }
.card h3 { margin: 0 0 14px; }
.row { display: flex; gap: 8px; }
.row.end { justify-content: flex-end; margin-top: 14px; }
.row input, .row select { padding: 10px 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--panel2); }
.row input { flex: 1; min-width: 0; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin: 8px 0 0; }
.saved { list-style: none; padding: 0; margin: 0; max-height: 50vh; overflow: auto; }
.saved li { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.saved li span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved li.current span { color: var(--accent2); font-weight: 600; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 30; box-shadow: 0 6px 24px rgba(0,0,0,.3); }

@media (max-width: 860px) {
  .mail { grid-template-columns: 1fr; }
  .mail.viewing .list { display: none; }
  .mail:not(.viewing) .view { display: none; }
  .back { display: inline-flex; }
  .addr { font-size: 15px; }
  .frame { min-height: 60vh; }
}
