:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-tertiary: #1a1a26;
  --bg-hover: #222233;
  --bg-active: #2a2a3d;
  --accent: #00e5ff;
  --accent-dim: #00a0b2;
  --accent-glow: rgba(0, 229, 255, 0.15);
  --text-primary: #e8e8f0;
  --text-secondary: #8888a0;
  --text-muted: #555566;
  --border: #2a2a3d;
  --danger: #ff4466;
  --success: #00cc88;
  --font-mono: 'JetBrains Mono', monospace;
  --font-sans: 'Space Grotesk', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

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

.screen { display: none; height: 100vh; }
.screen.active { display: flex; }

/* Auth Screen */
.auth-container {
  margin: auto;
  max-width: 420px;
  width: 100%;
  padding: 2rem;
}

.logo { text-align: center; margin-bottom: 2.5rem; }
.logo-icon {
  font-size: 3rem;
  color: var(--accent);
  text-shadow: 0 0 30px var(--accent-glow);
  margin-bottom: 0.5rem;
}
.logo h1 { font-size: 2rem; font-weight: 700; letter-spacing: -0.02em; }
.accent { color: var(--accent); }
.tagline { color: var(--text-secondary); margin-top: 0.5rem; font-size: 0.95rem; }

.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
  font-weight: 500;
}
.hint { color: var(--text-muted); font-weight: 400; }

input[type="text"], input[type="email"], input[type="password"], textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}
input:focus, textarea:focus { border-color: var(--accent); }

.btn-primary {
  width: 100%;
  padding: 0.85rem;
  background: var(--accent);
  color: var(--bg-primary);
  border: none;
  border-radius: 8px;
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 0.5rem;
}
.btn-primary:hover { background: #33ecff; box-shadow: 0 0 20px var(--accent-glow); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  padding: 0.5rem 1rem;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-secondary:hover { border-color: var(--accent); }

.btn-danger {
  padding: 0.5rem 1rem;
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 6px;
  font-family: var(--font-sans);
  cursor: pointer;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.4rem;
}
.btn-icon:hover { color: var(--accent); }

/* Setup Steps */
.setup-steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-bottom: 2rem;
}
.step {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  transition: color 0.3s;
}
.step.active { color: var(--accent); }
.step.done { color: var(--success); }
.step-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
}
.step.active .step-num { background: var(--accent); color: var(--bg-primary); border-color: var(--accent); }
.step.done .step-num { background: var(--success); color: var(--bg-primary); border-color: var(--success); }
.step-line {
  width: 40px;
  height: 1px;
  background: var(--border);
  margin: 0 0.5rem;
}

.setup-panel { animation: fadeIn 0.3s ease; }
.setup-panel.hidden { display: none; }
.setup-title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}
.setup-desc {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
  line-height: 1.5;
}
.setup-nav {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
}
.setup-nav .btn-secondary { flex: 0 0 auto; width: auto; padding: 0.85rem 1.5rem; }
.setup-nav .btn-primary { flex: 1; }

.field-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

/* Email input row */
.email-input-row {
  display: flex;
  align-items: center;
  gap: 0;
}
.email-local {
  border-radius: 8px 0 0 8px !important;
  flex: 1;
}
.email-at {
  padding: 0.75rem 0.5rem;
  background: var(--bg-active);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.95rem;
}
.email-domain {
  padding: 0.75rem 0.8rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 0 8px 8px 0;
  color: var(--accent);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

/* Security info */
.security-info {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.security-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--bg-tertiary);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.security-icon { font-size: 1.3rem; flex-shrink: 0; margin-top: 0.1rem; }
.security-item strong {
  font-size: 0.85rem;
  display: block;
  margin-bottom: 0.15rem;
}
.security-item p {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.3;
}

/* Ready state */
.ready-state { text-align: center; }
.ready-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg-primary);
  font-size: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
  box-shadow: 0 0 40px var(--accent-glow);
}
.ready-details {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin: 1.5rem 0;
  text-align: left;
}
.ready-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0;
}
.ready-item:not(:last-child) { border-bottom: 1px solid var(--border); padding-bottom: 0.6rem; margin-bottom: 0.4rem; }
.ready-item .label { font-size: 0.8rem; color: var(--text-secondary); }
.ready-item code {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--accent);
  background: var(--bg-active);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.82rem;
  cursor: pointer;
  margin-top: 1rem;
  font-family: var(--font-sans);
  text-decoration: underline;
  display: block;
  width: 100%;
  text-align: center;
}
.btn-link:hover { color: var(--accent); }

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

/* App Layout */
.app-layout {
  display: grid;
  grid-template-columns: 240px 360px 1fr;
  height: 100vh;
  width: 100vw;
}

/* Sidebar */
.sidebar {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}
.logo-small {
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent);
  margin-bottom: 0.75rem;
}
.btn-compose {
  width: 100%;
  padding: 0.65rem;
  background: var(--accent);
  color: var(--bg-primary);
  border: none;
  border-radius: 6px;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-compose:hover { background: #33ecff; }

.mailbox-list { flex: 1; padding: 0.5rem; overflow-y: auto; }
.mailbox-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-secondary);
  transition: all 0.15s;
}
.mailbox-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.mailbox-item.active { background: var(--bg-active); color: var(--accent); }
.mailbox-icon { margin-right: 0.5rem; font-size: 1.1rem; }
.mailbox-count {
  background: var(--accent);
  color: var(--bg-primary);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.sidebar-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.user-info {
  font-size: 0.8rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Email List Panel */
.email-list-panel {
  background: var(--bg-primary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}
.panel-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  text-transform: capitalize;
}
.search-bar input {
  padding: 0.55rem 0.8rem;
  font-size: 0.85rem;
  background: var(--bg-tertiary);
}

.email-list { flex: 1; overflow-y: auto; }
.email-item {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}
.email-item:hover { background: var(--bg-hover); }
.email-item.active { background: var(--bg-active); border-left: 3px solid var(--accent); }
.email-item.unread { border-left: 3px solid var(--accent); }
.email-item.unread .email-subject { font-weight: 600; color: var(--text-primary); }

.email-from {
  font-size: 0.85rem;
  color: var(--text-primary);
  font-weight: 500;
  display: flex;
  justify-content: space-between;
}
.email-date { font-size: 0.75rem; color: var(--text-muted); font-weight: 400; }
.email-subject {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.2rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.email-preview {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.email-badges { display: flex; gap: 0.3rem; margin-top: 0.3rem; }
.badge {
  font-size: 0.65rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-weight: 600;
}
.badge-encrypted { background: var(--accent-glow); color: var(--accent); }
.badge-attachment { background: rgba(255,255,255,0.05); color: var(--text-muted); }
.badge-starred { color: #ffcc00; }

/* Email Detail */
.email-detail-panel {
  background: var(--bg-primary);
  overflow-y: auto;
}
.email-detail { padding: 1.5rem; }
.email-detail-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.email-detail-subject {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}
.email-detail-meta {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.email-detail-from { font-size: 0.9rem; color: var(--text-secondary); }
.email-detail-from strong { color: var(--text-primary); }
.email-detail-date { font-size: 0.8rem; color: var(--text-muted); }
.email-detail-to { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.3rem; }

.email-detail-body {
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text-primary);
}
.email-detail-body p { margin-bottom: 0.8rem; }

.email-detail-actions {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.5rem;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 60vh;
  color: var(--text-muted);
}
.empty-icon { font-size: 3rem; margin-bottom: 1rem; opacity: 0.3; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 640px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.modal-header h3 { font-size: 1.1rem; font-weight: 600; }
.btn-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}
.btn-close:hover { color: var(--text-primary); }

.compose-form .form-group { margin-bottom: 0.6rem; }
.compose-form input, .compose-form textarea { font-size: 0.9rem; }
.compose-form textarea {
  resize: vertical;
  min-height: 200px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.6;
}
.compose-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.75rem;
}
.compose-actions > div { display: flex; gap: 0.5rem; }
.encrypt-toggle {
  font-size: 0.85rem;
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

/* Settings */
.settings-section {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.settings-section:last-child { border-bottom: none; }
.settings-section h4 {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}
.key-display {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent);
  background: var(--bg-tertiary);
  padding: 0.6rem;
  border-radius: 6px;
  word-break: break-all;
  margin-bottom: 0.75rem;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  color: var(--text-muted);
}

/* Responsive */
@media (max-width: 900px) {
  .app-layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .email-detail-panel { display: none; }
}
@media (max-width: 1200px) and (min-width: 901px) {
  .app-layout { grid-template-columns: 200px 1fr; }
  .email-detail-panel { display: none; }
}
