/* ════════════════════════════════════════════════════════
   CFJ-LINK 对客端 — Design Tokens & Base Styles
   A-1 批次：仅 tokens + reset + 骨架布局
   ════════════════════════════════════════════════════════ */

:root {
  color-scheme: light;

  /* 颜色 — 主题 */
  --bg:        #FFFFFF;
  --bg-2:      #F1F5FF;
  --surface:   #FFFFFF;
  --surface-2: #F7FAFF;

  /* 颜色 — 边框 */
  --border:        rgba(18, 50, 180, .09);
  --border-strong: rgba(18, 50, 180, .15);

  /* 颜色 — 文字 */
  --text:    #0B1630;
  --text-2:  #2E4070;
  --muted:   #6A7FA8;

  /* 颜色 — 强调 */
  --accent:    #1B6FF8;
  --accent-2:  #00C4FF;
  --glow:      rgba(27, 111, 248, .18);
  --pill:      #EBF0FF;
  --pill-text: #1B6FF8;

  /* 颜色 — 语义 */
  --danger: #EF4444;
  --warn:   #F59E0B;
  --safe:   #22C55E;

  /* 字体 */
  --font-heading: 'Syne', 'Noto Sans SC', 'Noto Sans TC', sans-serif;
  --font-body:    'Manrope', 'Noto Sans SC', 'Noto Sans TC', 'Noto Sans Arabic', sans-serif;
  --font-mono:    'JetBrains Mono', monospace;

  /* 字号 — clamp 响应式 */
  --fs-xs: clamp(10px, 1.8vw, 11.5px);
  --fs-sm: clamp(11.5px, 2vw, 13px);
  --fs-md: clamp(13px, 2.2vw, 15px);
  --fs-lg: clamp(15px, 2.6vw, 18px);
  --fs-xl: clamp(20px, 4vw, 26px);

  /* 间距 */
  --sp-xs: 4px;
  --sp-sm: 8px;
  --sp-md: 16px;
  --sp-lg: 24px;
  --sp-xl: 32px;

  /* 圆角 */
  --radius:    14px;
  --radius-lg: 22px;
  --radius-pill: 100px;

  /* 阴影 */
  --shadow-sm: 0 2px 8px rgba(27, 111, 248, .05);
  --shadow-md: 0 8px 32px rgba(27, 111, 248, .10);

  /* 布局 */
  --tab-h: 60px;
  --safe-top:    env(safe-area-inset-top, 44px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* 动画 */
  --transition-fast: .15s ease;
  --transition-base: .25s cubic-bezier(.16, 1, .3, 1);
  --transition-slow: .35s cubic-bezier(.16, 1, .3, 1);
}

/* ── 深色主题（手动切换） ── */
[data-theme="dark"] {
  color-scheme: dark;
  --bg:        #070D1A;
  --bg-2:      #0D1829;
  --surface:   #101828;
  --surface-2: #0D1729;
  --border:        rgba(255, 255, 255, .09);
  --border-strong: rgba(255, 255, 255, .15);
  --text:    #EBF2FF;
  --text-2:  #9DB5DA;
  --muted:   #5E7A9E;
  --accent:    #3B82F6;
  --accent-2:  #22D3EE;
  --glow:      rgba(59, 130, 246, .22);
  --pill:      #162038;
  --pill-text: #60A5FA;
}

/* ── 跟随系统深色（未手动切换时） ── */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg:        #070D1A;
    --bg-2:      #0D1829;
    --surface:   #101828;
    --surface-2: #0D1729;
    --border:        rgba(255, 255, 255, .09);
    --border-strong: rgba(255, 255, 255, .15);
    --text:    #EBF2FF;
    --text-2:  #9DB5DA;
    --muted:   #5E7A9E;
    --accent:    #3B82F6;
    --accent-2:  #22D3EE;
    --glow:      rgba(59, 130, 246, .22);
    --pill:      #162038;
    --pill-text: #60A5FA;
  }
}

/* ════════════════════════════════════════════════════════
   Reset
   ════════════════════════════════════════════════════════ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--transition-base), color var(--transition-base);
}

[dir="rtl"] {
  text-align: right;
}

a {
  color: inherit;
  text-decoration: none;
}

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

input, select, textarea {
  font-family: inherit;
  color: inherit;
}

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

[hidden] {
  display: none !important;
}

/* ════════════════════════════════════════════════════════
   App Shell — 全局布局
   ════════════════════════════════════════════════════════ */
#app {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
  background: var(--bg);
}

.screen.active {
  z-index: 2;
  opacity: 1;
  pointer-events: auto;
}

.scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--tab-h) + var(--safe-bottom) + 16px);
}

.scroll::-webkit-scrollbar {
  display: none;
}

/* ════════════════════════════════════════════════════════
   Topbar
   ════════════════════════════════════════════════════════ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(max(var(--safe-top), 20px) + 4px) var(--sp-md) 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

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

.logo-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--accent);
  color: #FFF;
  font-family: var(--font-heading);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: -.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.topbar-brand {
  font-family: var(--font-heading);
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--border-strong);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  background: transparent;
}

.icon-btn:hover,
.icon-btn:active {
  border-color: var(--accent);
  color: var(--accent);
}

/* ════════════════════════════════════════════════════════
   Health Badge
   ════════════════════════════════════════════════════════ */
.health-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: rgba(34, 197, 94, .1);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--safe);
  font-weight: 600;
  transition: all var(--transition-base);
}

.health-badge.degraded {
  background: rgba(245, 158, 11, .1);
  color: var(--warn);
}

.health-badge.down {
  background: rgba(239, 68, 68, .1);
  color: var(--danger);
}

.health-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 6px currentColor;
  animation: pulse-dot 2.2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  60% { opacity: .5; }
}

/* ════════════════════════════════════════════════════════
   Tabbar
   ════════════════════════════════════════════════════════ */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg);
  border-top: 1px solid var(--border);
  display: flex;
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding-top: 8px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: .8px;
  text-transform: uppercase;
  transition: color var(--transition-fast);
}

.tab-item.active {
  color: var(--accent);
}

.tab-label {
  display: block;
}

/* ════════════════════════════════════════════════════════
   Login Screen
   ════════════════════════════════════════════════════════ */
#screen-login {
  background: var(--bg-2);
  overflow-y: auto;
  align-items: center;
}

.login-wrap {
  width: 100%;
  max-width: 420px;
  padding: calc(max(var(--safe-top), 32px) + 8px) var(--sp-lg) calc(var(--safe-bottom) + 32px);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100%;
}

.login-header {
  text-align: center;
  margin-bottom: 28px;
  width: 100%;
}

.login-logo {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: var(--accent);
  color: #FFF;
  font-family: var(--font-heading);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -.5px;
  margin: 0 auto 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-brand {
  font-family: var(--font-heading);
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -.02em;
}

.login-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  letter-spacing: .06em;
}

.login-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 28px var(--sp-lg);
  box-shadow: var(--shadow-md);
}

.login-title {
  font-family: var(--font-heading);
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 4px;
}

.login-quote {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 20px;
  line-height: 1.5;
  font-style: italic;
  min-height: 1.5em;
}

.login-error {
  color: var(--danger);
  font-family: var(--font-mono);
  font-size: 11.5px;
  margin-bottom: 12px;
  padding: 10px 14px;
  background: rgba(239, 68, 68, .08);
  border-radius: var(--radius);
  border: 1px solid rgba(239, 68, 68, .2);
}

.form-field {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  background: var(--bg);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  padding: 11px 14px;
  outline: none;
  transition: border-color var(--transition-fast);
  -webkit-appearance: none;
}

.form-input:focus {
  border-color: var(--accent);
}

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #FFF;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 14px;
  padding: 13px;
  border-radius: var(--radius-pill);
  transition: all var(--transition-fast);
  margin-top: 4px;
}

.btn-primary:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: .5;
  cursor: not-allowed;
  transform: none;
}

.login-link-row {
  text-align: right;
  margin-top: 10px;
}

.login-link {
  font-size: 12.5px;
  color: var(--muted);
  cursor: pointer;
  transition: color var(--transition-fast);
}

.login-link:hover {
  color: var(--accent);
}

.login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0;
  color: var(--muted);
  font-size: 12px;
}

.login-divider span {
  flex: 1;
  height: 1px;
  background: var(--border);
}

.login-divider em {
  font-style: normal;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .08em;
}

.social-row {
  display: flex;
  gap: 8px;
}

.btn-social {
  flex: 1;
  padding: 10px 8px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 500;
  transition: all var(--transition-fast);
}

.btn-social:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.login-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 13px;
  color: var(--muted);
}

.login-footer .login-link {
  color: var(--accent);
  font-weight: 600;
  margin-left: 4px;
}

.legal-notice {
  width: 100%;
  margin-top: 10px;
  padding: 10px 14px;
  background: rgba(239, 68, 68, .06);
  border-radius: var(--radius);
  border: 1px solid rgba(239, 68, 68, .15);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--danger);
  line-height: 1.5;
  opacity: .9;
}

/* ════════════════════════════════════════════════════════
   Bottom Sheet
   ════════════════════════════════════════════════════════ */
.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 1800;
  background: rgba(0, 0, 0, .5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
}

.sheet-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  width: 100%;
  max-width: 580px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-bottom: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 0 0 calc(var(--safe-bottom) + 16px);
  transform: translateY(100%);
  transition: transform var(--transition-slow);
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
}

.sheet-overlay.open .sheet {
  transform: translateY(0);
}

.sheet-drag {
  width: 40px;
  height: 4px;
  border-radius: 10px;
  background: var(--border-strong);
  margin: 12px auto 0;
}

.sheet-title {
  font-family: var(--font-heading);
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  padding: 16px var(--sp-md) 14px;
  border-bottom: 1px solid var(--border);
}

.sheet-body {
  overflow-y: auto;
  padding: var(--sp-md);
  flex: 1;
}

.sheet-body::-webkit-scrollbar {
  display: none;
}

/* ════════════════════════════════════════════════════════
   Language Sheet
   ════════════════════════════════════════════════════════ */
#lang-overlay .sheet {
  padding: var(--sp-md) var(--sp-md) calc(var(--safe-bottom) + 20px);
}

.lang-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: var(--sp-sm) 0;
}

.lang-item {
  padding: 12px 8px;
  text-align: center;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  background: transparent;
  transition: all var(--transition-fast);
}

.lang-item:hover,
.lang-item.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--pill);
}

/* ════════════════════════════════════════════════════════
   Toast
   ════════════════════════════════════════════════════════ */
.toast-wrap {
  position: fixed;
  top: calc(max(var(--safe-top), 28px) + 60px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--text);
  color: var(--bg);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  padding: 10px 20px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
  opacity: 0;
  transform: translateY(-8px);
  transition: all var(--transition-base);
  max-width: 80vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  background: var(--danger);
  color: #FFF;
}

/* ════════════════════════════════════════════════════════
   Tab Content placeholder (业务页面由 app.js 注入)
   ════════════════════════════════════════════════════════ */
.tab-content {
  background: var(--bg);
}
