/* ============================================================
   Email Manager — Mobile-first, Apple-inspired design system
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg:            #f5f5f7;
  --card:          #ffffff;
  --border:        #e5e5ea;
  --border-subtle: #f2f2f7;
  --txt:           #1c1c1e;
  --txt-sub:       #6e6e73;
  --txt-muted:     #aeaeb2;
  --accent:        #3b82f6;
  --accent-soft:   rgba(59, 130, 246, 0.09);
  --success:       #34c759;
  --success-soft:  rgba(52, 199, 89, 0.10);
  --danger:        #ff3b30;
  --danger-soft:   rgba(255, 59, 48, 0.08);
  --shadow-sm:     0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow:        0 4px 20px rgba(0,0,0,0.08);
  --radius:        14px;
  --radius-sm:     10px;
  --radius-xs:     7px;
  --sans:          'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono:          'SF Mono', 'JetBrains Mono', Menlo, monospace;
  --nav-h:         64px;
  --safe-b:        env(safe-area-inset-bottom, 0px);
  --safe-t:        env(safe-area-inset-top, 0px);
}

[data-theme="dark"] {
  --bg:            #1c1c1e;
  --card:          #2c2c2e;
  --border:        #3a3a3c;
  --border-subtle: #2c2c2e;
  --txt:           #f5f5f7;
  --txt-sub:       #aeaeb2;
  --txt-muted:     #636366;
  --accent-soft:   rgba(59, 130, 246, 0.15);
  --success-soft:  rgba(52, 199, 89, 0.15);
  --danger-soft:   rgba(255, 59, 48, 0.15);
  --shadow-sm:     0 1px 3px rgba(0,0,0,0.25);
  --shadow:        0 4px 20px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; overflow-x: hidden; }
html, body { height: 100%; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--txt);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior-y: none;
  overflow-x: hidden;
  transition: background 0.3s, color 0.3s;
}

a { color: inherit; text-decoration: none; }

::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Auth page ─────────────────────────────────────────── */

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px 20px;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 32px 28px 28px;
  box-shadow: var(--shadow);
}

.auth-icon {
  width: 48px; height: 48px;
  background: var(--accent-soft);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: var(--accent);
  margin-bottom: 18px;
}
.auth-icon svg { width: 24px; height: 24px; }

.auth-card h1 {
  font-size: 22px; font-weight: 700; color: var(--txt);
  margin-bottom: 4px; letter-spacing: -0.02em;
}
.auth-sub { font-size: 14px; color: var(--txt-sub); margin-bottom: 28px; }

.auth-error {
  font-size: 13px; color: var(--danger);
  background: var(--danger-soft);
  padding: 10px 12px; border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

.auth-card form { display: flex; flex-direction: column; gap: 14px; }

/* ── Form elements ─────────────────────────────────────── */

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--txt-sub); }

.field input,
.field select,
.auth-card input[type="password"] {
  width: 100%;
  padding: 13px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 16px;
  font-family: var(--sans);
  color: var(--txt);
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
}

.field input:focus,
.field select:focus,
.auth-card input[type="password"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; min-width: 0; }

.input-with-action { display: flex; gap: 8px; }
.input-with-action input { flex: 1; min-width: 0; font-family: var(--mono); font-size: 14px; padding: 13px 12px; }

/* ── Buttons ───────────────────────────────────────────── */

.btn-primary {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 15px 16px;
  border: none; border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-weight: 600; font-size: 16px; font-family: var(--sans);
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  letter-spacing: -0.01em;
  -webkit-appearance: none;
}
.btn-primary:active { opacity: 0.85; transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-mini {
  flex-shrink: 0;
  padding: 0 16px;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--txt-sub);
  font-size: 14px; font-weight: 600; font-family: var(--sans);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.btn-mini:active { background: var(--border); color: var(--txt); }

/* ── Topbar ────────────────────────────────────────────── */

.topbar {
  position: sticky; top: 0; z-index: 100;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 0 16px;
  height: 56px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}

.topbar-brand { display: flex; align-items: center; gap: 10px; }

.topbar-logo {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; flex-shrink: 0;
}
.topbar-logo svg { width: 17px; height: 17px; }

.topbar-title {
  font-size: 17px; font-weight: 700; color: var(--txt);
  letter-spacing: -0.02em;
}

.topbar-right { display: flex; align-items: center; gap: 4px; }

.status-dot {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
}
.status-dot-indicator {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success); flex-shrink: 0;
  transition: background 0.3s;
}
.status-dot-indicator.bad { background: var(--danger); }

/* ── Search bar ────────────────────────────────────────── */

.search-bar-wrap {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  position: sticky; top: 56px; z-index: 90;
}

.search-wrap {
  position: relative;
  width: 100%;
}
.search-wrap svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--txt-muted); pointer-events: none;
}
.search-wrap input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  border-radius: 10px;
  border: none;
  background: var(--bg);
  font-size: 16px; font-family: var(--sans); color: var(--txt);
  -webkit-appearance: none; appearance: none;
}
.search-wrap input:focus { outline: none; }
.search-wrap input::placeholder { color: var(--txt-muted); }

/* ── Page body ─────────────────────────────────────────── */

.page-body {
  padding: 12px 16px calc(var(--nav-h) + var(--safe-b) + 80px);
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

/* ── Inbox shortcut banner ─────────────────────────────── */

.inbox-banner {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
  color: var(--txt);
  transition: background 0.15s;
  -webkit-user-select: none; user-select: none;
}
.inbox-banner:active { background: var(--bg); }

.inbox-banner-icon {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.inbox-banner-icon svg { width: 22px; height: 22px; }
.inbox-banner-info { flex: 1; min-width: 0; }
.inbox-banner-title { font-size: 15px; font-weight: 600; color: var(--txt); letter-spacing: -0.01em; }
.inbox-banner-sub { font-size: 13px; color: var(--txt-sub); margin-top: 2px; }
.inbox-banner-arrow { color: var(--txt-muted); flex-shrink: 0; }
.inbox-banner-arrow svg { width: 18px; height: 18px; }

/* ── Section headers ───────────────────────────────────── */

.list-section-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 2px 8px;
}
.list-section-title {
  font-size: 12px; font-weight: 600; color: var(--txt-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.list-section-count {
  font-size: 12px; font-weight: 600; color: var(--txt-muted);
  background: var(--border-subtle);
  padding: 2px 8px; border-radius: 999px;
}

/* ── Account list ──────────────────────────────────────── */

.account-list { display: flex; flex-direction: column; gap: 1px; }

.account-card {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: background 0.1s;
  margin-bottom: 6px;
  min-height: 64px;
}
.account-card:active { background: var(--bg); }

@keyframes mintIn {
  0%   { opacity: 0; transform: translateY(-8px); }
  100% { opacity: 1; transform: translateY(0); }
}
.account-card.minted {
  animation: mintIn 0.3s ease-out;
  border-color: rgba(59,130,246,0.4);
}

.account-avatar {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
  flex-shrink: 0;
}

.account-id { flex: 1; min-width: 0; }
.account-text .addr {
  font-size: 15px; font-weight: 600; color: var(--txt);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.account-text .meta { font-size: 12px; color: var(--txt-muted); margin-top: 2px; }

.account-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* action buttons — larger touch targets on mobile */
.action-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--txt-sub);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.action-btn:active { background: var(--border-subtle); }
.action-btn.danger:active { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.action-btn svg { width: 16px; height: 16px; pointer-events: none; }

/* ── Empty state ───────────────────────────────────────── */

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 52px 20px; gap: 10px; text-align: center; color: var(--txt-muted);
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); width: 100%;
}
.empty-state-icon {
  width: 48px; height: 48px; border-radius: 14px;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 2px;
}
.empty-state-icon svg { width: 24px; height: 24px; }
.empty-state p { font-size: 14px; color: var(--txt-sub); line-height: 1.5; max-width: 220px; }

/* ── Log card ──────────────────────────────────────────── */

.log-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 4px 16px;
  margin-bottom: 8px;
}

.log-list { display: flex; flex-direction: column; }
.log-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 11px 0;
  border-bottom: 1px solid var(--border-subtle);
  gap: 12px;
}
.log-row:last-child { border-bottom: none; }
.log-email { font-size: 13px; font-weight: 500; color: var(--txt); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log-badge {
  font-size: 11px; font-weight: 600;
  padding: 3px 9px; border-radius: 999px;
  flex-shrink: 0;
}
.log-badge.ok  { background: var(--success-soft); color: var(--success); }
.log-badge.err { background: var(--danger-soft);  color: var(--danger); }

/* ── Domain chips ──────────────────────────────────────── */

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  font-size: 13px; font-weight: 500;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--txt-sub);
  cursor: pointer;
  transition: all 0.15s;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Bottom navigation ─────────────────────────────────── */

.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + var(--safe-b));
  background: var(--card);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex; align-items: flex-start; justify-content: space-around;
  padding-top: 8px; z-index: 100;
}

.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 11px; font-weight: 600;
  color: var(--txt-muted);
  cursor: pointer; padding: 8px 28px;
  border: none; background: none;
  text-decoration: none;
  transition: color 0.15s;
  -webkit-user-select: none; user-select: none;
}
.nav-item.active { color: var(--accent); }
.nav-item:active { opacity: 0.6; }
.nav-item svg { width: 24px; height: 24px; }

/* ── FAB ───────────────────────────────────────────────── */

.fab {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  right: 20px;
  width: 52px; height: 52px;
  background: var(--accent);
  color: #fff;
  border: none; border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(59,130,246,0.35);
  z-index: 99;
  transition: transform 0.15s, box-shadow 0.15s;
}
.fab:active { transform: scale(0.92); box-shadow: 0 2px 8px rgba(59,130,246,0.25); }
.fab svg { width: 24px; height: 24px; }

/* ── Sheet overlay ─────────────────────────────────────── */

.sheet-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 200; opacity: 0; pointer-events: none;
  transition: opacity 0.3s;
}
.sheet-overlay.visible { opacity: 1; pointer-events: all; }

/* ── Create email bottom sheet ─────────────────────────── */

.create-sheet {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  z-index: 201;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  max-height: 92dvh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.create-sheet.visible { transform: translateY(0); }

.sheet-handle {
  width: 36px; height: 4px;
  background: var(--border);
  border-radius: 4px;
  margin: 12px auto 0;
  flex-shrink: 0;
}

.create-sheet-inner {
  padding: 16px 20px calc(24px + var(--safe-b));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; gap: 14px;
}

.create-sheet-header,
.sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 4px;
}
.create-sheet-title,
.sheet-title { font-size: 17px; font-weight: 700; color: var(--txt); letter-spacing: -0.02em; }

.sheet-body {
  flex: 1;
  min-height: 0;
  padding: 12px 20px calc(28px + var(--safe-b));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sheet-close-btn {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: var(--bg);
  border-radius: 8px; color: var(--txt-sub); cursor: pointer;
}
.sheet-close-btn:active { background: var(--border); }
.sheet-close-btn svg { width: 16px; height: 16px; }

/* ── Toast ─────────────────────────────────────────────── */

#toast {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-b) + 80px);
  left: 50%; transform: translateX(-50%) translateY(16px);
  background: var(--txt); color: #fff;
  padding: 11px 20px; border-radius: 999px;
  font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow);
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 210;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); }

/* ── Icon button ───────────────────────────────────────── */

.icon-btn {
  width: 44px; height: 44px;
  border-radius: var(--radius-sm);
  border: none; background: transparent;
  color: var(--txt-sub); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background 0.15s, color 0.15s;
}
.icon-btn:active { background: var(--border-subtle); transform: scale(0.9); }
.icon-btn svg { width: 20px; height: 20px; }

/* ── Settings sheet rows ───────────────────────────────── */

.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; background: var(--card);
  border-radius: var(--radius-sm); margin-bottom: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
}
.settings-row-left { display: flex; align-items: center; gap: 12px; }
.settings-row-icon {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
}
.settings-row-icon svg { width: 18px; height: 18px; }
.settings-row-label { font-size: 14px; font-weight: 500; color: var(--txt); }
.settings-row-sub   { font-size: 12px; color: var(--txt-muted); margin-top: 1px; }

.toggle-track {
  width: 44px; height: 26px; border-radius: 13px;
  background: var(--border); position: relative;
  cursor: pointer; transition: background 0.2s; flex-shrink: 0;
}
.toggle-track.on { background: var(--accent); }
.toggle-thumb {
  position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.2s;
}
.toggle-track.on .toggle-thumb { transform: translateX(18px); }

.settings-danger-row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; background: var(--card);
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  color: var(--danger); font-size: 14px; font-weight: 500;
  cursor: pointer; text-decoration: none; margin-top: 8px;
}
.settings-danger-row svg { width: 20px; height: 20px; }
.settings-danger-row:active { opacity: 0.7; }

/* ── Tiny helper text ──────────────────────────────────── */

.tiny-note { font-size: 12px; color: var(--txt-muted); line-height: 1.5; }

/* ── Desktop layout (≥ 640px) ──────────────────────────── */

@media (min-width: 640px) {
  .page-body {
    padding-bottom: calc(var(--nav-h) + var(--safe-b) + 40px);
    padding-left: 20px; padding-right: 20px;
    margin: 0 auto;
  }

  .fab { right: max(20px, calc(50% - 300px + 20px)); }

  .create-sheet {
    max-width: 480px;
    left: 50%; right: auto;
    transform: translateX(-50%) translateY(100%);
  }
  .create-sheet.visible {
    transform: translateX(-50%) translateY(0);
  }

  #toast { bottom: calc(var(--nav-h) + var(--safe-b) + 90px); }
}

/* ── Language toggle ───────────────────────────────────── */

.lang-toggle {
  display: flex;
  gap: 4px;
  align-items: center;
}

.lang-btn {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--txt-sub);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  min-height: 28px;
  min-width: 36px;
}

.lang-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
