:root {
  --bg: #0a0e1a;
  --surface: rgba(18, 24, 42, 0.85);
  --surface2: rgba(28, 36, 58, 0.9);
  --border: rgba(148, 163, 184, 0.12);
  --text: #e8edf7;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary2: #6366f1;
  --accent: #22d3ee;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 14px;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Vazirmatn', 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

.hidden { display: none !important; }

.bg-orbs { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.35;
  animation: float 12s ease-in-out infinite;
}
.orb-1 { width: 420px; height: 420px; background: #3b82f6; top: -120px; right: -80px; }
.orb-2 { width: 360px; height: 360px; background: #8b5cf6; bottom: -100px; left: -60px; animation-delay: -4s; }
.orb-3 { width: 280px; height: 280px; background: #06b6d4; top: 40%; left: 35%; animation-delay: -7s; }

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(20px, -30px) scale(1.05); }
}

.fade-in { animation: fadeIn 0.5s var(--transition) both; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.slide-in { animation: slideIn 0.35s ease both; }
@keyframes slideIn {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: translateX(0); }
}

.screen { position: relative; z-index: 1; min-height: 100vh; }

/* Login */
.login-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  gap: 1.5rem;
}
.brand { text-align: center; }
.brand h1 {
  font-size: 2rem;
  background: linear-gradient(135deg, #fff, var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-top: 0.5rem;
}
.brand p { color: var(--muted); margin-top: 0.25rem; }
.brand-icon {
  width: 72px; height: 72px;
  margin: 0 auto;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem;
  box-shadow: 0 12px 40px rgba(59, 130, 246, 0.4);
  animation: pulse 3s ease-in-out infinite;
}
.brand-icon.sm { width: 36px; height: 36px; font-size: 1rem; border-radius: 10px; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 12px 40px rgba(59, 130, 246, 0.35); }
  50% { box-shadow: 0 12px 50px rgba(99, 102, 241, 0.55); }
}

.glass {
  background: var(--surface);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.login-card { width: 100%; max-width: 400px; padding: 1.75rem; }

.tabs { display: flex; gap: 0.5rem; margin-bottom: 1.25rem; }
.tab {
  flex: 1; padding: 0.65rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 10px;
  cursor: pointer;
  transition: var(--transition);
  display: flex; align-items: center; justify-content: center; gap: 0.4rem;
  font-family: inherit;
}
.tab:hover { color: var(--text); border-color: var(--primary); }
.tab.active {
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  color: #fff; border-color: transparent;
}

.field-group { margin-bottom: 1rem; }
.field-group label {
  display: flex; align-items: center; gap: 0.35rem;
  font-size: 0.85rem; color: var(--muted); margin-bottom: 0.35rem;
}
input, textarea, select {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(10, 14, 26, 0.6);
  color: var(--text);
  font-family: inherit;
  transition: var(--transition);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.65rem 1.1rem;
  border: none; border-radius: 10px;
  font-family: inherit; font-weight: 500;
  cursor: pointer; transition: var(--transition);
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  color: #fff; width: 100%;
}
.btn-primary:hover { transform: translateY(-2px); filter: brightness(1.1); }
.btn-glow { box-shadow: 0 8px 24px rgba(59, 130, 246, 0.35); }
.btn-ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); background: var(--surface2); }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.85rem; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-icon {
  width: 36px; height: 36px; padding: 0;
  border-radius: 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-icon:hover { background: var(--primary); border-color: var(--primary); }
.btn-icon.active { background: var(--primary); color: #fff; }

.alert { padding: 0.75rem; border-radius: 8px; font-size: 0.9rem; margin-top: 0.75rem; }
.alert-error { background: rgba(239, 68, 68, 0.15); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.3); }
.alert-success { background: rgba(34, 197, 94, 0.15); color: #86efac; border: 1px solid rgba(34, 197, 94, 0.3); }
.login-links { text-align: center; margin-top: 0.75rem; }
.login-links a { color: var(--accent); text-decoration: none; font-size: 0.9rem; }
.login-links a:hover { text-decoration: underline; }
.hint { color: var(--muted); font-size: 0.85rem; margin-bottom: 0.75rem; }
#forgot-panel h3, #reset-panel h3 { margin-bottom: 0.75rem; display: flex; align-items: center; gap: 0.4rem; }
#forgot-panel input, #reset-panel input { margin-bottom: 0.5rem; }

/* App layout */
#app-screen { display: flex; min-height: 100vh; }
.sidebar {
  width: 260px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-left: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 0.6rem;
  font-weight: 700; font-size: 1.1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.user-badge {
  font-size: 0.8rem;
  color: var(--accent);
  background: rgba(34, 211, 238, 0.1);
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  word-break: break-all;
}
.nav { display: flex; flex-direction: column; gap: 0.25rem; flex: 1; }
.nav-btn {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.7rem 0.85rem;
  border: none; border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  text-align: right;
  transition: var(--transition);
  width: 100%;
}
.nav-btn:hover { background: var(--surface2); color: var(--text); }
.nav-btn.active {
  background: linear-gradient(90deg, rgba(59, 130, 246, 0.25), transparent);
  color: var(--text);
  border-right: 3px solid var(--primary);
}
.nav-btn .badge {
  margin-right: auto;
  background: var(--primary);
  color: #fff;
  font-size: 0.7rem;
  padding: 0.1rem 0.45rem;
  border-radius: 20px;
  min-width: 20px;
  text-align: center;
}
.logout { margin-top: auto; }

.content {
  flex: 1;
  padding: 1.5rem;
  overflow: auto;
  max-height: 100vh;
}

.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.5rem; flex-wrap: wrap; gap: 1rem;
}
.page-header h1 {
  font-size: 1.5rem;
  display: flex; align-items: center; gap: 0.5rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  transition: var(--transition);
}
.card:hover { border-color: rgba(59, 130, 246, 0.25); }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
  transition: var(--transition);
}
.stat-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); }
.stat-card i { font-size: 1.75rem; color: var(--accent); display: block; margin-bottom: 0.5rem; }
.stat-card strong { display: block; font-size: 1.75rem; color: #fff; }
.stat-card span { font-size: 0.85rem; color: var(--muted); }

.toolbar { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.toolbar input, .toolbar select { flex: 1; min-width: 140px; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.85rem; text-align: right; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 0.85rem; }
tr { transition: var(--transition); }
tbody tr:hover { background: rgba(59, 130, 246, 0.06); }

.progress {
  height: 6px; background: var(--surface2);
  border-radius: 3px; overflow: hidden; margin-top: 0.35rem;
}
.progress span {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 3px;
  transition: width 0.6s ease;
}

/* Mail client */
.mail-app {
  display: grid;
  grid-template-columns: 200px 320px 1fr;
  gap: 0;
  height: calc(100vh - 3rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.mail-folders {
  border-left: 1px solid var(--border);
  padding: 1rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  background: rgba(10, 14, 26, 0.5);
}
.folder-btn {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  border: none; border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  transition: var(--transition);
  width: 100%;
  text-align: right;
}
.folder-btn:hover { background: var(--surface2); color: var(--text); }
.folder-btn.active { background: rgba(59, 130, 246, 0.2); color: var(--text); }
.folder-btn i { font-size: 1.1rem; width: 22px; }

.mail-list {
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.mail-list-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 0.5rem;
}
.search-box {
  position: relative;
}
.search-box i {
  position: absolute;
  right: 0.75rem; top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
}
.search-box input { padding-right: 2.25rem; }

.mail-items { flex: 1; overflow-y: auto; }
.mail-item {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: var(--transition);
}
.mail-item:hover { background: rgba(59, 130, 246, 0.08); }
.mail-item.active { background: rgba(59, 130, 246, 0.15); border-right: 3px solid var(--primary); }
.mail-item.unread .mail-subject { font-weight: 700; color: #fff; }
.mail-item.unread::before {
  content: '';
  display: inline-block;
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 50%;
  margin-left: 6px;
}
.mail-subject { font-size: 0.95rem; margin-bottom: 0.2rem; }
.mail-meta { font-size: 0.78rem; color: var(--muted); }
.mail-star { color: var(--warning); }

.mail-detail {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: rgba(10, 14, 26, 0.3);
}
.mail-detail-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  gap: 1rem;
}
.mail-detail-empty i { font-size: 4rem; opacity: 0.3; }
.mail-detail-header {
  padding: 1.25rem;
  border-bottom: 1px solid var(--border);
}
.mail-detail-actions {
  display: flex; gap: 0.5rem; flex-wrap: wrap;
  margin-top: 0.75rem;
}
.mail-detail-body {
  flex: 1;
  padding: 1.25rem;
  overflow-y: auto;
  white-space: pre-wrap;
  line-height: 1.7;
}

.compose-panel, .settings-panel {
  padding: 1.5rem;
  max-width: 640px;
}
.compose-panel h2, .settings-panel h2 {
  margin-bottom: 1rem;
  display: flex; align-items: center; gap: 0.5rem;
}
.compose-toggle {
  margin: -0.25rem 0 0.75rem;
}
.compose-extra-fields {
  margin-bottom: 0.5rem;
}

.compose-recipients-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}
.contact-quick-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}
.contact-quick-btn {
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  font-size: 0.8rem;
  cursor: pointer;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.contact-quick-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.contact-picker {
  margin: 0 0 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface2);
}
.contact-picker-list {
  max-height: 220px;
  overflow-y: auto;
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.contact-picker-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.45rem 0.5rem;
  border-radius: 8px;
  background: var(--surface);
}
.contact-picker-info {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}
.contact-picker-info span {
  font-size: 0.8rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
}
.contact-picker-actions {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}
.row-actions {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.deliverability-panel { margin-top: 1rem; }
.dns-status-grid {
  display: flex; flex-wrap: wrap; gap: 0.5rem;
  margin: 0.75rem 0 1rem;
}
.dns-status {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.35rem 0.65rem; border-radius: 999px; font-size: 0.85rem;
  border: 1px solid var(--border);
}
.dns-status.ok { color: var(--success); border-color: rgba(34,197,94,0.35); }
.dns-status.bad { color: var(--danger); border-color: rgba(239,68,68,0.35); }
.dns-records code.dns-copy {
  display: block;
  padding: 0.65rem 0.75rem;
  margin: 0.35rem 0 0.85rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.78rem;
  word-break: break-all;
  white-space: pre-wrap;
}
.dns-recommendations {
  margin: 0.75rem 0 1rem;
  padding-right: 1.25rem;
  color: var(--muted);
  line-height: 1.7;
}

.attachment-preview {
  display: flex; flex-wrap: wrap; gap: 0.75rem;
  margin-top: 0.75rem;
}
.attachment-chip {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-width: 100%;
}
.attachment-chip img {
  width: 48px; height: 48px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}
.attachment-chip span {
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
}
.attachment-remove {
  border: none; background: transparent;
  color: var(--muted); font-size: 1.2rem;
  cursor: pointer; line-height: 1;
  padding: 0 0.2rem;
}
.attachment-remove:hover { color: var(--danger); }

.mail-attachments {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.attachment-grid {
  display: flex; flex-wrap: wrap; gap: 1rem;
  margin-top: 0.5rem;
}
.attachment-item {
  display: flex; flex-direction: column; gap: 0.35rem;
  max-width: 220px;
}
.attachment-item img {
  max-width: 100%;
  max-height: 180px;
  border-radius: 8px;
  border: 1px solid var(--border);
  object-fit: contain;
  background: var(--surface2);
}
.attachment-item span {
  font-size: 0.8rem;
  color: var(--muted);
  word-break: break-all;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.85rem 1.5rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 1000;
  animation: fadeIn 0.3s ease;
}
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }

.toggle {
  display: flex; align-items: center; gap: 0.5rem;
  cursor: pointer;
}
.toggle input { width: auto; accent-color: var(--primary); }

.setup-wrap { max-width: 520px; }
.setup-card { max-height: 80vh; overflow-y: auto; }
.setup-steps {
  display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 1rem;
  font-size: 0.75rem; color: var(--muted);
}
.setup-step {
  padding: 0.25rem 0.5rem; border-radius: 6px;
  border: 1px solid var(--border);
}
.setup-step.active { border-color: var(--primary); color: var(--primary); }
.setup-step.done { border-color: var(--success); color: var(--success); }

@media (max-width: 1024px) {
  .mail-app { grid-template-columns: 1fr; height: auto; }
  .mail-folders { flex-direction: row; flex-wrap: wrap; border-left: none; border-bottom: 1px solid var(--border); }
  .mail-list, .mail-detail { min-height: 300px; }
  #app-screen { flex-direction: column; }
  .sidebar { width: 100%; border-left: none; border-bottom: 1px solid var(--border); }
}
