:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --panel2: #243044;
  --border: #2d3a4f;
  --text: #e7ecf3;
  --muted: #8b9bb4;
  --accent: #3b82f6;
  --accent2: #22c55e;
  --danger: #ef4444;
  --warn: #f59e0b;
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

.boot { padding: 40px; text-align: center; color: var(--muted); }

.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 5; border-right: none; border-bottom: 1px solid var(--border); }
  .nav-folders { display: flex; flex-wrap: wrap; gap: 6px; }
  .nav-folders button { flex: 1 1 auto; text-align: center; }
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.brand { font-weight: 700; font-size: 18px; padding: 4px 8px; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; margin-top: 2px; }
.nav-folders button, .sidebar .btn {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
}
.nav-folders button:hover, .sidebar .btn:hover { background: var(--panel2); }
.nav-folders button.active { background: var(--accent); color: #fff; font-weight: 600; }

.main { display: flex; flex-direction: column; min-height: 100vh; min-width: 0; }
.topbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--panel);
}
.topbar .search { flex: 1; min-width: 160px; }
.topbar input[type="search"], .field input, .field textarea, .field select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
}
.toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 16px;
  border-bottom: 1px solid var(--border); background: #121820;
}
.btn {
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
}
.btn:hover { filter: brightness(1.1); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { background: #3b1515; border-color: #7f1d1d; color: #fecaca; }
.btn-success { background: #14532d; border-color: #166534; color: #bbf7d0; }
.btn-ghost { background: transparent; }

.content { display: grid; grid-template-columns: 1fr 1.1fr; flex: 1; min-height: 0; }
@media (max-width: 900px) {
  .content { grid-template-columns: 1fr; }
  .reader { border-left: none; border-top: 1px solid var(--border); min-height: 40vh; }
}

.list { overflow: auto; max-height: calc(100vh - 130px); }
.msg-row {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.msg-row:hover { background: var(--panel); }
.msg-row.active { background: var(--panel2); }
.msg-row.unread .subject { font-weight: 700; }
.msg-row .from { font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-row .subject { font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-row .snippet { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-row .date { font-size: 11px; color: var(--muted); margin-top: 4px; }

.reader { border-left: 1px solid var(--border); padding: 16px; overflow: auto; max-height: calc(100vh - 130px); background: #11161e; }
.reader h2 { margin: 0 0 8px; font-size: 18px; }
.reader .meta { font-size: 13px; color: var(--muted); margin-bottom: 16px; line-height: 1.5; }
.reader .body { white-space: pre-wrap; font-size: 14px; line-height: 1.55; }

.empty { padding: 32px; text-align: center; color: var(--muted); }

.login-screen {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(ellipse at top, #1e3a5f 0%, var(--bg) 55%);
}
.login-card {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
}
.login-card h1 { margin: 0 0 8px; font-size: 24px; }
.login-card p { color: var(--muted); line-height: 1.5; }
.login-card .btn-primary { width: 100%; padding: 12px; font-size: 15px; margin-top: 12px; }
.note { font-size: 12px; color: var(--muted); margin-top: 16px; background: var(--bg); padding: 10px; border-radius: 8px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: grid; place-items: center; z-index: 50; padding: 16px;
}
.modal {
  width: min(560px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  max-height: 90vh; overflow: auto;
}
.modal h3 { margin: 0 0 12px; }
.field { margin-bottom: 10px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field textarea { min-height: 140px; resize: vertical; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 12px; }

.toast {
  position: fixed; bottom: 18px; right: 18px; z-index: 99;
  background: var(--panel2); border: 1px solid var(--border);
  padding: 10px 14px; border-radius: 10px; font-size: 13px;
  box-shadow: 0 8px 30px rgba(0,0,0,.35);
}
.toast.error { border-color: #7f1d1d; color: #fecaca; }
.toast.ok { border-color: #166534; color: #bbf7d0; }

.sched-list { padding: 12px 16px; }
.sched-item {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; margin-bottom: 8px;
}
.sched-item .row { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.badge {
  display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--panel2); color: var(--muted);
}
.badge.pending { background: #422006; color: #fcd34d; }
.badge.sent { background: #14532d; color: #bbf7d0; }
.badge.failed { background: #450a0a; color: #fecaca; }
