:root {
  color-scheme: light;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 2px 6px rgba(15, 23, 42, 0.08), 0 10px 24px rgba(15, 23, 42, 0.05);
}

body {
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}
a {
  color: var(--primary);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
.wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 24px 24px;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.row {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}
.muted {
  color: var(--muted);
}
.grid {
  display: grid;
  gap: 12px;
}
.nav {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
form {
  margin: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  padding: 12px 0;
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.brand {
  font-weight: 800;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.brand a {
  color: var(--text);
  text-decoration: none;
}
.brand a:hover {
  text-decoration: none;
}

.tabs {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.tabs .btn {
  border-radius: 999px;
  padding: 10px 14px;
}
.tab-panel {
  display: none;
}
.tab-panels[data-active="users"] .tab-panel[data-tab="users"],
.tab-panels[data-active="manage"] .tab-panel[data-tab="manage"] {
  display: grid;
  gap: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.02s ease;
}
button.btn {
  font: inherit;
}
.btn:hover {
  background: #f1f5f9;
}
.btn:active {
  transform: translateY(1px);
}
.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  font-weight: 600;
}
.btn.primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}
.btn.danger {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.35);
  color: #991b1b;
}
.btn.danger:hover {
  background: rgba(239, 68, 68, 0.12);
}
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.6;
  cursor: not-allowed;
}
.btn.sm {
  padding: 6px 10px;
  border-radius: 8px;
  gap: 6px;
  font-size: 13px;
}
.btn.icon {
  padding: 6px 8px;
}
.btn-icon {
  width: 16px;
  height: 16px;
}

details.popover {
  position: relative;
}
details.popover > summary {
  list-style: none;
}
details.popover > summary::-webkit-details-marker {
  display: none;
}
.popover-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 260px;
  max-width: min(320px, 92vw);
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--shadow);
  z-index: 1000;
}
.popover-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  user-select: none;
}
.popover-sep {
  height: 1px;
  background: var(--border);
  margin: 10px 0;
}
.bulk-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

input,
textarea,
select {
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: inherit;
  width: 100%;
  box-sizing: border-box;
}
input[type="checkbox"],
input[type="radio"] {
  width: auto;
  padding: 0;
}
input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
label {
  display: block;
  margin: 10px 0 6px;
  font-weight: 650;
}
code {
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 6px;
}

.toast {
  max-width: 720px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  box-shadow: var(--shadow);
}
.toast.ok {
  border-color: rgba(34, 197, 94, 0.35);
  background: rgba(34, 197, 94, 0.12);
  color: #166534;
}
.toast.err {
  border-color: rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.12);
  color: #991b1b;
}

.scroll-box {
  height: 480px;
  overflow: auto;
  padding-right: 6px;
}
.batch {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}
.batch + .batch {
  margin-top: 10px;
}
.batch > summary {
  cursor: pointer;
  padding: 12px;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
  list-style: none;
}
.batch > summary::-webkit-details-marker {
  display: none;
}
.batch > summary .meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.batch > summary .actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-left: auto;
}
.batch > summary .toggle {
  color: var(--muted);
  font-size: 12px;
}
.batch > summary .batch-note {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 180px;
}
.batch-note-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  padding: 0;
  font: inherit;
  text-align: left;
  max-width: 320px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.batch-note-btn:hover {
  text-decoration: underline;
}
.batch-note-btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}
.batch .batch-body {
  padding: 0 12px 12px;
}
.batch .batch-preview,
.batch .batch-full {
  padding: 0 12px 12px;
}
.batch .mono-lines {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
  background: #f1f5f9;
  border-radius: 8px;
  padding: 10px;
  border: 1px solid var(--border);
}
.batch:not([open]) .batch-full {
  display: none;
}
.batch[open] .batch-preview {
  display: none;
}

.table {
  width: 100%;
  border-collapse: collapse;
}
.table th,
.table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.table tr:nth-child(even) td {
  background: #f8fafc;
}
.table tbody tr:hover td {
  background: rgba(59, 130, 246, 0.08);
}

.empty {
  padding: 18px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  background: #f8fafc;
  color: var(--muted);
  text-align: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #f1f5f9;
  font-size: 12px;
  font-weight: 650;
  line-height: 1.4;
  color: var(--muted);
  white-space: nowrap;
  vertical-align: middle;
}
.badge.danger {
  border-color: rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.12);
  color: #991b1b;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.45);
  z-index: 9000;
}
.modal-overlay[data-open="1"] {
  display: flex;
}
.modal {
  width: 100%;
  max-width: 600px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.modal-title {
  font-weight: 750;
}
.modal-close {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}
.modal-close:hover {
  color: var(--text);
}
.modal-body {
  padding: 14px;
  overflow: auto;
  flex: 1;
  min-height: 0;
}
.modal-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.email-item {
  display: block;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: #ffffff;
  color: inherit;
  text-decoration: none;
}
.email-item:hover {
  background: #f8fafc;
  text-decoration: none;
}
.email-item + .email-item {
  margin-top: 10px;
}
.email-subject {
  font-weight: 650;
}
.email-meta {
  color: var(--muted);
  margin-top: 4px;
  font-size: 13px;
}
.email-snippet {
  color: var(--muted);
  margin-top: 6px;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}
.email-html-frame {
  width: 100%;
  height: 70vh;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #ffffff;
}

/* 收件箱三列布局（标签 / 邮箱 / 邮件） */
.inbox-layout-3col {
  display: grid;
  grid-template-columns: 200px 300px 1fr;
  gap: 10px;
  min-height: 620px;
  align-items: start;
}
.inbox-col {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 200px);
  position: sticky;
  top: 80px;
}
.inbox-col-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}
.inbox-col-body {
  flex: 1;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.inbox-tags .inbox-col-body {
  overflow-y: auto;
}
.inbox-recipients .inbox-col-body {
  overflow: hidden;
}
.inbox-emails .inbox-col-body {
  overflow-y: auto;
}
.inbox-col .back-btn {
  display: none;
}

.tag-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.tag-select {
  flex: 1;
  appearance: none;
  border: 1px solid var(--border);
  background: #ffffff;
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  transition: background 0.15s ease, border-color 0.15s ease;
  text-align: left;
  color: inherit;
}
.tag-row.active .tag-select {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.08);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.12);
}
.tag-left {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.tag-name {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tag-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}
.tag-row:hover .tag-actions,
.tag-row:focus-within .tag-actions {
  opacity: 1;
  pointer-events: auto;
}
@media (hover: none) {
  .tag-actions {
    opacity: 1;
    pointer-events: auto;
  }
}
.tag-actions .btn {
  padding: 6px 10px;
  border-radius: 8px;
}

.bulk-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8fafc;
}
.bulk-left {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 650;
}

.inbox-item-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}
.inbox-item-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.recipient-check {
  margin: 0;
  flex-shrink: 0;
}
.tag-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.tag-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  display: inline-block;
  border: 1px solid rgba(15, 23, 42, 0.12);
}
.tag-more {
  font-size: 12px;
  color: var(--muted);
}

@media (max-width: 900px) {
  .inbox-layout-3col {
    grid-template-columns: 1fr;
  }
  .inbox-col {
    position: static;
    max-height: none;
    display: none;
  }
  .inbox-col .back-btn {
    display: inline-flex;
  }
  .inbox-layout-3col[data-view="tags"] .inbox-tags {
    display: flex;
  }
  .inbox-layout-3col[data-view="recipients"] .inbox-recipients {
    display: flex;
  }
  .inbox-layout-3col[data-view="emails"] .inbox-emails {
    display: flex;
  }
}

/* 收件箱左右分栏布局 */
.inbox-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 16px;
  min-height: 600px;
}
@media (max-width: 800px) {
  .inbox-layout {
    grid-template-columns: 1fr;
  }
  .inbox-detail {
    display: none;
  }
  .inbox-detail.mobile-show {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 200;
    background: var(--bg);
    overflow: auto;
    padding: 16px;
  }
}

/* 左侧邮箱列表 */
.inbox-sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 200px);
  position: sticky;
  top: 80px;
}
.inbox-search {
  position: relative;
}
.inbox-search input {
  padding: 8px 10px;
  padding-left: 36px;
  width: 100%;
}
.inbox-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--muted);
  pointer-events: none;
}
.inbox-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 4px;
}
.inbox-list::-webkit-scrollbar {
  width: 6px;
}
.inbox-list::-webkit-scrollbar-track {
  background: transparent;
}
.inbox-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
.inbox-list::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

/* 邮箱卡片 */
.inbox-item {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  cursor: pointer;
  transition: all 0.15s ease;
}
.inbox-item:hover {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.04);
}
.inbox-item.active {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.08);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}
.inbox-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.inbox-item-recipient {
  font-weight: 700;
  font-size: 14px;
  word-break: break-all;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.inbox-item-count {
  flex-shrink: 0;
}
.inbox-item[data-hidden="1"] {
  display: none;
}

/* 右侧邮件详情 */
.inbox-detail {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 200px);
  position: sticky;
  top: 80px;
}
.inbox-detail-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}
.inbox-detail-title {
  font-weight: 700;
  font-size: 16px;
  word-break: break-all;
}
.inbox-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
.inbox-detail-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--muted);
  font-size: 14px;
}
.inbox-detail .back-btn {
  display: none;
}
@media (max-width: 800px) {
  .inbox-detail .back-btn {
    display: inline-flex;
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}
.spinner {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 2px solid rgba(100, 116, 139, 0.35);
  border-top-color: rgba(59, 130, 246, 0.95);
  animation: spin 1s linear infinite;
  display: inline-block;
}
.refresh-btn .spinner {
  display: none;
}
.refresh-btn .countdown {
  display: none;
  font-variant-numeric: tabular-nums;
}
.refresh-btn.refreshing .spinner {
  display: inline-block;
}
.refresh-btn.refreshing .countdown {
  display: inline;
}
.refresh-btn.refreshing .label {
  display: none;
}
.refresh-btn.refreshing .refresh-icon {
  display: none;
}

.tag-create-btn {
  margin-top: auto;
}

#navOverlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(248, 250, 252, 0.65);
  backdrop-filter: blur(6px);
  z-index: 9999;
}
#navOverlay .toast {
  margin: 0 16px;
}

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 160ms;
}
::view-transition-old(root) {
  animation-name: fade-out;
}
::view-transition-new(root) {
  animation-name: fade-in;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(2px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes fade-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn {
    transition: none;
  }
  .spinner {
    animation: none;
  }
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation: none;
  }
}
