:root {
  --bg: #f5f7f9;
  --panel: #ffffff;
  --panel-soft: #f9fbfc;
  --line: #dfe5ea;
  --text: #17202a;
  --muted: #6a7683;
  --primary: #0f8b8d;
  --primary-dark: #0a6f72;
  --danger: #c73535;
  --warning: #b66f00;
  --shadow: 0 8px 24px rgba(30, 45, 62, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea,
select {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 28px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--primary);
  font-weight: 800;
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.status-pill {
  flex: 0 0 auto;
  padding: 6px 10px;
  border-radius: 999px;
  background: #edf4f4;
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 700;
}

.shell {
  width: min(1240px, calc(100vw - 32px));
  margin: 22px auto 48px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.toolbar,
.import-panel,
.table-card,
.mail-head {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.toolbar {
  display: grid;
  grid-template-columns: 140px minmax(220px, 1fr) 100px auto;
  gap: 14px;
  align-items: end;
  padding: 16px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span,
.switch span,
.pager label {
  color: var(--muted);
  font-size: 13px;
}

.field input,
.field select,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
  outline: none;
}

.field input:focus,
textarea:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 139, 141, 0.16);
}

.switch {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.switch input {
  width: 17px;
  height: 17px;
  accent-color: var(--primary);
}

.import-panel {
  margin-top: 16px;
  padding: 16px;
}

textarea {
  display: block;
  min-height: 130px;
  resize: vertical;
  font-family: Consolas, "SFMono-Regular", monospace;
  line-height: 1.5;
}

#file-input {
  display: none;
}

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

.actions.split {
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
}

.btn {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 700;
}

.btn:hover {
  border-color: var(--primary);
  color: var(--primary-dark);
}

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn.primary:hover {
  background: var(--primary-dark);
  color: #fff;
}

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

.btn.ghost {
  background: transparent;
}

.btn.compact {
  min-height: 34px;
  padding: 6px 12px;
}

.table-card {
  margin-top: 16px;
  overflow: hidden;
}

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

tr:last-child td {
  border-bottom: 0;
}

.check-col {
  width: 42px;
}

.mono {
  font-family: Consolas, "SFMono-Regular", monospace;
}

.clip {
  display: inline-block;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}

.secret {
  color: var(--muted);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mini {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12px;
  border-radius: 7px;
}

.empty {
  display: none;
  padding: 36px;
  text-align: center;
  color: var(--muted);
}

.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: var(--panel-soft);
}

.pager select {
  width: auto;
  padding: 6px 8px;
}

.page-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.page-buttons button {
  min-width: 32px;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  cursor: pointer;
}

.page-buttons button.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.mail-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
}

.mail-title {
  flex: 1;
  min-width: 0;
}

#current-email {
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#current-folder {
  color: var(--muted);
  font-size: 13px;
}

.seen {
  color: var(--muted);
}

.unseen {
  color: var(--warning);
  font-weight: 800;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(13, 23, 33, 0.62);
}

.modal.open {
  display: flex;
}

.dialog {
  width: min(880px, 100%);
  max-height: min(760px, calc(100vh - 40px));
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  background: white;
  border-radius: 8px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.22);
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--line);
}

.dialog h2 {
  margin: 0;
  font-size: 19px;
  line-height: 1.35;
}

.dialog p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.dialog-tools {
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.mail-content {
  overflow: auto;
  padding: 20px;
  line-height: 1.65;
}

.mail-content img {
  max-width: 100%;
  height: auto;
}

.mail-content pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: Consolas, "SFMono-Regular", monospace;
}

.loading {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.72);
}

.spinner {
  width: 46px;
  height: 46px;
  border: 4px solid #cfe4e4;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.toast {
  position: fixed;
  top: 78px;
  right: 22px;
  z-index: 50;
  width: min(360px, calc(100vw - 32px));
  padding: 14px 16px;
  border-radius: 8px;
  background: var(--text);
  color: white;
  box-shadow: var(--shadow);
  line-height: 1.45;
}

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

.toast.success {
  background: var(--primary-dark);
}

@media (max-width: 860px) {
  .topbar {
    padding: 0 16px;
  }

  .brand-subtitle,
  .status-pill {
    display: none;
  }

  .shell {
    width: min(100vw - 20px, 1240px);
    margin-top: 12px;
  }

  .toolbar {
    grid-template-columns: 1fr;
  }

  .actions.split,
  .mail-head {
    align-items: stretch;
    flex-direction: column;
  }

  .actions .btn,
  .actions.split > .btn,
  .mail-head .btn {
    width: 100%;
  }

  table {
    min-width: 760px;
  }
}
