:root {
  --accent: #7c3aed;
  --accent-soft: #ede9fe;
  --bg: #f6f5fa;
  --panel: #ffffff;
  --ink: #1f1a2e;
  --muted: #6b6480;
  --line: #e4e1ee;
  --mark: #fde68a;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(31, 26, 46, .06), 0 4px 16px rgba(31, 26, 46, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --accent-soft: #2e1f52; --bg: #14111c; --panel: #1d1927; --ink: #efeaf7; --muted: #9c95b1; --line: #2c2739; --mark: #6b5b12;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
h1, h2, h3 { margin: 0 0 8px; font-weight: 600; }
h1 { font-size: 20px; } h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); } h3 { font-size: 17px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: 8px 0 0; }
[hidden] { display: none !important; }

.screen { min-height: 100%; }
.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; width: min(420px, calc(100% - 32px)); margin: 10vh auto; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.logo { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, var(--accent), #a78bfa); position: relative; flex: none; }
.logo::after { content: ""; position: absolute; inset: 10px; border: 2px solid #fff; border-radius: 3px; }
.logo.small { width: 28px; height: 28px; border-radius: 8px; } .logo.small::after { inset: 8px; }

label { display: block; margin: 12px 0 0; font-size: 13px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; }
input, select { width: 100%; margin-top: 4px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); font: inherit; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
label.check input { width: auto; margin: 0; }

.btn { padding: 9px 14px; border-radius: 8px; border: 1px solid transparent; font: inherit; cursor: pointer; text-decoration: none; display: inline-block; }
.btn.primary { background: var(--accent); color: #fff; margin-top: 16px; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary.ok { background: var(--ok); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); margin-top: 0; }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.danger { color: var(--danger); }
.icon-btn { border: 0; background: transparent; font-size: 20px; color: var(--ink); cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--accent-soft); }

.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar .title { flex: 1; }
.search { flex: 1; display: flex; gap: 6px; align-items: center; }
.search input { margin: 0; }
.user { display: flex; align-items: center; gap: 8px; }
.user .muted { font-size: 13px; }

.layout { display: grid; grid-template-columns: 260px 1fr; min-height: calc(100vh - 57px); }
.panel { background: var(--panel); border-right: 1px solid var(--line); padding: 16px; }
.panel .btn { margin-top: 16px; width: 100%; }
.results { padding: 12px 16px 40px; }
.meta { font-size: 13px; margin: 4px 0 8px; }
.list { list-style: none; margin: 0; padding: 0; }
.hit { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 8px; cursor: pointer; }
.hit:hover, .hit.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.hit .line1 { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--muted); }
.hit .subject { font-weight: 600; margin: 2px 0; }
.hit .snippet { font-size: 13px; color: var(--muted); }
.hit mark, .preview mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); margin-left: 6px; }
.badge.out { background: #dcfce7; color: #166534; }

.preview { position: fixed; inset: 57px 0 0 0; background: var(--panel); z-index: 6; overflow: auto; }
@media (min-width: 1100px) { .preview { left: auto; width: 48vw; border-left: 1px solid var(--line); } }
.preview-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions .btn.primary { margin-top: 0; }
#preview-body { padding: 16px 20px 40px; }
.hdr { display: grid; grid-template-columns: 70px 1fr; gap: 4px 8px; font-size: 13px; margin-bottom: 14px; }
.hdr dt { color: var(--muted); } .hdr dd { margin: 0; word-break: break-word; }
.body { white-space: pre-wrap; word-break: break-word; font-size: 14px; }
.attachments { margin: 14px 0; display: flex; gap: 8px; flex-wrap: wrap; }
.attachments a { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 13px; text-decoration: none; color: var(--ink); }

.admin { padding: 16px; max-width: 1100px; margin: 0 auto; }
.admin .card { width: auto; margin: 0 0 16px; padding: 18px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; }
.row { display: flex; gap: 8px; margin-top: 14px; justify-content: flex-end; }
.row .btn.primary { margin-top: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }

dialog { border: 0; border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; width: min(420px, calc(100% - 32px)); background: var(--panel); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.4); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 20; box-shadow: var(--shadow); }
.toast.ok { background: var(--ok); color: #fff; } .toast.err { background: var(--danger); color: #fff; }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .panel { display: none; }
  .panel.open { display: block; border-right: 0; border-bottom: 1px solid var(--line); }
  .user .muted { display: none; }
  .hdr { grid-template-columns: 1fr; }
}
