/* 亚马逊关键词搜索量监控 · 视觉系统 v2
 * 设计原则：清晰、克制、专业，带有 subtle 的质感与动效
 */

@import url('https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&display=swap');

:root {
  /* 基础色板 — light */
  --bg: #f8fafc;
  --bg-elevated: #ffffff;
  --fg: #0f172a;
  --fg-strong: #020617;
  --muted: #64748b;
  --border: #e2e8f0;
  --border-subtle: #f1f5f9;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-fg: #ffffff;
  --accent-soft: rgba(37, 99, 235, 0.08);
  --up: #dc2626;
  --up-soft: rgba(220, 38, 38, 0.08);
  --down: #16a34a;
  --down-soft: rgba(22, 163, 74, 0.08);
  --warning: #d97706;
  --warning-soft: rgba(217, 119, 6, 0.08);
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 16px 48px rgba(15, 23, 42, 0.12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --transition: 150ms cubic-bezier(0.16, 1, 0.3, 1);
  --transition-slow: 260ms cubic-bezier(0.16, 1, 0.3, 1);
}

body[data-theme="dark"] {
  --bg: #0b1120;
  --bg-elevated: #0f172a;
  --fg: #e2e8f0;
  --fg-strong: #f8fafc;
  --muted: #94a3b8;
  --border: #1e293b;
  --border-subtle: #162032;
  --accent: #60a5fa;
  --accent-hover: #93c5fd;
  --accent-fg: #0f172a;
  --accent-soft: rgba(96, 165, 250, 0.12);
  --up: #f87171;
  --up-soft: rgba(248, 113, 113, 0.12);
  --down: #4ade80;
  --down-soft: rgba(74, 222, 128, 0.12);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, 0.12);
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== 通用 ===== */
.glass {
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), var(--shadow-sm);
}

body[data-theme="dark"] .glass {
  background: rgba(15, 23, 42, 0.72);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), var(--shadow-sm);
}

/* ===== 顶部栏 ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
}

@media (max-width: 640px) {
  .topbar { padding: 12px 16px; flex-wrap: wrap; }
}

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

.logo {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: var(--accent-fg);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.logo svg { width: 22px; height: 22px; }

.title-block h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--fg-strong);
}

.meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 11px;
  line-height: 1.4;
  border: 1px solid transparent;
}

.badge.status-live {
  background: var(--down-soft);
  color: var(--down);
}

.badge.status-off {
  background: var(--warning-soft);
  color: var(--warning);
}

.badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.8;
}

.badge.status-live .dot { animation: pulse 2s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 0.5; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.1); }
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ===== 按钮 ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--fg);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  line-height: 1.4;
  white-space: nowrap;
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition), border-color var(--transition);
  user-select: none;
}

.btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
  border-color: var(--border);
}

.btn:active:not(:disabled) {
  transform: translateY(0) scale(0.98);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: transparent;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.25);
}

body[data-theme="dark"] .btn-primary:hover:not(:disabled) {
  box-shadow: 0 4px 14px rgba(96, 165, 250, 0.25);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: transparent;
}

.btn-icon {
  padding: 8px;
  border-radius: var(--radius-md);
}

.btn-icon svg { width: 18px; height: 18px; }

/* ===== 主内容区 ===== */
main {
  padding: 22px;
  max-width: 1400px;
  margin: 0 auto;
}

@media (max-width: 640px) {
  main { padding: 16px; }
}

/* ===== 控制面板 ===== */
.controls {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}

.controls label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.controls label.search {
  flex: 1;
  min-width: 180px;
}

select, input, textarea {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--fg);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

select:focus, input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--bg-elevated);
}

.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input-wrap svg {
  position: absolute;
  left: 10px;
  width: 16px;
  height: 16px;
  color: var(--muted);
  pointer-events: none;
}

.search-input-wrap input {
  padding-left: 32px;
  width: 100%;
}

.spacer { flex: 1; }

/* ===== 添加面板 ===== */
.add-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 18px;
  animation: fadeDown 260ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.add-panel.hidden { display: none; }

@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 860px) {
  .add-panel { grid-template-columns: 1fr; }
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--transition), border-color var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-sm);
  border-color: var(--border);
}

.card h3 {
  margin: 0 0 14px;
  font-size: 14px;
  font-weight: 700;
  color: var(--fg-strong);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card h3 svg {
  width: 16px;
  height: 16px;
  color: var(--accent);
}

.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row input, .row select { flex: 1; min-width: 140px; }

.hint {
  color: var(--muted);
  font-size: 12px;
  margin: 0 0 12px;
  line-height: 1.5;
}

code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  border: 1px solid var(--border-subtle);
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 100px;
  margin-bottom: 10px;
  line-height: 1.6;
}

/* ===== 消息提示 ===== */
.msg {
  margin: 0 0 18px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: fadeDown 260ms cubic-bezier(0.16, 1, 0.3, 1) both;
  border: 1px solid transparent;
}

.msg.hidden { display: none; }

.msg-ok {
  background: var(--down-soft);
  color: var(--down);
  border-color: rgba(22, 163, 74, 0.2);
}

.msg-err {
  background: var(--up-soft);
  color: var(--up);
  border-color: rgba(220, 38, 38, 0.2);
}

.msg svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* ===== 表格 ===== */
.table-wrap {
  overflow: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--transition);
}

.table-wrap:hover {
  box-shadow: var(--shadow-sm);
}

.table-wrap::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.table-wrap::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}

.table-wrap::-webkit-scrollbar-track {
  background: transparent;
}

table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  min-width: 720px;
}

th, td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

th {
  background: var(--bg);
  position: sticky;
  top: 0;
  font-weight: 700;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  z-index: 10;
  border-bottom: 1px solid var(--border);
}

tbody tr {
  transition: background var(--transition);
}

tbody tr:hover td {
  background: var(--accent-soft);
}

tbody tr:last-child td {
  border-bottom: none;
}

td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

.model-cell {
  font-weight: 700;
  color: var(--fg-strong);
  background: var(--bg);
  border-right: 1px solid var(--border);
  vertical-align: top;
}

.kw {
  color: var(--accent);
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: color var(--transition);
}

.kw:hover {
  color: var(--accent-hover);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.kw svg {
  width: 13px;
  height: 13px;
  opacity: 0.7;
}

.wow {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
  font-size: 12px;
}

.wow svg { width: 12px; height: 12px; }

.wow.up { color: var(--up); }
.wow.down { color: var(--down); }
.wow.none { color: var(--muted); font-weight: 500; }

.group-sep td { border-top: 2px solid var(--border); }

.empty-cell {
  padding: 48px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.empty-cell svg {
  width: 40px;
  height: 40px;
  color: var(--border);
  margin-bottom: 12px;
}

/* Skeleton loading */
.skeleton {
  background: linear-gradient(90deg, var(--border-subtle) 25%, var(--border) 50%, var(--border-subtle) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: 6px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-row td {
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.skeleton-line { height: 12px; }

/* ===== 趋势弹窗 ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
  opacity: 0;
  animation: modalIn 220ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.modal.hidden { display: none; }

@keyframes modalIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 22px;
  width: min(800px, 96vw);
  max-height: 92vh;
  overflow: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(12px) scale(0.98);
  animation: cardIn 260ms cubic-bezier(0.16, 1, 0.3, 1) 40ms forwards;
}

@keyframes cardIn {
  to { transform: translateY(0) scale(1); }
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--fg-strong);
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-head h3 svg {
  width: 18px;
  height: 18px;
  color: var(--accent);
}

#trendChart {
  min-height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#trendChart svg {
  width: 100%;
  height: auto;
  max-height: 360px;
}

#trendChart .chart-empty {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 40px 0;
}

/* ===== 响应式 ===== */
@media (max-width: 640px) {
  .controls { flex-direction: column; align-items: stretch; }
  .controls label { width: 100%; }
  .controls label.search { min-width: auto; }
  .spacer { display: none; }
  .top-actions { width: 100%; justify-content: flex-end; }

  .title-block h1 { font-size: 16px; }
  .logo { width: 36px; height: 36px; }
  .logo svg { width: 20px; height: 20px; }

  .modal-card { padding: 16px; width: 100%; border-radius: var(--radius-lg); }
}

/* ===== 减少动画偏好 ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
