:root {
  --bg: #0b1120;
  --bg-elevated: #111827;
  --bg-card: #131c2e;
  --bg-hover: #1a253d;
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.28);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent: #10b981;
  --accent-hover: #059669;
  --accent-soft: rgba(16, 185, 129, 0.14);
  --accent-border: rgba(16, 185, 129, 0.35);
  --danger: #f43f5e;
  --danger-soft: rgba(244, 63, 94, 0.14);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.15);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow: 0 18px 40px rgba(2, 6, 23, 0.45);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at top right, rgba(16, 185, 129, 0.12), transparent 36%),
              radial-gradient(circle at top left, rgba(59, 130, 246, 0.08), transparent 34%),
              var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.ic {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* TOPBAR */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(12px);
  background: rgba(11, 17, 32, 0.82);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  display: grid;
  place-items: center;
}

.brand-icon svg {
  width: 20px;
  height: 20px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-text strong {
  font-size: 1rem;
  letter-spacing: -0.01em;
}

.brand-text small {
  font-size: 0.78rem;
  color: var(--accent);
  font-weight: 500;
}

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

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 999px;
}

.status-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
}

.status-pill.polling .dot {
  animation: pulse 1.8s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { box-shadow: 0 0 0 7px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* MAIN CONTAINER */
.container {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ADDRESS CARD */
.address-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow);
}

.address-card h1 {
  margin: 0 0 4px;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0 0 16px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.address-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.email-input-group {
  flex: 1;
  min-width: 260px;
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 4px 12px 4px 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.email-input-group:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18);
}

.email-input {
  flex: 1;
  min-width: 110px;
  background: transparent;
  border: 0;
  outline: none;
  color: var(--text);
  font-size: 1rem;
  padding: 10px 0;
  font-weight: 500;
}

.email-input::placeholder {
  color: var(--text-dim);
  font-weight: 400;
}

.at-sign {
  color: var(--text-dim);
  font-weight: 600;
  padding: 0 6px;
  user-select: none;
}

.domain-static {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.95rem;
  user-select: none;
  white-space: nowrap;
}

.domain-select {
  background: var(--bg-card);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font-size: 0.92rem;
  font-weight: 600;
  outline: none;
  cursor: pointer;
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  font-weight: 600;
  padding: 10px 16px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
  white-space: nowrap;
}

.btn:active {
  transform: translateY(1px);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.83rem;
  border-radius: var(--radius-sm);
}

.btn-primary {
  background: var(--accent);
  color: #042f2e;
}

.btn-primary:hover {
  background: #34d399;
}

.btn-secondary {
  background: rgba(30, 41, 59, 0.7);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.btn-dev {
  background: var(--amber-soft);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.35);
  font-size: 0.82rem;
  padding: 7px 12px;
}

.btn-dev:hover {
  background: rgba(245, 158, 11, 0.25);
}

.btn-icon {
  background: rgba(30, 41, 59, 0.7);
  color: var(--text);
  border-color: var(--border);
  padding: 7px 9px;
  border-radius: var(--radius-sm);
}

.btn-icon:hover {
  background: var(--bg-hover);
}

.btn-danger-ghost {
  background: transparent;
  color: #fda4af;
  border-color: rgba(244, 63, 94, 0.3);
}

.btn-danger-ghost:hover {
  background: var(--danger-soft);
  color: #fff;
}

.spin {
  animation: spin 0.75s linear infinite;
}

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

.quick-actions {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* RECENT CHIPS */
.recent-section {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.recent-label {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.recent-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.recent-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.recent-chip button {
  background: none;
  border: 0;
  color: inherit;
  cursor: pointer;
  padding: 0;
  font-size: inherit;
}

.recent-chip .open-chip:hover {
  color: var(--accent);
}

.recent-chip .remove-chip {
  color: var(--text-dim);
  font-weight: 700;
  padding-left: 2px;
}

.recent-chip .remove-chip:hover {
  color: var(--danger);
}

/* WORKSPACE SPLIT PANE */
.workspace {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 16px;
  min-height: 540px;
  flex: 1;
}

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.panel-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-title-wrap h2 {
  margin: 0;
  font-size: 1rem;
}

.count-badge {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent-border);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}

.panel-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
}

.toggle-chip input {
  accent-color: var(--accent);
  cursor: pointer;
}

.active-inbox-bar {
  padding: 9px 16px;
  background: rgba(15, 23, 42, 0.55);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.8rem;
}

.active-inbox-email {
  color: var(--accent);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.last-sync {
  color: var(--text-dim);
  white-space: nowrap;
}

/* MESSAGE LIST */
.message-list {
  flex: 1;
  overflow-y: auto;
  max-height: 68vh;
}

.message-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  gap: 12px;
  transition: background 0.12s ease;
}

.message-item:hover {
  background: var(--bg-hover);
}

.message-item.active {
  background: rgba(16, 185, 129, 0.12);
  box-shadow: inset 3px 0 0 var(--accent);
}

.msg-avatar {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: rgba(51, 65, 85, 0.65);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.95rem;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

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

.msg-top-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}

.msg-sender {
  font-weight: 600;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-time {
  font-size: 0.75rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.msg-subject {
  font-size: 0.88rem;
  font-weight: 600;
  color: #e2e8f0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 3px;
}

.msg-snippet {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.msg-otp-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 7px;
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 0.76rem;
  font-weight: 700;
  background: var(--accent-soft);
  color: #34d399;
  border: 1px solid var(--accent-border);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* EMPTY STATES */
.empty-state {
  padding: 56px 24px;
  text-align: center;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
}

.empty-icon {
  font-size: 2.3rem;
  margin-bottom: 10px;
}

.empty-title {
  margin: 0 0 6px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.empty-desc {
  margin: 0;
  font-size: 0.88rem;
  max-width: 340px;
}

/* READER PANEL */
.reader-mobile-bar {
  display: none;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.reader-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.reader-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}

.reader-subject-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.detail-subject {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.35;
  word-break: break-word;
}

.reader-meta {
  display: grid;
  gap: 4px;
  font-size: 0.85rem;
}

.meta-row {
  display: flex;
  gap: 10px;
}

.meta-label {
  width: 64px;
  flex-shrink: 0;
  color: var(--text-dim);
}

.meta-val {
  color: var(--text-muted);
  word-break: break-word;
}

/* OTP BANNER */
.otp-banner {
  margin: 14px 20px 0;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.16), rgba(6, 182, 212, 0.1));
  border: 1px solid var(--accent-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.otp-info {
  display: flex;
  flex-direction: column;
}

.otp-tag {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #6ee7b7;
}

.otp-code {
  font-size: 1.55rem;
  letter-spacing: 0.14em;
  color: #ffffff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ATTACHMENTS */
.attachments-bar {
  margin: 12px 20px 0;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* VIEW TABS */
.view-tabs {
  display: flex;
  gap: 6px;
  padding: 12px 20px 10px;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border-strong);
}

/* READER BODY */
.reader-body {
  flex: 1;
  padding: 16px 20px 20px;
  display: flex;
  flex-direction: column;
}

.email-iframe {
  width: 100%;
  min-height: 460px;
  height: 60vh;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #ffffff;
}

.email-text {
  margin: 0;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: #e2e8f0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88rem;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
  min-height: 260px;
  max-height: 60vh;
  overflow-y: auto;
}

/* FOOTER */
.footer {
  text-align: center;
  padding: 14px 20px 22px;
  color: var(--text-dim);
  font-size: 0.8rem;
}

.footer p {
  margin: 0;
}

/* TOAST */
.toast-container {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: #0f172a;
  color: var(--text);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.86rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: fadeSlide 0.18s ease-out;
}

.toast.error {
  border-color: rgba(244, 63, 94, 0.55);
  color: #fecdd3;
}

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

/* RESPONSIVE MOBILE */
@media (max-width: 880px) {
  .container {
    padding: 14px;
  }

  .address-card {
    padding: 16px;
  }

  .workspace {
    grid-template-columns: 1fr;
    min-height: 440px;
  }

  .workspace.mobile-reading .list-panel {
    display: none;
  }

  .workspace:not(.mobile-reading) .reader-panel {
    display: none;
  }

  .workspace.mobile-reading .reader-mobile-bar {
    display: block;
  }

  .message-list {
    max-height: none;
  }

  .email-iframe {
    height: 65vh;
    min-height: 400px;
  }
}
