/* ===== CSS Variables ===== */
:root {
  --bg-deep: #0B1120;
  --bg-surface: #131C2E;
  --bg-card: #1A2540;
  --bg-card-hover: #1F2D4A;
  --border: rgba(6, 182, 212, 0.15);
  --border-hover: rgba(6, 182, 212, 0.4);
  --accent: #06B6D4;
  --accent-bright: #22D3EE;
  --accent-glow: rgba(6, 182, 212, 0.12);
  --success: #10B981;
  --error: #EF4444;
  --text: #E2E8F0;
  --text-muted: #8B9DC3;
  --text-dim: #5B6B85;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --shadow-glow: 0 0 20px rgba(6, 182, 212, 0.08);
  --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --sidebar-w: 220px;
  --sidebar-bg: #0D1525;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'Noto Sans SC', 'Figtree', system-ui, sans-serif;
  background: var(--bg-deep);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;          /* 移除移动端 300ms 点按延迟 */
  overscroll-behavior-y: contain;      /* 防误触下拉刷新 */
}

/* Ambient background */
body::before {
  content: '';
  position: fixed;
  top: -50%; left: -50%;
  width: 200%; height: 200%;
  background: radial-gradient(ellipse at 30% 20%, rgba(6,182,212,0.03) 0%, transparent 50%),
              radial-gradient(ellipse at 70% 80%, rgba(16,185,129,0.02) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}
.container { max-width: 1100px; margin: 0 auto; padding: 0 24px; position: relative; z-index: 1; }

/* ===== Sidebar Layout ===== */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 10;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand img { height: 32px; width: 32px; object-fit: contain; }
.sidebar-brand span {
  font-family: 'Figtree', sans-serif;
  font-weight: 700; font-size: 15px;
  color: var(--accent-bright);
  letter-spacing: -0.02em;
  line-height: 1.3;
}

.sidebar-nav { padding: 12px 0; flex: 1; }

.nav-group { margin-bottom: 4px; }
.nav-group-title {
  padding: 10px 16px 4px;
  font-size: 11px; font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px;
  margin: 2px 8px;
  font-size: 13px; font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 6px;
  transition: var(--transition);
}
.nav-item:hover { color: var(--text); background: var(--bg-card); }
.nav-item.active {
  color: var(--accent-bright);
  background: var(--accent-glow);
  border-left: 3px solid var(--accent);
  margin-left: 8px;
  padding-left: 13px;
}

.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }

.sidebar-logout {
  padding: 16px; border-top: 1px solid var(--border);
}
.sidebar-logout a {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; font-size: 13px; color: var(--text-dim);
  text-decoration: none; border-radius: 6px;
  transition: var(--transition);
}
.sidebar-logout a:hover { color: var(--error); background: rgba(239,68,68,0.08); }
.sidebar-logout svg { width: 16px; height: 16px; }

/* Content area */
.content {
  flex: 1; margin-left: var(--sidebar-w);
  padding: 32px; position: relative; z-index: 1;
  min-height: 100vh;
}

/* ===== KPI Cards ===== */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  transition: var(--transition);
}
.kpi-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
  box-shadow: var(--shadow-glow);
}
.kpi-card .kpi-label {
  font-size: 12px; color: var(--text-muted);
  font-weight: 500; margin-bottom: 8px;
}
.kpi-card .kpi-value {
  font-family: 'Figtree', sans-serif;
  font-size: 28px; font-weight: 700;
  color: var(--accent-bright);
  letter-spacing: -0.02em;
}

/* Cards grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-decoration: none; color: inherit;
  transition: var(--transition);
  cursor: pointer;
  position: relative; overflow: hidden;
}
.card::after {
  content: '';
  position: absolute; top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-bright));
  opacity: 0; transition: var(--transition);
}
.card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
  box-shadow: var(--shadow-glow);
  transform: translateY(-2px);
}
.card:hover::after { opacity: 1; }
.card-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  background: var(--accent-glow);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 14px;
}
.card-icon svg { width: 20px; height: 20px; color: var(--accent); }
.card h3 { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.card p { font-size: 13px; color: var(--text-muted); line-height: 1.5; }

/* Stats bar */
.stats {
  display: flex; gap: 24px; margin-bottom: 28px;
  padding: 14px 20px;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.stat { font-size: 13px; color: var(--text-muted); }
.stat strong { color: var(--text); font-family: 'Figtree', sans-serif; font-weight: 600; }

/* Forms */
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; }
input[type="text"], input[type="password"], input[type="file"], select {
  width: 100%; padding: 10px 14px;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 14px; font-family: inherit;
  transition: var(--transition);
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
select { cursor: pointer; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 24px; border: none; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: var(--transition);
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #0891B2);
  color: #fff;
  box-shadow: 0 2px 12px rgba(6, 182, 212, 0.25);
}
.btn-primary:hover { box-shadow: 0 4px 20px rgba(6, 182, 212, 0.4); transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-ghost {
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-muted); }
.btn { min-height: 44px; }  /* WCAG 2.5.5 touch target */

/* Keyboard focus visibility (WCAG 2.4.7) */
a:focus-visible, button:focus-visible, select:focus-visible, input:focus-visible,
.nav-item:focus-visible, .tab:focus-visible, .card:focus-visible {
  outline: 3px solid var(--accent-bright);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Reduced motion (WCAG 2.3.3) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .card:hover { transform: none; }
  .btn-primary:hover { transform: none; }
}

/* Status / result area */
.status {
  margin-top: 16px; padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px; display: none;
}
.status.show { display: block; }
.status.loading { background: rgba(6,182,212,0.08); color: var(--accent-bright); border: 1px solid rgba(6,182,212,0.2); }
.status.error { background: rgba(239,68,68,0.08); color: var(--error); border: 1px solid rgba(239,68,68,0.2); }
.status.success { background: rgba(16,185,129,0.08); color: var(--success); border: 1px solid rgba(16,185,129,0.2); }
.result { margin-top: 20px; }
.result img { border-radius: var(--radius); border: 1px solid var(--border); max-width: 100%; }

/* Page heading */
.page-head { margin-bottom: 28px; }
.page-head h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.page-head p { font-size: 14px; color: var(--text-muted); margin-top: 6px; }

/* Back link */
.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text-dim); text-decoration: none;
  font-size: 13px; margin-top: 24px;
  transition: var(--transition);
}
.back-link:hover { color: var(--accent); }

/* Breadcrumb */
.breadcrumb {
  display: flex; gap: 8px; align-items: center;
  font-size: 13px; color: var(--text-dim);
  margin-bottom: 20px;
}
.breadcrumb a { color: var(--text-muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb span { color: var(--text-dim); }

/* Login page */
.login-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
  background: url('/static/login-bg.png') center/cover no-repeat fixed;
  position: relative;
}
.login-wrap::before {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(ellipse at 30% 40%, rgba(6,182,212,0.08) 0%, transparent 60%),
              linear-gradient(180deg, rgba(11,17,32,0.55) 0%, rgba(11,17,32,0.75) 100%);
  pointer-events: none;
}
.login-card {
  background: rgba(19, 28, 46, 0.82);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border: 1px solid rgba(6, 182, 212, 0.25);
  border-radius: var(--radius); padding: 44px 40px;
  width: 100%; max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 40px rgba(6,182,212,0.08);
  text-align: center;
  position: relative; z-index: 1;
}
.login-card h1 {
  font-size: 22px; font-weight: 700; text-align: center;
  margin-bottom: 8px; color: var(--text);
}
.login-card .subtitle { text-align: center; color: var(--text-muted); font-size: 13px; margin-bottom: 28px; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 8px; }

/* Spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid var(--accent-glow);
  border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}

/* Table */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; background: var(--bg-card); }
th, td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
th { background: var(--bg-surface); font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-card-hover); }
td a { color: var(--accent); text-decoration: none; }
td a:hover { color: var(--accent-bright); }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tab {
  padding: 10px 18px; font-size: 13px; font-weight: 500;
  color: var(--text-muted); cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: var(--transition); white-space: nowrap;
  background: none; border-top: none; border-left: none; border-right: none;
  font-family: inherit;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-bright); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Timeline */
.timeline { position: relative; padding-left: 20px; }
.timeline::before { content: ''; position: absolute; left: 6px; top: 4px; bottom: 4px; width: 2px; background: var(--border); }
.tl-item { position: relative; margin-bottom: 16px; padding: 12px 16px; background: var(--bg-surface); border-radius: var(--radius-sm); border: 1px solid var(--border); }
.tl-item::before { content: ''; position: absolute; left: -17px; top: 16px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.tl-time { font-size: 11px; color: var(--text-dim); margin-bottom: 4px; }
.tl-content { font-size: 13px; }

/* Badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-teal { background: rgba(6,182,212,0.12); color: var(--accent-bright); }
.badge-green { background: rgba(16,185,129,0.12); color: var(--success); }
.badge-red { background: rgba(239,68,68,0.12); color: var(--error); }
.badge-gray { background: rgba(139,157,195,0.1); color: var(--text-muted); }

/* Form row (2-col) */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* Detail header */
.detail-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.detail-head h1 { font-size: 22px; }
.detail-meta { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--text-muted); }

/* Search bar */
.search-bar { display: flex; gap: 12px; margin-bottom: 20px; align-items: center; }
.search-bar input { max-width: 300px; }

/* Empty state */
.empty { text-align: center; padding: 40px 20px; color: var(--text-dim); font-size: 14px; }

/* Quick-add form */
.quick-add { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 16px; margin-top: 16px; }
.quick-add h4 { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; font-weight: 600; }
.quick-add .form-row { gap: 12px; }
.quick-add .btn { margin-top: 12px; padding: 8px 16px; font-size: 13px; }

/* Zebra striping for tables */
.table-wrap tbody tr:nth-child(even) { background: rgba(6, 182, 212, 0.03); }
.table-wrap tbody tr:hover td { background: var(--bg-card-hover); }

/* KPI card accent bar */
.kpi-card { position: relative; overflow: hidden; }
.kpi-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-bright));
  opacity: 0.7;
}
.kpi-value { font-family: 'Figtree', sans-serif; font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.kpi-label { font-size: 12px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }

/* Mini bar chart (30-day revenue trend) */
.bar-chart { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding: 8px 4px 0; }
.bar-chart .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.bar-chart .bar { width: 100%; max-width: 28px; border-radius: 3px 3px 0 0;
  background: linear-gradient(180deg, var(--accent-bright), var(--accent));
  transition: var(--transition); min-height: 2px; }
.bar-chart .bar:hover { filter: brightness(1.3); }
.bar-chart .bar-label { font-size: 9px; color: var(--text-dim); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 100%; text-align: center; }
.bar-chart .bar-empty { color: var(--text-dim); font-size: 12px; padding: 40px 0; text-align: center; width: 100%; }

/* Dict edit row toggle */
tr.edit-row { display: none; }
tr.edit-row.active { display: table-row; }

/* Table mobile: scroll + word-break */
.table-wrap { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
td, th { word-break: break-word; }

/* Responsive 2-col grid: stacks on mobile */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 24px; }
.grid-2b { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }

/* Mobile header (hidden on PC) */
.mobile-header { display: none; }
.sidebar-overlay { display: none; }

/* Responsive */
@media (max-width: 768px) {
  .mobile-header {
    display: flex; align-items: center; gap: 12px;
    position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
    height: 48px; padding: 0 12px;
    background: var(--sidebar-bg); color: var(--text);
  }
  .hamburger {
    background: none; border: none; color: var(--text); cursor: pointer;
    min-width: 44px; min-height: 44px;                      /* WCAG 触控目标 */
    display: inline-flex; align-items: center; justify-content: center;
  }
  .hamburger svg { width: 22px; height: 22px; }
  .mobile-title { font-size: 15px; font-weight: 600; }

  /* 移动端触控与输入优化 */
  .sidebar .nav-item { min-height: 44px; padding: 12px 16px; justify-content: flex-start; }
  .sidebar .nav-item svg { width: 18px; height: 18px; }
  .sidebar-logout a { min-height: 44px; }
  input, select { font-size: 16px; }   /* 防 iOS 聚焦自动放大 */
  td .btn, td form { margin: 2px 4px 2px 0; }   /* 表格按钮触控间距 */
  .content { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }

  .sidebar-overlay {
    position: fixed; inset: 0; z-index: 999;
    background: rgba(0,0,0,0.4); opacity: 0; pointer-events: none;
    transition: opacity 0.25s ease;
  }
  .sidebar-overlay.open { opacity: 1; pointer-events: auto; }

  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 1001;
    width: 240px; min-width: 240px;
    transform: translateX(-100%); transition: transform 0.25s ease;
  }
  .sidebar.open { transform: translateX(0); }

  .content { margin-left: 0 !important; padding: 60px 16px 16px; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr !important; }
  .grid-2b { grid-template-columns: 1fr !important; }
}
@media (max-width: 640px) {
  .content { padding: 12px; }
  .grid { grid-template-columns: 1fr; }
  .stats { flex-direction: column; gap: 8px; }
  .detail-head { flex-direction: column; align-items: flex-start; }
  .kpi-row { grid-template-columns: 1fr; }
  .login-wrap { padding: 16px; }
  .login-card { padding: 24px; }
  .form-row { grid-template-columns: 1fr; }
  .search-bar { flex-direction: column; }
  .search-bar input { max-width: none; }
}
