/* ===== CSS Custom Properties ===== */
:root {
  /* Dark theme colors */
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-tertiary: #1a1a25;
  --bg-card: rgba(26, 26, 37, 0.7);
  
  /* Accent colors - Purple/Violet theme */
  --accent-primary: #8b5cf6;
  --accent-secondary: #a78bfa;
  --accent-tertiary: #c4b5fd;
  --accent-glow: rgba(139, 92, 246, 0.4);
  
  /* Text colors */
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  /* Status colors */
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;
  
  /* Borders & shadows */
  --border-color: rgba(148, 163, 184, 0.1);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 64px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 40px var(--accent-glow);
  
  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  
  /* Border radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.5rem;
  
  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===== Glass Effect ===== */
.glass {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-color);
}

/* ===== Typography ===== */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.3;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }

a {
  color: var(--accent-secondary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--accent-tertiary);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-base);
}

.btn svg {
  width: 18px;
  height: 18px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary), #7c3aed);
  color: white;
  box-shadow: var(--shadow-sm), 0 0 20px var(--accent-glow);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md), 0 0 30px var(--accent-glow);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-color: var(--accent-primary);
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-icon:hover {
  background: var(--bg-tertiary);
  color: var(--accent-secondary);
}

.btn-icon svg {
  width: 20px;
  height: 20px;
}

/* ===== Form Elements ===== */
.form-group {
  margin-bottom: var(--space-lg);
}

.form-group label {
  display: block;
  margin-bottom: var(--space-sm);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
}

input[type="text"],
input[type="email"],
input[type="password"] {
  width: 100%;
  padding: var(--space-md);
  font-family: inherit;
  font-size: 1rem;
  color: var(--text-primary);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

input::placeholder {
  color: var(--text-muted);
}

.input-wrapper {
  position: relative;
  display: flex;
}

.input-wrapper input {
  flex: 1;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: none;
}

.input-suffix {
  display: flex;
  align-items: center;
  padding: 0 var(--space-md);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-left: none;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ===== Screens ===== */
.screen {
  display: none;
  min-height: 100vh;
}

.screen.active {
  display: block;
}

/* ===== Auth Screen ===== */
.auth-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--space-lg);
}

.auth-card {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 420px;
  padding: var(--space-2xl);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
}

.auth-header {
  text-align: center;
  margin-bottom: var(--space-xl);
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.logo-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--accent-primary), #7c3aed);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-glow);
}

.logo-icon svg {
  width: 28px;
  height: 28px;
  color: white;
}

.logo h1 {
  font-size: 1.75rem;
  font-weight: 700;
}

.logo .accent {
  background: linear-gradient(135deg, var(--accent-secondary), var(--accent-tertiary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo.small {
  justify-content: flex-start;
  gap: var(--space-sm);
}

.logo.small .logo-icon {
  width: 36px;
  height: 36px;
}

.logo.small .logo-icon svg {
  width: 20px;
  height: 20px;
}

.logo.small span {
  font-size: 1.125rem;
  font-weight: 600;
}

.tagline {
  color: var(--text-muted);
  font-size: 0.9375rem;
}

.auth-tabs {
  display: flex;
  gap: var(--space-xs);
  padding: var(--space-xs);
  margin-bottom: var(--space-xl);
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
}

.tab-btn {
  flex: 1;
  padding: var(--space-md);
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.tab-btn:hover {
  color: var(--text-secondary);
}

.tab-btn.active {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

.auth-form {
  display: none;
}

.auth-form.active {
  display: block;
  animation: fadeIn var(--transition-base);
}

.auth-form .btn {
  width: 100%;
  margin-top: var(--space-md);
}

.error-message {
  margin-top: var(--space-lg);
  padding: var(--space-md);
  color: var(--error);
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  text-align: center;
  display: none;
}

.error-message.show {
  display: block;
  animation: shake 0.4s ease;
}

/* Background effects */
.auth-bg-effects {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.5;
  animation: float 8s ease-in-out infinite;
}

.orb-1 {
  width: 400px;
  height: 400px;
  background: var(--accent-primary);
  top: -100px;
  right: -100px;
  animation-delay: 0s;
}

.orb-2 {
  width: 300px;
  height: 300px;
  background: #7c3aed;
  bottom: -50px;
  left: -100px;
  animation-delay: -3s;
}

.orb-3 {
  width: 200px;
  height: 200px;
  background: var(--accent-tertiary);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation-delay: -5s;
}

/* ===== Mail Screen ===== */
#mail-screen {
  display: none;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

#mail-screen.active {
  display: grid;
}

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  border-right: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

.sidebar-header {
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border-color);
}

.sidebar-nav {
  flex: 1;
  padding: var(--space-md);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.nav-item:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.nav-item.active {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(124, 58, 237, 0.1));
  color: var(--accent-secondary);
}

.nav-item svg {
  width: 20px;
  height: 20px;
}

.badge {
  margin-left: auto;
  min-width: 24px;
  height: 24px;
  padding: 0 var(--space-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: white;
  background: var(--accent-primary);
  border-radius: 12px;
}

.badge:empty {
  display: none;
}

.sidebar-footer {
  padding: var(--space-md);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.user-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--space-md);
  min-width: 0;
}

.avatar {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border-radius: 50%;
  flex-shrink: 0;
}

.avatar svg {
  width: 18px;
  height: 18px;
  color: var(--text-muted);
}

.user-email {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Main content */
.mail-main {
  padding: var(--space-xl);
  background: var(--bg-primary);
  overflow-y: auto;
}

.mail-view {
  display: none;
  animation: fadeIn var(--transition-base);
}

.mail-view.active {
  display: block;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-xl);
}

.view-header h2 {
  color: var(--text-primary);
}

.header-actions {
  display: flex;
  gap: var(--space-md);
}

/* Email List */
.email-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.email-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: var(--space-lg);
  align-items: center;
  padding: var(--space-lg);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.email-item:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent-primary);
  transform: translateX(4px);
}

.email-item.unread {
  border-left: 3px solid var(--accent-primary);
}

.email-item.unread .email-sender,
.email-item.unread .email-subject {
  font-weight: 600;
}

.email-avatar {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent-primary), #7c3aed);
  border-radius: 50%;
  font-weight: 600;
  color: white;
  font-size: 1rem;
}

.email-body {
  min-width: 0;
}

.email-sender {
  font-size: 0.9375rem;
  color: var(--text-primary);
  margin-bottom: var(--space-xs);
}

.email-subject {
  font-size: 0.875rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-preview {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: var(--space-xs);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-meta {
  text-align: right;
  flex-shrink: 0;
}

.email-date {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-2xl);
  text-align: center;
}

.empty-state svg {
  width: 64px;
  height: 64px;
  color: var(--text-muted);
  margin-bottom: var(--space-lg);
}

.empty-state h3 {
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
}

.empty-state p {
  color: var(--text-muted);
  font-size: 0.9375rem;
}

/* Loading state */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-2xl);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loading-state p {
  margin-top: var(--space-md);
  color: var(--text-muted);
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  margin-top: var(--space-xl);
}

.pagination button {
  padding: var(--space-sm) var(--space-md);
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.pagination button:hover:not(:disabled) {
  background: var(--bg-tertiary);
  border-color: var(--accent-primary);
  color: var(--text-primary);
}

.pagination button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pagination button.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: white;
}

.pagination-info {
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* Email Content */
.email-content {
  padding: var(--space-xl);
  border-radius: var(--radius-lg);
  background: var(--bg-secondary);
}

.email-header {
  margin-bottom: var(--space-xl);
  padding-bottom: var(--space-xl);
  border-bottom: 1px solid var(--border-color);
}

.email-header h1 {
  font-size: 1.5rem;
  margin-bottom: var(--space-lg);
  line-height: 1.4;
}

.email-from {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.email-from .email-avatar {
  width: 48px;
  height: 48px;
}

.from-details {
  flex: 1;
}

.from-name {
  font-weight: 600;
  color: var(--text-primary);
}

.from-address {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.email-to {
  margin-top: var(--space-md);
  font-size: 0.875rem;
  color: var(--text-muted);
}

.email-body-content {
  line-height: 1.7;
  color: var(--text-secondary);
}

.email-body-content p {
  margin-bottom: var(--space-md);
}

.email-body-content a {
  color: var(--accent-secondary);
}

.email-body-content img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
}

/* Toast notifications */
.toast-container {
  position: fixed;
  bottom: var(--space-lg);
  right: var(--space-lg);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  animation: slideIn var(--transition-base);
}

.toast.success {
  border-color: var(--success);
}

.toast.error {
  border-color: var(--error);
}

.toast-icon {
  width: 20px;
  height: 20px;
}

.toast.success .toast-icon {
  color: var(--success);
}

.toast.error .toast-icon {
  color: var(--error);
}

/* ===== Animations ===== */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  50% { transform: translateX(8px); }
  75% { transform: translateX(-4px); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes float {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(10px, -20px); }
  50% { transform: translate(-10px, 10px); }
  75% { transform: translate(15px, 15px); }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  #mail-screen.active {
    grid-template-columns: 1fr;
  }
  
  .sidebar {
    display: none;
  }
  
  .auth-card {
    padding: var(--space-xl);
  }
  
  .email-item {
    grid-template-columns: 1fr;
    gap: var(--space-md);
  }
  
  .email-avatar {
    display: none;
  }
  
  .email-meta {
    text-align: left;
  }
}
