:root {
  --bg: #f6f7f9; --panel: #fff; --text: #111827; --muted: #6b7280; --border: #e5e7eb;
  --accent: #2563eb; --accent-text: #fff; --danger: #dc2626; --ok: #16a34a; --warn: #d97706;
  --radius: 8px; --shadow: 0 1px 2px rgba(0,0,0,.06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 15px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1115; --panel: #171a21; --text: #e5e7eb; --muted: #9ca3af; --border: #2a2f3a; --accent: #3b82f6; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.3rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; word-break: break-all; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem;
  background: var(--panel); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; color: var(--text); }
.topbar nav { display: flex; gap: .2rem; flex-wrap: wrap; }
.topbar nav a { padding: .35rem .6rem; border-radius: 6px; color: var(--text); }
.topbar nav a.active { background: var(--accent); color: var(--accent-text); text-decoration: none; }
.menu-btn { display: none; }
.badge { display: inline-block; min-width: 1.3em; padding: 0 .35em; border-radius: 1em; background: var(--danger); color: #fff; font-size: .75rem; text-align: center; }

main { max-width: 1100px; margin: 0 auto; padding: 1rem; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem 1rem; }
.grid2 .full { grid-column: 1 / -1; }

button, .btn { font: inherit; padding: .45rem .9rem; border-radius: 6px; border: 1px solid var(--border); background: var(--panel);
  color: var(--text); cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--danger); border-color: var(--danger); }
button.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; width: 100%; padding: .45rem .6rem; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text); }
input[type=checkbox], input[type=radio] { width: auto; flex: 0 0 auto; margin: .2rem 0 0; }
input[type=color] { padding: 2px; height: 2.3rem; }
textarea { min-height: 14rem; resize: vertical; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .2rem; }
label.inline { display: flex; align-items: center; gap: .4rem; color: var(--text); font-size: .95rem; }
label.inline input { width: auto; }
.field { margin-bottom: .75rem; }

.list { list-style: none; margin: 0; padding: 0; }
.item { display: flex; gap: .75rem; padding: .7rem .5rem; border-bottom: 1px solid var(--border); cursor: pointer; align-items: flex-start; }
.item:hover { background: rgba(37,99,235,.05); }
.item.unread .subj, .item.unread .who { font-weight: 700; }
.item .main { flex: 1; min-width: 0; }
.item .line { display: flex; gap: .5rem; align-items: baseline; }
.item .who { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40%; }
.item .subj { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .snip { color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .date { color: var(--muted); font-size: .8rem; white-space: nowrap; margin-left: auto; }
.label { display: inline-block; padding: .05rem .45rem; border-radius: 4px; color: #fff; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.status { display: inline-block; padding: .05rem .45rem; border-radius: 4px; font-size: .75rem; font-weight: 600; border: 1px solid currentColor; }
.status.draft { color: var(--warn); } .status.approved { color: var(--accent); } .status.sent { color: var(--ok); } .status.failed { color: var(--danger); }

.msg { border-top: 1px solid var(--border); padding: 1rem 0; }
.msg:first-child { border-top: 0; }
.msg .hdr { display: flex; gap: .5rem; flex-wrap: wrap; align-items: baseline; margin-bottom: .5rem; }
.body { white-space: pre-wrap; word-wrap: break-word; font-size: .95rem; line-height: 1.45; }
.notice { padding: .6rem .8rem; border-radius: 6px; background: rgba(217,119,6,.12); border: 1px solid rgba(217,119,6,.4); margin-bottom: 1rem; }
.notice.err { background: rgba(220,38,38,.1); border-color: rgba(220,38,38,.4); }
.notice.ok { background: rgba(22,163,74,.1); border-color: rgba(22,163,74,.4); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem; border-bottom: 1px solid var(--border); vertical-align: top; font-size: .9rem; }
th { color: var(--muted); font-weight: 600; }

.login { max-width: 360px; margin: 10vh auto; }
.toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: .6rem 1rem;
  border-radius: 6px; z-index: 50; max-width: 90vw; }
.toast.err { background: var(--danger); }
.qr { width: 200px; height: 200px; background: #fff; padding: 8px; border-radius: 6px; }

@media (max-width: 760px) {
  .menu-btn { display: inline-block; }
  .topbar { flex-wrap: wrap; }
  .topbar nav { display: none; width: 100%; flex-direction: column; }
  .topbar nav.open { display: flex; }
  .grid2 { grid-template-columns: 1fr; }
  .item .who { max-width: 50%; }
  table.responsive thead { display: none; }
  table.responsive td { display: block; border: 0; padding: .2rem .5rem; }
  table.responsive tr { display: block; border-bottom: 1px solid var(--border); padding: .5rem 0; }
  main { padding: .5rem; }
}
