:root {
  --bg: #0f1117;
  --panel: #161923;
  --panel-2: #1d212e;
  --border: #2a2f3d;
  --text: #e7e9ee;
  --muted: #9096a8;
  --accent: #4f7cff;
  --danger: #ff5c5c;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.75rem; }
.error { color: var(--danger); font-size: 0.85rem; }

button { font: inherit; cursor: pointer; }
input, textarea, select {
  font: inherit; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 0.5rem 0.6rem; width: 100%;
}
label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.7rem; }
label input, label select, label textarea { margin-top: 0.25rem; color: var(--text); }

.primary-btn {
  background: var(--accent); color: white; border: none; border-radius: 6px;
  padding: 0.55rem 0.9rem; font-weight: 600;
}
.primary-btn:hover { filter: brightness(1.08); }
.ghost-btn {
  background: transparent; color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 0.45rem 0.75rem;
}
.ghost-btn:hover { border-color: var(--accent); }
.link-btn { background: none; border: none; color: var(--muted); text-decoration: underline; }

/* ---------- Auth ---------- */
.auth-screen { height: 100vh; display: flex; align-items: center; justify-content: center; }
.auth-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 2rem; width: 320px;
}
.auth-card h1 { margin: 0 0 0.25rem; }

/* ---------- App layout ---------- */
.app { display: grid; grid-template-columns: 240px 340px 1fr; height: 100vh; }

.sidebar {
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 1rem;
}
.sidebar-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.sidebar-header h1 { font-size: 1.1rem; margin: 0; }

.account-list { display: flex; flex-direction: column; gap: 0.25rem; margin-top: 1rem; flex: 1; overflow-y: auto; }
.account-item {
  display: flex; align-items: center; gap: 0.5rem; text-align: left;
  background: transparent; border: none; color: var(--text); border-radius: 6px;
  padding: 0.5rem 0.6rem;
}
.account-item:hover { background: var(--panel-2); }
.account-item.active { background: var(--panel-2); font-weight: 600; }
.account-item .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.account-item .err { color: var(--danger); margin-left: auto; font-size: 0.9rem; }

.sidebar-footer { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.5rem; }

/* ---------- Message list ---------- */
.message-pane { border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.toolbar { padding: 0.75rem; border-bottom: 1px solid var(--border); display: flex; gap: 0.5rem; align-items: center; }
.unread-toggle { display: flex; align-items: center; gap: 0.3rem; font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
.unread-toggle input { width: auto; }

.message-list { overflow-y: auto; flex: 1; }
.message-row {
  padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--border); cursor: pointer;
}
.message-row:hover { background: var(--panel-2); }
.message-row.selected { background: var(--panel-2); border-left: 3px solid var(--accent); }
.message-row.unread .m-subject { font-weight: 700; }
.message-row .m-top { display: flex; justify-content: space-between; gap: 0.5rem; }
.message-row .m-from { font-size: 0.85rem; }
.message-row .m-date { font-size: 0.72rem; color: var(--muted); white-space: nowrap; }
.message-row .m-subject { font-size: 0.88rem; margin: 0.15rem 0; }
.message-row .m-snippet { font-size: 0.78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-row .m-account { font-size: 0.68rem; padding: 0.05rem 0.4rem; border-radius: 999px; display: inline-block; margin-top: 0.25rem; }

/* ---------- Reader ---------- */
.reader-pane { display: flex; flex-direction: column; overflow: hidden; }
.reader-empty { margin: auto; color: var(--muted); }
.reader { display: flex; flex-direction: column; height: 100%; }
.reader-header { padding: 1rem; border-bottom: 1px solid var(--border); }
.reader-header h2 { margin: 0 0 0.4rem; font-size: 1.15rem; }
.reader-meta { display: flex; justify-content: space-between; font-size: 0.85rem; margin-bottom: 0.6rem; }
.reader-actions { display: flex; gap: 0.5rem; }
.reader-body { flex: 1; border: none; width: 100%; background: white; }

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 10;
}
.modal-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 1.5rem; width: 420px; max-height: 85vh; overflow-y: auto;
}
.modal-card h2 { margin-top: 0; }
.modal-card h3 { font-size: 0.85rem; color: var(--muted); margin: 1rem 0 0.5rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }
.row { display: flex; gap: 0.5rem; }
.row .grow { flex: 1; }
.row .narrow { width: 90px; }
.checkbox { display: flex; align-items: center; gap: 0.4rem; flex-direction: row-reverse; justify-content: flex-end; }
.checkbox input { width: auto; }
