:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #e4e6eb;
  --text: #1a1a1f;
  --muted: #6b7280;
  --accent: #245bff;
  --accent-ink: #ffffff;
  --hover: #f0f3ff;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: #c0392b; font-size: 13px; min-height: 18px; margin-top: 4px; }

/* Login */
.login { display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 32px; width: 320px; display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,.08);
}
.login-card input, .login-card button { padding: 11px 13px; border-radius: 10px; font-size: 15px; }
.login-card input { border: 1px solid var(--border); }
.login-card button { border: 0; background: var(--accent); color: var(--accent-ink); cursor: pointer; font-weight: 600; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.logo { display: inline-grid; place-items: center; width: 28px; height: 28px; background: var(--accent); color: #fff; border-radius: 8px; }

/* App layout */
.app { display: grid; grid-template-columns: 240px 340px 1fr; height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); padding: 18px 14px; display: flex; flex-direction: column; gap: 14px; }
.compose { border: 0; background: var(--accent); color: #fff; padding: 11px; border-radius: 12px; font-weight: 600; cursor: pointer; }
nav { display: flex; flex-direction: column; gap: 2px; }
.nav { padding: 9px 11px; border-radius: 10px; cursor: pointer; color: var(--text); text-decoration: none; }
.nav:hover { background: var(--hover); }
.nav.active { background: var(--hover); font-weight: 600; }
.spacer { flex: 1; }
.account { border-top: 1px solid var(--border); padding-top: 12px; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 4px 0; font-size: 13px; }

.list-pane { border-right: 1px solid var(--border); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.list-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.list-head h2 { margin: 0; font-size: 16px; }
.ghost { background: none; border: 0; font-size: 18px; cursor: pointer; color: var(--muted); }
.list { overflow-y: auto; }
.row { padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; }
.row:hover { background: var(--hover); }
.row.active { background: var(--hover); }
.row .top { display: flex; justify-content: space-between; gap: 8px; }
.row .who { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.row .subj { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: #eef; color: var(--accent); margin-left: 6px; }

.read-pane { min-height: 0; overflow-y: auto; }
.reader { padding: 28px 32px; }
.reader.empty { display: grid; place-items: center; height: 100%; }
.empty-state { color: var(--muted); text-align: center; max-width: 360px; }
.msg-subject { font-size: 22px; font-weight: 700; margin: 0 0 6px; }
.msg-meta { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.msg-body { white-space: pre-wrap; }
.notice { background: #fff8e1; border: 1px solid #ffe08a; color: #7a5a00; padding: 14px 16px; border-radius: 12px; margin: 16px; font-size: 13px; }

/* Compose modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; }
.compose-card { background: var(--panel); width: min(640px, 92vw); border-radius: 16px; padding: 18px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.compose-card header { display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.compose-card label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; }
.compose-card input, .compose-card textarea { border: 1px solid var(--border); border-radius: 10px; padding: 10px; font: inherit; color: var(--text); }
.compose-card input:disabled { background: #f6f7f9; color: var(--muted); }
.compose-card footer { display: flex; justify-content: space-between; align-items: center; }
#send-btn { border: 0; background: var(--accent); color: #fff; padding: 10px 20px; border-radius: 10px; font-weight: 600; cursor: pointer; }
#send-btn:disabled { opacity: .6; cursor: default; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; }
  .sidebar { flex-direction: row; align-items: center; flex-wrap: wrap; }
  .sidebar .spacer { display: none; }
}
