/* ==========================================================================
 * VPN Gate L2TP Browser — 样式表
 * 设计原则：Mobile First、卡片式、大按钮、现代风格、流畅动画
 * 主题：浅色 / 深色，默认跟随系统（prefers-color-scheme），可手动切换
 * ========================================================================== */

/* ---------------------- 主题变量（浅色为基准） ---------------------- */
:root {
  --bg: #f4f6fb;
  --bg-elev: #ffffff;
  --bg-elev-2: #eef1f7;
  --text: #1b1f27;
  --text-dim: #6b7280;
  --primary: #1f6feb;
  --primary-soft: rgba(31, 111, 235, 0.12);
  --border: #e3e7ef;
  --shadow: 0 6px 20px rgba(20, 30, 60, 0.08);
  --shadow-press: 0 2px 8px rgba(20, 30, 60, 0.12);
  --fav: #f5b301;
  --danger: #e5484d;
  --radius: 16px;
  --radius-sm: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* 系统为深色时，未手动指定 light/dark 的情况下使用深色变量 */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --bg-elev: #171a21;
    --bg-elev-2: #1f232c;
    --text: #e8ebf0;
    --text-dim: #9aa3b2;
    --primary: #4c8dff;
    --primary-soft: rgba(76, 141, 255, 0.16);
    --border: #2a2f3a;
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
    --shadow-press: 0 2px 8px rgba(0, 0, 0, 0.5);
    --fav: #ffcd3c;
    --danger: #ff6b6f;
  }
}

/* 手动指定浅色：覆盖系统深色 */
html[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-elev: #ffffff;
  --bg-elev-2: #eef1f7;
  --text: #1b1f27;
  --text-dim: #6b7280;
  --primary: #1f6feb;
  --primary-soft: rgba(31, 111, 235, 0.12);
  --border: #e3e7ef;
  --shadow: 0 6px 20px rgba(20, 30, 60, 0.08);
  --shadow-press: 0 2px 8px rgba(20, 30, 60, 0.12);
  --fav: #f5b301;
  --danger: #e5484d;
}

/* 手动指定深色：覆盖系统浅色 */
html[data-theme="dark"] {
  --bg: #0f1115;
  --bg-elev: #171a21;
  --bg-elev-2: #1f232c;
  --text: #e8ebf0;
  --text-dim: #9aa3b2;
  --primary: #4c8dff;
  --primary-soft: rgba(76, 141, 255, 0.16);
  --border: #2a2f3a;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  --shadow-press: 0 2px 8px rgba(0, 0, 0, 0.5);
  --fav: #ffcd3c;
  --danger: #ff6b6f;
}

/* ---------------------- 基础重置 ---------------------- */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "HarmonyOS Sans SC",
    "PingFang SC", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  transition: background-color 0.3s ease, color 0.3s ease;
}

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

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

/* ---------------------- 顶部应用栏 ---------------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}

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

.brand-logo {
  font-size: 26px;
  line-height: 1;
}

.brand-title {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.2px;
}

.brand-sub {
  font-size: 11px;
  margin: 0;
  color: var(--text-dim);
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--bg-elev-2);
  font-size: 19px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, background-color 0.2s ease;
}

.icon-btn:active {
  transform: scale(0.9);
}

/* 刷新按钮旋转动画（加载时加上 .spinning） */
.icon-btn.spinning {
  animation: spin 0.9s linear infinite;
}

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

/* ---------------------- 搜索栏 ---------------------- */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 16px 0;
  padding: 0 12px;
  height: 46px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

.search-icon {
  font-size: 16px;
  opacity: 0.7;
}

.search-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 16px;
}

.search-input::placeholder {
  color: var(--text-dim);
}

/* 隐藏原生 search 清除按钮，使用自定义 */
.search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.search-clear {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--bg-elev-2);
  color: var(--text-dim);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------------------- 状态栏 ---------------------- */
.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 18px 4px;
  font-size: 12px;
  color: var(--text-dim);
}

.auto-refresh {
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  user-select: none;
}

.auto-refresh.off {
  background: var(--bg-elev-2);
  color: var(--text-dim);
}

/* ---------------------- 视图切换动画 ---------------------- */
.view {
  padding: 8px 16px calc(24px + var(--safe-bottom));
}

.view-panel {
  animation: fadeSlide 0.28s ease both;
}

.view-panel[hidden] {
  display: none;
}

@keyframes fadeSlide {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------------------- 国家列表 ---------------------- */
.country-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.country-card {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.2s ease;
  animation: cardIn 0.3s ease both;
}

.country-card:active {
  transform: scale(0.98);
  box-shadow: var(--shadow-press);
}

.flag {
  font-size: 28px;
  line-height: 1;
}

.c-name {
  font-size: 16px;
  font-weight: 600;
}

.c-count {
  min-width: 38px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 4px 8px;
  border-radius: 999px;
}

.fav-star {
  font-size: 20px;
  color: var(--text-dim);
  padding: 4px;
  line-height: 1;
}

.fav-star.on {
  color: var(--fav);
}

.fav-star.big {
  font-size: 26px;
}

/* ---------------------- 返回按钮 ---------------------- */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 4px 0 12px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 999px;
  transition: transform 0.12s ease;
}

.back-btn:active {
  transform: scale(0.95);
}

/* ---------------------- 国家详情头部 ---------------------- */
.country-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 4px 14px;
}

.country-head .flag.big {
  font-size: 40px;
}

.c-title {
  font-size: 20px;
  font-weight: 700;
}

.c-sub {
  font-size: 13px;
  color: var(--text-dim);
}

/* ---------------------- 排序栏 ---------------------- */
.sort-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.sort-bar::-webkit-scrollbar {
  display: none;
}

.sort-btn {
  flex: 0 0 auto;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: all 0.18s ease;
}

.sort-btn.active {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
}

/* ---------------------- 节点列表 ---------------------- */
.node-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.node-card {
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.2s ease;
  animation: cardIn 0.3s ease both;
}

.node-card:active {
  transform: scale(0.98);
  box-shadow: var(--shadow-press);
}

.node-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.node-ip {
  font-size: 16px;
  font-weight: 600;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

.node-ping {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
}

.node-meta {
  display: flex;
  gap: 14px;
  font-size: 13px;
  color: var(--text-dim);
}

.node-isp {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-dim);
}

/* ---------------------- 节点详情卡片 ---------------------- */
.detail-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px 16px 18px;
  animation: cardIn 0.3s ease both;
}

.detail-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.detail-field:last-of-type {
  border-bottom: none;
}

.detail-field .label {
  font-size: 14px;
  color: var(--text-dim);
}

.detail-field .value {
  font-size: 16px;
  font-weight: 600;
  text-align: right;
}

.detail-field .value.mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

.copy-btn {
  width: 100%;
  margin-top: 14px;
  padding: 14px;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  background: var(--primary);
  border-radius: var(--radius-sm);
  transition: transform 0.12s ease, filter 0.2s ease;
}

.copy-btn:active {
  transform: scale(0.97);
  filter: brightness(0.92);
}

/* ---------------------- 空状态 / 错误 ---------------------- */
.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 16px;
  font-size: 14px;
}

.error-box {
  margin: 8px 0;
  padding: 16px;
  border: 1px solid var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, var(--bg-elev));
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
}

.error-box h3 {
  margin: 0 0 8px;
  font-size: 15px;
  color: var(--danger);
}

.error-box code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  word-break: break-all;
}

/* ---------------------- 页脚 ---------------------- */
.app-footer {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  padding: 8px 16px calc(16px + var(--safe-bottom));
}

/* ---------------------- 加载遮罩 ---------------------- */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  backdrop-filter: blur(2px);
}

.loading-overlay[hidden] {
  display: none;
}

.spinner {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}

.loading-text {
  font-size: 14px;
  color: var(--text-dim);
  margin: 0;
}

/* ---------------------- Toast ---------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  z-index: 60;
  max-width: 86%;
  padding: 12px 18px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 600;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------------------- 动画关键帧 ---------------------- */
@keyframes cardIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 尊重“减少动画”偏好 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
