/* /static/css/components/ip-widget.css */
/* 描述: IP 地理位置专业级仪表盘样式 */
/* 设计理念: 非对称布局 + 品牌隐喻 + 色彩编码 + 安全信任矩阵 + 毛玻璃特效 */

/* ============================================
   主容器 - 仅保留个性化样式，基础样式由 .card 提供
   ============================================ */
.ip-widget-container {
  min-height: 300px;
  display: flex;
  flex-direction: column;
}

/* ============================================
   背景水印（运营商缩写）- 使用伪元素实现，不影响布局
   顶部固定，部分超出容器隐藏
   ============================================ */
.ip-widget-container::after {
  content: attr(data-watermark);
  position: absolute;
  left: 0;
  top: -0.5rem; /* 顶部固定，稍微超出 */
  font-size: 16.25rem; /* 260px */
  font-weight: 900;
  font-style: italic;
  opacity: 0.02;
  pointer-events: none;
  transition: opacity 1s ease;
  z-index: 0 !important; /* 保持在背景层，不遮挡内容 */
  line-height: 1;
  user-select: none;
  white-space: nowrap;
}

.ip-widget-container:hover::after {
  opacity: 0.04;
}

/* 确保水印在毛玻璃背景层之上，但在内容之下 */
.card.glass-card.ip-widget-container::after {
  z-index: 0 !important;
}

/* ============================================
   非对称布局（主内容区域）
   ============================================ */
.ip-widget-main {
  display: flex;
  gap: 2rem;
  padding: 1.5rem;
  position: relative;
  z-index: 10;
  flex: 1;
}

.ip-widget-core {
  flex: 1; /* 45% - 给右侧更多空间 */
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.ip-widget-details {
  flex: 1.2; /* 55% - 更大空间显示地图 */
  display: grid;
  grid-template-columns: 1fr minmax(200px, 300px); /* 文字自适应，地图 200-300px */
  grid-template-rows: repeat(3, auto);
  align-content: center;
  gap: 1rem 1.5rem;
  border-left: 1px solid rgba(148, 163, 184, 0.2);
  padding-left: 1.5rem;
  position: relative;
  min-height: 180px;
}

:is(.dark .ip-widget-details) {
  border-left-color: rgba(148, 163, 184, 0.1);
}

/* ============================================
   地图区域（正常 flex/grid 项目，参与自适应）
   ============================================ */
.ip-widget-map-layer {
  grid-column: 2;
  grid-row: 1 / -1; /* 跨越所有行 */
  position: relative;
  z-index: 0;
  overflow: hidden;
  border-radius: 0.75rem;
  min-height: 160px;
  opacity: 0.8; /* 80% 透明度 */
}

/* 暗色模式：反转地图颜色 */
:is(.dark .ip-widget-map-layer) {
  filter: invert(1) hue-rotate(180deg) brightness(0.9) contrast(0.9);
}

/* 地图瓦片网格（3x3 拼接） */
.ip-widget-map-grid {
  position: absolute;
  top: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(3, 205px); /* 256px 缩放 80% */
  grid-template-rows: repeat(3, 205px);
  /* transform 由 JS 动态设置 */
}

.ip-widget-map-grid img {
  width: 205px;
  height: 205px;
  max-width: none;
  display: block;
}

:is(.dark .ip-widget-map-layer) {
  /* 暗色模式保持一致 */
}

/* 位置标记点（红色圆点 + 脉冲动画） */
.ip-widget-map-layer::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1rem; /* 16px */
  height: 1rem;
  background: rgb(239, 68, 68); /* 红色 */
  border: 3px solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow:
    0 0 0 0 rgba(239, 68, 68, 0.7),
    0 2px 8px rgba(0, 0, 0, 0.3);
  animation: marker-pulse 2s ease-in-out infinite;
  z-index: 10;
  pointer-events: none;
}

/* 暗色模式优化 */
:is(.dark .ip-widget-map-layer::after) {
  border-color: rgba(255, 255, 255, 0.8);
  background: rgb(248, 113, 113);
}

/* 脉冲动画 */
@keyframes marker-pulse {
  0% {
    box-shadow:
      0 0 0 0 rgba(239, 68, 68, 0.7),
      0 2px 8px rgba(0, 0, 0, 0.3);
  }
  50% {
    box-shadow:
      0 0 0 8px rgba(239, 68, 68, 0),
      0 2px 8px rgba(0, 0, 0, 0.3);
  }
  100% {
    box-shadow:
      0 0 0 0 rgba(239, 68, 68, 0),
      0 2px 8px rgba(0, 0, 0, 0.3);
  }
}

/* ============================================
   状态指示灯
   ============================================ */
.ip-widget-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.ip-widget-status-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: rgb(16, 185, 129);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
}

.ip-widget-status-label {
  font-size: 0.625rem; /* 10px */
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgb(100, 116, 139);
}

:is(.dark .ip-widget-status-label) {
  color: rgb(148, 163, 184);
}

/* ============================================
   IP 地址显示（等宽字体）
   ============================================ */
.ip-widget-ip-display {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.ip-widget-ip-text {
  font-family: 'Courier New', 'Monaco', 'Consolas', monospace;
  font-size: 3rem; /* 48px */
  font-weight: 700;
  letter-spacing: -0.05em;
  line-height: 1;
  color: var(--text-theme-main);
}

.ip-widget-copy-btn {
  padding: 0.5rem;
  border-radius: 0.75rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(148, 163, 184, 0.1);
  color: rgb(148, 163, 184);
  transition: all 0.2s ease;
  cursor: pointer;
  flex-shrink: 0;
}

.ip-widget-copy-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-theme-main);
}

.ip-widget-copy-btn:active {
  transform: scale(0.9);
}

.ip-widget-copy-btn.copied {
  color: rgb(16, 185, 129);
}

/* ============================================
   IP 操作按钮组
   ============================================ */
.ip-widget-ip-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ip-widget-toggle-btn {
  padding: 0.5rem;
  border-radius: 0.75rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(148, 163, 184, 0.1);
  color: rgb(148, 163, 184);
  transition: all 0.2s ease;
  cursor: pointer;
  flex-shrink: 0;
}

.ip-widget-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-theme-main);
}

.ip-widget-toggle-btn:active {
  transform: scale(0.9);
}

/* 显示状态（眼睛打开） */
.ip-widget-toggle-btn.visible {
  color: rgb(59, 130, 246);
}

/* ============================================
   运营商徽标卡片
   ============================================ */
.ip-widget-isp-card {
  background: linear-gradient(
    to right,
    rgba(255, 255, 255, 0.04),
    transparent
  );
  border: 1px solid rgba(148, 163, 184, 0.1);
  border-radius: 1rem;
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

:is(.dark .ip-widget-isp-card) {
  background: linear-gradient(
    to right,
    rgba(255, 255, 255, 0.02),
    transparent
  );
}

.isp-logo-badge {
  width: 3rem;
  height: 3rem;
  background: #ffffff;
  border-radius: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-style: italic;
  color: #0c0c0e;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
  font-size: 1.25rem;
  line-height: 1;
  position: relative; /* 修复：支持内部 absolute 定位的 logo */
  overflow: hidden; /* 修复：确保图片不溢出圆角 */
}

.isp-info {
  flex: 1;
  min-width: 0;
}

.isp-label {
  font-size: 0.625rem; /* 10px */
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgb(100, 116, 139);
  margin-bottom: 0.25rem;
}

:is(.dark .isp-label) {
  color: rgb(148, 163, 184);
}

.isp-name {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-theme-main);
  line-height: 1.2;
}

.isp-name-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.isp-asn {
  font-family: 'Courier New', 'Monaco', 'Consolas', monospace;
  font-size: 0.75rem;
  color: rgba(59, 130, 246, 0.8);
  margin-top: 0.125rem;
}

:is(.dark .isp-asn) {
  color: rgba(96, 165, 250, 0.8);
}

/* ============================================
   信息行（色彩编码）
   ============================================ */
.ip-info-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  grid-column: 1; /* 文字列 */
}

/* 明确指定每行位置，避免地图隐藏时布局错乱 */
/* 注意：nth-of-type 按 div 类型计数，地图是第 1 个 div */
.ip-info-row:nth-of-type(2) { grid-row: 1; } /* 地理位置 */
.ip-info-row:nth-of-type(3) { grid-row: 2; } /* 精确坐标 */
.ip-info-row:nth-of-type(4) { grid-row: 3; } /* 本地时区 */

.ip-info-icon {
  padding: 0.5rem;
  border-radius: 0.75rem;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 地理位置 - 蓝色 */
.ip-info-icon.geo {
  background: rgba(59, 130, 246, 0.1);
  color: rgb(59, 130, 246);
}

:is(.dark .ip-info-icon.geo) {
  background: rgba(59, 130, 246, 0.15);
  color: rgb(96, 165, 250);
}

/* 坐标 - 紫色 */
.ip-info-icon.compass {
  background: rgba(99, 102, 241, 0.1);
  color: rgb(99, 102, 241);
}

:is(.dark .ip-info-icon.compass) {
  background: rgba(99, 102, 241, 0.15);
  color: rgb(129, 140, 248);
}

/* 时区 - 橙色 */
.ip-info-icon.clock {
  background: rgba(251, 146, 60, 0.1);
  color: rgb(251, 146, 60);
}

:is(.dark .ip-info-icon.clock) {
  background: rgba(251, 146, 60, 0.15);
  color: rgb(251, 146, 60);
}

.ip-info-content {
  flex: 1;
  min-width: 0;
}

.ip-info-label {
  font-size: 0.5625rem; /* 9px */
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: rgb(100, 116, 139);
  margin-bottom: 0.125rem;
}

:is(.dark .ip-info-label) {
  color: rgb(148, 163, 184);
}

.ip-info-value {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-theme-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================
   安全信任矩阵（底部状态栏）
   ============================================ */
.ip-widget-security-bar {
  height: 3.5rem; /* 56px */
  background: rgba(255, 255, 255, 0.02);
  border-top: 1px solid rgba(148, 163, 184, 0.1);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

:is(.dark .ip-widget-security-bar) {
  background: rgba(0, 0, 0, 0.1);
}

.security-badges {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.security-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.6875rem; /* 11px */
  font-weight: 600;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.security-badge i {
  font-size: 0.875rem;
  line-height: 1;
}

/* 未检测到状态（灰色） */
.security-badge.clear {
  background: rgba(148, 163, 184, 0.1);
  color: rgb(100, 116, 139);
  border-color: rgba(148, 163, 184, 0.2);
}

:is(.dark .security-badge.clear) {
  background: rgba(148, 163, 184, 0.15);
  color: rgb(148, 163, 184);
  border-color: rgba(148, 163, 184, 0.3);
}

/* 风险状态（红色） */
.security-badge.risk {
  background: rgba(239, 68, 68, 0.1);
  color: rgb(239, 68, 68);
  border-color: rgba(239, 68, 68, 0.2);
}

:is(.dark .security-badge.risk) {
  background: rgba(239, 68, 68, 0.15);
  color: rgb(248, 113, 113);
  border-color: rgba(239, 68, 68, 0.3);
}

/* 中性状态（蓝色，数据中心） */
.security-badge.neutral {
  background: rgba(59, 130, 246, 0.1);
  color: rgb(59, 130, 246);
  border-color: rgba(59, 130, 246, 0.2);
}

:is(.dark .security-badge.neutral) {
  background: rgba(59, 130, 246, 0.15);
  color: rgb(96, 165, 250);
  border-color: rgba(59, 130, 246, 0.3);
}

/* ============================================
   信任评分徽章
   ============================================ */
.trust-score-badge {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.375rem 0.75rem;
  border-radius: 9999px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

:is(.dark .trust-score-badge) {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.3);
}

.trust-pulse {
  position: relative;
  width: 0.5rem;
  height: 0.5rem;
}

.trust-pulse::before {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  background: rgb(16, 185, 129);
  border-radius: 50%;
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.trust-pulse::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  background: rgb(16, 185, 129);
  border-radius: 50%;
}

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

.trust-score-text {
  font-size: 0.625rem; /* 10px */
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: rgb(16, 185, 129);
}

:is(.dark .trust-score-text) {
  color: rgb(52, 211, 153);
}

/* ============================================
   展开详情区域
   ============================================ */
.ip-widget-expanded {
  padding: 0 1.5rem;
  border-top: 1px solid var(--border-color);
  background: var(--inner-surface-bg);
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
}

.ip-widget-expanded:not(.hidden) {
  max-height: 600px;
  opacity: 1;
  padding: 1.5rem;
}

/* ============================================
   响应式设计
   ============================================ */

/* 中等宽度：左侧区域自适应缩小，保持两列布局 */
@media (max-width: 1280px) and (min-width: 1025px) {
  .ip-widget-ip-text {
    font-size: 2.25rem; /* 36px */
  }

  .ip-widget-brand-watermark {
    font-size: 12rem;
  }

  .isp-name {
    font-size: 1rem;
  }

  .ip-widget-details {
    grid-template-columns: 1fr minmax(180px, 250px); /* 缩小地图 */
  }
}

/* 1024px 及以下：地图单独一行 */
@media (max-width: 1024px) and (min-width: 769px) {
  .ip-widget-ip-text {
    font-size: 2rem; /* 32px */
  }

  .ip-widget-brand-watermark {
    font-size: 10rem;
  }

  .isp-name {
    font-size: 1rem;
  }

  .ip-widget-details {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    gap: 1rem;
  }

  .ip-widget-map-layer {
    grid-column: 1;
    grid-row: auto;
    min-height: 140px;
    max-height: 180px;
  }

  .ip-info-row {
    grid-column: 1;
  }

  /* 重置行定位，使用自动流 */
  .ip-info-row:nth-of-type(2),
  .ip-info-row:nth-of-type(3),
  .ip-info-row:nth-of-type(4) {
    grid-row: auto;
  }
}

@media (max-width: 768px) {
  .ip-widget-main {
    flex-direction: column;
    gap: 1.5rem;
  }

  .ip-widget-details {
    border-left: none;
    border-top: 1px solid rgba(148, 163, 184, 0.2);
    padding-left: 0;
    padding-top: 1.5rem;
    /* 移动端改为单列布局 */
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    gap: 1rem;
  }

  :is(.dark .ip-widget-details) {
    border-top-color: rgba(148, 163, 184, 0.1);
  }

  /* 移动端地图显示在文字下方 */
  .ip-widget-map-layer {
    grid-column: 1;
    grid-row: auto;
    min-height: 120px;
    max-height: 150px;
  }

  .ip-info-row {
    grid-column: 1;
  }

  .ip-widget-ip-text {
    font-size: 2rem; /* 32px */
  }

  .ip-widget-brand-watermark {
    font-size: 10rem; /* 160px */
    /* 保持左侧垂直居中定位，仅调整字号 */
  }

  .security-badges {
    gap: 0.5rem;
  }

  .security-badge {
    font-size: 0.625rem; /* 10px */
    padding: 0.25rem 0.5rem;
  }

  .ip-widget-security-bar {
    padding: 0 1rem;
  }
}

@media (max-width: 480px) {
  .ip-widget-ip-text {
    font-size: 1.5rem; /* 24px */
  }

  .isp-logo-badge {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1rem;
  }

  .isp-name {
    font-size: 1rem;
  }

  .security-indicators {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .trust-score-badge {
    padding: 0.25rem 0.5rem;
  }
}
