:root {
  --bg-app: #08090d;
  --bg-panel: #0e1118;
  --bg-panel-hover: #141823;
  --bg-panel-active: #191f2e;
  --bg-subtle: rgba(255, 255, 255, 0.03);
  --border-color: #1a1e2a;
  --border-active: #2b3348;
  --text-main: #f1f3f8;
  --text-muted: #8b92a4;
  --text-faint: #4e5566;
  --accent-blue: #3b82f6;
  --accent-hover: #2563eb;
  --success-dot: #10b981;
  --danger: #ef4444;
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

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

body {
  background-color: var(--bg-app);
  color: var(--text-main);
  font-family: var(--font-ui);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.5;
}

.app-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100vh;
}

/* --- Top Navigation --- */
.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
}

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

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: #141823;
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-main);
}

.brand-name {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.domain-tag {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  padding: 2px 8px;
  border-radius: 999px;
  font-family: var(--font-mono);
}

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

.status-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
}

.status-indicator {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--success-dot);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
}

.poll-counter {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-faint);
}

.icon-action-btn {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.15s ease;
}
.icon-action-btn:hover {
  background: var(--bg-panel-hover);
  color: var(--text-main);
  border-color: var(--border-active);
}
.icon-action-btn.muted {
  opacity: 0.5;
}

/* --- Address Control Strip --- */
.address-strip {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 16px;
}

.address-box {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.address-field-wrap {
  flex: 1;
  min-width: 260px;
  position: relative;
  cursor: pointer;
}

.address-field-wrap input {
  width: 100%;
  height: 42px;
  background: #080a0f;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 500;
  color: #e2e8f0;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.address-field-wrap input:hover {
  border-color: var(--border-active);
}

.copied-badge {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: #10b981;
  color: #032b1d;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}
.copied-badge.show {
  opacity: 1;
}

.address-btn-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Unified clean buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 42px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-primary {
  background: #ffffff;
  color: #08090d;
}
.btn-primary:hover {
  background: #e2e8f0;
}

.btn-secondary {
  background: var(--bg-panel-hover);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}
.btn-secondary:hover {
  background: #1a2030;
  border-color: var(--border-active);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.1);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.2);
}
.btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
}

.btn-icon-only {
  width: 42px;
  padding: 0;
}

.sync-icon.spinning {
  animation: rotateSync 0.8s infinite linear;
}
@keyframes rotateSync {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* --- Workspace Split Pane --- */
.workspace {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
  flex: 1;
  min-height: 560px;
}

/* Left: Feed Pane */
.feed-pane {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.feed-top {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.feed-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-main);
}

.count-pill {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--bg-panel-hover);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
}

.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-input-wrap svg {
  position: absolute;
  left: 10px;
  color: var(--text-faint);
}
.search-input-wrap input {
  width: 100%;
  height: 32px;
  background: #080a0f;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0 10px 0 32px;
  color: var(--text-main);
  font-size: 0.82rem;
  outline: none;
}
.search-input-wrap input:focus {
  border-color: var(--border-active);
}

.feed-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.feed-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  transition: background 0.12s ease;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.feed-item:hover {
  background: var(--bg-panel-hover);
}
.feed-item.active {
  background: var(--bg-panel-active);
  border-left: 2px solid #ffffff;
}

.item-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.item-sender {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-stamp {
  font-size: 0.72rem;
  color: var(--text-faint);
  flex-shrink: 0;
}
.item-headline {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-preview {
  font-size: 0.78rem;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Empty State */
.empty-feed {
  padding: 60px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
}
.pulse-ring {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
  animation: ringPulse 2s infinite cubic-bezier(0.45, 0, 0.55, 1);
  margin-bottom: 16px;
}
@keyframes ringPulse {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.6); }
  70% { box-shadow: 0 0 0 14px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}
.empty-main {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 4px;
}
.empty-sub {
  font-size: 0.78rem;
  color: var(--text-faint);
  max-width: 240px;
  line-height: 1.4;
}

/* Right: Reader Pane */
.reader-pane {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.reader-idle {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 40px;
  text-align: center;
  color: var(--text-faint);
  gap: 12px;
}
.idle-glyph {
  opacity: 0.4;
}
.reader-idle p {
  font-size: 0.88rem;
}

.reader-content {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.reader-nav {
  padding: 10px 18px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  background: #080a0f;
}
.btn-back-link {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-back-link:hover {
  color: var(--text-main);
}
.nav-spacer {
  flex: 1;
}
.btn-clean-action {
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-clean-action:hover {
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.3);
  background: rgba(239, 68, 68, 0.05);
}

/* OTP Banner */
.otp-banner {
  background: #0d1e17;
  border-bottom: 1px solid #163e2d;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.otp-caption {
  font-size: 0.82rem;
  color: #6ee7b7;
  font-weight: 500;
}
.otp-val {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  color: #ffffff;
  background: #052e16;
  border: 1px solid #10b981;
  padding: 2px 10px;
  border-radius: 4px;
  letter-spacing: 0.08em;
}
.btn-copy-otp {
  margin-left: auto;
  background: #10b981;
  color: #032b1d;
  border: none;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.15s ease;
}
.btn-copy-otp:hover {
  filter: brightness(1.1);
}

/* Email Meta Header */
.email-header {
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--border-color);
}
.email-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 10px;
}
.email-meta-bar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}
.sender-block {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.sender-title {
  font-size: 0.88rem;
  font-weight: 600;
}
.sender-addr {
  font-size: 0.8rem;
  color: var(--text-faint);
  font-family: var(--font-mono);
}
.meta-timestamp {
  font-size: 0.8rem;
  color: var(--text-faint);
}

/* Email Body Pane */
.email-body-pane {
  flex: 1;
  background: #080a0f;
  overflow-y: auto;
  position: relative;
}
.body-text-viewport {
  padding: 22px;
  color: #d1d5db;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}
#htmlFrame {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-box {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
  max-width: 320px;
  width: 100%;
  text-align: center;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.modal-head h4 {
  font-size: 0.92rem;
  font-weight: 600;
}
.btn-close-modal {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 1rem;
  cursor: pointer;
}
.modal-content canvas {
  margin: 0 auto 12px;
  background: white;
  padding: 8px;
  border-radius: 6px;
}
.qr-email-mono {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  word-break: break-all;
}

/* Toast Stack */
.toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast-node {
  background: #141824;
  border: 1px solid var(--border-active);
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  font-weight: 500;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  animation: toastIn 0.2s ease;
}
@keyframes toastIn {
  from { transform: translateY(10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.toast-node.success {
  border-left: 3px solid var(--success-dot);
}
.toast-node.error {
  border-left: 3px solid var(--danger);
}

.hidden {
  display: none !important;
}

/* Mobile Responsive */
@media (max-width: 820px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .feed-pane.mobile-hidden {
    display: none;
  }
  .reader-pane.mobile-active {
    display: flex;
  }
  .reader-pane:not(.mobile-active) {
    display: none;
  }
  .btn-back-link {
    display: inline-block;
  }
}
