:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: #e2e5ea;
  --text: #1c2430;
  --muted: #6b7686;
  --accent: #2f6df6;
  --accent-dark: #2457cc;
  --danger: #d33a3a;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}
.hidden { display: none !important; }
button {
  font: inherit;
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
button:hover { background: var(--accent-dark); }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
button.ghost:hover { background: #eef0f3; color: var(--text); }
.msg { min-height: 1.2em; font-size: 0.9rem; color: var(--danger); }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.06);
}
.login-box h1 { margin: 0 0 20px; font-size: 1.4rem; }
.login-box label, .modal-box label { display: block; margin-bottom: 14px; font-size: 0.85rem; color: var(--muted); }
.login-box input, .modal-box input, .modal-box textarea {
  display: block; width: 100%; margin-top: 5px;
  padding: 10px; border: 1px solid var(--line); border-radius: 6px;
  font: inherit; color: var(--text); background: #fff;
}
.login-box button { width: 100%; margin-top: 6px; }

/* App layout */
.app { height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; }
.whoami { color: var(--muted); font-size: 0.9rem; margin-right: auto; }
.layout { flex: 1; display: grid; grid-template-columns: 220px 340px 1fr; min-height: 0; }
.folders, .list, .reader { overflow-y: auto; min-height: 0; }
.folders { background: var(--panel); border-right: 1px solid var(--line); padding: 8px; }
.list { background: #fbfbfc; border-right: 1px solid var(--line); }
.reader { padding: 20px 24px; }

.folder {
  padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 0.9rem;
  display: flex; justify-content: space-between; align-items: center;
}
.folder:hover { background: #eef0f3; }
.folder.active { background: var(--accent); color: #fff; }

.msgrow {
  padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.msgrow:hover { background: #eef2fb; }
.msgrow.active { background: #e2ebfe; }
.msgrow.unread .msgrow-from, .msgrow.unread .msgrow-subject { font-weight: 700; }
.msgrow-top { display: flex; justify-content: space-between; gap: 8px; }
.msgrow-from { font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msgrow-date { font-size: 0.75rem; color: var(--muted); white-space: nowrap; }
.msgrow-subject { font-size: 0.85rem; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }

.reader .hint { color: var(--muted); }
.reader-head { border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 16px; }
.reader-head h2 { margin: 0 0 8px; font-size: 1.2rem; }
.reader-meta { font-size: 0.85rem; color: var(--muted); line-height: 1.6; }
.reader-actions { margin: 12px 0; display: flex; gap: 8px; }
.reader-body { line-height: 1.55; white-space: pre-wrap; word-wrap: break-word; }
.reader-body iframe { width: 100%; border: none; min-height: 60vh; }
.attachments { margin-top: 16px; font-size: 0.85rem; color: var(--muted); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: grid; place-items: center; padding: 20px; }
.modal-box {
  background: var(--panel); border-radius: 12px; padding: 24px; width: 100%; max-width: 560px;
  max-height: 90vh; overflow-y: auto;
}
.modal-box h2 { margin: 0 0 16px; }
.modal-actions { display: flex; gap: 10px; margin-top: 4px; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .folders, .list { max-height: 30vh; }
}
