/* ─── Reset & Base ─────────────────────────────────────────────────────────── */

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

:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-tertiary: #1a2235;
  --bg-card: #151c2c;
  --bg-hover: #1e2a3e;
  --bg-input: #0d1320;
  --border: #1e2d42;
  --border-light: #263552;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #22c55e;
  --accent-hover: #16a34a;
  --accent-glow: rgba(34, 197, 94, 0.15);
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);
  --transition: 0.2s ease;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── App Layout ──────────────────────────────────────────────────────────── */

.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ─── Header ──────────────────────────────────────────────────────────────── */

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 0;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  color: var(--text-primary);
  letter-spacing: 0.5px;
}

.logo svg {
  color: var(--accent);
}

.logo strong {
  font-weight: 700;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition);
}

.status-badge.connected .status-dot {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

.status-badge.error .status-dot {
  background: var(--danger);
  box-shadow: 0 0 8px var(--danger);
}

/* ─── Input Section ───────────────────────────────────────────────────────── */

.input-section {
  padding: 32px 0 20px;
}

.input-section h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}

.subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.email-input-wrapper {
  display: flex;
  gap: 10px;
}

.email-input-wrapper input {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 15px;
  font-family: 'Inter', sans-serif;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.email-input-wrapper input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.email-input-wrapper input::placeholder {
  color: var(--text-muted);
}

.btn-primary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  white-space: nowrap;
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

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

.input-options {
  margin-top: 12px;
}

.option-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  max-width: 300px;
}

.option-label .optional {
  color: var(--text-muted);
  font-weight: 400;
}

.option-label input {
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-family: 'Inter', sans-serif;
  outline: none;
  transition: border-color var(--transition);
}

.option-label input:focus {
  border-color: var(--accent);
}

.option-label input::placeholder {
  color: var(--text-muted);
}

/* ─── Action Bar ──────────────────────────────────────────────────────────── */

.action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.action-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.monitoring-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

.monitoring-label.active {
  color: var(--accent);
}

.action-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.notice {
  font-size: 12px;
  color: var(--warning);
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.3s ease;
  white-space: nowrap;
}

.notice.visible {
  opacity: 1;
}

.btn-secondary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-light);
}

.btn-secondary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-danger {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.4);
}

.auto-refresh-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  padding: 6px 10px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* ─── Inbox Table ─────────────────────────────────────────────────────────── */

.inbox-section {
  padding: 0 0 40px;
}

.inbox-table {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-card);
}

.inbox-header {
  display: grid;
  grid-template-columns: 8px 1fr 2fr 80px 70px;
  gap: 16px;
  padding: 14px 20px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.inbox-body {
  min-height: 200px;
}

.email-row {
  display: grid;
  grid-template-columns: 8px 1fr 2fr 80px 70px;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  align-items: center;
  transition: background var(--transition);
  cursor: default;
}

.email-row:last-child {
  border-bottom: none;
}

.email-row:hover {
  background: var(--bg-hover);
}

.email-row .col-status {
  display: flex;
  align-items: center;
}

.email-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.email-dot.error {
  background: var(--danger);
}

.email-dot.read {
  background: transparent;
  border: 1px solid var(--text-muted);
}

.col-sender {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.col-subject {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.col-time {
  font-size: 12px;
  color: var(--text-muted);
  text-align: right;
}

.col-view {
  text-align: right;
}

.btn-view {
  padding: 5px 14px;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-view:hover {
  background: var(--accent);
  color: #fff;
}

/* ─── Empty State ─────────────────────────────────────────────────────────── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-muted);
  text-align: center;
}

.empty-state svg {
  opacity: 0.3;
  margin-bottom: 16px;
}

.empty-state h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.empty-state p {
  font-size: 13px;
  max-width: 360px;
  line-height: 1.5;
}

/* ─── Email Viewer Overlay ────────────────────────────────────────────────── */

.email-viewer-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  z-index: 100;
  display: none;
  overflow-y: auto;
}

.email-viewer-overlay.active {
  display: block;
}

.email-viewer {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
}

.email-viewer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.btn-back {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-back:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
}

.email-viewer-actions {
  display: flex;
  gap: 8px;
}

.btn-icon {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: all var(--transition);
}

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

.email-viewer-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.email-viewer-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-muted);
  flex-shrink: 0;
}

.email-viewer-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.email-viewer-from {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.email-viewer-date {
  font-size: 12px;
  color: var(--text-muted);
}

.email-viewer-subject {
  font-size: 13px;
  color: var(--text-muted);
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 24px;
  font-family: 'Inter', monospace;
}

.email-viewer-subject span {
  color: var(--text-primary);
  font-weight: 500;
}

.email-viewer-body {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 300px;
  overflow: hidden;
}

.email-iframe {
  width: 100%;
  min-height: 400px;
  border: none;
  background: #fff;
  border-radius: var(--radius);
}

.email-source-view {
  padding: 20px;
  margin: 0;
  font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-muted);
  background: transparent;
  border: none;
  overflow-x: auto;
  max-height: 600px;
  overflow-y: auto;
}

/* ─── Loading spinner ─────────────────────────────────────────────────────── */

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

.pending-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--accent-glow);
  border: 1px solid rgba(34, 197, 94, 0.3);
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
}

/* ─── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 640px) {
  .app {
    padding: 0 12px;
  }

  .inbox-header,
  .email-row {
    grid-template-columns: 8px 1fr 1fr 60px;
    gap: 10px;
    padding: 12px 14px;
  }

  .col-time {
    display: none;
  }

  .email-input-wrapper {
    flex-direction: column;
  }

  .action-bar {
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
  }

  .action-right {
    width: 100%;
    justify-content: space-between;
  }
}
