/* ═══════════════════════════════════════════════════════════
   WebMail — Gmail-style UI
   Font: DM Sans (body) + DM Mono (meta)
   Theme: Clean light, Google-inspired palette
   ═══════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&family=DM+Mono:wght@400;500&display=swap');

/* ── Reset & Variables ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #f6f8fc;
  --surface:     #ffffff;
  --surface2:    #f1f3f4;
  --border:      #e0e0e0;
  --border-light:#f1f3f4;
  --text:        #202124;
  --text-2:      #5f6368;
  --text-3:      #80868b;
  --accent:      #1a73e8;
  --accent-h:    #1557b0;
  --accent-bg:   #e8f0fe;
  --danger:      #d93025;
  --danger-bg:   #fce8e6;
  --warn:        #f29900;
  --success:     #188038;
  --unread-bg:   #ffffff;
  --read-bg:     #f2f6fc;
  --hover-bg:    #f2f6fc;
  --active-bg:   #d3e3fd;
  --shadow-sm:   0 1px 2px rgba(60,64,67,.1), 0 1px 3px rgba(60,64,67,.08);
  --shadow-md:   0 1px 3px rgba(60,64,67,.15), 0 4px 8px rgba(60,64,67,.1);
  --shadow-lg:   0 4px 12px rgba(60,64,67,.15), 0 8px 24px rgba(60,64,67,.1);
  --radius:      8px;
  --radius-sm:   4px;
  --radius-lg:   16px;
  --sidebar-w:   256px;
  --header-h:    64px;
  --font:        'DM Sans', sans-serif;
  --font-mono:   'DM Mono', monospace;
  --transition:  0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout Shell ──────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100vh; }

/* ── Login Screen ──────────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: linear-gradient(135deg, #f6f8fc 0%, #e8f0fe 100%);
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
}

.login-logo svg { width: 40px; height: 40px; }

.login-logo-text {
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.5px;
}

.login-subtitle {
  color: var(--text-2);
  font-size: 14px;
  margin-bottom: 32px;
}

.login-card h2 {
  font-size: 24px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 4px;
}

.form-group {
  margin-bottom: 16px;
  text-align: left;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(26,115,232,.15);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
  padding: 12px;
  font-size: 15px;
}
.btn-primary:hover { background: var(--accent-h); box-shadow: var(--shadow-sm); }
.btn-primary:active { transform: scale(0.98); }

.btn-ghost {
  background: transparent;
  color: var(--accent);
}
.btn-ghost:hover { background: var(--accent-bg); }

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
}
.btn-danger:hover { background: #f5c6c2; }

.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-icon {
  width: 36px; height: 36px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-2);
  flex-shrink: 0;
}
.btn-icon:hover { background: var(--surface2); }

.login-error {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

/* ── Top Header ────────────────────────────────────────── */
#header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  width: var(--sidebar-w);
  flex-shrink: 0;
}

.header-logo svg { width: 32px; height: 32px; }

.header-logo-text {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.3px;
}

.search-bar {
  flex: 1;
  max-width: 680px;
  position: relative;
}

.search-bar input {
  width: 100%;
  padding: 10px 16px 10px 44px;
  background: var(--surface2);
  border: 1.5px solid transparent;
  border-radius: 24px;
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  outline: none;
  transition: all var(--transition);
}

.search-bar input:focus {
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.search-bar .search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-2);
  pointer-events: none;
}

.search-bar .search-clear {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  display: none;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}

/* ── Main Body ─────────────────────────────────────────── */
#main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg);
  overflow-y: auto;
  padding: 8px 0;
  border-right: 1px solid transparent;
}

.compose-btn {
  margin: 8px 16px 16px;
  padding: 16px 24px;
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-lg);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  border: none;
  width: calc(100% - 32px);
  box-shadow: var(--shadow-md);
  transition: box-shadow var(--transition);
  font-family: var(--font);
}

.compose-btn:hover { box-shadow: var(--shadow-lg); }
.compose-btn svg { color: var(--text-2); }

.nav-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  border-radius: 0 24px 24px 0;
  cursor: pointer;
  color: var(--text);
  font-size: 14px;
  font-weight: 400;
  transition: background var(--transition);
  margin-right: 16px;
  user-select: none;
}

.nav-item:hover { background: var(--surface2); }
.nav-item.active { background: var(--active-bg); font-weight: 600; }
.nav-item svg { flex-shrink: 0; }

.nav-badge {
  margin-left: auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  font-family: var(--font-mono);
}

/* ── Email List Panel ──────────────────────────────────── */
#email-list-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border);
  min-width: 300px;
  max-width: 480px;
}

.panel-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.panel-title {
  font-size: 16px;
  font-weight: 600;
  padding: 0 8px;
  color: var(--text);
  flex: 1;
}

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

.email-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto auto;
  gap: 2px 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  background: var(--unread-bg);
  transition: background var(--transition);
  position: relative;
}

.email-item:hover { background: var(--hover-bg); }
.email-item.read   { background: var(--read-bg); }
.email-item.read .email-sender { font-weight: 400; color: var(--text-2); }
.email-item.active  { background: var(--accent-bg); }

.email-avatar {
  grid-row: 1 / 3;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
  align-self: center;
}

.email-sender {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-date {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  align-self: center;
  font-family: var(--font-mono);
}

.email-subject {
  grid-column: 2 / 4;
  font-size: 13px;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-subject strong {
  color: var(--text);
  font-weight: 500;
}

.unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  position: absolute;
  left: 5px;
  top: 50%;
  transform: translateY(-50%);
}

.email-item.read .unread-dot { display: none; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.page-info {
  font-size: 13px;
  color: var(--text-2);
  font-family: var(--font-mono);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 24px;
  color: var(--text-3);
  gap: 16px;
  text-align: center;
}

.empty-state svg { opacity: 0.4; }
.empty-state p { font-size: 15px; }

/* ── Email View Panel ──────────────────────────────────── */
#email-view-panel {
  flex: 1.5;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
}

#email-view-panel .panel-toolbar {
  border-left: none;
}

.email-view-content {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
}

.email-view-subject {
  font-size: 22px;
  font-weight: 400;
  color: var(--text);
  margin-bottom: 20px;
  line-height: 1.3;
}

.email-view-meta {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.email-view-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
}

.email-view-from { font-weight: 600; font-size: 14px; }
.email-view-from-email { font-size: 13px; color: var(--text-2); }
.email-view-date { font-size: 12px; color: var(--text-3); margin-top: 2px; font-family: var(--font-mono); }

.email-view-body {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}

.email-view-body iframe {
  width: 100%;
  border: none;
  min-height: 200px;
}

.no-email-selected {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  gap: 16px;
}

.no-email-selected svg { opacity: 0.25; }
.no-email-selected p { font-size: 16px; }

/* ── Compose Modal ─────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 500;
  display: none;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 0;
}

.modal-overlay.open { display: flex; }

.compose-modal {
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-lg);
  width: 560px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  margin: 0 24px;
  overflow: hidden;
  animation: slideUp 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.compose-header {
  padding: 12px 16px;
  background: var(--text);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: move;
}

.compose-header span { font-size: 14px; font-weight: 500; }

.compose-header-actions { display: flex; gap: 4px; }
.compose-header-actions button {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  opacity: 0.8;
  transition: opacity var(--transition), background var(--transition);
}
.compose-header-actions button:hover { opacity: 1; background: rgba(255,255,255,.15); }

.compose-field {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}

.compose-field label {
  font-size: 13px;
  color: var(--text-2);
  width: 40px;
  flex-shrink: 0;
}

.compose-field input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  background: transparent;
}

.compose-field-subject input { font-weight: 500; }

.compose-body textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  padding: 16px;
  font-size: 14px;
  font-family: var(--font);
  line-height: 1.6;
  color: var(--text);
  background: transparent;
  min-height: 240px;
}

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

/* ── Settings Modal ────────────────────────────────────── */
.settings-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 600;
  background: rgba(0,0,0,0.4);
}

.settings-modal.open { display: flex; }

.settings-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 440px;
  overflow: hidden;
  animation: fadeScaleIn 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes fadeScaleIn {
  from { transform: scale(0.95); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

.settings-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.settings-header h3 { font-size: 18px; font-weight: 600; }

.settings-body { padding: 24px; }
.settings-body h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 16px;
}

.settings-body .form-group { margin-bottom: 12px; }

.settings-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ── Toast ─────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  background: #323232;
  color: #fff;
  font-size: 14px;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastIn 0.25s ease;
  pointer-events: all;
}

.toast.success { background: #188038; }
.toast.error   { background: var(--danger); }

@keyframes toastIn {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

@keyframes toastOut {
  from { opacity: 1; }
  to   { opacity: 0; transform: translateY(8px); }
}

/* ── Loading ───────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.loading-row {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  gap: 12px;
  color: var(--text-2);
}

/* ── Dropdown Menu ─────────────────────────────────────── */
.dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  padding: 8px 0;
  z-index: 300;
  display: none;
  border: 1px solid var(--border);
}

.dropdown-menu.open { display: block; animation: fadeScaleIn 0.15s ease; }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition);
}

.dropdown-item:hover { background: var(--surface2); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-divider { height: 1px; background: var(--border); margin: 4px 0; }

.dropdown-email {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-2);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  font-family: var(--font-mono);
}

/* ── Folder Icon Colors ────────────────────────────────── */
.icon-inbox   { color: #1a73e8; }
.icon-sent    { color: #188038; }
.icon-drafts  { color: #f29900; }
.icon-trash   { color: #9e9e9e; }
.icon-spam    { color: #d93025; }
.icon-folder  { color: #9e9e9e; }

/* ── Scrollbar ─────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #dadce0; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #bdc1c6; }

/* ── Utility ───────────────────────────────────────────── */
.hidden { display: none !important; }
.flex-1 { flex: 1; }
.text-muted { color: var(--text-2); }
.ml-auto { margin-left: auto; }

/* ── Reply Box ─────────────────────────────────────────── */
.reply-box {
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  margin: 16px 32px 32px;
  overflow: hidden;
  flex-shrink: 0;
}

.reply-box-header {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-2);
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
  display: flex;
  align-items: center;
  gap: 8px;
}

.reply-box textarea {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  padding: 14px;
  font-size: 14px;
  font-family: var(--font);
  line-height: 1.6;
  min-height: 100px;
  color: var(--text);
  background: var(--surface);
}

.reply-box-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--surface);
}

/* ── Search Results Banner ─────────────────────────────── */
.search-banner {
  padding: 8px 16px;
  background: var(--accent-bg);
  color: var(--accent);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}

/* ── Responsive tweaks ─────────────────────────────────── */
@media (max-width: 900px) {
  #email-view-panel { display: none; }
  #email-list-panel { max-width: 100%; }
  #email-view-panel.show { display: flex; position: fixed; inset: var(--header-h) 0 0 0; z-index: 200; }
}

@media (max-width: 600px) {
  :root { --sidebar-w: 200px; }
  .compose-modal { width: 100%; margin: 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
}
