:root {
  --bg: #09090b;
  --bg-panel: #0c0c0e;
  --bg-panel-2: #131316;
  --bg-hover: #1a1a1e;
  --bg-active: #1e1a12;
  --border: #212126;
  --border-soft: #1a1a1e;
  --text: #f4f4f5;
  --text-dim: #9b9ba3;
  --text-faint: #5c5c66;
  --accent: #f59e0b;
  --accent-2: #fbbf24;
  --accent-soft: rgba(245, 158, 11, 0.12);
  --accent-ring: rgba(245, 158, 11, 0.35);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.1);
  --success: #34d399;
  --radius-sm: 7px;
  --radius: 11px;
  --radius-lg: 18px;
  --shadow-lg: 0 20px 50px -12px rgba(0, 0, 0, 0.6);
  --shadow-md: 0 8px 24px -6px rgba(0, 0, 0, 0.5);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent-soft); color: var(--accent-2); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #232328; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #2e2e35; }

.hidden { display: none !important; }

/* ===== Auth screen ===== */
.auth-screen {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 16px;
  overflow: hidden;
}

.auth-glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(600px circle at 15% 15%, rgba(245, 158, 11, 0.10), transparent 55%),
    radial-gradient(500px circle at 85% 85%, rgba(251, 191, 36, 0.07), transparent 55%);
}

.auth-card {
  position: relative;
  width: 100%;
  max-width: 400px;
  background: linear-gradient(175deg, #101012, #0a0a0c);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
  animation: rise 0.5s var(--ease);
}

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

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
}

.logo-mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0a0a0a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 18px;
  box-shadow: 0 6px 16px -4px rgba(245, 158, 11, 0.5);
  flex-shrink: 0;
}
.logo-mark.small { width: 30px; height: 30px; font-size: 14px; border-radius: 9px; box-shadow: 0 4px 10px -3px rgba(245, 158, 11, 0.45); }

.logo-text {
  font-size: 19px;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.01em;
}
.logo-text b { color: var(--accent-2); font-weight: 800; }
.logo-text.small { font-size: 15px; }

.auth-subtitle {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  margin: 10px 0 26px;
  line-height: 1.5;
}
.auth-subtitle b { color: var(--text); font-weight: 600; }

.auth-tabs {
  position: relative;
  display: flex;
  background: var(--bg-panel-2);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 22px;
}

.auth-tab {
  position: relative;
  z-index: 1;
  flex: 1;
  padding: 9px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  transition: color 0.2s var(--ease);
}
.auth-tab.active { color: #0a0a0a; }

.auth-tab-indicator {
  position: absolute;
  top: 4px;
  left: 4px;
  width: calc(50% - 4px);
  height: calc(100% - 8px);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 7px;
  transition: transform 0.28s var(--ease);
  box-shadow: 0 4px 12px -2px rgba(245, 158, 11, 0.4);
}
.auth-tabs:has(.auth-tab[data-tab="register"].active) .auth-tab-indicator {
  transform: translateX(100%);
}

.auth-form { display: flex; flex-direction: column; gap: 6px; animation: fade 0.25s var(--ease); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.auth-form label { font-size: 12px; font-weight: 500; color: var(--text-dim); margin-top: 10px; }

input[type="text"], input[type="email"], input[type="password"] {
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
input::placeholder { color: var(--text-faint); }
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.form-error {
  color: var(--danger);
  font-size: 12.5px;
  min-height: 18px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.form-error:not(:empty)::before { content: '⚠'; font-size: 11px; }

.btn-primary {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0a0a0a;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  font-weight: 700;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: filter 0.15s var(--ease), transform 0.1s var(--ease), box-shadow 0.15s var(--ease);
  box-shadow: 0 6px 16px -4px rgba(245, 158, 11, 0.35);
}
.btn-primary:hover { filter: brightness(1.07); box-shadow: 0 8px 20px -4px rgba(245, 158, 11, 0.5); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary.full { width: 100%; margin-top: 18px; }
.btn-primary:disabled { opacity: 0.7; cursor: default; transform: none; }

.btn-spinner {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(10, 10, 10, 0.25);
  border-top-color: #0a0a0a;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
.btn-primary.loading .btn-label { visibility: hidden; position: absolute; }
.btn-primary.loading .btn-spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  padding: 9px 15px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  transition: all 0.15s var(--ease);
}
.btn-ghost:hover { color: var(--text); border-color: #38383f; background: var(--bg-hover); }
.btn-ghost.small { padding: 7px 11px; font-size: 12px; }
.btn-ghost.danger:hover { color: var(--danger); border-color: rgba(248, 113, 113, 0.4); background: var(--danger-soft); }

/* ===== App shell ===== */
.app-screen {
  display: grid;
  grid-template-columns: 264px 330px 1fr;
  height: 100vh;
  animation: fade 0.3s var(--ease);
}

.sidebar {
  background: var(--bg-panel);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  padding: 18px 16px;
}

.sidebar-header { display: flex; align-items: center; gap: 9px; margin-bottom: 18px; padding: 0 2px; }

.mailbox-list { flex: 1; overflow-y: auto; margin: 4px -6px 0; padding: 0 6px; }

.mailbox-item {
  position: relative;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-bottom: 3px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease);
}
.mailbox-item:hover { background: var(--bg-hover); }
.mailbox-item.active {
  background: var(--bg-active);
  border-color: rgba(245, 158, 11, 0.25);
}
.mailbox-item.active::before {
  content: '';
  position: absolute;
  left: -16px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}

.mailbox-email {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unread-badge {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0a0a0a;
  font-size: 10.5px;
  font-weight: 800;
  border-radius: 20px;
  padding: 2px 7px;
  flex-shrink: 0;
  min-width: 18px;
  text-align: center;
}

.mailbox-delete {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 13px;
  padding: 3px 5px;
  border-radius: 5px;
  display: none;
  flex-shrink: 0;
  line-height: 1;
}
.mailbox-item:hover .mailbox-delete { display: inline-block; }
.mailbox-delete:hover { color: var(--danger); background: var(--danger-soft); }

.sidebar-footer {
  border-top: 1px solid var(--border-soft);
  padding-top: 14px;
  margin-top: 10px;
}

.user-chip { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; padding: 0 2px; }

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--bg-hover), var(--bg-panel-2));
  border: 1px solid var(--border);
  color: var(--accent-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12.5px;
  flex-shrink: 0;
}

.user-info { overflow: hidden; }
.user-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-email { font-size: 11.5px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }

.sidebar-actions { display: flex; gap: 7px; }
.sidebar-actions button { flex: 1; }
#logout-btn { flex: 0 0 auto; padding: 9px 11px; }

/* ===== Message list pane ===== */
.message-list-pane {
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.pane-header { padding: 18px 18px 14px; border-bottom: 1px solid var(--border-soft); }
.pane-header h2 {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-tabs { display: flex; gap: 6px; }
.folder-tab {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 7px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s var(--ease);
}
.folder-tab:hover { color: var(--text); }
.folder-tab.active { color: #0a0a0a; background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; font-weight: 700; }

.message-list { flex: 1; overflow-y: auto; }

.message-row {
  position: relative;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background 0.12s var(--ease);
}
.message-row:hover { background: var(--bg-hover); }
.message-row.active { background: var(--bg-active); }
.message-row.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 2.5px;
  background: var(--accent);
}
.message-row.unread .message-from { font-weight: 700; color: var(--text); }
.message-row.unread .message-subject { font-weight: 500; color: var(--text-dim); }
.message-row.unread .message-row-top::after {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  margin-left: 4px;
}

.message-row-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.message-from { font-size: 13px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.message-date { font-size: 11px; color: var(--text-faint); flex-shrink: 0; }
.message-subject { font-size: 12.5px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== Detail pane ===== */
.message-detail-pane { overflow-y: auto; padding: 28px 32px; }

.detail-header { border-bottom: 1px solid var(--border-soft); padding-bottom: 18px; margin-bottom: 20px; }
.detail-subject { font-size: 19px; font-weight: 700; margin: 0 0 14px; letter-spacing: -0.01em; }
.detail-meta { font-size: 13px; color: var(--text-dim); line-height: 1.8; }
.detail-meta b { color: var(--text-faint); font-weight: 500; margin-right: 4px; }
.detail-meta span { color: var(--text); }

.detail-actions { display: flex; gap: 8px; margin-top: 16px; }
.detail-actions button { display: inline-flex; align-items: center; gap: 6px; }

.detail-body { font-size: 14.5px; line-height: 1.7; color: var(--text); word-wrap: break-word; }
.detail-body iframe { width: 100%; min-height: 320px; border: 1px solid var(--border); background: #fff; border-radius: var(--radius); }

.empty-hint {
  color: var(--text-faint);
  font-size: 13px;
  padding: 36px 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.empty-hint svg { opacity: 0.4; }
.empty-hint.center { display: flex; align-items: center; justify-content: center; height: 100%; padding: 0; }

/* ===== Modals ===== */
.modal {
  position: fixed; inset: 0;
  background: rgba(5, 5, 6, 0.7);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  animation: fade 0.15s var(--ease);
}

.modal-card {
  background: linear-gradient(175deg, #101012, #0a0a0c);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px;
  width: 90%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  animation: rise 0.25s var(--ease);
}
.modal-card h3 { margin: 0 0 16px; font-size: 16px; font-weight: 700; }
.modal-hint { font-size: 12.5px; color: var(--text-dim); line-height: 1.6; }
.modal-hint code { background: var(--bg-panel-2); border: 1px solid var(--border); padding: 1px 6px; border-radius: 5px; font-size: 11.5px; color: var(--accent-2); }

.mailbox-input-row {
  display: flex;
  align-items: center;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.mailbox-input-row:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.mailbox-input-row input { border: none; background: transparent; flex: 1; }
.mailbox-input-row input:focus { border: none; box-shadow: none; }
#mailbox-domain-suffix { padding: 0 13px; color: var(--text-faint); font-size: 13px; white-space: nowrap; }

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

.key-display {
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 13px;
  font-family: "SF Mono", ui-monospace, monospace;
  font-size: 12px;
  word-break: break-all;
  color: var(--accent-2);
  margin: 12px 0;
  line-height: 1.5;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: #131316;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  z-index: 100;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toast-in 0.25s var(--ease);
}
.toast::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--success); flex-shrink: 0; }
.toast.error::before { background: var(--danger); }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@media (max-width: 900px) {
  .app-screen { grid-template-columns: 1fr; }
  .sidebar, .message-list-pane { display: none; }
}
