/* ===== CSS Variables ===== */
:root {
  --bg: #0a0a0f;
  --surface: #111118;
  --surface2: #16161f;
  --border: #1e1e2e;
  --border-light: #2a2a3e;
  --blue: #3b82f6;
  --blue-light: #60a5fa;
  --blue-dim: rgba(59, 130, 246, 0.15);
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-dim: #475569;
  --red: #f87171;
  --green: #22c55e;
  --yellow: #fbbf24;
  --radius: 10px;
  --radius-sm: 6px;
}

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

a {
  color: var(--blue-light);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button {
  cursor: pointer;
  font-family: inherit;
  border: none;
  outline: none;
}

input, select {
  font-family: inherit;
  outline: none;
}

/* ===== Utility ===== */
.hidden { display: none !important; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s ease;
  cursor: pointer;
}

.btn-primary {
  background: var(--blue);
  color: #fff;
  border: 1px solid transparent;
}

.btn-primary:hover {
  background: var(--blue-light);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-light);
}

.btn-ghost:hover {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--blue);
}

.btn-danger {
  background: transparent;
  color: var(--red);
  border: 1px solid rgba(248, 113, 113, 0.3);
}

.btn-danger:hover {
  background: rgba(248, 113, 113, 0.1);
}

/* ===== Spinner ===== */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

.spinner-blue {
  border-color: rgba(59,130,246,0.2);
  border-top-color: var(--blue);
}

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

/* ===== Toast ===== */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface2);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 0.85rem;
  color: var(--text);
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  z-index: 9999;
  transform: translateY(80px);
  opacity: 0;
  transition: all 0.3s ease;
  max-width: 320px;
}

#toast.show {
  transform: translateY(0);
  opacity: 1;
}

#toast.success { border-left: 3px solid var(--green); }
#toast.error   { border-left: 3px solid var(--red); }
#toast.info    { border-left: 3px solid var(--blue); }

/* ===== Nav ===== */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
  text-decoration: none;
}

.nav-brand svg {
  color: var(--blue);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ===== Page container ===== */
.page {
  max-width: 680px;
  margin: 0 auto;
  padding: 40px 20px;
}

/* ===== Card ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  position: relative;
  overflow: hidden;
}

.card-accent::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--blue), var(--blue-light));
}

/* ===== Form elements ===== */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-input {
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text);
  font-size: 0.9rem;
  transition: border-color 0.2s;
  width: 100%;
}

.form-input:focus {
  border-color: var(--blue);
}

.form-input::placeholder {
  color: var(--text-dim);
}

.form-select {
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text);
  font-size: 0.9rem;
  width: 100%;
  cursor: pointer;
  transition: border-color 0.2s;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-select:focus {
  border-color: var(--blue);
}

.form-select option {
  background: var(--surface2);
}

/* ===== Address display ===== */
.address-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
}

.address-text {
  flex: 1;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.95rem;
  color: var(--blue-light);
  word-break: break-all;
}

.copy-btn {
  background: transparent;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  color: var(--text-muted);
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s;
  flex-shrink: 0;
}

.copy-btn:hover {
  border-color: var(--blue);
  color: var(--blue-light);
}

.copy-btn.copied {
  border-color: var(--green);
  color: var(--green);
}

/* ===== Timer / badge ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 500;
}

.badge-blue {
  background: var(--blue-dim);
  color: var(--blue-light);
  border: 1px solid rgba(59,130,246,0.2);
}

.badge-green {
  background: rgba(34,197,94,0.1);
  color: var(--green);
  border: 1px solid rgba(34,197,94,0.2);
}

.badge-yellow {
  background: rgba(251,191,36,0.1);
  color: var(--yellow);
  border: 1px solid rgba(251,191,36,0.2);
}

.badge-red {
  background: rgba(248,113,113,0.1);
  color: var(--red);
  border: 1px solid rgba(248,113,113,0.2);
}

/* ===== Message list ===== */
.msg-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.msg-item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  border: 1px solid transparent;
}

.msg-item:hover {
  background: var(--surface2);
  border-color: var(--border);
}

.msg-item.unread {
  background: rgba(59,130,246,0.04);
}

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

.msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--blue-dim);
  border: 1px solid rgba(59,130,246,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--blue-light);
  flex-shrink: 0;
  text-transform: uppercase;
}

.msg-body {
  flex: 1;
  min-width: 0;
}

.msg-from {
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-subject {
  font-size: 0.9rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 2px 0;
}

.msg-time {
  font-size: 0.75rem;
  color: var(--text-dim);
  flex-shrink: 0;
  margin-top: 2px;
}

.unread-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--blue);
  flex-shrink: 0;
  margin-top: 6px;
}

/* ===== Message viewer ===== */
.msg-viewer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.msg-viewer-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.msg-viewer-subject {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
}

.msg-viewer-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.msg-viewer-body {
  padding: 24px;
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--text);
  overflow-x: auto;
}

.msg-viewer-body iframe {
  width: 100%;
  border: none;
  min-height: 300px;
  background: #fff;
  border-radius: var(--radius-sm);
}

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-dim);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  opacity: 0.3;
}

.empty-state p {
  font-size: 0.9rem;
}

/* ===== Advanced toggle ===== */
.advanced-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  margin-bottom: 16px;
  width: fit-content;
}

.advanced-toggle:hover {
  color: var(--blue-light);
}

.advanced-toggle svg {
  transition: transform 0.2s;
}

.advanced-toggle.open svg {
  transform: rotate(180deg);
}

.advanced-panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 16px;
  display: none;
}

.advanced-panel.open {
  display: block;
}

/* ===== Progress bar ===== */
.progress-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--blue-light));
  border-radius: 2px;
  transition: width 1s linear;
}

/* ===== Divider ===== */
.divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
  .page {
    padding: 20px 14px;
  }

  .card {
    padding: 20px 16px;
  }

  .nav {
    padding: 12px 16px;
  }

  .msg-viewer-header,
  .msg-viewer-body {
    padding: 16px;
  }
}
/* ===== Mobile Responsive Overrides ===== */
@media (max-width: 600px) {

  /* Nav: tighter padding */
  .nav {
    padding: 10px 14px;
    gap: 8px;
  }

  /* Hide brand text, keep icon only */
  .nav-brand .nav-brand-text {
    display: none;
  }

  /* Icon-only buttons: hide label spans */
  .btn .btn-label {
    display: none;
  }

  /* Make icon-only buttons square and compact */
  .btn-icon-mobile {
    padding: 8px !important;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
  }

  /* Nav actions tighter gap */
  .nav-actions {
    gap: 6px;
  }

  /* Timer badge smaller */
  .badge {
    font-size: 0.72rem;
    padding: 3px 8px;
  }

  /* Address card: stack vertically */
  .address-card-row {
    flex-direction: column !important;
    align-items: flex-start !important;
  }

  .address-card-status {
    align-items: flex-start !important;
  }

  /* Address text smaller on mobile */
  .address-text {
    font-size: 0.78rem;
  }

  /* Page padding */
  .page {
    padding: 16px 12px;
  }

  /* Card padding */
  .card {
    padding: 16px 14px;
  }

  /* Message viewer header/body */
  .msg-viewer-header,
  .msg-viewer-body {
    padding: 14px;
  }

  /* Verification page: remove card box, fill screen */
  .waf-card {
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    padding: 32px 20px 24px !important;
    max-width: 100% !important;
  }

  .waf-card::before {
    display: none !important;
  }
}
