/**
 * ApipSearch 设计系统 v3（克制扁平风）
 * 图标: Tabler Icons (https://tabler.io/icons) - MIT License
 *
 * 设计取向：中性底色 + 1px 描边卡片 + 单一强调色，不使用渐变与装饰光效。
 *
 * 目录
 *  1. 设计令牌（暗色 / 浅色）
 *  2. 基础重置与排版
 *  3. 布局骨架与页头
 *  4. 卡片
 *  5. 按钮
 *  6. 表单（输入框 / 下拉 / 开关 / 勾选）
 *  7. 状态（空态 / 加载 / 错误 / Toast）
 *  8. 首页（搜索 / 结果 / 最近查询）
 *  9. 工具类与响应式
 */

/* ============================================================
 * 1. 设计令牌
 * ============================================================ */

:root {
  color-scheme: dark;

  /* — 表面层级 — */
  --bg: #0f1115;
  --surface: #171a20;
  --surface-2: #1e222a;
  --inset: #12151a;
  --sidebar-bg: #13161c;

  /* — 边框 — */
  --border: #262b34;
  --border-2: #333a46;

  /* — 文字 — */
  --text: #e4e7ec;
  --text-2: #9aa1ae;
  --text-3: #6b7280;

  /* — 强调色（单一主色，不使用渐变） — */
  --accent: #5b8cff;
  --accent-hover: #6d99ff;
  --accent-soft: rgba(91, 140, 255, 0.12);
  --accent-ring: rgba(91, 140, 255, 0.3);
  --accent-fg: #ffffff;

  /* — 语义色 — */
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.12);
  --warning: #eab308;
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.12);
  --info: #38bdf8;

  /* — 圆角 — */
  --r-xs: 6px;
  --r-sm: 8px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-full: 999px;

  /* — 阴影（仅浮层使用） — */
  --sh-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --sh-md: 0 8px 24px rgba(0, 0, 0, 0.4);

  /* — 动效 — */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --t: 0.15s;

  /* — 字体 — */
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Hiragino Sans GB', 'Microsoft YaHei', Roboto, Helvetica, Arial, sans-serif;
  --mono: 'JetBrains Mono', 'SFMono-Regular', 'Cascadia Code', 'Fira Code',
    Consolas, 'Courier New', monospace;

  /* — 侧栏尺寸 — */
  --sidebar-w: 176px;
  --sidebar-w-collapsed: 56px;

  /* — 兼容旧变量名（JS 中仍以 var(--color-*) 引用） — */
  --color-primary: var(--accent);
  --color-error: var(--danger);
  --color-success: var(--success);
  --color-warning: var(--warning);
  --color-text: var(--text);
  --color-text-secondary: var(--text-2);
  --color-text-muted: var(--text-3);
  --color-bg: var(--bg);
  --color-bg-card: var(--surface);
  --color-bg-hover: var(--surface-2);
  --color-border: var(--border);
  --radius: var(--r-md);
  --radius-sm: var(--r-sm);
  --radius-lg: var(--r-lg);
  --shadow: var(--sh-md);
  --shadow-sm: var(--sh-sm);
  --transition: var(--t);
}

/* ===== 浅色主题 ===== */
:root[data-theme='light'] {
  color-scheme: light;

  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --inset: #fafbfc;
  --sidebar-bg: #fbfcfd;

  --border: #e3e6ea;
  --border-2: #cfd4db;

  --text: #1a1d23;
  --text-2: #565d69;
  --text-3: #868d99;

  --accent: #3f6bff;
  --accent-hover: #2f5bf0;
  --accent-soft: rgba(63, 107, 255, 0.09);
  --accent-ring: rgba(63, 107, 255, 0.26);

  --success: #0f9b73;
  --success-soft: rgba(15, 155, 115, 0.1);
  --warning: #c28a04;
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.09);
  --info: #0284c7;

  --sh-sm: 0 1px 3px rgba(16, 24, 40, 0.06);
  --sh-md: 0 8px 24px rgba(16, 24, 40, 0.1);
}

/* ============================================================
 * 2. 基础重置与排版
 * ============================================================ */

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

h1, h2, h3 {
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button {
  font-family: inherit;
  font-size: inherit;
}

input, select {
  font-family: inherit;
  font-size: inherit;
}

/* 滚动条 */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--r-full);
  border: 3px solid transparent;
  background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-2);
  background-clip: content-box;
}

/* 焦点可见性 */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent-ring);
  outline-offset: 1px;
}

/* ============================================================
 * 3. 布局骨架与页头
 * ============================================================ */

.layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.content {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 28px 40px;
}

.page {
  max-width: 760px;
  margin: 0 auto;
}

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

.page-head-main {
  min-width: 0;
}

.page-title {
  font-size: 18px;
  font-weight: 600;
}

.page-subtitle {
  margin-top: 3px;
  font-size: 13px;
  color: var(--text-3);
}

.page-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* 列表区块的小标题 */
.section-label {
  margin: 24px 0 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
}

/* ============================================================
 * 4. 卡片
 * ============================================================ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 18px 20px;
  margin-bottom: 14px;
}

.card:last-child {
  margin-bottom: 0;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.card-desc {
  font-size: 12.5px;
  color: var(--text-3);
  margin-top: 2px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.card-head-text {
  min-width: 0;
}

.card-head-extra {
  flex-shrink: 0;
}

/* ============================================================
 * 5. 按钮
 * ============================================================ */

.btn-primary,
.btn-secondary,
.btn-ghost,
.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--t) var(--ease), color var(--t) var(--ease),
    border-color var(--t) var(--ease);
  user-select: none;
}

.btn-primary {
  padding: 10px 20px;
  background: var(--accent);
  color: var(--accent-fg);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:active {
  opacity: 0.9;
}

.btn-secondary {
  padding: 9px 15px;
  background: var(--surface);
  border-color: var(--border);
  color: var(--text-2);
}

.btn-secondary:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn-ghost {
  padding: 7px 12px;
  background: transparent;
  color: var(--text-2);
}

.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn-danger {
  padding: 9px 15px;
  background: transparent;
  border-color: rgba(239, 68, 68, 0.4);
  color: var(--danger);
}

.btn-danger:hover {
  background: var(--danger-soft);
}

.btn-primary:disabled,
.btn-secondary:disabled,
.btn-danger:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 图标按钮 */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--t) var(--ease), color var(--t) var(--ease),
    border-color var(--t) var(--ease);
}

.btn-icon:hover {
  background: var(--surface-2);
  border-color: var(--border-2);
  color: var(--accent);
}

/* 文字按钮 */
.btn-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  background: transparent;
  border: none;
  border-radius: var(--r-xs);
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--t) var(--ease);
}

.btn-link:hover {
  background: var(--accent-soft);
}

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

.btn-link-danger:hover {
  background: var(--danger-soft);
}

/* ============================================================
 * 6. 表单
 * ============================================================ */

.field {
  margin-bottom: 14px;
}

.field:last-child {
  margin-bottom: 0;
}

.field-label {
  display: block;
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 6px;
}

.field-hint {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 5px;
}

.form-input,
.form-select {
  width: 100%;
  padding: 9px 12px;
  background: var(--inset);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}

.form-input::placeholder {
  color: var(--text-3);
}

.form-input:hover,
.form-select:hover {
  border-color: var(--border-2);
}

.form-input:focus,
.form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 32px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239aa1ae' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

/* 带图标的输入框 */
.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrap .input-icon {
  position: absolute;
  left: 11px;
  display: flex;
  color: var(--text-3);
  pointer-events: none;
}

.input-wrap .form-input {
  padding-left: 34px;
}

.input-wrap:focus-within .input-icon {
  color: var(--accent);
}

/* 开关 */
.switch {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
}

.switch input[type='checkbox'] {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex-shrink: 0;
  width: 36px;
  height: 20px;
  margin-top: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--r-full);
  cursor: pointer;
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease);
}

.switch input[type='checkbox']::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: var(--text-3);
  border-radius: 50%;
  transition: transform var(--t) var(--ease), background var(--t) var(--ease);
}

.switch input[type='checkbox']:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.switch input[type='checkbox']:checked::after {
  transform: translateX(16px);
  background: #fff;
}

.switch-text {
  display: block;
  flex: 1;
  min-width: 0;
}

.switch-title {
  display: block;
  font-size: 14px;
}

.switch-desc {
  display: block;
  font-size: 12.5px;
  color: var(--text-3);
}

/* 行式设置项 */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.setting-row:first-child {
  padding-top: 0;
}

.setting-row:last-child {
  padding-bottom: 0;
  border-bottom: none;
}

.setting-row .switch {
  flex: 1;
}

.setting-row-text {
  min-width: 0;
}

.setting-row-title {
  font-size: 14px;
}

.setting-row-desc {
  font-size: 12.5px;
  color: var(--text-3);
  margin-top: 1px;
}

.setting-row-control {
  flex-shrink: 0;
}

.setting-row-control .form-select {
  min-width: 110px;
}

/* 单选 / 勾选 */
.radio-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.radio-label,
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

.radio-label input[type='radio'],
.checkbox-label input[type='checkbox'] {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

/* ============================================================
 * 7. 状态
 * ============================================================ */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 56px 20px;
  text-align: center;
}

.empty-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  color: var(--text-3);
  opacity: 0.6;
}

.empty-title {
  font-size: 14px;
  color: var(--text-2);
}

.empty-desc {
  font-size: 13px;
  color: var(--text-3);
  margin-top: 3px;
}

.empty-action {
  margin-top: 14px;
}

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 52px 20px;
  color: var(--text-3);
  font-size: 13px;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid var(--border-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.error-message {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: var(--danger-soft);
  border: 1px solid rgba(239, 68, 68, 0.28);
  border-radius: var(--r-md);
  color: var(--danger);
  font-size: 13.5px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 200;
  transform: translateX(-50%);
  padding: 9px 18px;
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: var(--r-sm);
  font-size: 13.5px;
  box-shadow: var(--sh-md);
  transition: opacity var(--t) var(--ease);
  opacity: 1;
  pointer-events: none;
}

.toast.hidden {
  opacity: 0;
}

/* ============================================================
 * 8. 首页
 * ============================================================ */

/* 搜索栏 */
.search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
}

.search-field {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  min-width: 0;
}

.search-field .input-icon {
  position: absolute;
  left: 12px;
  display: flex;
  color: var(--text-3);
  pointer-events: none;
}

.search-field:focus-within .input-icon {
  color: var(--accent);
}

.search-input {
  width: 100%;
  padding: 10px 36px 10px 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text);
  font-size: 14px;
  font-family: var(--mono);
  outline: none;
  transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}

.search-input::placeholder {
  font-family: var(--font);
  color: var(--text-3);
}

.search-input:hover {
  border-color: var(--border-2);
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-clear {
  position: absolute;
  right: 9px;
  display: none;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-3);
  cursor: pointer;
  transition: background var(--t) var(--ease), color var(--t) var(--ease);
}

.search-clear.visible {
  display: flex;
}

.search-clear:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.search-btn {
  flex-shrink: 0;
  padding-left: 22px;
  padding-right: 22px;
}

/* 快捷示例（朴素文字链接） */
.search-hints {
  margin: -8px 0 20px;
  font-size: 12.5px;
  color: var(--text-3);
}

.hint-link {
  padding: 0 1px;
  background: transparent;
  border: none;
  color: var(--text-2);
  font-size: 12.5px;
  font-family: var(--mono);
  cursor: pointer;
}

.hint-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* 结果卡片 */
.result-container {
  margin-bottom: 20px;
}

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  /* 分栏依据卡片自身宽度，而非视口：侧栏收起/展开会改变卡片宽度 */
  container-type: inline-size;
  container-name: result-card;
}

/* 结果主体：窄卡片上下堆叠（先数据后地图），宽卡片为左数据（窄）+ 右地图（方） */
.result-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1px;
  background: var(--border);
}

/* 卡片够宽时才分两栏（与视口无关，侧栏收起后即使窗口不变也会重新分栏） */
@container result-card (min-width: 540px) {
  .result-body.has-globe {
    grid-template-columns: minmax(0, 240px) minmax(0, 1fr);
  }
}

/* 不支持容器查询时退回视口断点（老版本 Chromium） */
@supports not (container-type: inline-size) {
  @media (min-width: 900px) {
    .result-body.has-globe {
      grid-template-columns: minmax(0, 240px) minmax(0, 1fr);
    }
  }
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 18px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.result-header-main {
  min-width: 0;
}

.result-ip {
  display: block;
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
  word-break: break-all;
}

.result-summary {
  display: block;
  margin-top: 1px;
  font-size: 13px;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 字段列表：改为「标签 + 值」的横向行式排版，去掉 1px 网格分隔 */
.result-grid {
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

.result-item {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 9px 18px;
}

.result-item + .result-item {
  border-top: 1px solid var(--border);
}

.result-item .label {
  flex: 0 0 5em;
  font-size: 12.5px;
  color: var(--text-3);
}

.result-item .value {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 无数据的字段弱化显示，避免满屏「-」抢视线 */
.result-item .value.is-empty {
  color: var(--text-3);
}

.result-item .value.mono {
  font-family: var(--mono);
  font-size: 13px;
}

.result-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding: 10px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  font-size: 12px;
  color: var(--text-3);
}

/* 最近查询 */
.recent-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.recent-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color var(--t) var(--ease), background var(--t) var(--ease);
}

.recent-item:hover {
  border-color: var(--accent);
  background: var(--surface-2);
}

.recent-item-main {
  flex: 1;
  min-width: 0;
}

.recent-item-ip {
  display: block;
  font-family: var(--mono);
  font-size: 13.5px;
  color: var(--accent);
}

.recent-item-summary {
  display: block;
  font-size: 12.5px;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-item-time {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-3);
}

/* ============================================================
 * 9. 工具类与响应式
 * ============================================================ */

.hidden {
  display: none !important;
}

.mono {
  font-family: var(--mono);
}

/* 移动端（≤768px）的布局增强见 mobile.css：抽屉侧栏、触控尺寸、安全区、动态视口高度等 */

/* 窄卡片：标签列收窄，给值留出更多空间（以卡片宽度为准，与侧栏状态无关） */
@container result-card (max-width: 380px) {
  .result-item {
    gap: 10px;
  }

  .result-item .label {
    flex-basis: 4.5em;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
