:root {
  --bg-canvas: #060608;
  --bg-card: #0c0c0f;
  --bg-inset: #101014;
  --bg-surface: #141419;
  --bg-surface-hover: #1b1b22;
  --border-subtle: #1f1f26;
  --border-strong: #2c2c35;
  --border-focus: #525260;
  --text-primary: #f4f4f5;
  --text-secondary: #a1a1aa;
  --text-muted: #787885;
  --accent-white: #ffffff;
  --accent-dark: #09090b;
  --status-active: #22c55e;
  --danger: #ef4444;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 9px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 2px solid #d4d4d8;
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Shell */
.app-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px 36px;
}

/* Header */
.brand-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
}

.brand-logo {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--accent-white);
  color: var(--accent-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  transform: rotate(-5deg);
  flex-shrink: 0;
}

.brand-logo svg {
  width: 23px;
  height: 23px;
}

.brand-title {
  margin: 0;
  font-size: 27px;
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.05;
  color: #ffffff;
}

.brand-subtitle {
  margin: 3px 0 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.brand-tagline {
  margin: 3px 0 0;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* Primary Control Bar */
.control-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 9px;
}

.address-builder {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 5px 5px 5px 14px;
  transition: border-color 0.15s ease;
}

.address-builder:focus-within {
  border-color: var(--border-focus);
}

.prefix-input {
  flex: 1;
  min-width: 90px;
  background: transparent;
  border: none;
  outline: none;
  color: #ffffff;
  font-family: "JetBrains Mono", "Inter", monospace;
  font-size: 15px;
  font-weight: 600;
  text-align: left;
  letter-spacing: -0.01em;
}

.prefix-input:focus-visible {
  outline: none;
}

.prefix-input::placeholder {
  color: #4b4b56;
  font-weight: 500;
}

.domain-display {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 5px 10px;
  border-radius: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-family: "JetBrains Mono", "Inter", monospace;
  font-size: 13.5px;
  font-weight: 500;
  user-select: none;
  flex-shrink: 0;
}

.domain-at {
  color: var(--text-muted);
}

.domain-select {
  background: transparent;
  color: var(--text-primary);
  border: none;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  outline: none;
  cursor: pointer;
}

.btn-set {
  background: var(--accent-white);
  color: var(--accent-dark);
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
  flex-shrink: 0;
}

.btn-set:hover {
  opacity: 0.9;
}

.btn-set:active {
  transform: scale(0.98);
}

.control-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.btn-action {
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 15px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn-action svg {
  width: 15px;
  height: 15px;
  color: var(--text-secondary);
}

.btn-action:hover {
  background: var(--bg-surface-hover);
  border-color: #3d3d48;
}

/* Split Workspace */
.workspace {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 345px 1fr;
  gap: 16px;
  min-height: 520px;
  height: clamp(520px, calc(100vh - 205px), 800px);
}

.inbox-panel,
.reader-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* Inbox Sidebar */
.inbox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 15px 16px 12px;
}

.inbox-title-wrap {
  display: flex;
  align-items: center;
  gap: 9px;
}

.inbox-icon {
  width: 17px;
  height: 17px;
  color: var(--text-secondary);
}

.inbox-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.unread-badge {
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 2px 7px;
  border-radius: 999px;
  background: #ffffff;
  color: #09090b;
}

.inbox-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.refresh-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 11px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  color: var(--text-primary);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.refresh-btn:hover {
  background: var(--bg-surface-hover);
  border-color: #3d3d48;
}

.refresh-btn svg {
  width: 14px;
  height: 14px;
  color: var(--text-secondary);
  transition: transform 0.35s ease;
}

.refresh-btn.spinning svg {
  transform: rotate(180deg);
}

.refresh-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.15;
}

.refresh-main {
  font-size: 12px;
  font-weight: 600;
}

.refresh-sub {
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.search-wrap {
  position: relative;
  margin: 0 16px 13px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 9px 12px 9px 35px;
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s ease;
}

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

.search-input:focus {
  border-color: var(--border-focus);
}

.message-list {
  flex: 1;
  overflow-y: auto;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
}

.empty-inbox {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 36px 20px;
  text-align: center;
}

.empty-tray-icon {
  width: 34px;
  height: 34px;
  color: #363640;
  margin-bottom: 10px;
}

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

.empty-sub {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

/* Message Item */
.message-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-bottom: 1px solid #17171c;
  border-left: 2px solid transparent;
  padding: 13px 16px;
  cursor: pointer;
  color: inherit;
  transition: background-color 0.12s ease;
}

.message-item:hover {
  background: #121216;
}

.message-item.selected {
  background: #17171d;
  border-left-color: #ffffff;
}

.message-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.message-sender {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}

.message-item.unread .message-sender {
  font-weight: 700;
  color: #ffffff;
}

.unread-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ffffff;
  flex-shrink: 0;
}

.message-time {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  flex-shrink: 0;
}

.message-subject {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}

.message-snippet {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Email Reader */
.reader-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 36px 24px;
  text-align: center;
}

.reader-empty-badge {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  margin-bottom: 15px;
}

.reader-empty-badge svg {
  width: 25px;
  height: 25px;
}

.reader-empty-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.reader-empty-sub {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

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

.reader-top {
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--border-subtle);
  background: #0e0e12;
}

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

.mobile-back-btn {
  display: none;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--text-primary);
  padding: 6px;
  cursor: pointer;
}

.mobile-back-btn svg {
  width: 16px;
  height: 16px;
}

.reader-subject {
  margin: 0;
  flex: 1;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.35;
  color: #ffffff;
  word-break: break-word;
}

.reader-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.view-tabs {
  display: inline-flex;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  padding: 2px;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 7px;
  cursor: pointer;
}

.tab-btn.active {
  background: #ffffff;
  color: #09090b;
  font-weight: 600;
}

.icon-subtle-btn,
.icon-danger-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

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

.icon-subtle-btn.is-active {
  color: #ffffff;
  border-color: #464654;
}

.icon-danger-btn:hover {
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.45);
}

.icon-subtle-btn svg,
.icon-danger-btn svg {
  width: 15px;
  height: 15px;
}

.reader-meta {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
}

.meta-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.meta-label {
  color: var(--text-muted);
}

.meta-value {
  color: var(--text-secondary);
  word-break: break-all;
}

.meta-dot {
  color: var(--text-muted);
}

.meta-date {
  color: var(--text-muted);
}

.otp-banner {
  margin-top: 12px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 6px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
}

.otp-label {
  font-size: 12px;
  color: var(--text-secondary);
}

.otp-code {
  font-family: "JetBrains Mono", monospace;
  font-size: 14px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: 0.08em;
}

.otp-copy-btn {
  background: #ffffff;
  color: #09090b;
  border: none;
  border-radius: 7px;
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}

.attachments-bar {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attachment-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 12px;
  text-decoration: none;
}

.attachment-pill[href]:hover {
  background: var(--bg-surface-hover);
}

.attachment-size {
  color: var(--text-muted);
  font-size: 11px;
}

.reader-body {
  flex: 1;
  min-height: 0;
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.html-frame {
  width: 100%;
  flex: 1;
  min-height: 300px;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: #ffffff;
}

.html-frame.dark-paper {
  background: #0e0e12;
}

.text-viewer {
  margin: 0;
  flex: 1;
  overflow: auto;
  padding: 16px;
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  font-family: "JetBrains Mono", monospace;
  font-size: 12.5px;
  line-height: 1.65;
  color: #d4d4d8;
  white-space: pre-wrap;
  word-break: break-word;
}

.headers-viewer {
  flex: 1;
  overflow: auto;
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 12px;
}

.header-row {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 10px;
  padding: 7px 6px;
  border-bottom: 1px solid #191920;
  font-size: 12px;
}

.header-key {
  font-family: "JetBrains Mono", monospace;
  color: var(--text-secondary);
  font-weight: 600;
  word-break: break-word;
}

.header-val {
  font-family: "JetBrains Mono", monospace;
  color: #d4d4d8;
  word-break: break-all;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 4, 6, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal-card {
  width: 100%;
  max-width: 500px;
  max-height: 80vh;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.6);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.modal-subtitle {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-close svg {
  width: 18px;
  height: 18px;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-empty {
  text-align: center;
  padding: 28px 12px;
  color: var(--text-muted);
  font-size: 13px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
}

.history-item.current {
  border-color: #464654;
}

.history-addr-btn {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 0;
}

.history-addr {
  display: block;
  font-family: "JetBrains Mono", "Inter", monospace;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-time {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-muted);
}

.history-item-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mini-icon-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  color: var(--text-secondary);
  padding: 5px 8px;
  font-size: 11.5px;
  cursor: pointer;
}

.mini-icon-btn:hover {
  color: #ffffff;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
}

.btn-secondary-danger {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.btn-secondary-danger:hover {
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.45);
}

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

.toast {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  color: #ffffff;
  font-size: 13px;
  font-weight: 500;
  padding: 10px 14px;
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
  animation: toastIn 0.16s ease-out;
}

.toast.error {
  border-color: rgba(239, 68, 68, 0.5);
  color: #fecaca;
}

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

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #272730;
  border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
  background: #3a3a46;
}

/* Responsive */
@media (max-width: 960px) {
  .control-card {
    flex-direction: column;
    align-items: stretch;
  }

  .control-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

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

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

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

  .mobile-back-btn {
    display: inline-flex;
  }

  .inbox-panel,
  .reader-panel {
    min-height: 460px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 18px 14px 28px;
  }

  .address-builder {
    flex-wrap: wrap;
    padding: 8px;
  }

  .prefix-input {
    min-width: 120px;
  }

  .btn-set {
    width: 100%;
    padding: 10px;
  }

  .reader-title-row {
    flex-wrap: wrap;
  }

  .reader-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .header-row {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}
