/* ========== Design Tokens ========== */
:root {
  --color-bg: #0a0a0f;
  --color-surface: #13131a;
  --color-surface-2: #1a1a24;
  --color-surface-3: #22222e;
  --color-border: rgba(255, 255, 255, 0.06);
  --color-border-hover: rgba(255, 255, 255, 0.12);
  --color-text: #e8e8ed;
  --color-text-secondary: #8b8b9e;
  --color-text-muted: #5a5a6e;
  --color-primary: #6366f1;
  --color-primary-light: #818cf8;
  --color-primary-dark: #4f46e5;
  --color-accent: #8b5cf6;
  --color-danger: #ef4444;
  --color-success: #22c55e;
  --color-warning: #f59e0b;
  --gradient-primary: linear-gradient(135deg, #6366f1, #8b5cf6);
  --gradient-bg: linear-gradient(180deg, #0a0a0f 0%, #0f0f1a 100%);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font);
  background: var(--gradient-bg);
  color: var(--color-text);
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  min-height: 100vh;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

/* ========== Login Screen ========== */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 20px;
}

.login-backdrop {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 0;
  pointer-events: none;
}

.backdrop-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.4;
  animation: float 20s ease-in-out infinite;
}

.orb-1 {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, #6366f1, transparent 70%);
  top: -10%;
  right: -5%;
  animation-delay: 0s;
}

.orb-2 {
  width: 350px;
  height: 350px;
  background: radial-gradient(circle, #8b5cf6, transparent 70%);
  bottom: -15%;
  left: -10%;
  animation-delay: -7s;
}

.orb-3 {
  width: 250px;
  height: 250px;
  background: radial-gradient(circle, #a78bfa, transparent 70%);
  top: 40%;
  left: 50%;
  animation-delay: -14s;
}

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  25% { transform: translate(30px, -40px) scale(1.05); }
  50% { transform: translate(-20px, 20px) scale(0.95); }
  75% { transform: translate(15px, 30px) scale(1.02); }
}

.login-card {
  position: relative;
  z-index: 1;
  background: rgba(19, 19, 26, 0.8);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  animation: slideUp 0.6s ease-out;
}

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

.login-header {
  text-align: center;
  margin-bottom: 36px;
}

.logo-icon {
  margin-bottom: 20px;
  display: inline-block;
  animation: pulse-glow 3s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { filter: drop-shadow(0 0 8px rgba(99, 102, 241, 0.3)); }
  50% { filter: drop-shadow(0 0 16px rgba(99, 102, 241, 0.5)); }
}

.login-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.login-subtitle {
  color: var(--color-text-secondary);
  font-size: 0.9rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  margin-bottom: 8px;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 14px;
  color: var(--color-text-muted);
  pointer-events: none;
  transition: color var(--transition);
}

.input-wrapper input {
  width: 100%;
  padding: 14px 14px 14px 46px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-family: var(--font);
  font-size: 0.95rem;
  transition: all var(--transition);
  outline: none;
}

.input-wrapper input::placeholder {
  color: var(--color-text-muted);
}

.input-wrapper input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.input-wrapper input:focus + .input-icon,
.input-wrapper:has(input:focus) .input-icon {
  color: var(--color-primary-light);
}

.btn-primary {
  position: relative;
  width: 100%;
  padding: 14px;
  background: var(--gradient-primary);
  border: none;
  border-radius: var(--radius-md);
  color: white;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  overflow: hidden;
  margin-top: 4px;
}

.btn-primary::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.1), transparent);
  opacity: 0;
  transition: opacity var(--transition);
}

.btn-primary:hover::before {
  opacity: 1;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.spinner {
  animation: spin 1s linear infinite;
}

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

.error-msg {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  color: #fca5a5;
  font-size: 0.85rem;
  text-align: center;
  animation: shake 0.4s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* ========== App Header ========== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: rgba(19, 19, 26, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-logo {
  display: flex;
}

.header-left h2 {
  font-size: 1.2rem;
  font-weight: 600;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-email {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  background: var(--color-surface-2);
  padding: 6px 14px;
  border-radius: 100px;
  border: 1px solid var(--color-border);
}

.btn-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-icon:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
  border-color: var(--color-border-hover);
}

.btn-logout:hover {
  color: var(--color-danger);
  border-color: rgba(239, 68, 68, 0.3);
}

.btn-icon.refreshing svg {
  animation: spin 1s linear infinite;
}

/* ========== Inbox ========== */
.inbox-main {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px;
}

/* Loading Shimmer */
.loading-state {
  padding: 8px 0;
}

.loading-shimmer {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.shimmer-row {
  height: 76px;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  position: relative;
  overflow: hidden;
}

.shimmer-row::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.03), transparent);
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--color-text-secondary);
}

.empty-state h3 {
  margin-top: 16px;
  font-size: 1.2rem;
  color: var(--color-text);
}

.empty-state p {
  margin-top: 8px;
  font-size: 0.9rem;
}

/* Error State */
.error-state {
  text-align: center;
  padding: 80px 20px;
}

.error-state h3 {
  margin-top: 16px;
  font-size: 1.2rem;
  color: var(--color-danger);
}

.error-state p {
  margin-top: 8px;
  color: var(--color-text-secondary);
  font-size: 0.9rem;
}

.btn-secondary {
  margin-top: 20px;
  padding: 10px 24px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-family: var(--font);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-secondary:hover {
  background: var(--color-surface-3);
  border-color: var(--color-border-hover);
}

/* Email List */
.email-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.email-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  animation: fadeIn 0.3s ease-out both;
}

.email-item:hover {
  background: var(--color-surface-2);
  border-color: var(--color-border-hover);
  transform: translateX(4px);
  box-shadow: var(--shadow-sm);
}

.email-item.unread {
  border-left: 3px solid var(--color-primary);
}

.email-item.unread .email-subject {
  font-weight: 600;
  color: var(--color-text);
}

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

.email-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--gradient-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1rem;
  color: white;
  flex-shrink: 0;
  text-transform: uppercase;
}

.email-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.email-top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.email-from {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-date {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.email-subject {
  font-size: 0.9rem;
  color: var(--color-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-preview {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-indicators {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.indicator-attachment {
  color: var(--color-text-muted);
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 24px;
  padding: 16px 0;
}

.btn-page {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  font-family: var(--font);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-page:hover:not(:disabled) {
  background: var(--color-surface-2);
  border-color: var(--color-border-hover);
  color: var(--color-text);
}

.btn-page:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.page-info {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
}

/* ========== Email Detail Modal ========== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  justify-content: center;
  overflow-y: auto;
  padding: 40px 20px;
  animation: fadeInOverlay 0.2s ease-out;
}

@keyframes fadeInOverlay {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 800px;
  max-height: fit-content;
  box-shadow: var(--shadow-lg);
  animation: slideUpModal 0.3s ease-out;
  align-self: flex-start;
}

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

.modal-header {
  display: flex;
  justify-content: flex-end;
  padding: 16px 20px 0;
}

.modal-close-btn {
  border: none;
  background: var(--color-surface-2);
}

.modal-close-btn:hover {
  background: var(--color-surface-3);
}

.modal-body {
  padding: 0 32px 32px;
}

.email-detail-header {
  margin-bottom: 24px;
}

.detail-subject {
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.4;
  margin-bottom: 20px;
}

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

.detail-from {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--gradient-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1rem;
  color: white;
  text-transform: uppercase;
}

.detail-from-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.detail-from-name {
  font-weight: 500;
  font-size: 0.95rem;
}

.detail-from-email {
  font-size: 0.82rem;
  color: var(--color-text-muted);
}

.detail-date {
  font-size: 0.82rem;
  color: var(--color-text-muted);
}

.email-detail-body {
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--color-text-secondary);
  word-break: break-word;
}

.email-detail-body iframe {
  width: 100%;
  border: none;
  border-radius: var(--radius-sm);
  min-height: 400px;
  background: white;
}

/* ========== Responsive ========== */
@media (max-width: 640px) {
  .login-card {
    padding: 36px 24px;
  }

  .app-header {
    padding: 12px 16px;
  }

  .user-email {
    display: none;
  }

  .inbox-main {
    padding: 16px;
  }

  .email-item {
    padding: 14px 16px;
    gap: 12px;
  }

  .email-avatar {
    width: 36px;
    height: 36px;
    font-size: 0.85rem;
  }

  .modal-overlay {
    padding: 20px 12px;
  }

  .modal-body {
    padding: 0 20px 24px;
  }

  .detail-subject {
    font-size: 1.15rem;
  }

  .detail-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
}
