:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --accent: #f59e0b;
  --green: #10b981;
  --green-dark: #059669;
  --red: #ef4444;
  --page: #f0f4ff;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 20px 60px rgba(37, 99, 235, 0.10), 0 4px 16px rgba(0,0,0,0.05);
  --shadow-sm: 0 4px 12px rgba(0,0,0,0.06);
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* === Reset & Base === */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  min-height: 100svh;
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  background: var(--page);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* === LOGIN PAGE === */
.login-wrapper {
  min-height: 100svh;
  display: grid;
  place-items: center;
  position: relative;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 50%, #3b82f6 100%);
  overflow: hidden;
}

.login-decoration {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.deco-circle {
  position: absolute;
  border-radius: 50%;
  opacity: 0.08;
  background: #fff;
}
.deco-circle-1 { width: 500px; height: 500px; top: -150px; right: -100px; }
.deco-circle-2 { width: 300px; height: 300px; bottom: -80px; left: -60px; opacity: 0.06; }
.deco-circle-3 { width: 180px; height: 180px; top: 40%; left: 10%; opacity: 0.04; }

/* === Card === */
.card {
  width: 100%;
  max-width: 420px;
  padding: 40px 32px 36px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
  position: relative;
  z-index: 1;
  animation: cardIn 0.6s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(30px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.logo-mark {
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, var(--primary), #6366f1);
  border-radius: 16px;
  display: grid;
  place-items: center;
  margin: 0 auto 16px;
  color: #fff;
  font-size: 1.4rem;
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.3);
}

.logo {
  font-family: 'Space Mono', monospace;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
  letter-spacing: -0.5px;
}

.subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 28px;
}

/* === Form Fields === */
.field {
  position: relative;
  margin-bottom: 14px;
}

.field-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  font-size: 0.85rem;
  pointer-events: none;
  transition: color var(--transition);
}

.field input {
  width: 100%;
  padding: 15px 48px 15px 44px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text);
  outline: none;
  transition: all var(--transition);
}

.field input::placeholder { color: #94a3b8; }

.field input:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

.field input:focus ~ .field-icon,
.field:focus-within .field-icon {
  color: var(--primary);
}

.toggle-password {
  position: absolute;
  top: 50%;
  right: 14px;
  transform: translateY(-50%);
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.9rem;
  color: #94a3b8;
  padding: 4px;
  border-radius: 6px;
  transition: color var(--transition);
}
.toggle-password:hover { color: var(--primary); }

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 15px 24px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(rgba(255,255,255,0.15), transparent);
  opacity: 0;
  transition: opacity var(--transition);
}
.btn:hover::after { opacity: 1; }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #4f46e5);
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.3);
  margin-top: 8px;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 24px rgba(37, 99, 235, 0.35); }
.btn-primary:active { transform: translateY(0); }

.btn-green {
  background: linear-gradient(135deg, var(--green), #059669);
  box-shadow: 0 4px 16px rgba(16, 185, 129, 0.3);
}
.btn-green:hover { transform: translateY(-1px); box-shadow: 0 6px 24px rgba(16, 185, 129, 0.35); }

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 2px solid var(--border);
  box-shadow: none;
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.btn-outline::after { display: none; }

/* === Messages === */
#message {
  margin-top: 14px;
  font-size: 0.88rem;
  font-weight: 500;
  min-height: 1.2em;
}
.error { color: var(--red); }
.success { color: var(--green); }

/* === MAIN APP === */
.app-shell {
  min-height: 100svh;
  background: var(--page);
  animation: fadeIn 0.5s ease both;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Top Nav */
.top-nav {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: 'Space Mono', monospace;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text);
  text-decoration: none;
}

.nav-brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), #6366f1);
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 0.9rem;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-user {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-right: 8px;
}

.btn-logout {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text-muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  transition: all var(--transition);
}
.btn-logout:hover {
  border-color: var(--red);
  color: var(--red);
  background: #fef2f2;
}

/* Main Content */
.main-content {
  max-width: 700px;
  margin: 0 auto;
  padding: 40px 20px 60px;
}

/* Stats Cards */
.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  transition: all var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  margin-bottom: 14px;
}

.stat-icon.blue { background: var(--primary-light); color: var(--primary); }
.stat-icon.green { background: #d1fae5; color: var(--green); }

.stat-number {
  font-family: 'Space Mono', monospace;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.stat-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
}

/* Action Buttons */
.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 32px;
}

.action-card {
  background: #fff;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}
.action-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--primary);
  transform: scaleX(0);
  transition: transform var(--transition);
}
.action-card:hover::before { transform: scaleX(1); }
.action-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.12);
}

.action-card.green-card:hover { border-color: var(--green); }
.action-card.green-card::before { background: var(--green); }
.action-card.green-card:hover { box-shadow: 0 8px 24px rgba(16, 185, 129, 0.12); }

.action-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  margin: 0 auto 14px;
  font-size: 1.2rem;
}

.action-icon.blue { background: var(--primary-light); color: var(--primary); }
.action-icon.green { background: #d1fae5; color: var(--green); }

.action-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}
.action-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Email List */
.email-section {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}

.email-section-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.email-section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.email-section-title i { color: var(--primary); }

.email-count-badge {
  background: var(--primary-light);
  color: var(--primary);
  font-family: 'Space Mono', monospace;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
}

.email-list {
  max-height: 300px;
  overflow-y: auto;
}

.email-item {
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid #f1f5f9;
  transition: background var(--transition);
}
.email-item:last-child { border-bottom: none; }
.email-item:hover { background: #f8fafc; }

.email-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary-light), #e0e7ff);
  display: grid;
  place-items: center;
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}

.email-info { flex: 1; min-width: 0; }

.email-addr {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.email-delete {
  background: none;
  border: none;
  color: #cbd5e1;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 6px;
  border-radius: 8px;
  transition: all var(--transition);
}
.email-delete:hover { color: var(--red); background: #fef2f2; }

.email-empty {
  padding: 40px 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.email-empty i {
  font-size: 2rem;
  color: #cbd5e1;
  display: block;
  margin-bottom: 10px;
}

/* === POPUP / MODAL === */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 2000;
  place-items: center;
  animation: overlayIn 0.2s ease both;
}
.modal-overlay.active { display: grid; }

@keyframes overlayIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: #fff;
  border-radius: var(--radius);
  padding: 0;
  width: 92%;
  max-width: 440px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.2);
  animation: modalIn 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
  overflow: hidden;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  padding: 24px 24px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: #f1f5f9;
  border-radius: 10px;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  font-size: 1rem;
  transition: all var(--transition);
}
.modal-close:hover { background: #fee2e2; color: var(--red); }

.modal-body {
  padding: 20px 24px 24px;
}

.modal-field {
  position: relative;
  margin-bottom: 16px;
}

.modal-field i {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  font-size: 0.85rem;
}

.modal-input {
  width: 100%;
  padding: 14px 14px 14px 42px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text);
  outline: none;
  transition: all var(--transition);
}
.modal-input::placeholder { color: #94a3b8; }
.modal-input:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

.modal-msg {
  margin-top: 10px;
  font-size: 0.85rem;
  font-weight: 500;
  min-height: 1.2em;
}

/* Send Email Modal */
.send-preview {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 16px;
}

.send-preview-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 6px;
}

.send-preview-count {
  font-family: 'Space Mono', monospace;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}

.modal-textarea {
  width: 100%;
  padding: 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text);
  outline: none;
  resize: vertical;
  min-height: 80px;
  transition: all var(--transition);
  margin-bottom: 6px;
}
.modal-textarea::placeholder { color: #94a3b8; }
.modal-textarea:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

.modal-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.modal-group {
  margin-bottom: 14px;
}

/* === TOAST === */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: #fff;
  padding: 14px 24px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 12px 40px rgba(0,0,0,0.2);
  z-index: 5000;
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  white-space: nowrap;
}

.toast.show { transform: translateX(-50%) translateY(0); }
.toast.toast-success .toast-icon { color: var(--green); }
.toast.toast-error .toast-icon { color: var(--red); }

/* === Loading Spinner === */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.btn.loading { pointer-events: none; opacity: 0.85; }

/* === Scrollbar === */
.email-list::-webkit-scrollbar { width: 6px; }
.email-list::-webkit-scrollbar-track { background: transparent; }
.email-list::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
.email-list::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* === Responsive === */
@media (max-width: 520px) {
  .card { margin: 16px; padding: 32px 20px 28px; }
  .stats-row { grid-template-columns: 1fr; }
  .action-grid { grid-template-columns: 1fr; }
  .main-content { padding: 24px 16px 40px; }
  .nav-user { display: none; }
}


/* === Failed Emails === */
.stat-icon.red { background: #fee2e2; color: #ef4444; }

.stats-row { grid-template-columns: 1fr 1fr 1fr; }

.failed-section .email-section-title i { color: #ef4444; }

.failed-badge {
  background: #fee2e2 !important;
  color: #ef4444 !important;
}

.failed-avatar {
  background: linear-gradient(135deg, #fee2e2, #fecaca) !important;
  color: #ef4444 !important;
}

.failed-email-item {
  border-left: 3px solid #ef4444;
}

.failed-subject {
  font-size: 0.78rem;
  color: #64748b;
  margin-top: 2px;
  font-style: italic;
}

.failed-error {
  font-size: 0.75rem;
  color: #dc2626;
  margin-top: 2px;
  word-break: break-word;
}

@media (max-width: 520px) {
  .stats-row { grid-template-columns: 1fr !important; }
}

/* === Email Type Badge === */
.email-type-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  background: #dbeafe;
  color: #2563eb;
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}