:root {
  --bg: #0f1115;
  --panel: #171a21;
  --border: #262b36;
  --text: #e6e8ec;
  --muted: #8a90a0;
  --accent: #4f8cff;
  --accent-hover: #6ba0ff;
  --danger: #ff6b6b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.screen { height: 100vh; }
#login-view[hidden], #app-view[hidden] { display: none !important; }

/* Login */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card h1 {
  margin: 0 0 12px;
  font-size: 22px;
  text-align: center;
}
input, textarea {
  background: #0c0e12;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}
button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}
button:hover { background: var(--accent-hover); }
button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 400;
}
button.ghost:hover { background: var(--panel); }
.error { color: var(--danger); font-size: 13px; min-height: 16px; margin: 0; }

/* App shell */
#app-view { display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.brand { font-weight: 700; font-size: 18px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
#user-email { color: var(--muted); font-size: 13px; }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 360px 1fr;
  overflow: hidden;
}

.message-list {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}
.pager { display: flex; align-items: center; gap: 8px; }
.pager button { padding: 4px 10px; }
#messages { overflow-y: auto; flex: 1; }

.message-row {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.message-row:hover { background: var(--panel); }
.message-row.active { background: #1c2130; }
.message-row.unread .msg-subject { font-weight: 700; }
.msg-from { font-size: 13px; color: var(--muted); }
.msg-subject { font-size: 14px; margin: 2px 0; }
.msg-date { font-size: 11px; color: var(--muted); }

.message-view { padding: 24px; overflow-y: auto; }
.empty-state { color: var(--muted); text-align: center; margin-top: 60px; }
.msg-header { border-bottom: 1px solid var(--border); padding-bottom: 16px; margin-bottom: 16px; }
.msg-header h2 { margin: 0 0 8px; font-size: 20px; }
.msg-meta { color: var(--muted); font-size: 13px; }
.msg-body { white-space: pre-wrap; line-height: 1.6; font-size: 14px; }
.msg-body iframe { width: 100%; height: 70vh; border: none; background: white; border-radius: 8px; }

/* Compose modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal[hidden] { display: none; }
.compose-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 480px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.compose-card h2 { margin: 0 0 4px; font-size: 18px; }
.compose-card textarea { min-height: 180px; resize: vertical; }
.compose-actions { display: flex; justify-content: flex-end; gap: 10px; }
