/* ============================================================
   Rail Web — base.css
   风格：Vercel/Geist 克制精致
   配色：纯中性灰 + 语义色 + 列车色（硬编码）
   字体：阿里巴巴普惠体 (UI) + Cascadia Code (mono)
   主题：默认浅色 + 跟随系统（data-theme 单维度）
   ============================================================ */

/* ---------- 字体加载（阿里巴巴普惠体 CDN） ---------- */
@font-face {
  font-family: 'Alibaba PuHuiTi';
  src: url('https://static.cdn.sunmi.com/assets/fonts/Alibaba-PuHuiTi-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Alibaba PuHuiTi';
  src: url('https://static.cdn.sunmi.com/assets/fonts/Alibaba-PuHuiTi-Medium.ttf') format('truetype');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Alibaba PuHuiTi';
  src: url('https://static.cdn.sunmi.com/assets/fonts/Alibaba-PuHuiTi-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* ============================================================
   设计 Token
   ============================================================ */
:root {
  /* 间距（4px 网格） */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  /* 圆角（Geist 风：偏小、精致） */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;
  --radius-full: 9999px;
  /* 通用卡片圆角（history var(--radius) 的别名；此前未定义导致部分卡片圆角失效） */
  --radius: 8px;

  /* 字号 */
  --text-xs: 11px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-md: 15px;
  --text-lg: 17px;
  --text-xl: 20px;
  --text-2xl: 24px;
  --text-3xl: 32px;

  /* 字重 */
  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;

  /* 字体族 */
  --font-ui: 'Alibaba PuHuiTi', -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', sans-serif;
  --font-mono: 'Cascadia Code', 'Cascadia Mono', 'JetBrains Mono', 'SF Mono', 'Consolas', 'Menlo', 'Alibaba PuHuiTi', monospace;

  /* ---------- 浅色主题（默认） ---------- */
  --bg-base: #FFFFFF;
  --bg-card: #FAFAFA;
  --bg-elevated: #FFFFFF;
  --bg-hover: #F5F5F5;
  --bg-muted: #F0F0F0;

  --border: #EAEAEA;
  --border-strong: #D4D4D4;

  --text-primary: #0A0A0A;
  --text-secondary: #666666;
  /* 对比度达标：#999(≈2.85:1) 不达标，提至 #767676(≈4.5:1，过 WCAG AA) */
  --text-muted: #767676;
  --text-inverse: #FFFFFF;

  /* 链接色（与旧项目保持一致的语义信息色） */
  --link-color: #2563EB;
  --link-color-hover: #1D4ED8;

  /* 品牌强调色（全站唯一品牌色：主强调 / 激活态 / 关键标记。链接色独立，不混用） */
  --accent: #2563EB;
  --accent-hover: #1D4ED8;
  --accent-soft: rgba(37, 99, 235, 0.08);

  /* 语义色（深浅共用色相，深色主题略调亮） */
  --error: #DC2626;
  --error-bg: #FEF2F2;
  --success: #16A34A;
  --success-bg: #F0FDF4;
  --warning: #CA8A04;
  --warning-bg: #FEFCE8;

  /* 阴影（Geist 风：极柔和） */
  --shadow-static: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
  --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.06), 0 2px 4px rgba(0, 0, 0, 0.04);
  --shadow-modal: 0 16px 48px rgba(0, 0, 0, 0.10), 0 4px 12px rgba(0, 0, 0, 0.05);
  --shadow-toast: 0 8px 24px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04);

  /* 动画 */
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.3s cubic-bezier(0.4, 0, 0.2, 1);

  /* 列车色（硬编码，按车型前缀） */
  --train-red: #DC2626;        /* CR400AF / CR300AF 系 */
  --train-yellow: #CA8A04;     /* CR400BF / CR300BF 系 */
  --train-green: #16A34A;      /* CR200J 系 */
  --train-blue: #2563EB;       /* CRH 系（和谐号） */
  --train-dark-green: #166534; /* K / T / Z / 纯数字 */
  --train-default: #6B7280;    /* 未知车型 */

  /* z-index */
  --z-navbar: 100;
  --z-dropdown: 200;
  --z-modal-backdrop: 1000;
  --z-modal: 1100;
  --z-lightbox: 1150;
  --z-toast: 1200;
  --z-tooltip: 1300;

  /* 页面尺寸 */
  --page-max-width: 1024px;
  --page-padding: 24px;
  --navbar-height: 56px;
}

/* ---------- 深色主题 ---------- */
[data-theme="dark"] {
  --bg-base: #0A0A0A;
  --bg-card: #111111;
  --bg-elevated: #1A1A1A;
  --bg-hover: #1F1F1F;
  --bg-muted: #262626;

  --border: #262626;
  --border-strong: #404040;

  --text-primary: #FAFAFA;
  --text-secondary: #A3A3A3;
  /* 深色对比度：#737373(≈4.1:1) 不达标，提至 #8A8A8A(≈5.7:1) */
  --text-muted: #8A8A8A;
  --text-inverse: #0A0A0A;

  /* 链接色（深色主题：提高对比度） */
  --link-color: #60A5FA;
  --link-color-hover: #93C5FD;

  /* 品牌强调色（深色主题：提亮以保证对比度） */
  --accent: #60A5FA;
  --accent-hover: #93C5FD;
  --accent-soft: rgba(96, 165, 250, 0.14);

  --error: #F87171;
  --error-bg: rgba(220, 38, 38, 0.1);
  --success: #4ADE80;
  --success-bg: rgba(22, 163, 74, 0.1);
  --warning: #FACC15;
  --warning-bg: rgba(202, 138, 4, 0.1);

  --shadow-static: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.4), 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-modal: 0 16px 48px rgba(0, 0, 0, 0.6), 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-toast: 0 8px 24px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3);

  --train-red: #F87171;
  --train-yellow: #FACC15;
  --train-green: #4ADE80;
  --train-blue: #60A5FA;
  --train-dark-green: #86EFAC;
  --train-default: #9CA3AF;
}

/* ============================================================
   Reset
   ============================================================ */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: 1.55;
  background-color: var(--bg-base);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv11', 'ss01';
  transition: background-color var(--transition), color var(--transition);
  min-height: 100vh;
}

input, button, select, textarea, label {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  touch-action: manipulation;
}

button {
  background: none;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
}

/* 默认 a 继承（navbar / 按钮等不加修饰），带 href 的链接走链接色 */
a {
  color: inherit;
  text-decoration: none;
  touch-action: manipulation;
}
/* 真正的链接（带 href 且非按钮/非菜单）—— 与旧项目一致：链接色 + 下划线 */
a[href]:not(.btn):not(.navbar-brand):not(.navbar-link):not(.tab):not(.skip-link):not(.auth-link):not(.about-link):not(.settings-sidebar-link):not(.nav-bell):not(.mobile-tabs a) {
  color: var(--link-color);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
  transition: color var(--transition-fast);
}
a[href]:not(.btn):not(.navbar-brand):not(.navbar-link):not(.tab):not(.skip-link):not(.auth-link):not(.about-link):not(.settings-sidebar-link):not(.nav-bell):not(.mobile-tabs a):hover {
  color: var(--link-color-hover);
  text-decoration-thickness: 2px;
}
a[href]:not(.btn):not(.navbar-brand):not(.navbar-link):not(.tab):not(.skip-link):not(.auth-link):not(.about-link):not(.settings-sidebar-link):not(.nav-bell):not(.mobile-tabs a):active {
  opacity: 0.85;
}

ul, ol {
  list-style: none;
}

img, svg {
  display: block;
  max-width: 100%;
}

::selection {
  background-color: var(--text-primary);
  color: var(--bg-base);
}

/* 滚动条（Geist 风：极细、中性） */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* 焦点态（无主题色，用文字色作焦点） */
:focus-visible {
  outline: 2px solid var(--text-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ============================================================
   通用工具类
   ============================================================ */
.mono {
  font-family: var(--font-mono);
  font-feature-settings: 'tnum', 'zero';
}

.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }
.text-error { color: var(--error); }
.text-success { color: var(--success); }

.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-md { font-size: var(--text-md); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }
.text-3xl { font-size: var(--text-3xl); }

.font-medium { font-weight: var(--font-medium); }
.font-semibold { font-weight: var(--font-semibold); }
.font-bold { font-weight: var(--font-bold); }

/* 页面容器 */
.page-container {
  max-width: var(--page-max-width);
  margin: 0 auto;
  padding: var(--space-5) var(--page-padding) var(--space-7);
}

/* ============================================================
   加载态（复用原 rail 加载态：5 个箭头依次淡入淡出）
   ============================================================ */
.loading-state,
.full-page-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-7) 0;
  color: var(--text-secondary);
}

.full-page-loading {
  flex: 1;
  min-height: 60vh;
  padding: var(--space-8) 0;
}

.arrow-loader {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-5);
}

.arrow-loader .arrow {
  width: 24px;
  height: 24px;
  fill: var(--text-primary);
  opacity: 0.12;
  animation: loadingArrowFade 1.5s ease-in-out infinite backwards;
}

.arrow-loader .arrow:nth-child(1) { animation-delay: 0s; }
.arrow-loader .arrow:nth-child(2) { animation-delay: 0.15s; }
.arrow-loader .arrow:nth-child(3) { animation-delay: 0.3s; }
.arrow-loader .arrow:nth-child(4) { animation-delay: 0.45s; }
.arrow-loader .arrow:nth-child(5) { animation-delay: 0.6s; }

@keyframes loadingArrowFade {
  0%, 100% { opacity: 0.12; }
  35%, 55% { opacity: 1; }
  70% { opacity: 0.2; }
}

.loading-subtitle {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  min-height: 20px;
  text-align: center;
  letter-spacing: 0.3px;
}

/* 旋转 spinner（用于按钮内 / 行内小加载） */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 1.5px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: -2px;
}

.spinner-lg {
  width: 28px;
  height: 28px;
  border-width: 2px;
}

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

/* 骨架屏（极简：脉冲灰块） */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-muted) 0%,
    var(--bg-hover) 50%,
    var(--bg-muted) 100%
  );
  background-size: 200% 100%;
  animation: skeletonPulse 1.8s ease-in-out infinite;
  border-radius: var(--radius-md);
}

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

/* ============================================================
   主题切换闪烁防护：在 html 上加 theme-transitioning 类可禁用过渡
   ============================================================ */
.theme-transitioning,
.theme-transitioning *,
.theme-transitioning *::before,
.theme-transitioning *::after {
  transition: none !important;
}

/* ============================================================
   全局渐入动画（页面挂载时）
   ============================================================ */
.fade-in {
  animation: fadeIn var(--transition-slow) ease-out;
}

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

/* 错页 */
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-7) 0;
  color: var(--text-secondary);
  text-align: center;
}

.error-state .error-title {
  font-size: var(--text-lg);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.error-state .error-desc {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  max-width: 360px;
}

/* ===== 启动遮罩：加载期间顶栏(navbar)始终可见，内容区被箭头遮罩盖住 =====
   配合 web/assets/js/auth.js 的 revealApp() —— 它在加载完成后给 <html> 加 .app-ready 并淡出遮罩。
   - 遮罩 z-index 设在 --z-navbar 之下（见 #boot-overlay），使其始终位于顶栏之下，
     故加载时顶栏照常显示，只有内容区被不透明箭头遮罩覆盖；
   - 数据驱动页面（如 trips.html）设 window.__bootManual=true，待内容渲染完再调 revealApp；
     无异步数据的页面（登录/注册等）在 window.load 后自动揭示（见 auth.js）。
   只作用于新前端（index.html 旧壳不加载 base.css，不受影响）。 */

/* 居中加载指示：复用 .arrow-loader（5 个箭头依次淡入淡出），
   由 web/assets/js/auth.js 启动时注入 #boot-overlay 到 <html>。
   只作用于新前端（旧前端 index.html 不加载 base.css）。 */
#boot-overlay {
  position: fixed;
  inset: 0;
  /* 位于顶栏(--z-navbar=100)之下：加载时顶栏照常可见，遮罩只剩内容区 */
  z-index: calc(var(--z-navbar) - 1);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-base, #ffffff);
  transition: opacity 0.28s ease;
}

#boot-overlay .arrow-loader {
  margin-bottom: 14px;
}

#boot-overlay .boot-sub {
  font-size: var(--text-sm, 14px);
  color: var(--text-secondary, #8a8f98);
  letter-spacing: 0.4px;
}

/* 启动期间隐藏顶栏右侧的用户信息（用户名/头像），只保留品牌+导航 tab 可见，
   避免登录态在加载动画之上"露馅"。visibility 保留占位，揭开后无位移跳动。 */
html:not(.app-ready) .navbar-right {
  visibility: hidden;
}

/* 双保险：启动期间隐藏整块内容区(main)，确保加载箭头遮罩之下没有任何页面内容
   （含个人信息卡片 / 行程列表 / 页面级加载态）透出，即使遮罩背景异常也绝不会"露馅"。
   导航栏(.navbar)在 main 之外，故 tab 仍照常可见。揭开(.app-ready)后自动恢复。 */
html:not(.app-ready) main {
  visibility: hidden;
}

/* ready 后淡出（auth.js 随后移除节点） */
.app-ready #boot-overlay {
  opacity: 0;
  pointer-events: none;
}

/* ============================================================
   移动端字号放大（仅覆盖 token，所有组件自动跟随，无需逐页改）
   桌面端保持 14px 基准；≤768px 升到 16px 正文 / 14px 小字，
   解决手机端字号偏小问题。布局无需逐个重写——全站吃 var(--text-*)。
   ============================================================ */
@media (max-width: 768px) {
  :root {
    /* 克制版移动端缩放：保持清晰的字号层级（非老人机式等大膨胀）。
       桌面基准 xs11/sm13/base14/md15/lg17/xl20；手机仅温和上调，
       xs/sm 补到可读下限，base 达 iOS 输入不缩放门槛 16px，lg/xl 不额外膨胀。 */
    --text-xs: 13px;   /* 说明/标签/底部 tab：比正文小一档，保留层级 */
    --text-sm: 15px;   /* 次要正文：手机较桌面 13→15，清晰变大 */
    --text-base: 16px; /* 正文：iOS 输入不缩放门槛 + 舒适基准 */
    --text-md: 17px;   /* 站名/车次号等中等强调 */
    --text-lg: 18px;   /* 小标题 */
    --text-xl: 20px;   /* 页面标题（与桌面同值，不额外膨胀） */
    /* --text-2xl(24) / --text-3xl(32) 已足够大，保持原值 */
  }

  /* iOS 防自动缩放：输入框计算字号 < 16px 时，Safari 聚焦会强制放大整页。
     此处把【所有】表单控件强制抬到 16px 硬门槛，根治点输入框就放大。
     - 用 !important + 元素级选择器，确保不被任何组件级更高特异性规则
       （如 .schedule-table/.sched-edit-table .form-input）或内联 font-size 击穿。
     - 不碰 viewport 的 user-scalable/maximum-scale，保留用户双指缩放能力。 */
  input, select, textarea,
  .form-input,
  .form-select,
  .form-textarea {
    font-size: 16px !important;
  }

  /* 移动端按钮字号统一：主按钮 16、小按钮 15（仍小一档）、大按钮 17。
     避免「小按钮（.btn-sm）被个别组件抬到 text-base，反而比主按钮还大」的不统一。 */
  .btn { font-size: var(--text-base); }
  .btn-sm { font-size: var(--text-sm); }
  .btn-lg { font-size: var(--text-md); }

  /* 日期/时间/日期时间原生选择器有固定最小宽度，在 flex/grid 容器里会撑破布局溢出。
     iOS Safari 原生 date/time 选择器有硬编码最小宽度（~300px），常规 min-width:0 无效。
     用 -webkit-appearance:none 剥离原生渲染 + 强制尺寸约束 + overflow:hidden 兜底。 */
  input[type="date"],
  input[type="time"],
  input[type="datetime-local"] {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    box-sizing: border-box;
    text-align: left !important;
    -webkit-appearance: none;
    appearance: none;
    overflow: hidden;
  }
  /* 并排网格里的 time 输入（到达时刻）：iOS 强制收缩到容器 */
  .form-group > div[style*="grid"] input[type="time"] {
    width: 100% !important;
    min-width: 0 !important;
    overflow: hidden;
  }

  /* 关键：网格/弹性项默认 min-width:auto（=min-content），原生 date/time
     输入的固有最小宽度会让「时间」列比「文本」列宽。给项容器加
     min-width:0，1fr 轨道才会真正等宽。覆盖两处网格容器：
     - trip-add 的 .form-group（到达日期 | 到达时刻 并排）
     - trip-import 的 .imp-dt-cell（imp-edit-grid 2 列） */
  .form-group,
  .imp-dt-cell { min-width: 0; }

  /* 到达日期 | 到达时刻 并排网格：强制不溢出 + 等宽 */
  .form-group > div[style*="grid-template-columns"] {
    min-width: 0;
    overflow: hidden;
  }
}

/* ============================================================
   白屏兜底（不依赖 JS）：即使 auth.js 完全未加载 / 在执行到揭示逻辑前抛错，
   内容也在 6s 后强制显示，避免 html:not(.app-ready) main{visibility:hidden}
   导致永久空白。JS 正常揭示（<html> 加 .app-ready）后本选择器失效，动画不触发。
   （JS 侧另有 window error / unhandledrejection 监听 + 超时兜底，双保险。）
   ============================================================ */
@keyframes forceRevealMain { to { visibility: visible; } }
html:not(.app-ready) main {
  /* 0 时长、6s 延迟、forwards 保留终态：6s 一到强制可见 */
  animation: forceRevealMain 0s linear 6s forwards;
}

