:root {
  --bg: #f6f8fc;
  --surface: #fff;
  --sidebar-w: 256px;
  --primary: #1a73e8;
  --primary-hover: #1765cc;
  --text: #202124;
  --muted: #5f6368;
  --border: #e0e0e0;
  --unread-bg: #f2f6fc;
  --star: #f4b400;
  --compose-shadow: 0 8px 10px 1px rgba(0,0,0,.14), 0 3px 14px 2px rgba(0,0,0,.12);
  --font: 'Roboto', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; }

/* Auth */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #e8f0fe 0%, #f6f8fc 100%); }
.auth-card { background: var(--surface); padding: 48px 40px; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.12); width: 100%; max-width: 420px; }
.auth-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.gmail-m { display: inline-flex; width: 40px; height: 40px; background: linear-gradient(135deg, #ea4335, #fbbc04, #34a853, #4285f4); border-radius: 8px; color: #fff; font-weight: 700; font-size: 22px; align-items: center; justify-content: center; }
.auth-logo h1 { font-size: 22px; font-weight: 400; }
.auth-sub { color: var(--muted); margin-bottom: 24px; font-size: 14px; }
.auth-form label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; }
.auth-form input { width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 4px; font-size: 15px; }
.auth-form input:focus { outline: 2px solid var(--primary); border-color: transparent; }
.username-row { display: flex; align-items: center; gap: 4px; }
.username-row input { flex: 1; }
.domain-suffix { color: var(--muted); font-size: 15px; white-space: nowrap; }
.btn-primary { width: 100%; margin-top: 24px; padding: 12px; background: var(--primary); color: #fff; border: none; border-radius: 24px; font-size: 14px; font-weight: 500; cursor: pointer; }
.btn-primary:hover { background: var(--primary-hover); }
.auth-error { background: #fce8e6; color: #c5221f; padding: 10px 12px; border-radius: 4px; font-size: 13px; margin-bottom: 12px; }
.auth-footer { margin-top: 24px; text-align: center; font-size: 13px; color: var(--muted); }
.auth-footer a { color: var(--primary); text-decoration: none; }

/* Top bar */
.top-bar { display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--bg); position: sticky; top: 0; z-index: 100; }
.search-wrap { flex: 1; max-width: 720px; display: flex; align-items: center; background: #eaf1fb; border-radius: 24px; padding: 0 16px; height: 48px; }
.search-wrap:focus-within { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.search-icon { opacity: .6; margin-right: 8px; }
.search-form { flex: 1; }
.search-input { width: 100%; border: none; background: transparent; font-size: 16px; outline: none; }
.top-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.user-chip { font-size: 13px; color: var(--muted); background: #e8eaed; padding: 6px 12px; border-radius: 16px; }
.icon-btn { background: none; border: none; cursor: pointer; font-size: 18px; padding: 8px; border-radius: 50%; color: var(--muted); text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: rgba(0,0,0,.06); }

/* Shell */
.app-shell { display: flex; min-height: calc(100vh - 64px); }
.sidebar { width: var(--sidebar-w); padding: 8px 8px 8px 4px; flex-shrink: 0; }
.compose-btn { display: flex; align-items: center; gap: 12px; margin: 8px 8px 16px; padding: 0 24px 0 16px; height: 56px; background: #c2e7ff; border: none; border-radius: 16px; font-size: 14px; font-weight: 500; cursor: pointer; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.1); }
.compose-btn:hover { box-shadow: 0 1px 3px rgba(0,0,0,.2); background: #a8d9ff; }
.folder-nav { display: flex; flex-direction: column; gap: 2px; }
.folder-link { display: flex; align-items: center; gap: 16px; padding: 0 12px 0 26px; height: 32px; border-radius: 0 16px 16px 0; text-decoration: none; color: var(--text); font-size: 14px; }
.folder-link:hover, .folder-link.active { background: #d3e3fd; font-weight: 500; }
.folder-link.muted { color: var(--muted); }
.folder-icon { width: 20px; text-align: center; font-size: 14px; }
.more-folders summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 16px; padding: 0 12px 0 26px; height: 32px; font-size: 14px; border-radius: 0 16px 16px 0; }
.more-folders summary::-webkit-details-marker { display: none; }
.more-folders[open] summary { font-weight: 500; }

/* Main */
.mail-main { flex: 1; background: var(--surface); border-radius: 16px 0 0 0; margin-right: 16px; overflow: hidden; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.category-tabs { display: flex; border-bottom: 1px solid var(--border); padding: 0 16px; }
.tab { padding: 14px 16px; text-decoration: none; color: var(--muted); font-size: 14px; font-weight: 500; border-bottom: 3px solid transparent; display: flex; align-items: center; gap: 8px; }
.tab:hover { background: #f1f3f4; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.badge { background: var(--primary); color: #fff; font-size: 11px; padding: 2px 6px; border-radius: 10px; min-width: 18px; text-align: center; }

.toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-bottom: 1px solid var(--border); }
.toolbar-spacer { flex: 1; }
.msg-count { font-size: 12px; color: var(--muted); }

.message-list { list-style: none; }
.message-row { display: flex; align-items: center; padding: 0 8px; border-bottom: 1px solid #f0f0f0; height: 40px; }
.message-row:hover { box-shadow: inset 1px 0 0 #dadce0, inset -1px 0 0 #dadce0, 0 1px 2px rgba(0,0,0,.1); z-index: 1; position: relative; }
.message-row.unread { background: var(--unread-bg); font-weight: 500; }
.msg-check { margin: 0 4px; }
.star-btn { background: none; border: none; cursor: pointer; font-size: 18px; color: #dadce0; padding: 4px; }
.star-btn.starred { color: var(--star); }
.msg-link { flex: 1; display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; overflow: hidden; min-width: 0; padding: 0 8px; }
.msg-sender { width: 180px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.msg-subject-line { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; min-width: 0; }
.msg-subject { color: var(--text); }
.message-row.unread .msg-subject { font-weight: 700; }
.msg-snippet { color: var(--muted); font-weight: 400; }
.msg-attachments { display: flex; gap: 4px; flex-shrink: 0; }
.attach-chip { font-size: 11px; background: #f1f3f4; padding: 2px 8px; border-radius: 4px; color: var(--muted); white-space: nowrap; }
.msg-date { width: 80px; text-align: right; font-size: 12px; color: var(--muted); flex-shrink: 0; }
.empty-inbox { padding: 48px; text-align: center; color: var(--muted); }
.mail-error { padding: 16px; background: #fce8e6; color: #c5221f; margin: 16px; border-radius: 4px; font-size: 14px; }

/* Compose modal */
.compose-modal { position: fixed; bottom: 0; right: 24px; z-index: 200; }
.compose-modal.hidden { display: none; }
.compose-window { width: 500px; max-width: calc(100vw - 48px); background: var(--surface); border-radius: 8px 8px 0 0; box-shadow: var(--compose-shadow); }
.compose-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: #404040; color: #fff; border-radius: 8px 8px 0 0; font-size: 14px; }
.compose-header .icon-btn { color: #fff; }
.compose-field { display: flex; align-items: center; border-bottom: 1px solid var(--border); padding: 4px 16px; }
.compose-field label { width: 48px; font-size: 13px; color: var(--muted); }
.compose-field input { flex: 1; border: none; padding: 8px 0; font-size: 14px; outline: none; }
.compose-window textarea { width: 100%; border: none; padding: 16px; font-size: 14px; font-family: inherit; resize: vertical; outline: none; }
.compose-actions { padding: 12px 16px; display: flex; align-items: center; gap: 12px; }
.btn-send { background: var(--primary); color: #fff; border: none; padding: 10px 24px; border-radius: 24px; font-weight: 500; cursor: pointer; }
.btn-send:hover { background: var(--primary-hover); }
.btn-secondary { display: inline-block; padding: 10px 20px; border: 1px solid var(--border); border-radius: 24px; text-decoration: none; color: var(--text); font-size: 14px; }
.send-status { font-size: 13px; color: var(--muted); }

/* Read view */
.read-container { max-width: 900px; margin: 0 auto; padding: 24px; background: var(--surface); min-height: calc(100vh - 64px); border-radius: 16px 16px 0 0; }
.email-subject { font-size: 22px; font-weight: 400; margin-bottom: 16px; }
.email-meta { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.email-from strong { display: block; font-size: 14px; }
.email-addr { font-size: 12px; color: var(--muted); }
.email-date { font-size: 12px; color: var(--muted); }
.email-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.email-body { font-size: 14px; line-height: 1.6; }
.email-text { white-space: pre-wrap; font-family: inherit; border: none; background: none; }
.email-html img { max-width: 100%; }
.read-actions { margin-top: 32px; display: flex; gap: 12px; }

@media (max-width: 768px) {
  .sidebar { position: fixed; left: -280px; top: 64px; bottom: 0; background: var(--bg); z-index: 150; transition: left .2s; }
  .sidebar.open { left: 0; }
  .msg-sender { width: 100px; }
  .category-tabs { overflow-x: auto; }
}
