:root {
  --bg: #f6f8fc;
  --surface: #ffffff;
  --surface-2: #f1f3f4;
  --surface-hover: #eaeef3;
  --border: #e1e5ea;
  --border-strong: #c7cdd4;
  --text: #1f1f1f;
  --text-muted: #5f6368;
  --text-dim: #80868b;
  --unread-bg: #f2f6fc;
  --selected-bg: #d3e3fd;
  --selected-text: #041e49;
  --subject-color: #3c4043;
  --accent: #0b57d0;
  --accent-hover: #0842a0;
  --accent-text: #ffffff;
  --emerald: #137333;
  --amber: #b06000;
  --amber-bg: #fef7e0;
  --amber-border: #fdd663;
  --red: #c5221f;
  --blue: #0b57d0;
  --shadow-card: 0 1px 2px rgba(60, 64, 67, 0.12), 0 1px 3px 1px rgba(60, 64, 67, 0.06);
  --font-sans: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Roboto', 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

html[data-theme="dark"] {
  --bg: #111315;
  --surface: #1b1e22;
  --surface-2: #24282e;
  --surface-hover: #2c3138;
  --border: #2e333a;
  --border-strong: #404752;
  --text: #e8eaed;
  --text-muted: #9aa0a6;
  --text-dim: #757b82;
  --unread-bg: #20252d;
  --selected-bg: #1e3a5f;
  --selected-text: #e8f0fe;
  --subject-color: #bdc1c6;
  --accent: #8ab4f8;
  --accent-hover: #aecbfa;
  --accent-text: #0b192e;
  --emerald: #81c995;
  --amber: #fdd663;
  --amber-bg: rgba(253, 214, 99, 0.12);
  --amber-border: rgba(253, 214, 99, 0.3);
  --red: #f28b82;
  --blue: #8ab4f8;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.35);
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* App Shell */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Top Bar (Gmail / Outlook clean header) */
.topbar {
  height: 58px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  gap: 14px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.015em;
  color: var(--text);
  white-space: nowrap;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-text);
  display: grid;
  place-items: center;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--emerald);
  display: inline-block;
}

/* Address Bar */
.address-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  max-width: 780px;
  min-width: 0;
}

.address-input-wrap {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 220px;
  height: 38px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 0 0 12px;
  position: relative;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.address-input-wrap:focus-within {
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.address-input-wrap.invalid {
  border-color: var(--red);
}

.address-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  padding-right: 8px;
}

.domain-picker {
  position: relative;
  height: 100%;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.domain-trigger {
  height: 100%;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 11px;
  border-left: 1px solid var(--border);
  border-radius: 0 7px 7px 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  transition: background 0.12s ease, color 0.12s ease;
}

.domain-trigger:hover,
.domain-trigger[aria-expanded="true"] {
  color: var(--text);
  background: var(--surface-hover);
}

.domain-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 185px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  z-index: 60;
  display: none;
}

.domain-menu.open {
  display: block;
}

.domain-option {
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.domain-option:hover {
  background: var(--surface-2);
}

.domain-option.active {
  background: var(--selected-bg);
  color: var(--selected-text);
}

/* Buttons */
.btn {
  height: 36px;
  padding: 0 13px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.btn:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent-hover);
  color: var(--accent-text);
  border-color: var(--accent-hover);
}

.btn-sm {
  height: 30px;
  padding: 0 10px;
  font-size: 12.5px;
}

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

.btn-icon.btn-sm {
  width: 30px;
}

.btn-danger:hover {
  color: var(--red);
  border-color: var(--red);
  background: rgba(197, 34, 31, 0.06);
}

.btn.active {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

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

/* History Dropdown */
.dropdown-wrap {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14);
  z-index: 50;
  display: none;
}

.dropdown-menu.open {
  display: block;
}

.dropdown-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.dropdown-item {
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.dropdown-item:hover {
  background: var(--surface-2);
}

.dropdown-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Workspace Split Pane */
.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

.inbox-pane {
  width: 360px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.inbox-toolbar {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface);
}

.inbox-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
}

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

.count-pill {
  background: var(--surface-2);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 10px;
}

.search-box:focus-within {
  background: var(--surface);
  border-color: var(--accent);
}

.search-box input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 13px;
  color: var(--text);
}

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

.kbd {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 4px;
  padding: 1px 5px;
}

.inbox-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.mail-item {
  padding: 13px 16px;
  background: var(--unread-bg);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s ease;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.mail-item.is-read {
  background: var(--surface);
}

.mail-item:hover {
  background: var(--surface-hover);
}

.mail-item.selected {
  background: var(--selected-bg);
  box-shadow: inset 3px 0 0 var(--accent);
}

.mail-sender-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

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

.mail-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

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

.mail-item.is-read .mail-sender {
  font-weight: 500;
  color: var(--text-muted);
}

.mail-time {
  font-size: 11.5px;
  color: var(--text-dim);
  flex-shrink: 0;
}

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

.mail-item.is-read .mail-subject {
  font-weight: 400;
  color: var(--subject-color);
}

.mail-item.selected .mail-sender,
.mail-item.selected .mail-subject {
  color: var(--selected-text);
}

.mail-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.otp-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--amber);
  background: var(--amber-bg);
  border: 1px solid var(--amber-border);
  border-radius: 4px;
  padding: 1px 7px;
  cursor: pointer;
}

.redirect-badge {
  font-size: 11px;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
}

/* Reader Pane (Gmail/Outlook paper card on soft canvas) */
.reader-pane {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  min-height: 0;
  padding: 16px;
}

.reader-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  text-align: center;
  color: var(--text-dim);
}

.reader-empty-box {
  max-width: 420px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px 32px;
  background: var(--surface);
  box-shadow: var(--shadow-card);
}

.reader-empty-addr {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 14px;
  margin: 12px 0;
  word-break: break-all;
}

.shortcuts-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-dim);
}

#readerView {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.reader-toolbar {
  height: 48px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 6px;
  padding: 2px;
}

.segmented button {
  height: 26px;
  padding: 0 11px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: 4px;
}

.segmented button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.reader-header {
  padding: 18px 24px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.reader-subject {
  font-size: 19px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 12px 0;
  line-height: 1.35;
}

.reader-meta-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  font-size: 12.5px;
}

.meta-label {
  color: var(--text-dim);
  font-weight: 500;
}

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

.reader-body-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--surface);
}

.html-frame {
  width: 100%;
  min-height: 440px;
  height: 100%;
  border: none;
  background: var(--surface);
}

.raw-pre {
  margin: 0;
  padding: 20px 24px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
}

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

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #1f2937;
  color: #ffffff;
  padding: 9px 15px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  z-index: 200;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

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

/* First-time Session Spotlight Tour */
.tour-layer {
  position: fixed;
  inset: 0;
  z-index: 300;
}

.tour-spotlight {
  position: fixed;
  pointer-events: none;
  border-radius: 8px;
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.58);
  transition: top 0.18s ease, left 0.18s ease, width 0.18s ease, height 0.18s ease;
  z-index: 301;
}

.tour-popover {
  position: fixed;
  width: 300px;
  max-width: calc(100vw - 24px);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  z-index: 302;
}

.tour-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.tour-step {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent);
}

.tour-skip {
  font-size: 12px;
  color: var(--text-dim);
}

.tour-skip:hover {
  color: var(--text);
}

.tour-title {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 5px;
}

.tour-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 14px;
}

.tour-actions {
  display: flex;
  justify-content: flex-end;
}

/* Mobile Responsive */
.mobile-back {
  display: none;
}

@media (max-width: 860px) {
  .topbar {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 12px;
  }
  .address-bar {
    order: 3;
    max-width: 100%;
    flex-basis: 100%;
  }
  .inbox-pane {
    width: 100%;
    border-right: none;
  }
  .reader-pane {
    display: none;
    padding: 0;
  }
  #readerView {
    border-radius: 0;
    border: none;
  }
  .workspace.mobile-reading .inbox-pane {
    display: none;
  }
  .workspace.mobile-reading .reader-pane {
    display: flex;
  }
  .mobile-back {
    display: inline-flex;
  }
  .hide-sm {
    display: none;
  }
}
