:root {
  color-scheme: dark;
  --bg: #0f1115; --panel: #171a21; --panel2: #1e222b; --line: #2a2f3a; --text: #e8eaf0; --muted: #9aa1ae;
  --accent: #6366f1; --accent2: #4f46e5; --ok: #22c55e; --err: #ef4444; --warn: #f59e0b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: #a5b4fc; }
h1 { font-size: 24px; margin: 8px 0; } h2 { font-size: 20px; margin: 0 0 14px; } h3 { font-size: 16px; margin: 0 0 10px; }
.hidden { display: none !important; }
.small { font-size: 12px; } .muted { color: var(--muted); } .nowrap { white-space: nowrap; }
.center { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 14px; }
.card.narrow { max-width: 440px; width: 100%; text-align: center; }
.card.wide { max-width: 760px; width: 100%; max-height: 92vh; overflow: auto; }
.logo { font-weight: 800; letter-spacing: .3px; font-size: 18px; }
.logo::before { content: ""; display: inline-block; width: 10px; height: 10px; background: var(--accent); border-radius: 3px; margin-right: 8px; vertical-align: middle; }
button, .button { display: inline-block; font: inherit; font-weight: 600; color: #fff; background: var(--accent); border: 0; border-radius: 8px; padding: 8px 14px; cursor: pointer; text-decoration: none; }
button:hover, .button:hover { background: var(--accent2); }
button:disabled { opacity: .5; cursor: default; }
button.secondary, .button.secondary { background: var(--panel2); border: 1px solid var(--line); color: var(--text); }
button.secondary:hover { background: #262b36; }
button.danger { background: #b91c1c; } button.danger:hover { background: #991b1b; }
.big { padding: 12px 18px; font-size: 15px; width: 100%; text-align: center; }
.small-btn { padding: 6px 10px; font-size: 12px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input[type=checkbox] { width: auto; }
input[type=color] { padding: 2px; height: 38px; }
textarea { resize: vertical; }
label { display: block; margin: 0 0 12px; font-weight: 600; }
label > input, label > select, label > textarea { margin-top: 4px; font-weight: 400; }
label.check { display: flex; gap: 8px; align-items: baseline; font-weight: 400; margin: 6px 0; }
code { background: var(--panel2); padding: 2px 6px; border-radius: 6px; word-break: break-all; }
pre.body { white-space: pre-wrap; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; max-height: 260px; overflow: auto; font: 13px/1.5 ui-monospace, Menlo, monospace; }
.row { display: flex; gap: 8px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.wrap > * { width: auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.msg { min-height: 18px; margin: 6px 0 0; } .msg.ok { color: var(--ok); } .msg.err, .err { color: var(--err); }
.notice { background: #3b2f0a; border: 1px solid #6b5212; color: #fde68a; padding: 8px 12px; border-radius: 8px; }

/* layout */
#app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; gap: 12px; position: sticky; top: 0; height: 100vh; overflow: auto; }
.me { padding: 10px; background: var(--panel2); border-radius: 10px; }
.me-name { font-weight: 700; }
.role-pill { display: inline-block; color: #fff; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; margin-top: 6px; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { color: var(--text); text-decoration: none; padding: 8px 10px; border-radius: 8px; display: flex; justify-content: space-between; }
nav a:hover { background: var(--panel2); } nav a.active { background: var(--accent); }
.nav-title { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin: 10px 10px 2px; }
.badge:not(:empty) { background: var(--err); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; font-weight: 700; }
.limits { margin-top: auto; }
.content { padding: 22px; min-width: 0; }
.tab { display: none; } .tab.active { display: block; }

/* mail */
.mail-top { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.mail-top select { width: auto; max-width: 320px; }
.search { display: flex; gap: 6px; flex: 1; min-width: 220px; }
.mail-split { display: grid; grid-template-columns: minmax(260px, 380px) 1fr; gap: 12px; height: calc(100vh - 150px); }
.mail-list { overflow: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.mail-item { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 10px 12px; color: var(--text); font-weight: 400; }
.mail-item:hover { background: var(--panel2); } .mail-item.open { background: #232846; }
.mail-item .subject, .mail-item .summary { grid-column: 1 / -1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-item.unread .from, .mail-item.unread .subject { font-weight: 700; }
.mail-item.unread .from::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-right: 6px; }
.mail-view { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); display: flex; flex-direction: column; overflow: hidden; }
.mail-view .empty, .mail-view > p { padding: 16px; }
.mail-head { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.mail-body { flex: 1; width: 100%; border: 0; background: #fff; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }

/* tables, stats, roles */
.table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.table th, .table td { text-align: left; padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--muted); font-size: 12px; font-weight: 600; }
.table select { width: auto; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; } .stat .n { font-size: 26px; font-weight: 800; }
.roles { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; margin-bottom: 14px; }
.role-card { background: var(--panel); border: 1px solid var(--line); color: var(--text); text-align: left; font-weight: 400; display: flex; flex-direction: column; gap: 6px; }
.role-card .role-pill { align-self: flex-start; }
.role-card:hover { background: var(--panel2); }
.perm-checks fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 0 0 10px; padding: 8px 12px; }
.perm-checks legend { color: var(--muted); font-size: 12px; padding: 0 6px; }
.status { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--panel2); }
.s-waiting { color: var(--warn); } .s-sent { color: var(--ok); } .s-rejected, .s-failed { color: var(--err); }
ul.plain { list-style: none; padding: 0; margin: 0; } ul.plain li.no { color: var(--muted); } ul.plain li.yes { color: var(--ok); }

/* activity */
.activity { display: flex; flex-direction: column; gap: 6px; }
.act { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.act summary { cursor: pointer; }
.act.warn { border-color: #6b5212; background: #221c0b; }

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .mail-split { grid-template-columns: 1fr; height: auto; }
  .mail-list { max-height: 50vh; } .mail-view { min-height: 60vh; }
  .grid2 { grid-template-columns: 1fr; }
}
