/*
 * WordPress wp-admin 风格后台样式
 *
 * 配色完全对齐 wp-admin：
 *   - 侧栏 #1d2327，文字 #ffffff，悬停 #3d444d，活动项 #2271b7
 *   - 顶栏 #1d2327，左上 logo 区也是 #2271b7 主色块
 *   - 主色 #2271b7（WordPress 蓝）
 *   - 边框 #c3c4c7 / #dcdcde
 *   - 文字 #1d2327 / #50575e / #a7aaad
 */
* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  font-size: 14px;
  color: #1d2327;
  background: #f0f0f1;
  height: 100%;
}

a {
  color: #2271b7;
  text-decoration: none;
}
a:hover {
  color: #135e96;
  text-decoration: underline;
}

/* ============ 整体布局 ============ */

.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: 32px 1fr;
  grid-template-areas:
    "topbar topbar"
    "sidebar main";
  height: 100vh;
}

/* ============ 顶部 admin bar ============ */

.topbar {
  grid-area: topbar;
  background: #1d2327;
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 16px;
  font-size: 13px;
}
.topbar a {
  color: #fff;
  opacity: 0.85;
  margin-right: 12px;
}
.topbar a:hover {
  opacity: 1;
  text-decoration: none;
}
.topbar .topbar-spacer { flex: 1; }
.topbar .topbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar .topbar-user img {
  width: 24px; height: 24px; border-radius: 50%;
  background: #2271b7; display: inline-block;
}
.topbar .topbar-user .username {
  opacity: 0.95;
}
.topbar .topbar-user form { margin: 0; }
.topbar .topbar-user button {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 12px;
  cursor: pointer;
}
.topbar .topbar-user button:hover {
  background: rgba(255,255,255,0.1);
}

/* ============ 侧栏 ============ */

.sidebar {
  grid-area: sidebar;
  background: #1d2327;
  color: #fff;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar .sidebar-logo {
  background: #2271b7;
  padding: 16px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar .sidebar-logo img {
  width: 36px;
  height: 36px;
  background: #fff;
  border-radius: 50%;
  padding: 4px;
  object-fit: contain;
}
.sidebar .sidebar-logo .logo-text {
  font-weight: 600;
  font-size: 15px;
  color: #fff;
  line-height: 1.2;
}
.sidebar .sidebar-logo .logo-sub {
  font-size: 11px;
  opacity: 0.85;
  color: #fff;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  padding: 8px 0;
}
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: #fff;
  font-size: 14px;
  border-left: 3px solid transparent;
  text-decoration: none;
}
.sidebar nav a:hover {
  background: #3d444d;
  color: #fff;
}
.sidebar nav a.active {
  background: #2271b7;
  border-left-color: #72aee6;
  color: #fff;
}

.sidebar nav a .nav-icon {
  width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px;
  opacity: 0.85;
}

.sidebar .sidebar-footer {
  margin-top: auto;
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
  font-size: 11px;
  opacity: 0.6;
}

/* ============ 主内容区 ============ */

.main {
  grid-area: main;
  background: #f0f0f1;
  overflow-y: auto;
  padding: 24px 28px 60px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.page-header h1 {
  font-size: 23px;
  font-weight: 400;
  margin: 0;
  color: #1d2327;
}
.page-header .page-actions {
  display: flex;
  gap: 8px;
}

/* ============ 卡片 / 区块 ============ */

.card {
  background: #fff;
  border: 1px solid #dcdcde;
  border-radius: 4px;
  padding: 20px;
  margin-bottom: 18px;
}
.card h2 {
  margin: 0 0 12px;
  font-size: 18px;
  font-weight: 600;
  color: #1d2327;
}
.card .card-desc {
  color: #50575e;
  font-size: 13px;
  margin-bottom: 12px;
}

/* 状态条：仿 WP 的 updated notice */
.notice {
  padding: 10px 14px;
  border-left: 4px solid #2271b7;
  background: #f0f6fc;
  color: #1d2327;
  margin-bottom: 14px;
  border-radius: 2px;
  font-size: 13px;
}
.notice.success {
  background: #edfaef;
  border-left-color: #00a32a;
  color: #144722;
}
.notice.error {
  background: #fcf0f1;
  border-left-color: #d63638;
  color: #691c1c;
}
.notice.warn {
  background: #fcf9e8;
  border-left-color: #dba617;
  color: #5b4500;
}

/* ============ 表单 ============ */

.form-row {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.form-row .field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 160px;
}
.form-row .field label {
  font-size: 13px;
  color: #50575e;
  font-weight: 500;
}
.form-row .field input,
.form-row .field select,
.form-row .field textarea {
  border: 1px solid #8c8f94;
  border-radius: 3px;
  padding: 6px 10px;
  font-size: 14px;
  background: #fff;
  color: #1d2327;
  font-family: inherit;
}
.form-row .field input:focus,
.form-row .field select:focus,
.form-row .field textarea:focus {
  border-color: #2271b7;
  outline: none;
  box-shadow: 0 0 0 1px #2271b7;
}

textarea.kw-input {
  width: 100%;
  min-height: 80px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  padding: 10px 12px;
  border: 1px solid #8c8f94;
  border-radius: 3px;
  background: #fff;
  color: #1d2327;
}

input.url-input {
  width: 100%;
  border: 1px solid #8c8f94;
  border-radius: 3px;
  padding: 8px 10px;
  font-size: 14px;
}

/* ============ 按钮 ============ */

.btn {
  display: inline-block;
  padding: 6px 14px;
  font-size: 13px;
  border-radius: 3px;
  cursor: pointer;
  border: 1px solid transparent;
  background: #2271b7;
  color: #fff;
  text-decoration: none;
  font-family: inherit;
  line-height: 1.4;
}
.btn:hover { background: #135e96; color: #fff; text-decoration: none; }
.btn:disabled { background: #a7aaad; cursor: not-allowed; }

.btn.secondary {
  background: #fff;
  color: #2271b7;
  border-color: #2271b7;
}
.btn.secondary:hover {
  background: #f0f6fc;
  color: #135e96;
}

.btn.danger {
  background: #d63638;
}
.btn.danger:hover { background: #b52d31; }

.btn.large { padding: 8px 18px; font-size: 14px; }

/* ============ 表格 ============ */

.kw-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  font-size: 13px;
}
.kw-table thead th {
  background: #f6f7f7;
  color: #1d2327;
  font-weight: 600;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 2px solid #2271b7;
  position: sticky;
  top: 0;
  z-index: 1;
}
.kw-table tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid #f0f0f1;
  vertical-align: middle;
}
.kw-table tbody tr:nth-child(even) {
  background: #fafafa;
}
.kw-table tbody tr:hover {
  background: #f0f6fc;
}
.kw-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.kw-table .ctr { text-align: center; }
.kw-table .copyable {
  cursor: copy;
  color: #2271b7;
  text-decoration: underline dotted;
}
.kw-table .copyable:hover {
  background: #f0f6fc;
}
.kw-table .trend-up { color: #d63638; font-weight: 600; }
.kw-table .trend-down { color: #00a32a; font-weight: 600; }
.kw-table .trend-flat { color: #50575e; }
.kw-table .trend-inf { color: #d63638; font-weight: 700; }

.kw-table-wrap {
  max-height: 60vh;
  overflow: auto;
  border: 1px solid #dcdcde;
  border-radius: 4px;
}

/* ============ 分页 ============ */

.pager {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
.pager .page-label {
  min-width: 110px;
  text-align: center;
  color: #50575e;
  font-size: 13px;
}

/* ============ 登录页 ============ */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #f0f0f1 0%, #e5e5e5 100%);
}
.login-card {
  background: #fff;
  border: 1px solid #dcdcde;
  border-radius: 6px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.08);
  width: 360px;
  padding: 32px;
}
.login-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 600;
  text-align: center;
  color: #1d2327;
}
.login-card .sub {
  text-align: center;
  color: #50575e;
  font-size: 13px;
  margin-bottom: 20px;
}
.login-card .field {
  margin-bottom: 14px;
}
.login-card .field label {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
  color: #50575e;
  font-weight: 500;
}
.login-card .field input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #8c8f94;
  border-radius: 3px;
  font-size: 14px;
}
.login-card .field input:focus {
  outline: none;
  border-color: #2271b7;
  box-shadow: 0 0 0 1px #2271b7;
}
.login-card .submit-btn {
  width: 100%;
  padding: 10px;
  background: #2271b7;
  color: #fff;
  border: none;
  border-radius: 3px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
}
.login-card .submit-btn:hover { background: #135e96; }
.login-card .err {
  background: #fcf0f1;
  color: #691c1c;
  border-left: 4px solid #d63638;
  padding: 8px 12px;
  border-radius: 2px;
  font-size: 13px;
  margin-bottom: 14px;
}
.login-card .logo {
  display: block;
  margin: 0 auto 12px;
  width: 64px; height: 64px;
  background: #2271b7;
  border-radius: 50%;
  padding: 8px;
  object-fit: contain;
}

/* ============ 已保存的查询方案（关键词历史） ============ */

.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.card-header-row h2 { margin: 0; }
.card-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.card-header-actions input[type="text"] {
  border: 1px solid #8c8f94;
  border-radius: 3px;
  padding: 6px 10px;
  font-size: 13px;
  min-width: 220px;
  font-family: inherit;
  color: #1d2327;
  background: #fff;
}
.card-header-actions input[type="text"]:focus {
  outline: none;
  border-color: #2271b7;
  box-shadow: 0 0 0 1px #2271b7;
}
.muted { color: #a7aaad; font-weight: 400; font-size: 13px; }

.saved-plans-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
  margin-top: 4px;
}

.saved-plans-empty {
  grid-column: 1 / -1;
  padding: 18px 16px;
  background: #f6f7f7;
  border: 1px dashed #c3c4c7;
  border-radius: 3px;
  color: #50575e;
  font-size: 13px;
  text-align: center;
}

.saved-plan-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid #dcdcde;
  border-left: 3px solid #2271b7;
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.saved-plan-item:hover {
  background: #f0f6fc;
  border-color: #2271b7;
  box-shadow: 0 1px 2px rgba(34, 113, 183, 0.08);
}
.saved-plan-item:active {
  background: #e6f1fb;
}

.saved-plan-main {
  flex: 1;
  min-width: 0;
}
.saved-plan-name {
  font-size: 14px;
  font-weight: 600;
  color: #1d2327;
  word-break: break-word;
  margin-bottom: 4px;
}
.saved-plan-summary {
  font-size: 12px;
  color: #50575e;
  word-break: break-word;
  margin-bottom: 6px;
  line-height: 1.5;
  /* 限制两行省略 */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.saved-plan-meta {
  font-size: 12px;
  color: #72777c;
}
.saved-plan-stats {
  color: #a7aaad;
  margin-left: 2px;
}

.saved-plan-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.saved-plan-actions .btn {
  padding: 4px 10px;
  font-size: 12px;
  line-height: 1.4;
}

/* ============ 仪表盘小卡片 ============ */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat-card {
  background: #fff;
  border: 1px solid #dcdcde;
  border-radius: 4px;
  padding: 16px 18px;
}
.stat-card .stat-num {
  font-size: 28px;
  font-weight: 600;
  color: #2271b7;
  line-height: 1.1;
}
.stat-card .stat-label {
  margin-top: 4px;
  color: #50575e;
  font-size: 13px;
}

/* ============ Spinner / Loading ============ */

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid #dcdcde;
  border-top-color: #2271b7;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ code/pre ============ */

pre, code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
pre {
  background: #f6f7f7;
  border: 1px solid #dcdcde;
  border-radius: 3px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.5;
  overflow-x: auto;
}

/* ============ 自检结果 ============ */

.diag-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.diag-list li {
  padding: 6px 0;
  border-bottom: 1px dashed #f0f0f1;
  font-size: 13px;
}
.diag-list li:last-child { border-bottom: none; }
.diag-list .ok { color: #00a32a; font-weight: 600; }
.diag-list .bad { color: #d63638; font-weight: 600; }
.diag-list .warn { color: #dba617; font-weight: 600; }

@media (max-width: 720px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "main";
  }
  .sidebar { display: none; }
}