:root {
  --bg: #eef2f4;
  --bg-accent: #d9e6e3;
  --panel: #ffffff;
  --ink: #14201e;
  --muted: #6b7c78;
  --line: #d7e0dd;
  --brand: #0f7a66;
  --brand-soft: #e6f4f0;
  --danger: #c23b3b;
  --ok: #1f8a4c;
  --warn: #9a6b12;
  --shadow: 0 10px 30px rgba(20, 32, 30, 0.06);
  --radius: 14px;
  --font: "DM Sans", "Segoe UI", sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font);
  background:
    radial-gradient(900px 420px at 10% -10%, var(--bg-accent), transparent 60%),
    radial-gradient(700px 380px at 100% 0%, #e7eef5, transparent 55%),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

/* ========== App shell ========== */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #102421;
  color: #e8f2ef;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; gap: 12px; align-items: center; padding: 4px 6px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(145deg, #1aa887, #0d6b59);
  display: grid; place-items: center;
  font-weight: 700; letter-spacing: 0.02em;
}
.brand-name { font-weight: 700; font-size: 15px; }
.brand-tag { font-size: 11px; color: #9bb5af; margin-top: 2px; }

.side-nav { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.nav-item {
  border: 0; background: transparent; color: #c5d8d3;
  text-align: left; padding: 10px 12px; border-radius: 10px;
  font: inherit; font-weight: 500; cursor: pointer;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: rgba(26, 168, 135, 0.22); color: #fff; }

.side-meta { display: flex; flex-direction: column; gap: 8px; }
.side-links { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; align-items: center; }
.side-links a, .side-links .link-btn { color: #9ed7c8; background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }
.side-links a:hover, .side-links .link-btn:hover { color: #fff; text-decoration: underline; }
.meta-chip-btn { cursor: pointer; font: inherit; text-align: left; }
.meta-chip-btn:hover { filter: brightness(1.08); }

.integration-grid { display: grid; gap: 14px; }
.integration-grid .full { grid-column: 1 / -1; }
.key-row { display: flex; gap: 8px; }
.key-row input { flex: 1; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.code-block {
  margin: 0; padding: 12px 14px; border-radius: 10px;
  background: #102421; color: #d7efe8;
  font-family: ui-monospace, Consolas, monospace; font-size: 12px;
  white-space: pre-wrap; word-break: break-all; overflow: auto;
}
code { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

.main { padding: 28px; max-width: 1200px; width: 100%; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.panel-narrow { max-width: 420px; margin: 12vh auto 0; }
.panel-head {
  display: flex; justify-content: space-between; gap: 16px;
  align-items: flex-start; margin-bottom: 18px;
  flex-wrap: wrap;
}
.panel-head h1 { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; }
.panel-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; position: relative; }

.meta-chip {
  display: inline-flex; align-items: center;
  padding: 4px 9px; border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.12);
  font-size: 11px; color: #c5d8d3; width: fit-content;
}
.meta-chip.on { background: rgba(34,197,94,0.15); color: #86efac; border-color: transparent; }
.meta-chip.off { opacity: 0.8; }
.header .meta-chip, .meta-bar .meta-chip, .docs .meta-chip {
  border-color: var(--line); color: var(--muted); background: #fff;
}
.header .meta-chip.on, .meta-bar .meta-chip.on, .docs .meta-chip.on {
  background: #eaf8ef; color: var(--ok); border-color: transparent;
}

/* ========== Forms ========== */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 16px;
}
.form-grid .full { grid-column: 1 / -1; }
.input-group { margin-bottom: 14px; }
label { display: block; margin-bottom: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-size: 14px;
  background: #fbfcfb;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(15, 122, 102, 0.12);
}

.btn {
  border: 0; border-radius: 10px; padding: 9px 14px;
  font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: transform .12s, opacity .12s, background .12s;
}
.btn:hover { opacity: 0.92; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-secondary { background: #f3f6f5; color: var(--ink); border: 1px solid var(--line); }
.btn-danger-text { background: #fff5f5; color: var(--danger); border: 1px solid #f0d0d0; }

/* ========== Poll status ========== */
.poll-status {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand);
  font-size: 12px; font-weight: 600;
}
.poll-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #94a3b8;
}
.poll-dot.online {
  background: var(--ok);
  box-shadow: 0 0 0 0 rgba(31, 138, 76, 0.5);
  animation: pulse 1.8s infinite;
}
.poll-dot.offline { background: #94a3b8; }
.poll-dot.paused { background: var(--warn); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(31, 138, 76, 0.45); }
  70% { box-shadow: 0 0 0 8px rgba(31, 138, 76, 0); }
  100% { box-shadow: 0 0 0 0 rgba(31, 138, 76, 0); }
}

/* ========== Accounts ========== */
.account-count {
  display: inline-flex; min-width: 22px; height: 22px;
  padding: 0 7px; margin-left: 6px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand);
  font-size: 12px; align-items: center; justify-content: center;
}
.account-toolbar { margin-bottom: 12px; }
.account-filter { display: flex; gap: 6px; }
.filter-btn {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  border-radius: 999px; padding: 5px 12px; font: inherit; font-size: 12px; cursor: pointer;
}
.filter-btn.active { background: var(--brand); border-color: var(--brand); color: #fff; }

.search-container { min-width: 200px; }
.table-container {
  border: 1px solid var(--line); border-radius: 12px; overflow: auto; max-height: 560px;
}
.account-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.account-table th, .account-table td { padding: 12px 14px; border-bottom: 1px solid #eef2f1; text-align: left; }
.account-table th {
  position: sticky; top: 0; background: #f7faf9; color: var(--muted); font-weight: 600; z-index: 1;
}
.account-table tr:hover td { background: #f8fbfa; }
.account-table tr.filtered { display: none; }
.account-table .loading-row td, .account-table td[colspan] { text-align: center; padding: 36px; color: var(--muted); }

.account-email { font-weight: 600; cursor: pointer; }
.account-email:hover { color: var(--brand); }

.account-status {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600;
}
.status-polling { background: #eaf8ef; color: var(--ok); }
.status-polling::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 0 0 rgba(31, 138, 76, 0.45);
  animation: pulse 1.8s infinite;
}
.status-paused { background: #fff7e8; color: var(--warn); }
.status-offline { background: #f1f3f2; color: var(--muted); }
.status-idle { background: #f1f3f2; color: var(--muted); }

.password-wrapper { display: flex; align-items: center; gap: 6px; }
.password-text { font-family: ui-monospace, Consolas, monospace; color: var(--muted); font-size: 12px; }
.btn-copy-password {
  border: 1px solid var(--line); background: #fff; border-radius: 6px;
  padding: 3px 5px; cursor: pointer; color: var(--muted);
}
.btn-copy-password:hover { color: var(--brand); border-color: var(--brand); }
.remark-input {
  width: 100%; max-width: 280px; padding: 6px 8px;
  border: 1px solid transparent; background: #f6f8f7; border-radius: 8px;
}
.remark-input:focus { border-color: var(--brand); background: #fff; }
.scope-select {
  width: 100%; max-width: 220px; padding: 8px 10px;
  border: 1px solid var(--line); background: #fff; border-radius: 8px;
  font: inherit; font-size: 13px; color: var(--text); cursor: pointer;
}
.scope-select-wide { max-width: 100%; }
.scope-select:focus { border-color: var(--brand); outline: none; }

.export-menu {
  position: absolute; top: 100%; right: 90px; margin-top: 6px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); min-width: 140px; z-index: 20; overflow: hidden;
}
.export-menu button {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: 10px 12px; font: inherit; font-size: 13px; cursor: pointer;
}
.export-menu button:hover { background: var(--brand-soft); color: var(--brand); }

/* ========== Email list ========== */
.user-email { color: var(--brand); font-weight: 600; margin-top: 2px; }
.email-filter-bar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px; gap: 10px;
}
.email-count-label { font-size: 13px; color: var(--muted); }
.unified-email-container { min-height: 320px; }
.email-list { max-height: calc(100vh - 260px); overflow: auto; border: 1px solid var(--line); border-radius: 12px; }

.email-item {
  padding: 12px 14px; border-bottom: 1px solid #eef2f1; cursor: pointer;
  border-left: 3px solid transparent;
}
.email-item:hover { background: #f7faf9; }
.email-item.unread { border-left-color: var(--brand); background: #f4fbf8; }
.email-item.unread .email-subject { font-weight: 700; }
.email-content-wrapper { display: flex; gap: 10px; }
.sender-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 700; flex-shrink: 0;
}
.email-info { min-width: 0; flex: 1; }
.email-header { display: flex; justify-content: space-between; gap: 10px; }
.email-subject {
  font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.email-date { font-size: 12px; color: var(--muted); white-space: nowrap; }
.email-from { font-size: 12px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.email-status { display: flex; gap: 4px; align-items: center; }
.status-indicator { width: 6px; height: 6px; border-radius: 50%; background: #cbd5d1; }
.status-indicator.unread { background: var(--brand); }

.empty-state { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty-state strong { display: block; color: var(--ink); margin-bottom: 6px; }

.email-detail-header { border-bottom: 1px solid var(--line); padding-bottom: 14px; margin: 16px 0; }
.email-meta-info p { margin: 4px 0; color: var(--muted); font-size: 13px; }
.email-content-container { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-top: 12px; }
.content-type-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.content-tab {
  padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; cursor: pointer; font: inherit; font-size: 12px;
}
.content-tab.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.plain-content, .raw-content { padding: 16px; }
.html-content iframe { border: 0; width: 100%; min-height: 360px; background: #fff; }
.copy-button {
  position: absolute; top: 8px; right: 8px;
  padding: 4px 10px; background: var(--brand); color: #fff;
  border: 0; border-radius: 6px; font-size: 11px; cursor: pointer;
}
.email-content { position: relative; }

.loading { text-align: center; padding: 32px; color: var(--muted); }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid #dce7e3; border-top-color: var(--brand);
  animation: spin .8s linear infinite; margin: 0 auto 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast-host { position: sticky; top: 0; z-index: 30; }
.error, .success {
  padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; font-size: 13px;
}
.error { background: #fdeeee; color: var(--danger); }
.success { background: #eaf8ef; color: var(--ok); }

.pagination { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 12px; }

/* verification / batch */
.verification-results { margin-top: 16px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.verification-summary { padding: 12px; }
.verification-summary.has-success { background: #eaf8ef; }
.verification-summary.all-failed { background: #fdeeee; }
.verification-header, .verification-item {
  display: grid; grid-template-columns: 36px 1fr 140px;
  padding: 10px 12px; align-items: center; border-bottom: 1px solid #eef2f1;
}
.verification-header { background: #f7faf9; font-size: 12px; color: var(--muted); font-weight: 600; }
.verification-badge { padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.verification-badge.success { background: #eaf8ef; color: var(--ok); }
.verification-badge.error { background: #fdeeee; color: var(--danger); }
.verification-actions { display: flex; justify-content: flex-end; padding: 12px; }
.batch-header h3 { font-size: 1rem; margin-bottom: 4px; }

.account-select {
  min-width: 180px; padding: 8px 10px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; font: inherit;
}

/* public / docs reuse */
.container, .public-container, .docs { max-width: 960px; margin: 0 auto; padding: 28px 16px; }
.header { text-align: left; margin-bottom: 18px; }
.header h1 { font-size: 1.5rem; font-weight: 700; }
.header-sub { color: var(--muted); margin-top: 4px; font-size: 13px; }
.meta-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; align-items: center; }
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; margin-bottom: 16px;
}
.hint-text { margin-top: 6px; font-size: 12px; color: var(--muted); }
.meta-link { font-size: 12px; color: var(--brand); padding: 4px 8px; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: relative; height: auto;
    flex-direction: row; flex-wrap: wrap; align-items: center;
  }
  .side-nav { flex-direction: row; flex-wrap: wrap; flex: 1; }
  .side-meta { width: 100%; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .main { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
}
