/* Gmail-like Theme with Auto Light/Dark Mode */

/* Light Theme (default) */
:root {
  --bg: #f6f8fc;
  --sidebar-bg: #f6f8fc;
  --content-bg: #ffffff;
  --border: #e0e0e0;
  --text: #202124;
  --text-secondary: #5f6368;
  --primary: #1a73e8;
  --primary-hover: #1557b0;
  --red: #c5221f;
  --star-yellow: #f4b400;
  --star-empty: #dadce0;
  --unread-bg: #ffffff;
  --read-bg: #f2f6fc;
  --hover-bg: #f5f5f5;
  --selected-bg: #c2dbff;
  --success: #188038;
  --error: #c5221f;
  --shadow: 0 1px 2px 0 rgba(60,64,67,0.3), 0 1px 3px 1px rgba(60,64,67,0.15);
  --shadow-lg: 0 1px 3px 0 rgba(60,64,67,0.3), 0 4px 8px 3px rgba(60,64,67,0.15);
}

/* Dark Theme */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1f1f;
    --sidebar-bg: #2d2d2d;
    --content-bg: #292929;
    --border: #3c3c3c;
    --text: #e8eaed;
    --text-secondary: #9aa0a6;
    --primary: #8ab4f8;
    --primary-hover: #aecbfa;
    --red: #ea4335;
    --star-yellow: #fbbc04;
    --star-empty: #5f6368;
    --unread-bg: #292929;
    --read-bg: #202020;
    --hover-bg: #3c3c3c;
    --selected-bg: #394457;
    --success: #81c995;
    --error: #f28b82;
    --shadow: 0 1px 2px 0 rgba(0,0,0,0.3), 0 1px 3px 1px rgba(0,0,0,0.15);
    --shadow-lg: 0 1px 3px 0 rgba(0,0,0,0.3), 0 4px 8px 3px rgba(0,0,0,0.15);
  }
}

/* Reset and Base */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: 'Google Sans', Roboto, -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }

/* ============================================
   HEADER
   ============================================ */
.header {
  display: flex;
  flex-direction: row;
  align-items: center;
  padding: 8px 16px;
  background: var(--content-bg);
  border-bottom: 1px solid var(--border);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: 64px;
  gap: 16px;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
}
.menu-toggle:hover { background: var(--hover-bg); }

.logo {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  min-width: 200px;
}
.logo-icon { font-size: 28px; }
.logo-text {
  font-size: 22px;
  font-weight: 500;
  color: var(--text);
}

.back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 20px;
  color: var(--text);
  text-decoration: none;
}
.back-btn:hover { background: var(--hover-bg); text-decoration: none; }

.search-bar {
  flex: 1;
  display: flex;
  flex-direction: row;
  align-items: center;
  max-width: 720px;
  background: var(--bg);
  border-radius: 24px;
  padding: 0 16px;
  height: 48px;
}
.search-bar:focus-within {
  background: var(--content-bg);
  box-shadow: var(--shadow);
}
.search-icon {
  font-size: 18px;
  color: var(--text-secondary);
  margin-right: 12px;
}
.search-bar input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 16px;
  color: var(--text);
  outline: none;
}
.search-bar input::placeholder { color: var(--text-secondary); }

.header-spacer { flex: 1; }

.header-actions {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.live-indicator {
  color: var(--success);
  font-size: 10px;
  animation: pulse 2s infinite;
}
.live-indicator.active { color: var(--primary); }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.logout-link {
  color: var(--text-secondary);
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 4px;
}
.logout-link:hover { background: var(--hover-bg); text-decoration: none; }

/* User Menu */
.user-menu { position: relative; }
.user-btn {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 4px 4px;
  background: none;
  border: none;
  border-radius: 24px;
  cursor: pointer;
  color: var(--text);
}
.user-btn:hover { background: var(--hover-bg); }
.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 500;
}
.user-name {
  font-size: 13px;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dropdown-arrow { font-size: 12px; color: var(--text-secondary); }

.user-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  background: var(--content-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  min-width: 250px;
  z-index: 200;
}
.user-dropdown.show { display: block; }
.dropdown-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.dropdown-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 500;
}
.dropdown-info { flex: 1; }
.dropdown-email { font-weight: 500; font-size: 14px; }
.dropdown-role { font-size: 12px; color: var(--text-secondary); }
.dropdown-divider { height: 1px; background: var(--border); }
.dropdown-item {
  display: block;
  padding: 12px 16px;
  color: var(--text);
  font-size: 14px;
}
.dropdown-item:hover { background: var(--hover-bg); text-decoration: none; }

/* ============================================
   LAYOUT
   ============================================ */
.layout {
  display: flex;
  flex-direction: row;
  min-height: 100vh;
  padding-top: 64px;
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
  width: 256px;
  min-width: 256px;
  background: var(--sidebar-bg);
  padding: 8px 0;
  position: fixed;
  top: 64px;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 50;
}

.compose-btn {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  margin: 16px;
  padding: 14px 24px;
  background: var(--content-bg);
  border: none;
  border-radius: 16px;
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}
.compose-btn:hover { box-shadow: var(--shadow-lg); text-decoration: none; }
.compose-icon { font-size: 18px; }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 0;
}
.nav-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  height: 40px;
  margin: 0 8px 2px 8px;
  border-radius: 0 20px 20px 0;
  color: var(--text);
  font-size: 14px;
  text-decoration: none;
}
.nav-item:hover { background: var(--hover-bg); text-decoration: none; }
.nav-item.active {
  background: var(--selected-bg);
  font-weight: 600;
}
.nav-icon { font-size: 18px; width: 24px; text-align: center; }
.nav-label { flex: 1; }
.nav-badge {
  background: var(--red);
  color: white;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 12px 16px;
}

.sidebar-section { padding: 8px 16px; }
.sidebar-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  margin-bottom: 8px;
}
.filter-group { margin-bottom: 12px; }
.filter-label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.filter-select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--content-bg);
  color: var(--text);
  font-size: 13px;
}

/* ============================================
   MAIN CONTENT
   ============================================ */
.main-content {
  flex: 1;
  margin-left: 256px;
  background: var(--content-bg);
  min-height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
}

/* ============================================
   TOOLBAR
   ============================================ */
.toolbar {
  display: flex;
  flex-direction: row;
  align-items: center;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  min-height: 48px;
  background: var(--content-bg);
}
.toolbar-left {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 2px;
}
.toolbar-right {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.toolbar-btn {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 40px;
  height: 40px;
  padding: 0 12px;
  border: none;
  background: none;
  border-radius: 4px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
}
.toolbar-btn:hover { background: var(--hover-bg); }
.toolbar-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.toolbar-btn.primary { color: var(--primary); font-weight: 500; }
.toolbar-btn.starred { color: var(--star-yellow); }

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
}

.checkbox-wrapper {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  cursor: pointer;
}
.checkbox-wrapper input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--primary);
}
.checkmark { display: none; }

.pagination-info {
  font-size: 12px;
  color: var(--text-secondary);
  margin-right: 8px;
}
.pagination-btns {
  display: flex;
  flex-direction: row;
  gap: 2px;
}
.pagination-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: var(--text-secondary);
  font-size: 18px;
  text-decoration: none;
}
.pagination-btn:hover { background: var(--hover-bg); text-decoration: none; }
.pagination-btn.disabled { opacity: 0.3; pointer-events: none; }

/* ============================================
   EMAIL LIST
   ============================================ */
.email-list {
  flex: 1;
  background: var(--content-bg);
}

.email-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  height: 50px;
  padding: 0 8px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  background: var(--read-bg);
}
.email-row:hover { background: var(--hover-bg); }
.email-row.unread {
  background: var(--unread-bg);
  font-weight: 600;
}
.email-row.selected { background: var(--selected-bg); }

.email-row .checkbox-wrapper {
  flex-shrink: 0;
  width: 40px;
}

.star-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  font-size: 20px;
  color: var(--star-empty);
  cursor: pointer;
  border-radius: 50%;
}
.star-btn:hover { background: var(--hover-bg); color: var(--star-yellow); }
.star-btn.starred { color: var(--star-yellow); }

.email-link {
  flex: 1;
  display: flex;
  flex-direction: row;
  align-items: center;
  height: 100%;
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
  gap: 8px;
}
.email-link:hover { text-decoration: none; }

.email-sender {
  flex-shrink: 0;
  width: 180px;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-content {
  flex: 1;
  display: flex;
  flex-direction: row;
  align-items: baseline;
  overflow: hidden;
  min-width: 0;
}
.email-subject {
  flex-shrink: 0;
  max-width: 300px;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.email-preview {
  flex: 1;
  font-size: 14px;
  font-weight: 400;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-left: 4px;
}

.email-attachment {
  flex-shrink: 0;
  font-size: 16px;
  color: var(--text-secondary);
  margin: 0 8px;
}

.email-date {
  flex-shrink: 0;
  width: 80px;
  text-align: right;
  font-size: 12px;
  color: var(--text-secondary);
}
.email-row.unread .email-date { color: var(--text); font-weight: 600; }

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  text-align: center;
}
.empty-icon { font-size: 64px; opacity: 0.4; margin-bottom: 16px; }
.empty-text { font-size: 18px; color: var(--text); margin-bottom: 8px; }
.empty-subtext { font-size: 14px; color: var(--text-secondary); }

.pagination-footer {
  padding: 16px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
  border-top: 1px solid var(--border);
}

/* ============================================
   MESSAGE VIEW
   ============================================ */
.message-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0;
}

.message-toolbar {
  display: flex;
  flex-direction: row;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--content-bg);
  position: sticky;
  top: 64px;
  z-index: 10;
}
.message-toolbar .toolbar-left {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
}
.message-toolbar .toolbar-right {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.inline-form { display: inline; margin: 0; padding: 0; }

.message-content {
  padding: 24px;
  max-width: 900px;
}

.message-header { margin-bottom: 16px; }
.message-subject {
  font-size: 24px;
  font-weight: 400;
  margin: 0 0 12px 0;
  color: var(--text);
  line-height: 1.3;
}
.message-labels {
  display: flex;
  flex-direction: row;
  gap: 8px;
  flex-wrap: wrap;
}
.label {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 4px;
  background: var(--hover-bg);
  color: var(--text-secondary);
}
.label.starred { background: rgba(244, 180, 0, 0.2); color: var(--star-yellow); }
.label.unread { background: rgba(26, 115, 232, 0.1); color: var(--primary); }

.message-meta {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 16px;
  padding: 16px;
  background: var(--bg);
  border-radius: 8px;
  margin-bottom: 16px;
}
.sender-info {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 12px;
  flex: 1;
}
.sender-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 500;
  flex-shrink: 0;
}
.sender-details { flex: 1; }
.sender-name { font-size: 14px; }
.sender-email { color: var(--text-secondary); font-size: 13px; }
.recipient-line { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }
.cc-info { color: var(--text-secondary); }
.message-date {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.message-body {
  background: var(--content-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 16px;
}
.html-content iframe {
  width: 100%;
  min-height: 400px;
  border: none;
  background: white;
}
.text-version {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.text-version summary {
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13px;
}
.text-content {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  margin: 12px 0 0 0;
  font-size: 14px;
  line-height: 1.6;
}
.empty-body {
  color: var(--text-secondary);
  font-style: italic;
}

/* Attachments */
.attachments-section {
  background: var(--bg);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}
.attachments-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 14px;
  color: var(--text-secondary);
}
.attachments-list {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 8px;
}
.attachment-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--content-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
}
.attachment-item:hover { background: var(--hover-bg); text-decoration: none; }
.attachment-item.error { opacity: 0.6; }
.attachment-icon { font-size: 18px; }
.attachment-name { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-size { color: var(--text-secondary); font-size: 12px; }
.attachment-error { color: var(--error); font-size: 12px; }
.attachment-download { color: var(--primary); margin-left: auto; }

/* Tags Section */
.tags-section {
  background: var(--bg);
  border-radius: 8px;
  padding: 16px;
}
.tags-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 14px;
  color: var(--text-secondary);
}
.tags-list {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.tag {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--content-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  font-size: 13px;
  color: var(--text);
}
.tag-remove {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  font-size: 16px;
  line-height: 1;
}
.tag-remove:hover { color: var(--error); }
.add-tag-form {
  display: flex;
  flex-direction: row;
  gap: 8px;
}
.tag-input {
  flex: 1;
  max-width: 200px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--content-bg);
  color: var(--text);
  font-size: 13px;
}
.tag-add-btn {
  padding: 8px 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
.tag-add-btn:hover { background: var(--primary-hover); }

/* ============================================
   COMPOSE PAGE
   ============================================ */
.compose-page {
  min-height: calc(100vh - 64px);
  padding: 24px;
  margin-top: 64px;
  display: flex;
  justify-content: center;
}
.compose-card {
  width: 100%;
  max-width: 700px;
  background: var(--content-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.compose-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.compose-title {
  font-size: 18px;
  font-weight: 500;
  margin: 0;
}
.compose-close {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: var(--text-secondary);
  border-radius: 50%;
  text-decoration: none;
}
.compose-close:hover { background: var(--hover-bg); text-decoration: none; }

.compose-form { padding: 0; }
.compose-field {
  display: flex;
  flex-direction: row;
  align-items: center;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
}
.compose-label {
  width: 60px;
  font-size: 14px;
  color: var(--text-secondary);
}
.compose-input, .compose-select {
  flex: 1;
  padding: 14px 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.compose-body-field {
  display: block;
  padding: 0;
  border-bottom: none;
}
.compose-textarea {
  width: 100%;
  min-height: 300px;
  padding: 16px 20px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  outline: none;
}

.compose-attachments {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}
.compose-attachments-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}
.compose-attachments-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.compose-attachment-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}
.compose-attachment-item input { margin-right: 4px; }

/* File Upload Area */
.file-upload-area {
  margin-top: 8px;
}
.file-input {
  display: none;
}
.file-label {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 20px;
  border: 2px dashed var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
  transition: all 0.2s;
}
.file-label:hover {
  border-color: var(--primary);
  background: var(--hover-bg);
}
.file-icon {
  font-size: 24px;
}
.file-text {
  font-size: 13px;
  color: var(--text-secondary);
}
.file-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}
.file-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--content-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}
.file-item-icon {
  font-size: 16px;
}
.file-item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-item-size {
  color: var(--text-secondary);
  font-size: 12px;
}
.file-remove {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  border-radius: 50%;
  transition: all 0.15s;
}
.file-remove:hover {
  color: var(--red);
  background: rgba(197, 34, 31, 0.1);
}

/* Forward Attachments */
.forward-attachments {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.forward-attachments-title {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.compose-actions {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

/* ============================================
   LOGIN PAGE
   ============================================ */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-container {
  width: 100%;
  max-width: 400px;
  padding: 20px;
}
.login-card {
  background: var(--content-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 48px 40px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 24px;
}
.login-logo-icon { font-size: 40px; }
.login-logo-text { font-size: 28px; font-weight: 500; }
.login-title {
  text-align: center;
  font-size: 24px;
  font-weight: 400;
  margin: 0 0 8px 0;
}
.login-subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin: 0 0 32px 0;
}
.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.login-field { width: 100%; }
.login-input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--content-bg);
  color: var(--text);
  font-size: 16px;
}
.login-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.2);
}
.login-btn {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 8px;
}
.login-btn:hover { background: var(--primary-hover); }
.login-footer {
  text-align: center;
  margin-top: 24px;
}
.login-secure {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ============================================
   USERS PAGE
   ============================================ */
.users-page {
  min-height: calc(100vh - 64px);
  padding: 24px;
  margin-top: 64px;
}
.users-container {
  max-width: 1200px;
  margin: 0 auto;
}
.users-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.users-title {
  font-size: 24px;
  font-weight: 400;
  margin: 0;
}
.users-card {
  background: var(--content-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.users-table {
  width: 100%;
  border-collapse: collapse;
}
.users-table th,
.users-table td {
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.users-table th {
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: uppercase;
  background: var(--bg);
}
.users-table tr:hover td { background: var(--hover-bg); }
.users-table tr:last-child td { border-bottom: none; }

.user-cell {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
}
.user-avatar-small {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 500;
  flex-shrink: 0;
}
.user-info { display: flex; flex-direction: column; }
.user-email { font-weight: 500; }
.you-badge {
  font-size: 10px;
  background: var(--selected-bg);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text-secondary);
  margin-top: 2px;
  display: inline-block;
  width: fit-content;
}

.role-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.role-superadmin { background: rgba(197, 34, 31, 0.1); color: var(--red); }
.role-admin { background: rgba(26, 115, 232, 0.1); color: var(--primary); }
.role-viewer { background: rgba(24, 128, 56, 0.1); color: var(--success); }

.all-badge {
  font-size: 11px;
  background: var(--hover-bg);
  padding: 4px 8px;
  border-radius: 4px;
  color: var(--text-secondary);
}
.domain-list, .mailbox-list {
  font-size: 13px;
  color: var(--text-secondary);
}
.more-badge {
  font-size: 11px;
  background: var(--hover-bg);
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 4px;
}

.status-badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 4px;
}
.status-badge.active { background: rgba(24, 128, 56, 0.1); color: var(--success); }
.status-badge.inactive { background: rgba(197, 34, 31, 0.1); color: var(--error); }

.actions-cell {
  display: flex;
  flex-direction: row;
  gap: 8px;
}
.no-access { color: var(--text-secondary); }

.users-footer {
  padding: 16px;
  text-align: right;
}
.users-count {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ============================================
   USER FORM PAGE
   ============================================ */
.user-form-page {
  min-height: calc(100vh - 64px);
  padding: 24px;
  margin-top: 64px;
  display: flex;
  justify-content: center;
}
.user-form-card {
  width: 100%;
  max-width: 600px;
  background: var(--content-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.user-form-header {
  padding: 24px;
  border-bottom: 1px solid var(--border);
}
.user-form-title {
  font-size: 20px;
  font-weight: 500;
  margin: 0;
}
.user-form-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.user-form { padding: 24px; }
.form-section {
  margin-bottom: 32px;
}
.form-section:last-child { margin-bottom: 0; }
.form-section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 16px 0;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.form-field { margin-bottom: 20px; }
.form-field:last-child { margin-bottom: 0; }
.form-label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 8px;
}
.form-optional {
  font-weight: 400;
  color: var(--text-secondary);
  font-size: 13px;
}
.form-input, .form-select {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--content-bg);
  color: var(--text);
  font-size: 14px;
}
.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.2);
}
.form-input:disabled {
  background: var(--bg);
  color: var(--text-secondary);
}
.form-select-multi { min-height: 120px; }
.form-help {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 6px;
  line-height: 1.5;
}

.form-checkbox {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.form-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}
.checkbox-mark { display: none; }
.checkbox-label { font-size: 14px; }

.form-actions {
  display: flex;
  flex-direction: row;
  gap: 12px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  margin-top: 24px;
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--hover-bg); }
.btn-danger {
  background: var(--error);
  color: white;
}
.btn-danger:hover { opacity: 0.9; }
.btn-small {
  padding: 6px 12px;
  font-size: 12px;
}
.btn-icon { margin-right: 4px; }

/* ============================================
   ALERTS
   ============================================ */
.alert {
  padding: 12px 16px;
  border-radius: 4px;
  margin: 16px 20px;
  font-size: 14px;
}
.alert-success {
  background: rgba(24, 128, 56, 0.1);
  border: 1px solid var(--success);
  color: var(--success);
}
.alert-error {
  background: rgba(197, 34, 31, 0.1);
  border: 1px solid var(--error);
  color: var(--error);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1024px) {
  .email-sender { width: 140px; }
  .email-subject { max-width: 200px; }
}

@media (max-width: 768px) {
  .menu-toggle { display: block; }
  .logo { min-width: auto; }
  .logo-text { display: none; }
  .search-bar { display: none; }
  .user-name { display: none; }

  .sidebar {
    display: none;
    position: fixed;
    top: 64px;
    left: 0;
    bottom: 0;
    width: 280px;
    z-index: 200;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.show { display: block; }

  .main-content { margin-left: 0; }

  .email-sender { width: 100px; }
  .email-date { width: 60px; font-size: 11px; }
  .email-subject { max-width: 150px; }

  .message-toolbar {
    flex-wrap: wrap;
    gap: 4px;
  }
  .message-toolbar .toolbar-right {
    width: 100%;
    justify-content: flex-start;
    margin-top: 4px;
    margin-left: 0;
  }

  .compose-page, .users-page, .user-form-page {
    padding: 16px;
  }
}

@media (max-width: 480px) {
  .header { padding: 8px; gap: 8px; }
  .email-content { display: none; }
  .email-row { height: 60px; }
  .email-sender { width: auto; flex: 1; }
}

/* ============================================
   SETTINGS PAGE
   ============================================ */
.settings-page {
  padding: 24px;
  max-width: 700px;
  margin: 0 auto;
}

.settings-card {
  background: var(--content-bg);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.settings-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.settings-title {
  margin: 0;
  font-size: 20px;
  font-weight: 500;
  color: var(--text);
}

.settings-form {
  padding: 0;
}

.settings-section {
  padding: 24px;
  border-bottom: 1px solid var(--border);
}

.settings-section:last-child {
  border-bottom: none;
}

.settings-section-title {
  margin: 0 0 8px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.settings-description {
  color: var(--text-secondary);
  font-size: 13px;
  margin: 0 0 16px 0;
}

.settings-info {
  background: var(--bg);
  border-radius: 6px;
  padding: 12px 16px;
}

.settings-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
}

.settings-label {
  color: var(--text-secondary);
  font-size: 13px;
}

.settings-value {
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
}

.settings-textarea {
  width: 100%;
  min-height: 120px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--content-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  box-sizing: border-box;
}

.settings-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.2);
}

.char-count {
  text-align: right;
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.form-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.settings-actions {
  padding: 24px;
  display: flex;
  gap: 12px;
  background: var(--bg);
}

/* ============================================
   LOADING SPINNER
   ============================================ */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.loading-overlay.show {
  opacity: 1;
  visibility: visible;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.btn.loading {
  position: relative;
  pointer-events: none;
  color: transparent !important;
}

.btn.loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  margin-left: -8px;
  margin-top: -8px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.btn-primary.loading::after {
  border-color: white;
  border-top-color: transparent;
}

.toolbar-btn.loading {
  opacity: 0.6;
  pointer-events: none;
}

.email-row.loading {
  opacity: 0.5;
  pointer-events: none;
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: var(--content-bg);
  padding: 12px 24px;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  z-index: 10000;
  opacity: 0;
  transition: transform 0.3s, opacity 0.3s;
  display: flex;
  align-items: center;
  gap: 12px;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast-action {
  background: var(--primary);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
}

.toast-action:hover {
  opacity: 0.9;
}

/* ===== Modal Styles ===== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}
.modal.show {
  opacity: 1;
  visibility: visible;
}
.modal-content {
  background: var(--content-bg);
  border-radius: 12px;
  padding: 24px;
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-lg {
  max-width: 700px;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.modal-header h3 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--text);
}
.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.modal-close:hover {
  color: var(--text);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 20px;
}

/* ===== Page Container ===== */
.page-container {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
}
.page-card {
  background: var(--content-bg);
  border-radius: 12px;
  padding: 24px;
  box-shadow: var(--shadow);
}
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.page-title {
  margin: 0;
  font-size: 1.5rem;
  color: var(--text);
}
.search-box {
  margin-bottom: 20px;
}

/* ===== Form Styles ===== */
.form-row {
  display: flex;
  gap: 16px;
}
.flex-1 {
  flex: 1;
}
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--text);
}
.checkbox-label input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

/* ===== Contacts Page ===== */
.contacts-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.contact-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: var(--bg);
  border-radius: 8px;
  transition: background 0.15s;
}
.contact-row:hover {
  background: var(--hover-bg);
}
.contact-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1.25rem;
  flex-shrink: 0;
}
.contact-info {
  flex: 1;
  min-width: 0;
}
.contact-name {
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}
.favorite-star {
  color: var(--star-yellow);
}
.contact-email {
  color: var(--text-secondary);
  font-size: 0.875rem;
}
.contact-company {
  color: var(--text-secondary);
  font-size: 0.8rem;
}
.contact-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}
.contact-source {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 12px;
  background: var(--border);
  color: var(--text-secondary);
}
.contact-source.manual {
  background: var(--primary);
  color: white;
}
.contact-count {
  font-size: 0.75rem;
  color: var(--text-secondary);
}
.contact-actions {
  display: flex;
  gap: 8px;
}

/* ===== Templates Page ===== */
.templates-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.template-category {
  margin-bottom: 8px;
}
.template-category-title {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.875rem;
  text-transform: uppercase;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.template-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: var(--bg);
  border-radius: 8px;
  transition: background 0.15s;
}
.template-row:hover {
  background: var(--hover-bg);
}
.template-info {
  flex: 1;
  min-width: 0;
}
.template-name {
  font-weight: 600;
  color: var(--text);
}
.template-subject {
  color: var(--primary);
  font-size: 0.875rem;
  margin-top: 4px;
}
.template-preview {
  color: var(--text-secondary);
  font-size: 0.8rem;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.template-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}
.template-type {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 12px;
  background: var(--border);
  color: var(--text-secondary);
}
.template-uses {
  font-size: 0.75rem;
  color: var(--text-secondary);
}
.template-actions {
  display: flex;
  gap: 8px;
}

/* ===== Small Buttons ===== */
.btn-sm {
  padding: 6px 12px;
  font-size: 0.875rem;
}
.btn-danger {
  background: var(--red);
  color: white;
}
.btn-danger:hover {
  background: #a71c1a;
}

/* ===== Auto-complete ===== */
.autocomplete-container {
  position: relative;
}
.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--content-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  max-height: 200px;
  overflow-y: auto;
  z-index: 1000;
  display: none;
}
.autocomplete-dropdown.show {
  display: block;
}
.autocomplete-item {
  padding: 10px 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.autocomplete-item:hover,
.autocomplete-item.selected {
  background: var(--hover-bg);
}
.autocomplete-email {
  color: var(--text);
  font-weight: 500;
}
.autocomplete-name {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* ===== Dark Mode Toggle in Settings ===== */
.theme-toggle {
  display: flex;
  gap: 8px;
}
.theme-option {
  flex: 1;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}
.theme-option:hover {
  border-color: var(--primary);
}
.theme-option.active {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}
.theme-option-icon {
  font-size: 1.5rem;
  margin-bottom: 4px;
}
.theme-option-label {
  font-size: 0.875rem;
  font-weight: 500;
}

/* ===== Print Styles ===== */
@media print {
  .header, .sidebar, .toolbar, .compose-actions, .btn {
    display: none !important;
  }
  .layout {
    display: block;
  }
  .main-content {
    margin: 0;
    padding: 0;
  }
  .message-card {
    box-shadow: none;
    border: none;
  }
}

/* ===== Manual Dark Mode Override ===== */
[data-theme="dark"] {
  --bg: #1f1f1f;
  --sidebar-bg: #2d2d2d;
  --content-bg: #292929;
  --border: #3c3c3c;
  --text: #e8eaed;
  --text-secondary: #9aa0a6;
  --primary: #8ab4f8;
  --red: #ea4335;
  --star-yellow: #fbbc04;
  --unread-bg: #292929;
  --read-bg: #1f1f1f;
  --hover-bg: #3c3c3c;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
}

[data-theme="light"] {
  --bg: #f6f8fc;
  --sidebar-bg: #f6f8fc;
  --content-bg: #ffffff;
  --border: #e0e0e0;
  --text: #202124;
  --text-secondary: #5f6368;
  --primary: #1a73e8;
  --red: #c5221f;
  --star-yellow: #f4b400;
  --unread-bg: #ffffff;
  --read-bg: #f2f6fc;
  --hover-bg: #f5f5f5;
  --shadow: 0 1px 3px rgba(0,0,0,0.12);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
}
