:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;

  --blue-900: #0b2a5b;
  --blue-800: #0b3a78;
  --blue-700: #0d4aa3;
  --blue-600: #1565d8;
  --blue-500: #2f80ed;

  --green: #16a34a;
  --red: #ef4444;
  --yellow: #f59e0b;

  --shadow: 0 10px 30px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

.hidden { display: none !important; }

.app {
  height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
}

.sidebar {
  background: linear-gradient(180deg, var(--blue-600), #0a7bff);
  color: #fff;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

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

.brand__logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.18);
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: 1px;
}

.brand__title {
  font-size: 16px;
  font-weight: 800;
}

.brand__sub {
  font-size: 12px;
  opacity: 0.8;
  margin-top: 2px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav__item {
  border: 0;
  cursor: pointer;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  padding: 10px 12px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.nav__item:hover { background: rgba(255, 255, 255, 0.18); }

.nav__item--active {
  background: rgba(255, 255, 255, 0.26);
  box-shadow: 0 8px 20px rgba(0,0,0,0.12);
}

.nav__dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
}

.sidebar__footer {
  margin-top: auto;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.stat__label { font-size: 12px; opacity: 0.85; }
.stat__value { font-size: 22px; font-weight: 800; }

.main {
  padding: 22px;
  overflow: auto;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

.page-title {
  font-size: 20px;
  font-weight: 900;
}

.page-sub {
  font-size: 13px;
  color: var(--muted);
  margin-top: 6px;
}

.badge {
  font-size: 12px;
  color: var(--blue-800);
  background: rgba(21, 101, 216, 0.12);
  border: 1px solid rgba(21, 101, 216, 0.22);
  padding: 6px 10px;
  border-radius: 999px;
}

.badge--success {
  color: #065f46;
  background: #d1fae5;
  border-color: #6ee7b7;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.card__title {
  font-weight: 900;
  margin-bottom: 10px;
}

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toolbar__row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.toolbar__row--hint {
  align-items: center;
  justify-content: space-between;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 180px;
}

.field__label {
  font-size: 12px;
  color: var(--muted);
}

.input, .select, .textarea {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  background: #fff;
  font-size: 14px;
}

.input:focus, .select:focus, .textarea:focus {
  border-color: rgba(47, 128, 237, 0.6);
  box-shadow: 0 0 0 3px rgba(47, 128, 237, 0.12);
}

.select--sm { padding: 6px 10px; border-radius: 10px; }

.textarea {
  min-height: 260px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.spacer { flex: 1; }

.btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  cursor: pointer;
}

.btn:hover { background: #f8fafc; }

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

.btn--primary:hover { background: var(--blue-700); border-color: var(--blue-700); }

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

.btn--success:hover { filter: brightness(0.95); }

.btn--warn {
  background: var(--yellow);
  border-color: var(--yellow);
  color: #111827;
}

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

.btn--info {
  background: #3b82f6;
  border-color: #3b82f6;
  color: #fff;
}

.btn--info:hover { filter: brightness(0.95); }

.btn--ghost {
  background: transparent;
  border-color: rgba(255,255,255,0.35);
  color: #fff;
}

.btn--ghost:hover { background: rgba(255,255,255,0.14); }

.btn--block { width: 100%; }

.hint { font-size: 12px; color: var(--muted); }
.muted { color: var(--muted); font-size: 12px; }

.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(16, 24, 40, 0.15);
  min-width: 200px;
  z-index: 10;
  overflow: hidden;
}

.dropdown-item {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: 0;
  background: #fff;
  color: var(--text);
  text-align: left;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s;
}

.dropdown-item:hover {
  background: #f8fafc;
}

.table-wrap {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
}

.table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  font-size: 12px;
  color: var(--muted);
  text-align: left;
  padding: 10px;
  border-bottom: 1px solid var(--border);
}

.table tbody td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}

.table tbody tr:hover { background: #fbfdff; }

.col-check { width: 52px; }
.col-id { width: 70px; }
.col-status { width: 110px; }
.col-actions { width: 200px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 12px;
}

.pill--active {
  color: #065f46;
  background: #ecfdf5;
  border-color: #a7f3d0;
}

.pill--disabled {
  color: #7c2d12;
  background: #fff7ed;
  border-color: #fed7aa;
}

.action {
  display: inline-flex;
  gap: 8px;
}

.action .btn {
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 12px;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  padding: 10px 4px 0 4px;
}

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

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

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

.pager__numbers {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pager__btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
  min-width: 32px;
  height: 32px;
}

.pager__btn:hover {
  background: #f8fafc;
}

.pager__btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.page-num {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
  min-width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.page-num:hover {
  background: #f8fafc;
}

.page-num--active {
  background: var(--blue-600);
  border-color: var(--blue-600);
  color: #fff;
}

.page-num--ellipsis {
  border: none;
  background: transparent;
  cursor: default;
}

.page-num--ellipsis:hover {
  background: transparent;
}

.input--sm {
  padding: 6px 10px;
  border-radius: 6px;
  width: 60px;
  font-size: 13px;
}

.icon-btn {
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  color: var(--muted);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.52);
}

.modal__panel {
  position: relative;
  width: min(760px, calc(100vw - 24px));
  margin: 6vh auto;
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: 0 30px 70px rgba(0,0,0,0.25);
  overflow: hidden;
}

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

.modal__title {
  font-weight: 900;
}

.modal__body { padding: 14px; }
.modal__footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.about p { margin: 10px 0; color: var(--text); }

.import-tabs {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0;
}

.tab-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
}

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

.tab-btn--active {
  color: var(--blue-600);
  border-bottom-color: var(--blue-600);
  font-weight: 600;
}

.tab-content {
  position: relative;
}

.tab-pane {
  display: none;
}

.tab-pane--active {
  display: block;
}

.format-hint {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 13px;
  color: var(--text);
  line-height: 1.6;
  margin-top: 8px;
}

.format-hint div {
  margin: 4px 0;
}

.email-viewer {
  min-height: 400px;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
}

.email-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  max-height: 50vh;
  padding: 4px;
}

.email-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
  transition: all 0.2s;
  background: #fff;
}

.email-item:hover {
  background: #f8fafc;
  border-color: var(--blue-600);
  box-shadow: 0 2px 8px rgba(21, 101, 216, 0.1);
}

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

.email-item__from {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
}

.email-item__date {
  font-size: 12px;
  color: var(--muted);
}

.email-item__subject {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 4px;
}

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

.email-detail {
  overflow-y: auto;
  max-height: 50vh;
}

.email-detail__header {
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
  margin-bottom: 16px;
}

.email-detail__header h3 {
  font-size: 18px;
  font-weight: 700;
  margin: 12px 0;
  color: var(--text);
}

.email-detail__meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.email-detail__meta strong {
  color: var(--text);
}

.email-detail__body {
  padding: 16px;
  background: #f8fafc;
  border-radius: 10px;
  line-height: 1.6;
}

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  color: var(--muted);
  font-size: 14px;
}

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  padding: 20px;
}

.loading-state p {
  margin: 8px 0;
}

.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  color: var(--red);
  font-size: 14px;
  text-align: center;
  padding: 20px;
}

.error-state p {
  margin: 8px 0;
}

.error-state ul {
  list-style: disc;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.8;
}

.error-state .btn {
  margin-top: 12px;
}

@media (max-width: 980px) {
  .app { grid-template-columns: 84px 1fr; }
  .brand__text { display: none; }
  .nav__item span:last-child { display: none; }
  .sidebar { padding: 12px; }
  .sidebar__footer { display: none; }
  .grid2 { grid-template-columns: 1fr; }
}
