:root {
  --bg: #f5f6fa;
  --panel: #ffffff;
  --border: #e3e5ec;
  --text: #1c1e26;
  --text-muted: #6b7280;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --danger: #dc2626;
  --unread-dot: #4f46e5;
  --radius: 10px;
}

* { box-sizing: border-box; }

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

.screen { height: 100%; }
.screen[hidden] { display: none !important; }

/* ---------- Login ---------- */

#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 340px;
  box-shadow: 0 10px 30px rgba(20, 20, 40, 0.06);
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 22px;
}

.login-card .subtitle {
  margin: 0 0 24px;
  color: var(--text-muted);
  font-size: 14px;
}

.login-card label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.login-card input,
.modal-card input,
.modal-card textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
}

.login-card input:focus,
.modal-card input:focus,
.modal-card textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--panel);
}

.error-msg {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
}
.btn-secondary:hover { background: var(--bg); }

.btn-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  text-decoration: underline;
}

#login-form .btn-primary { width: 100%; }

/* ---------- App layout ---------- */

.app-layout {
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  font-weight: 700;
  font-size: 16px;
  color: var(--accent);
}

.topbar-spacer { flex: 1; }

.current-email {
  color: var(--text-muted);
  font-size: 13px;
}

.main-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 200px 340px 1fr;
  overflow: hidden;
}

/* Folders */

.folder-list {
  border-right: 1px solid var(--border);
  padding: 16px 8px;
  overflow-y: auto;
}

.folder-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 2px;
}

.folder-item:hover { background: var(--bg); }
.folder-item.active { background: #eef2ff; color: var(--accent); font-weight: 600; }

.folder-badge {
  background: var(--accent);
  color: white;
  font-size: 11px;
  border-radius: 999px;
  padding: 1px 7px;
  min-width: 18px;
  text-align: center;
}

/* Message list */

.message-list-pane {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.pane-header {
  padding: 14px 16px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

.message-list {
  flex: 1;
  overflow-y: auto;
}

.message-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.message-item:hover { background: var(--bg); }
.message-item.selected { background: #eef2ff; }

.message-item .from-line {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  margin-bottom: 3px;
}

.message-item.unread .from-line { font-weight: 700; }

.unread-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--unread-dot);
  flex-shrink: 0;
  visibility: hidden;
}
.message-item.unread .unread-dot { visibility: visible; }

.message-item .subject-line {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.message-item.unread .subject-line { font-weight: 600; }

.message-item .date-line {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
}

.pagination {
  display: flex;
  justify-content: space-between;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

.pagination button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 13px;
}
.pagination button:disabled { opacity: 0.4; cursor: default; }

/* Reading pane */

.reading-pane {
  overflow-y: auto;
  padding: 24px 28px;
}

.reading-empty {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 40px;
  text-align: center;
}

.reading-header h2 {
  margin: 0 0 12px;
  font-size: 20px;
}

.reading-meta {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.reading-body-html {
  width: 100%;
  min-height: 400px;
  border: none;
}

.reading-body-text {
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
}

/* Modal de composição */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 40, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.modal-overlay[hidden] { display: none; }

.modal-card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 28px;
  width: 480px;
  max-width: 90vw;
  box-shadow: 0 20px 50px rgba(20, 20, 40, 0.2);
}

.modal-card h2 {
  margin: 0 0 18px;
  font-size: 18px;
}

.modal-card label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

/* Responsivo simples */
@media (max-width: 900px) {
  .main-grid { grid-template-columns: 1fr; }
  .folder-list, .message-list-pane { display: none; }
}
