/* ============================================
   惊剪AI — Design Tokens & Base Styles
   ============================================ */

:root {
  /* Surface */
  --bg: #FAFAF7;
  --surface: #FFFFFF;
  --surface-2: #F4F3EE;
  --surface-3: #EDEBE3;

  /* Ink */
  --ink: #18181B;
  --ink-2: #3F3F46;
  --ink-3: #71717A;
  --ink-4: #A1A1AA;
  --ink-5: #D4D4D8;

  /* Borders */
  --border: #E8E6DF;
  --border-strong: #D6D3CA;
  --border-soft: #F0EEE7;

  /* Brand */
  --accent: #FF4D1F;       /* signature cut/speed */
  --accent-soft: #FFE8DE;
  --accent-ink: #C2380E;

  /* Status */
  --ok: #00A66E;
  --ok-soft: #DFF5EB;
  --warn: #C68A00;
  --warn-soft: #FBF1D2;
  --danger: #DC2626;
  --danger-soft: #FCE7E7;
  --info: #2563EB;
  --info-soft: #DBEAFE;

  /* Type */
  --font-sans: "Geist", "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "Geist Mono", "JetBrains Mono", "SF Mono", Menlo, monospace;

  /* Radii */
  --r-sm: 6px;
  --r: 10px;
  --r-lg: 14px;
  --r-xl: 20px;

  /* Shadow (very subtle) */
  --shadow-sm: 0 1px 0 rgba(24, 24, 27, 0.04), 0 1px 2px rgba(24, 24, 27, 0.04);
  --shadow: 0 4px 12px -2px rgba(24, 24, 27, 0.06), 0 2px 4px -2px rgba(24, 24, 27, 0.04);
  --shadow-lg: 0 12px 32px -8px rgba(24, 24, 27, 0.10), 0 4px 12px -4px rgba(24, 24, 27, 0.06);

  /* Layout */
  --sidebar-w: 232px;
  --sidebar-w-collapsed: 64px;
  --topbar-h: 56px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss01", "cv11";
}

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

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

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

.mono { font-family: var(--font-mono); font-feature-settings: "tnum"; }
.tnum { font-variant-numeric: tabular-nums; }

/* ============================================
   Layout: shell
   ============================================ */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  transition: grid-template-columns 220ms cubic-bezier(.2,.7,.2,1);
}
.app-shell.collapsed {
  grid-template-columns: var(--sidebar-w-collapsed) 1fr;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 18px 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border-soft);
}
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--ink);
  color: var(--bg);
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 14px;
  flex: 0 0 28px;
  position: relative;
  overflow: hidden;
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 45%, var(--accent) 45%, var(--accent) 52%, transparent 52%);
}
.brand-name {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  opacity: 1;
  transition: opacity 120ms;
}
.collapsed .brand-name { opacity: 0; }

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-top: 12px;
}
.nav-group-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-4);
  padding: 4px 10px 8px 10px;
  font-weight: 500;
  white-space: nowrap;
}
.collapsed .nav-group-label {
  font-size: 9px;
  padding: 4px 0 8px 0;
  text-align: center;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 450;
  white-space: nowrap;
  position: relative;
  cursor: pointer;
  transition: background 120ms, color 120ms;
}
.nav-item:hover {
  background: var(--surface-2);
  color: var(--ink);
}
.nav-item.active {
  background: var(--ink);
  color: var(--bg);
}
.nav-item.active .nav-icon { color: var(--bg); }
.nav-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  color: var(--ink-3);
  display: grid;
  place-items: center;
}
.nav-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity 120ms;
}
.collapsed .nav-label { opacity: 0; }
.nav-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-4);
  font-variant-numeric: tabular-nums;
}
.nav-item.active .nav-meta { color: var(--bg); opacity: 0.7; }
.collapsed .nav-meta { display: none; }

.sidebar-bottom {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--r-sm);
  cursor: pointer;
}
.user-pill:hover { background: var(--surface-2); }
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, #FF8A4F 100%);
  color: white;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 12px;
  flex: 0 0 28px;
}
.user-info { flex: 1; overflow: hidden; }
.user-name { font-size: 13px; font-weight: 500; }
.user-credits { font-size: 11px; color: var(--ink-3); font-family: var(--font-mono); }
.collapsed .user-info { display: none; }

/* ============================================
   Main column
   ============================================ */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  padding: 0 32px;
  gap: 18px;
  backdrop-filter: blur(8px);
}
.topbar-admin {
  border-bottom-color: var(--ink);
  box-shadow: inset 0 2px 0 var(--ink);
}
.topbar-collapse-btn {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: var(--r-sm);
  color: var(--ink-3);
}
.topbar-collapse-btn:hover { background: var(--surface-2); color: var(--ink); }

.crumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-3);
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 0;
}
.crumbs .sep { color: var(--ink-5); }
.crumbs .here { color: var(--ink); font-weight: 500; }

.topbar-right { margin-left: auto; display: flex; gap: 10px; align-items: center; }

.credit-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.credit-chip .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px var(--ok-soft);
}
.credit-chip .label { color: var(--ink-3); }
.credit-chip .val { color: var(--ink); font-weight: 600; }
.credit-chip .topup {
  margin-left: 4px;
  padding-left: 8px;
  border-left: 1px solid var(--border);
  color: var(--accent-ink);
  font-weight: 600;
}

.icon-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: var(--r-sm);
  color: var(--ink-3);
  border: 1px solid transparent;
}
.icon-btn:hover { background: var(--surface); border-color: var(--border); color: var(--ink); }
.icon-btn .badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
}

/* ============================================
   Page
   ============================================ */
.page {
  padding: 32px 48px 64px 48px;
  max-width: 1480px;
  width: 100%;
}
.page-narrow { max-width: 1080px; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border-soft);
}
.page-head-left { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.page-eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-4);
  font-weight: 500;
  font-family: var(--font-mono);
}
.page-title {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 0;
  text-wrap: balance;
}
.page-subtitle {
  color: var(--ink-3);
  font-size: 14px;
  margin-top: 4px;
}
.page-head-actions { display: flex; gap: 8px; }

/* ============================================
   Buttons
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: all 120ms;
  white-space: nowrap;
}
.btn-primary { background: var(--ink); color: var(--bg); }
.btn-primary:hover { background: #000; }
.btn-accent { background: var(--accent); color: white; }
.btn-accent:hover { background: var(--accent-ink); }
.btn-ghost { background: transparent; color: var(--ink-2); border-color: var(--border); background: var(--surface); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-quiet { background: transparent; color: var(--ink-2); }
.btn-quiet:hover { background: var(--surface-2); color: var(--ink); }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-lg { padding: 10px 18px; font-size: 14px; }
.btn-danger { color: var(--danger); background: var(--surface); border-color: var(--border); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }

/* ============================================
   Cards
   ============================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}
.card-pad { padding: 22px; }
.card-pad-lg { padding: 32px; }
.card-head {
  padding: 16px 22px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-head h3 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: -0.005em; }
.card-head .sub { font-size: 12px; color: var(--ink-3); font-family: var(--font-mono); }
.card-body { padding: 22px; }
.card-foot { padding: 12px 22px; border-top: 1px solid var(--border-soft); font-size: 12px; color: var(--ink-3); display: flex; justify-content: space-between; align-items: center; }

/* ============================================
   Stat / KPI
   ============================================ */
.kpi {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kpi-label { font-size: 12px; color: var(--ink-3); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-value {
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.03em;
  font-feature-settings: "tnum";
  line-height: 1.1;
}
.kpi-value .unit { font-size: 14px; color: var(--ink-3); margin-left: 4px; font-weight: 500; }
.kpi-delta { font-size: 12px; color: var(--ink-3); font-family: var(--font-mono); display: inline-flex; align-items: center; gap: 4px; }
.kpi-delta.up { color: var(--ok); }
.kpi-delta.down { color: var(--danger); }

/* ============================================
   Badges
   ============================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  font-family: var(--font-mono);
  background: var(--surface-2);
  color: var(--ink-2);
  border: 1px solid var(--border);
  white-space: nowrap;
  flex-shrink: 0;
}
.badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge.accent { background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; }
.badge.live .dot {
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

/* ============================================
   Tables
   ============================================ */
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.tbl th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-4);
  font-weight: 500;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}
.tbl td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--border-soft);
  color: var(--ink-2);
}
.tbl tr:last-child td { border-bottom: none; }
.tbl tr:hover td { background: var(--surface-2); }
.tbl .num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; color: var(--ink); }
.tbl .primary { color: var(--ink); font-weight: 500; }
.tbl .muted { color: var(--ink-4); font-family: var(--font-mono); font-size: 12px; }

/* ============================================
   Pipeline
   ============================================ */
.pipeline {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0;
}
.pipe-step {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
  min-width: 0;
}
.pipe-step-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}
.pipe-dot {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1.5px solid var(--border-strong);
  display: grid;
  place-items: center;
  position: relative;
}
.pipe-line {
  flex: 1;
  height: 1.5px;
  background: var(--border-strong);
  position: relative;
  overflow: hidden;
}
.pipe-step.done .pipe-dot {
  background: var(--ink);
  border-color: var(--ink);
}
.pipe-step.done .pipe-dot::after {
  content: "";
  width: 5px;
  height: 5px;
  background: var(--bg);
  border-radius: 50%;
}
.pipe-step.done .pipe-line { background: var(--ink); }
.pipe-step.active .pipe-dot {
  background: var(--surface);
  border-color: var(--accent);
}
.pipe-step.active .pipe-dot::before {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  opacity: 0.5;
  animation: ping 1.6s ease-out infinite;
}
.pipe-step.active .pipe-dot::after {
  content: "";
  width: 7px;
  height: 7px;
  background: var(--accent);
  border-radius: 50%;
}
.pipe-step.active .pipe-line {
  background: var(--border-strong);
}
.pipe-step.active .pipe-line::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--accent) 0%, transparent 100%);
  animation: pipeflow 1.4s linear infinite;
}
@keyframes ping {
  0% { transform: scale(0.8); opacity: 0.8; }
  100% { transform: scale(2.2); opacity: 0; }
}
@keyframes pipeflow {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}
.pipe-step-label { font-size: 11px; color: var(--ink-3); font-weight: 500; padding-left: 0; }
.pipe-step.active .pipe-step-label { color: var(--accent-ink); font-weight: 600; }
.pipe-step.done .pipe-step-label { color: var(--ink); }
.pipe-step-meta { font-size: 11px; color: var(--ink-4); font-family: var(--font-mono); }

/* ============================================
   Misc
   ============================================ */
.divider { height: 1px; background: var(--border-soft); margin: 24px 0; border: none; }
.divider-v { width: 1px; background: var(--border-soft); align-self: stretch; }

.kbd {
  display: inline-flex;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-3);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--surface-2);
  border-radius: 999px;
  font-size: 12px;
  color: var(--ink-2);
  border: 1px solid var(--border-soft);
}
.chip.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip:hover { background: var(--surface-3); }
.chip.active:hover { background: var(--ink); }

.search-input {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 6px 10px;
  flex: 0 1 320px;
  min-width: 140px;
}
.search-input input {
  flex: 1;
  border: none;
  outline: none;
  background: none;
  font-size: 13px;
}
.search-input input::placeholder { color: var(--ink-4); }
.search-input .kbd { margin-left: auto; }

.input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px 12px;
  font-size: 13px;
  width: 100%;
  outline: none;
  transition: border-color 120ms;
}
.input:focus { border-color: var(--ink-3); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12px; color: var(--ink-2); font-weight: 500; }
.field-hint { font-size: 11px; color: var(--ink-4); }

/* Toggle */
.toggle {
  position: relative;
  width: 32px;
  height: 18px;
  background: var(--ink-5);
  border-radius: 999px;
  cursor: pointer;
  transition: background 160ms;
}
.toggle::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: white;
  border-radius: 50%;
  transition: transform 160ms;
}
.toggle.on { background: var(--ink); }
.toggle.on::after { transform: translateX(14px); }

/* Striped placeholder for images */
.img-ph {
  background:
    repeating-linear-gradient(45deg, var(--surface-2) 0 6px, var(--surface) 6px 12px);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}
.img-ph::after {
  content: attr(data-label);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-4);
  background: var(--surface);
  padding: 2px 6px;
  border-radius: 3px;
  border: 1px solid var(--border);
}

/* Sparkline / chart helpers */
.spark {
  height: 32px;
  width: 100%;
}

/* Tweaks panel base (we use starter component) */

/* ============================================
   Responsive — mid-desktop (cramped laptop)
   ============================================ */
@media (max-width: 1180px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr) !important; }
  .page { padding: 28px 32px 56px 32px; }
}
@media (max-width: 1080px) {
  .grid-3 { grid-template-columns: repeat(2, 1fr) !important; }
  .search-input.hide-narrow { display: none; }
}

/* ============================================
   Responsive — H5
   ============================================ */
@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 0 1fr;
  }
  .app-shell.mobile-nav-open { grid-template-columns: var(--sidebar-w) 1fr; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-w);
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 220ms;
  }
  .app-shell.mobile-nav-open .sidebar { transform: translateX(0); }
  .topbar { padding: 0 16px; }
  .page { padding: 20px 16px 40px 16px; }
  .page-head { flex-direction: column; align-items: flex-start; gap: 16px; }
  .page-title { font-size: 22px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr !important; }
  .credit-chip .label { display: none; }
  .hide-mobile { display: none !important; }
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; }
.row { display: flex; gap: 12px; align-items: center; }
.col { display: flex; flex-direction: column; gap: 12px; }

/* Login page */
.login-bg {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg);
}
.login-left {
  padding: 48px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--ink);
  color: var(--bg);
  position: relative;
  overflow: hidden;
}
.login-right {
  padding: 48px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.login-card {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
@media (max-width: 900px) {
  .login-bg { grid-template-columns: 1fr; }
  .login-left { padding: 24px; min-height: 200px; }
  .login-right { padding: 24px; }
}

/* Pipeline rail animations for visual rhythm */
.tick-marks {
  display: flex;
  gap: 2px;
  align-items: flex-end;
  height: 32px;
}
.tick-marks > span {
  flex: 1;
  background: var(--surface-3);
  border-radius: 1px;
}

/* Sparkbar */
.sparkbars {
  display: flex;
  gap: 3px;
  align-items: flex-end;
  height: 48px;
}
.sparkbars > span {
  flex: 1;
  background: var(--ink);
  border-radius: 1px;
  min-width: 4px;
  opacity: 0.85;
}
.sparkbars > span.accent { background: var(--accent); opacity: 1; }
.sparkbars.muted > span { background: var(--ink-5); }
