:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --border: #e3e8f0;
  --text: #1a2233;
  --text-dim: #67718a;
  --accent: #2563eb;
  --accent-soft: #eaf1ff;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.07), 0 8px 24px rgba(16, 24, 40, 0.05);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }

button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 8px;
  padding: 7px 12px;
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: #f0f3f9; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #1d4fd8; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: #fdf0f0; border-color: #f3c3c3; }
.btn-ghost { border: none; background: transparent; color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); background: #eef1f7; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }

/* ---------- Login ---------- */
.login-screen {
  height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #dbeafe 0%, #f4f6fb 50%, #ede9fe 100%);
}
.login-card {
  background: var(--panel);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 44px 40px;
  width: 360px;
  text-align: center;
}
.login-logo { font-size: 42px; }
.login-card h1 { margin: 8px 0 2px; font-size: 24px; }
.login-sub { color: var(--text-dim); margin: 0 0 24px; font-size: 14px; }
.login-card input {
  width: 100%; margin-bottom: 12px;
  padding: 11px 14px;
  border: 1px solid var(--border); border-radius: 10px;
  background: #fafbfe;
}
.login-card input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.login-error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ---------- Layout ---------- */
.app { display: flex; height: 100vh; }

.sidebar {
  width: 230px; flex-shrink: 0;
  display: flex; flex-direction: column;
  padding: 18px 14px;
  border-right: 1px solid var(--border);
  background: var(--panel);
}
.brand { font-weight: 700; font-size: 17px; margin-bottom: 18px; display: flex; gap: 8px; align-items: center; }
.compose-btn { margin-bottom: 18px; padding: 10px; border-radius: 10px; font-weight: 600; }

.nav-section {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-dim); margin: 14px 6px 6px;
}
.nav-item {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%;
  padding: 8px 10px; margin-bottom: 2px;
  border: none; border-radius: 8px;
  background: transparent; color: var(--text);
  text-align: left; font-size: 14px;
}
.nav-item:hover { background: #f0f3f9; }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .badge {
  background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700;
  border-radius: 999px; padding: 1px 7px;
}
.nav-item.active .badge { background: var(--accent); }

.sidebar-footer { margin-top: auto; font-size: 12px; color: var(--text-dim); }
.sync-status { margin-bottom: 6px; line-height: 1.4; }
.sync-status .warn { color: #b45309; }
.user-row { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; font-weight: 600; color: var(--text); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.toolbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.toolbar input[type="search"] {
  flex: 0 0 320px;
  padding: 9px 14px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg);
}
.toolbar input[type="search"]:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.list-title { color: var(--text-dim); font-size: 13px; }

.panes { flex: 1; display: flex; min-height: 0; }

/* ---------- Email list ---------- */
.email-list {
  width: 380px; flex-shrink: 0;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--panel);
}
.email-row {
  display: block; width: 100%; text-align: left;
  padding: 12px 16px;
  border: none; border-bottom: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
}
.email-row:hover { background: #f7f9fd; }
.email-row.selected { background: var(--accent-soft); }
.email-row .row1 { display: flex; justify-content: space-between; gap: 8px; }
.email-row .from { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.email-row.unread .from::before { content: "●"; color: var(--accent); font-size: 10px; margin-right: 6px; vertical-align: 1px; }
.email-row .date { color: var(--text-dim); font-size: 12px; flex-shrink: 0; }
.email-row .subject { font-size: 13.5px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.email-row.unread .subject { font-weight: 600; }
.email-row .preview { color: var(--text-dim); font-size: 12.5px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.email-row .chips { margin-top: 5px; display: flex; gap: 5px; }
.chip {
  font-size: 10.5px; font-weight: 600;
  padding: 1px 8px; border-radius: 999px;
}
.chip.dev { background: #e0edff; color: #1d4fd8; }
.chip.brindha { background: #fce7f3; color: #be185d; }
.chip.shared { background: #dcfce7; color: #15803d; }
.chip.star { background: #fef3c7; color: #b45309; }
.chip.attach { background: #ede9fe; color: #6d28d9; }
.list-empty { padding: 40px 20px; text-align: center; color: var(--text-dim); }

/* ---------- Reader ---------- */
.reader { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
.reader-empty {
  margin: auto; text-align: center; color: var(--text-dim);
}
.reader-empty-icon { font-size: 46px; }
.reader-content {
  flex: 1; display: flex; flex-direction: column;
  padding: 20px 26px; min-height: 0;
}
.reader-actions { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.reader-content h2 { margin: 0 0 12px; font-size: 20px; }
.reader-meta { display: flex; gap: 12px; align-items: center; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; flex-shrink: 0;
}
.reader-from { font-weight: 600; font-size: 14px; }
.reader-to { color: var(--text-dim); font-size: 12.5px; margin-top: 1px; }
.reader-date { margin-left: auto; color: var(--text-dim); font-size: 12.5px; }
.reader-tags { margin: 10px 0 0; display: flex; gap: 6px; }
.reader-attachments { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.attachment-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 999px;
  font-size: 12.5px; text-decoration: none; color: var(--text);
}
.attachment-pill:hover { border-color: var(--accent); color: var(--accent); }
.reader-frame {
  flex: 1; margin-top: 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: #fff; width: 100%;
}

/* ---------- Compose modal ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(16, 24, 40, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal-card {
  width: 620px; max-width: calc(100vw - 32px); max-height: calc(100vh - 60px);
  overflow-y: auto;
  background: var(--panel); border-radius: 16px; box-shadow: var(--shadow);
  padding: 20px 24px;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 16px; margin-bottom: 14px; }
.modal-card label { display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 10px; }
.modal-card input, .modal-card select, .modal-card textarea {
  display: block; width: 100%; margin-top: 4px;
  padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: #fafbfe; color: var(--text);
}
.modal-card textarea { resize: vertical; }
.modal-card input:focus, .modal-card select:focus, .modal-card textarea:focus {
  outline: 2px solid var(--accent-soft); border-color: var(--accent);
}
.modal-footer { display: flex; justify-content: flex-end; align-items: center; gap: 12px; margin-top: 14px; }
.compose-error { color: var(--danger); font-size: 13px; flex: 1; }
.compose-attach { margin: 4px 0 12px; }
.compose-attach-btn { display: inline-flex; align-items: center; cursor: pointer; }
.compose-file-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.compose-file-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #f0f3f9; border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 10px; font-size: 12.5px;
}
.compose-file-chip button {
  border: none; background: transparent; color: var(--text-dim);
  cursor: pointer; padding: 0; font-size: 14px; line-height: 1;
}
.compose-file-chip button:hover { color: var(--danger); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #111827; color: #fff;
  padding: 10px 18px; border-radius: 10px;
  font-size: 14px; box-shadow: var(--shadow); z-index: 100;
}
