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

:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  
  --transition-fast: 0.1s ease-out;
  --transition-smooth: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

/* ===== Dark Theme (Default) ===== */
[data-theme="dark"] {
  --bg: #000000;
  --surface: #0a0a0a;
  --surface-hover: #141414;
  --border: #222222;
  --border-hover: #333333;
  
  --text-main: #ededed;
  --text-muted: #888888;
  --text-inverse: #000000;
  
  --accent: #ededed;
  --accent-hover: #ffffff;
  --accent-bg: rgba(255, 255, 255, 0.1);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-bg: rgba(239, 68, 68, 0.1);
  
  --modal-bg: rgba(0, 0, 0, 0.6);
  
  color-scheme: dark;
}

/* ===== Light Theme ===== */
[data-theme="light"] {
  --bg: #ffffff;
  --surface: #fafafa;
  --surface-hover: #f4f4f5;
  --border: #eaeaea;
  --border-hover: #d4d4d8;
  
  --text-main: #111111;
  --text-muted: #666666;
  --text-inverse: #ffffff;
  
  --accent: #111111;
  --accent-hover: #000000;
  --accent-bg: rgba(0, 0, 0, 0.05);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-bg: rgba(239, 68, 68, 0.05);
  
  --modal-bg: rgba(255, 255, 255, 0.6);
  
  color-scheme: light;
}

html, body { 
  height: 100%; 
  background-color: var(--bg);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--transition-smooth), color var(--transition-smooth);
}

a { color: var(--text-main); text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; font-size: 13px; font-weight: 500; }
input { font-family: inherit; }

.container {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ===== Header ===== */
.site-header {
  height: 64px;
  display: flex;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 100;
}

.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.01em;
  color: var(--text-main);
}

.brand svg {
  color: var(--text-main);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #f59e0b;
}
.status-dot.connected { background: #10b981; box-shadow: 0 0 8px rgba(16, 185, 129, 0.4); }
.status-dot.error { background: var(--danger); box-shadow: 0 0 8px rgba(239, 68, 68, 0.4); }

.btn-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: color var(--transition-fast);
}

.btn-icon:hover {
  color: var(--text-main);
}

[data-theme="dark"] .theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-light { display: block; }
[data-theme="light"] .theme-icon-dark { display: block; }
[data-theme="light"] .theme-icon-light { display: none; }

/* ===== App Main ===== */
.app {
  padding-top: 48px;
  padding-bottom: 64px;
  display: flex;
  flex-direction: column;
  gap: 64px;
}

/* ===== Email Section ===== */
.email-section {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.email-wrapper {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.email-container {
  display: flex;
  align-items: center;
  width: 100%;
  border-bottom: 1px solid var(--border);
  padding: 0 0 12px 0;
  transition: border-color var(--transition-fast);
}

.email-container:focus-within {
  border-color: var(--text-muted);
}

.email-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 500;
  outline: none;
  min-width: 0;
  text-align: left;
  letter-spacing: -0.02em;
}

.email-input::selection {
  background: var(--text-muted);
  color: var(--bg);
}

.btn-copy {
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: all var(--transition-fast);
}

.btn-copy:hover {
  color: var(--text-main);
  border-color: var(--border-hover);
  background: var(--surface-hover);
}

.btn-copy:active {
  transform: scale(0.97);
}

.email-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.divider {
  width: 1px;
  height: 16px;
  background: var(--border);
  margin: 0 4px;
}

.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  transition: color var(--transition-fast);
  font-size: 13px;
}

.btn-action:hover {
  color: var(--text-main);
}

.btn-danger:hover {
  color: var(--danger);
}

/* ===== Inbox Section ===== */
.inbox-section {
  display: flex;
  flex-direction: column;
}

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

.inbox-title {
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-main);
}

.count-badge {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.mail-list {
  display: flex;
  flex-direction: column;
}

.empty-state {
  padding: 48px 0;
  color: var(--text-muted);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 1.5px solid var(--border-hover);
  border-top-color: var(--text-muted);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.mail-item {
  position: relative;
  display: grid;
  grid-template-columns: 160px 1fr auto;
  gap: 16px;
  padding: 16px 0;
  padding-left: 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  align-items: center;
  transition: opacity var(--transition-fast);
}

.mail-item:hover {
  opacity: 0.6;
}

.mail-item.unread {
  font-weight: 500;
  color: var(--text-main);
}
.mail-item.unread .mail-subject {
  color: var(--text-main);
}
.mail-item.unread::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 50%;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-main);
  transform: translateY(-50%);
}

.mail-sender {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-main);
}

.mail-subject {
  font-size: 14px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.mail-time {
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

@media (max-width: 600px) {
  .email-input {
    font-size: 18px;
  }
  .mail-item {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 4px 16px;
    align-items: start;
  }
  .mail-item.unread::before {
    top: 22px;
    left: 0;
    transform: none;
  }
  .mail-subject {
    grid-column: 1 / -1;
  }
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--modal-bg);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fade-in var(--transition-fast);
}

.modal-panel {
  position: relative;
  width: 100%;
  max-width: 680px;
  max-height: 85vh;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
  animation: modal-enter var(--transition-smooth);
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modal-enter {
  from { opacity: 0; transform: scale(0.99) translateY(4px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  padding: 24px 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-header-actions {
  display: flex;
  justify-content: flex-end;
  margin: -8px -8px 0 0;
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 500;
  margin: 0;
  letter-spacing: -0.01em;
}

.modal-meta {
  padding: 0 24px 24px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.modal-meta strong {
  color: var(--text-main);
  font-weight: 500;
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  font-size: 14px;
  color: var(--text-main);
}

.modal-body iframe {
  width: 100%;
  min-height: 400px;
  border: none;
  background: #ffffff;
  border-radius: var(--radius-sm);
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(10px) scale(0.95);
  background: var(--text-main);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  transition: all var(--transition-fast);
  z-index: 300;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0) scale(1);
  opacity: 1;
}