/* =============================================================================
   MAISON · FUNDING ARB
   Palette: champagne (淡金色) · burgundy (勃艮第红) · cream (米白色) · warm ink
   Aesthetic: editorial + Apple-widget softness + private-bank quarterly report
   ========================================================================== */

:root {
  /* --- Cream / paper / white --- */
  --cream:         #F3EDDE;        /* page background */
  --cream-soft:    #ECE2CC;        /* secondary panels */
  --cream-paper:   #FBF7EC;        /* card inner glow */
  --cream-white:   #FEFDFA;        /* card background */

  /* --- Champagne (淡金色) --- */
  --gold-pale:     #EEDEB6;        /* faint highlight */
  --gold:          #C9A55D;        /* primary gold */
  --gold-deep:     #A58341;        /* rich gold */
  --gold-ghost:    rgba(201,165,93,0.14);

  /* --- Burgundy (勃艮第红) --- */
  --burgundy:      #6F2733;        /* primary accent, buttons, key numbers */
  --burgundy-rich: #8B3142;        /* hover */
  --burgundy-soft: #B94C5E;        /* warn/negative */
  --burgundy-ghost:rgba(111,39,51,0.08);

  /* --- Ink (text) --- */
  --ink:           #231811;        /* primary text on cream */
  --ink-soft:      #5C4A3D;        /* secondary text */
  --ink-faint:     #8B7565;        /* tertiary */

  /* --- Semantic (used sparingly) --- */
  --positive:      #5F6F47;        /* moss-green for profits */
  --negative:      #8B3142;        /* reuses burgundy for losses */
  --caution:       #B8803A;        /* warn, reused gold-deep */

  /* --- Structural --- */
  --rule:          rgba(35,24,17,0.08);
  --rule-strong:   rgba(35,24,17,0.16);
  --rule-gold:     rgba(201,165,93,0.35);

  /* --- Shadows (Apple widget style) --- */
  --shadow-sm:     0 1px 2px rgba(35,24,17,0.06);
  --shadow-card:   0 1px 2px rgba(35,24,17,0.04),
                   0 6px 20px rgba(35,24,17,0.05),
                   0 14px 32px rgba(35,24,17,0.04);
  --shadow-card-hi:0 2px 4px rgba(35,24,17,0.06),
                   0 10px 28px rgba(35,24,17,0.08),
                   0 22px 54px rgba(35,24,17,0.10);
  --shadow-dialog: 0 30px 80px rgba(35,24,17,0.18),
                   0 8px 24px rgba(35,24,17,0.10);

  /* --- Curves (iOS-ish) --- */
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 22px;
  --r-xl: 28px;

  /* --- Easing --- */
  --ease-out:  cubic-bezier(0.19, 1, 0.22, 1);
  --ease-soft: cubic-bezier(0.34, 1.56, 0.64, 1);

  /* --- Type ---
     Display  : 霞鹜文楷 (LXGW WenKai) for CJK — an elegant modern kaishu
                open-source handwriting-style font that pairs well with the
                editorial Maison aesthetic. Fraunces covers Latin/fallback.
     Body     : Noto Sans SC (中文黑体) + Manrope for Latin — clean,
                screen-optimised CJK with excellent rendering at small sizes.
     Mono     : JetBrains Mono for timestamps & numerics (Latin-only glyphs). */
  --f-display: 'LXGW WenKai', 'Noto Serif SC', 'Fraunces', 'Iowan Old Style',
               'Palatino', 'Georgia', 'STKaiti', 'KaiTi', serif;
  --f-body:    'Noto Sans SC', 'Manrope', -apple-system, BlinkMacSystemFont,
               'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei',
               'Helvetica Neue', sans-serif;
  --f-mono:    'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas,
               'Noto Sans Mono CJK SC', monospace;
}

/* ========================================================================== *
   RESET / BASE
 * ========================================================================== */

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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--f-body);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--cream);
  background-image:
    radial-gradient(ellipse at 20% -10%, rgba(201,165,93,0.14), transparent 55%),
    radial-gradient(ellipse at 110% 100%, rgba(111,39,51,0.06), transparent 50%),
    linear-gradient(180deg, var(--cream) 0%, #EFE5D0 100%);
  min-height: 100vh;
  position: relative;
  font-feature-settings: "ss01", "cv05";
  font-variant-numeric: tabular-nums;
}

/* Faint paper-grain overlay */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' seed='5'/><feColorMatrix values='0 0 0 0 0.14  0 0 0 0 0.09  0 0 0 0 0.06  0 0 0 0.05 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  opacity: 0.55;
  z-index: 0;
  mix-blend-mode: multiply;
}

.grain { position: absolute; width: 0; height: 0; visibility: hidden; }

a { color: inherit; }
button { font-family: inherit; cursor: pointer; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(35,24,17,0.18);
  border-radius: 10px;
  border: 2px solid var(--cream);
}
::-webkit-scrollbar-thumb:hover { background: rgba(35,24,17,0.32); }

/* ========================================================================== *
   LAYOUT
 * ========================================================================== */

.page {
  max-width: 1440px;
  margin: 0 auto;
  padding: 48px 56px 64px;
  position: relative;
  z-index: 1;
}
@media (max-width: 900px) { .page { padding: 28px 20px 48px; } }

/* ========================================================================== *
   MASTHEAD
 * ========================================================================== */

.masthead {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 32px;
  padding-bottom: 24px;
  margin-bottom: 40px;
  border-bottom: 1px solid var(--rule);
  position: relative;
}
.masthead::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -1px;
  width: 96px;
  height: 2px;
  background: linear-gradient(90deg, var(--gold), transparent);
}

.masthead-brand { display: flex; flex-direction: column; gap: 6px; }

.mono-eyebrow {
  font-family: var(--f-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.wordmark {
  font-family: var(--f-display);
  font-variation-settings: "opsz" 144, "SOFT" 40, "wght" 420;
  font-size: 42px;
  line-height: 1;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.wordmark em {
  font-style: italic;
  font-variation-settings: "opsz" 144, "SOFT" 80, "wght" 420;
  color: var(--burgundy);
}
.wordmark .amp {
  display: inline-block;
  color: var(--gold);
  margin: 0 2px;
  transform: translateY(-4px);
}

.masthead-meta { display: flex; gap: 36px; }
.meta-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 88px;
  text-align: right;
}
.meta-label {
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.meta-value {
  font-family: var(--f-display);
  font-variation-settings: "opsz" 72, "wght" 500;
  font-size: 18px;
  color: var(--ink);
  line-height: 1;
}
.meta-value.mono {
  font-family: var(--f-mono);
  font-weight: 500;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 10px;
  background: var(--cream-paper);
  border: 1px solid var(--rule);
  border-radius: 999px;
  font-family: var(--f-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}
.status-badge .status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--positive);
  box-shadow: 0 0 0 3px rgba(95,111,71,0.18);
}
.status-badge.paused  .status-dot { background: var(--caution); box-shadow: 0 0 0 3px rgba(184,128,58,0.18); }
.status-badge.stopped .status-dot { background: var(--burgundy); box-shadow: 0 0 0 3px rgba(111,39,51,0.18); }

/* ========================================================================== *
   ROWS
 * ========================================================================== */

.row { display: grid; gap: 24px; margin-bottom: 24px; }
.row-1 { grid-template-columns: 1fr; }
.row-2 { grid-template-columns: 1fr 1fr; }
.row-3 { grid-template-columns: repeat(3, 1fr); }
.row-strategy { grid-template-columns: 2fr 1fr; }
@media (max-width: 1000px) {
  .row-3 { grid-template-columns: 1fr; }
  .row-2 { grid-template-columns: 1fr; }
  .row-strategy { grid-template-columns: 1fr; }
}

/* ========================================================================== *
   CARD
 * ========================================================================== */

.card {
  position: relative;
  background: var(--cream-white);
  border: 0.5px solid var(--rule);
  border-radius: var(--r-xl);
  padding: 24px 26px 22px;
  box-shadow: var(--shadow-card);
  transition: transform 420ms var(--ease-out), box-shadow 420ms var(--ease-out);
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card-hi);
}
.card-eyebrow {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
}
.rubric {
  font-family: var(--f-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  color: var(--gold-deep);
}
.eyebrow-title {
  font-family: var(--f-display);
  font-variation-settings: "opsz" 72, "wght" 500;
  font-size: 15px;
  color: var(--ink);
  letter-spacing: 0.01em;
}
.eyebrow-meter {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.eyebrow-meter .pulse {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--burgundy);
  box-shadow: 0 0 0 0 rgba(111,39,51,0.45);
  animation: pulse 1.8s ease-out infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(111,39,51,0.45); }
  70%  { box-shadow: 0 0 0 9px rgba(111,39,51,0); }
  100% { box-shadow: 0 0 0 0 rgba(111,39,51,0); }
}

/* ------------- Stat card (P&L hero) ------------- */

.card-stat .hero-number {
  font-family: var(--f-display);
  font-variation-settings: "opsz" 144, "SOFT" 50, "wght" 400;
  font-size: 72px;
  line-height: 1;
  color: var(--ink);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}
.card-stat .hero-number.positive { color: var(--positive); }
.card-stat .hero-number.negative { color: var(--burgundy); }
.card-stat .hero-number-unit {
  font-family: var(--f-mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-top: 2px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--rule);
}
.micro-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 14px;
}
.micro-stats > div { display: flex; flex-direction: column; gap: 4px; }
.micro-stats dt {
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.micro-stats dd {
  font-family: var(--f-display);
  font-variation-settings: "opsz" 72, "wght" 500;
  font-size: 20px;
  color: var(--ink);
}

/* ------------- Latency card ------------- */

.card-lat .lat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 4px;
}
.lat-cell {
  background: var(--cream-paper);
  border-radius: var(--r-md);
  padding: 14px 12px;
  text-align: center;
  border: 0.5px solid var(--rule);
}
.lat-label {
  display: block;
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 8px;
}
.lat-val {
  display: block;
  font-family: var(--f-display);
  font-variation-settings: "opsz" 96, "wght" 500;
  font-size: 28px;
  line-height: 1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.card-footnote {
  margin-top: 14px;
  font-family: var(--f-mono);
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.02em;
}
.card-footnote .sep { opacity: 0.5; margin: 0 6px; }

/* ------------- Circuit / connections ------------- */

.circuit-badge {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--r-md);
  margin-bottom: 4px;
  border: 0.5px solid var(--rule);
  background: var(--cream-paper);
}
.circuit-badge .cb-level {
  font-family: var(--f-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--gold-deep);
}
.circuit-badge .cb-title {
  font-family: var(--f-display);
  font-variation-settings: "opsz" 72, "wght" 500;
  font-size: 16px;
  color: var(--ink);
}
.circuit-badge.level-0 { border-color: rgba(95,111,71,0.25); background: rgba(95,111,71,0.06); }
.circuit-badge.level-0 .cb-level { color: var(--positive); }
.circuit-badge.level-1 { border-color: rgba(184,128,58,0.30); background: rgba(184,128,58,0.09); }
.circuit-badge.level-1 .cb-level { color: var(--caution); }
.circuit-badge.level-2 { border-color: rgba(139,49,66,0.30); background: rgba(139,49,66,0.08); }
.circuit-badge.level-2 .cb-level { color: var(--burgundy-rich); }
.circuit-badge.level-3 { border-color: var(--burgundy); background: var(--burgundy-ghost); }
.circuit-badge.level-3 .cb-level,
.circuit-badge.level-3 .cb-title { color: var(--burgundy); }

.circuit-reason {
  font-size: 12px;
  color: var(--ink-soft);
  margin: 8px 2px 14px;
  min-height: 1.3em;
}

.conn-rail {
  display: flex;
  gap: 16px;
  padding: 10px 12px;
  background: var(--cream-paper);
  border-radius: var(--r-md);
  margin-bottom: 14px;
  border: 0.5px solid var(--rule);
}
.conn-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  font-family: var(--f-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ink-faint);
  transition: background 200ms, box-shadow 200ms;
}
.dot.on  { background: var(--positive); box-shadow: 0 0 0 3px rgba(95,111,71,0.18); }
.dot.off { background: var(--burgundy); box-shadow: 0 0 0 3px rgba(111,39,51,0.18); }
.dot.unk { background: var(--ink-faint); }

/* ------------- Buttons ------------- */

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 16px;
  border-radius: 11px;
  font-family: var(--f-body);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  border: 0.5px solid transparent;
  cursor: pointer;
  transition: transform 180ms var(--ease-soft),
              box-shadow 220ms var(--ease-out),
              background 200ms,
              color 200ms;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--burgundy);
  color: var(--cream-paper);
  box-shadow: 0 1px 0 rgba(255,255,255,0.1) inset,
              0 1px 3px rgba(111,39,51,0.25),
              0 4px 12px rgba(111,39,51,0.18);
}
.btn-primary:hover {
  background: var(--burgundy-rich);
  box-shadow: 0 1px 0 rgba(255,255,255,0.12) inset,
              0 2px 6px rgba(111,39,51,0.30),
              0 8px 18px rgba(111,39,51,0.22);
}
.btn-ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--rule-strong);
}
.btn-ghost:hover {
  background: var(--cream-paper);
  border-color: var(--burgundy);
  color: var(--burgundy);
}
.btn-danger {
  background: transparent;
  color: var(--burgundy);
  border-color: rgba(111,39,51,0.35);
}
.btn-danger:hover {
  background: var(--burgundy-ghost);
  border-color: var(--burgundy);
}

/* Legacy compatibility — app.js still creates these class names */
button.primary { /* map to new .btn.btn-primary visual */
  background: var(--burgundy);
  color: var(--cream-paper);
  padding: 9px 16px;
  border: none;
  border-radius: 11px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 1px 0 rgba(255,255,255,0.1) inset,
              0 1px 3px rgba(111,39,51,0.25);
}
button.danger {
  background: transparent;
  color: var(--burgundy);
  border: 0.5px solid rgba(111,39,51,0.35);
  padding: 9px 16px;
  border-radius: 11px;
  font-size: 13px;
  font-weight: 500;
}

/* ------------- Chart card ------------- */

.card-chart { min-height: 260px; }
.chart-wrap {
  position: relative;
  height: 220px;
  margin-top: 6px;
}

/* ------------- Strategy card ------------- */

.card-strategy .strategy-warning {
  display: inline-block;
  padding: 8px 14px;
  background: var(--gold-ghost);
  border-left: 2px solid var(--gold);
  border-radius: 4px;
  font-size: 12.5px;
  color: var(--ink-soft);
  margin-bottom: 20px;
  line-height: 1.45;
}
.card-strategy .strategy-warning em {
  color: var(--burgundy);
  font-style: normal;
  font-weight: 600;
}

.strategy-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px 24px;
  margin-bottom: 20px;
}
@media (max-width: 720px) { .strategy-grid { grid-template-columns: 1fr; } }

.strategy-field { display: flex; flex-direction: column; gap: 8px; }
.strategy-field .field-label {
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.field-input-row {
  display: flex;
  align-items: stretch;
  background: var(--cream-paper);
  border: 0.5px solid var(--rule-strong);
  border-radius: var(--r-md);
  transition: border-color 200ms, box-shadow 200ms;
}
.field-input-row:focus-within {
  border-color: var(--burgundy);
  box-shadow: 0 0 0 3px var(--burgundy-ghost);
}
.strategy-field input {
  flex: 1;
  background: transparent;
  border: 0;
  padding: 11px 14px;
  font-family: var(--f-mono);
  font-size: 14px;
  color: var(--ink);
  outline: none;
  min-width: 0;
}
.strategy-field input::-webkit-outer-spin-button,
.strategy-field input::-webkit-inner-spin-button {
  -webkit-appearance: none; margin: 0;
}
.field-unit {
  display: flex;
  align-items: center;
  padding: 0 14px;
  font-family: var(--f-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  border-left: 0.5px solid var(--rule-strong);
  background: rgba(0,0,0,0.01);
}

.strategy-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
}
#strategy-status {
  font-family: var(--f-mono);
  font-size: 11.5px;
  letter-spacing: 0.04em;
}
#strategy-status.success { color: var(--positive); }
#strategy-status.error   { color: var(--burgundy); }

/* ------------- Blacklist ------------- */

.blacklist-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 2px;
}
.blacklist-list li {
  padding: 10px 14px;
  border-radius: var(--r-md);
  background: var(--cream-paper);
  border: 0.5px solid var(--rule);
  font-family: var(--f-mono);
  font-size: 12px;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 12px;
}
.blacklist-list li.empty {
  color: var(--ink-faint);
  border-style: dashed;
  border-color: var(--rule);
  background: transparent;
  justify-content: center;
  font-family: var(--f-display);
  font-variation-settings: "opsz" 24, "wght" 400, "ital" 1;
  font-size: 13px;
}

/* ------------- Event log ------------- */

.eventlog {
  height: 200px;
  overflow-y: auto;
  padding: 12px 14px;
  background: var(--cream-paper);
  border: 0.5px solid var(--rule);
  border-radius: var(--r-md);
  font-family: var(--f-mono);
  font-size: 12px;
  line-height: 1.55;
  color: var(--ink);
}
.eventlog .evt {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 12px;
  padding: 3px 0;
  animation: evtIn 320ms var(--ease-out);
}
@keyframes evtIn {
  from { opacity: 0; transform: translateX(-6px); }
  to   { opacity: 1; transform: translateX(0); }
}
.eventlog .evt-ts    { color: var(--ink-faint); }
.eventlog .evt-type  { color: var(--gold-deep); font-weight: 600; letter-spacing: 0.06em; }
.eventlog .evt-body  { color: var(--ink); }
.eventlog .evt-level-warn  .evt-type { color: var(--caution); }
.eventlog .evt-level-error .evt-type { color: var(--burgundy); }

/* ------------- Trades table ------------- */

.trades-table-wrap {
  overflow-x: auto;
  margin-top: 6px;
  border-radius: var(--r-md);
  border: 0.5px solid var(--rule);
}
#trades-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  background: var(--cream-paper);
}
#trades-table thead th {
  position: sticky;
  top: 0;
  background: var(--cream-paper);
  padding: 11px 12px;
  text-align: left;
  font-family: var(--f-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  border-bottom: 1px solid var(--rule-strong);
  white-space: nowrap;
}
#trades-table tbody td {
  padding: 11px 12px;
  border-bottom: 0.5px solid var(--rule);
  font-family: var(--f-mono);
  color: var(--ink);
  white-space: nowrap;
  vertical-align: middle;
}
#trades-table tbody tr:hover td { background: rgba(201,165,93,0.08); }
#trades-table tbody tr:nth-child(even) td { background: rgba(35,24,17,0.015); }
#trades-table tbody tr:nth-child(even):hover td { background: rgba(201,165,93,0.08); }
#trades-table .trades-empty {
  text-align: center;
  padding: 30px 12px;
  color: var(--ink-faint);
  font-family: var(--f-display);
  font-variation-settings: "opsz" 24, "wght" 400, "ital" 1;
  font-style: italic;
  font-size: 14px;
  border-bottom: none;
}
#trades-table td.num    { text-align: right; font-variant-numeric: tabular-nums; }
#trades-table td.symbol { font-family: var(--f-mono); font-weight: 600; letter-spacing: 0.02em; }
#trades-table td .pnl-positive { color: var(--positive); font-weight: 600; }
#trades-table td .pnl-negative { color: var(--burgundy); font-weight: 600; }
#trades-table td .pnl-neutral  { color: var(--ink-soft); }

.exit-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  background: var(--gold-ghost);
  color: var(--gold-deep);
  border: 0.5px solid rgba(201,165,93,0.35);
}
.exit-badge.market { background: var(--burgundy-ghost); color: var(--burgundy); border-color: rgba(111,39,51,0.25); }
.exit-badge.ioc    { background: var(--gold-ghost);    color: var(--gold-deep); border-color: rgba(201,165,93,0.35); }

.col-detail { width: 48px; text-align: center; }
.btn-detail {
  background: transparent;
  border: 0.5px solid var(--rule-strong);
  color: var(--ink-soft);
  width: 30px; height: 30px;
  border-radius: 50%;
  font-family: var(--f-mono);
  font-weight: 600;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 180ms var(--ease-out);
}
.btn-detail:hover {
  background: var(--burgundy);
  border-color: var(--burgundy);
  color: var(--cream-paper);
  transform: scale(1.08);
}

/* ========================================================================== *
   DIALOG
 * ========================================================================== */

#trade-detail {
  padding: 0;
  border: none;
  border-radius: var(--r-xl);
  background: var(--cream-white);
  color: var(--ink);
  max-width: 780px;
  width: calc(100% - 40px);
  box-shadow: var(--shadow-dialog);
}
#trade-detail::backdrop {
  background: rgba(35,24,17,0.35);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.dialog-inner { padding: 28px 30px 24px; }
.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 20px;
}
.dialog-eyebrow {
  display: block;
  font-family: var(--f-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold-deep);
  margin-bottom: 4px;
}
.dialog-title {
  font-family: var(--f-display);
  font-variation-settings: "opsz" 72, "wght" 500;
  font-size: 22px;
  color: var(--ink);
}
.dialog-close {
  background: transparent;
  border: 0.5px solid var(--rule-strong);
  width: 34px; height: 34px;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 180ms var(--ease-out);
}
.dialog-close:hover {
  background: var(--burgundy);
  color: var(--cream-paper);
  border-color: var(--burgundy);
}
.detail-pre {
  font-family: var(--f-mono);
  font-size: 12.5px;
  line-height: 1.75;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--cream-paper);
  border: 0.5px solid var(--rule);
  border-radius: var(--r-md);
  padding: 18px 20px;
  max-height: 68vh;
  overflow-y: auto;
}

/* ========================================================================== *
   FOOTER
 * ========================================================================== */

.pagefoot {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
  display: flex;
  align-items: baseline;
  gap: 18px;
  font-family: var(--f-mono);
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
}
.foot-mark {
  font-family: var(--f-display);
  font-variation-settings: "opsz" 72, "wght" 500;
  font-size: 18px;
  color: var(--burgundy);
  line-height: 1;
}
.foot-mark sup { color: var(--gold); font-size: 0.6em; }
.foot-text em {
  font-style: italic;
  font-family: var(--f-display);
  color: var(--ink-soft);
  font-variation-settings: "opsz" 48, "SOFT" 60, "wght" 500, "ital" 1;
}
.foot-tel { margin-left: auto; }

/* ========================================================================== *
   REVEAL ANIMATION
 * ========================================================================== */

.reveal {
  opacity: 0;
  transform: translateY(10px);
  animation: reveal 560ms var(--ease-out) forwards;
}
.row-3 .reveal:nth-child(1) { animation-delay: 60ms; }
.row-3 .reveal:nth-child(2) { animation-delay: 120ms; }
.row-3 .reveal:nth-child(3) { animation-delay: 180ms; }
.row-2 .reveal:nth-child(1) { animation-delay: 220ms; }
.row-2 .reveal:nth-child(2) { animation-delay: 260ms; }
.row-strategy .reveal:nth-child(1) { animation-delay: 300ms; }
.row-strategy .reveal:nth-child(2) { animation-delay: 340ms; }
.row-1 .reveal { animation-delay: 380ms; }

@keyframes reveal {
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .reveal { animation: none; opacity: 1; transform: none; }
  .card:hover { transform: none; }
  .eventlog .evt { animation: none; }
  .eyebrow-meter .pulse { animation: none; }
}

/* ========================================================================== *
   UTILITIES + APP.JS COMPAT
 * ========================================================================== */

.mono { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.pnl-positive { color: var(--positive); font-weight: 600; }
.pnl-negative { color: var(--burgundy); font-weight: 600; }
.pnl-neutral  { color: var(--ink-soft); }

/* Stat value color helpers (app.js may add these) */
.stat-value.positive,
.stat-value.good    { color: var(--positive); }
.stat-value.negative,
.stat-value.bad     { color: var(--burgundy); }
.stat-value.neutral { color: var(--ink); }

/* Hide legacy widgets app.js doesn't know about */
.badge { display: none; }

/* ========================================================================== *
   SYSTEM HEALTH PANEL (§ 10)
 * ========================================================================== */

/* ── Grid of panes ──────────────────────────────────────────────────────── */

.sysheal-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin-top: 4px;
}

@media (max-width: 1100px) {
  .sysheal-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .sysheal-grid { grid-template-columns: 1fr; }
}

/* ── Individual pane ────────────────────────────────────────────────────── */

.sysheal-pane {
  padding-top: 14px;
  border-top: 0.5px solid var(--rule);
}

/* ── Pane heading ───────────────────────────────────────────────────────── */

.sysheal-h {
  font-family: var(--f-display);
  font-variation-settings: "opsz" 48, "wght" 500;
  font-size: 13px;
  color: var(--ink);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

/* ── Key–value list ─────────────────────────────────────────────────────── */

.sysheal-list {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 12px;
  align-items: baseline;
}

.sh-row {
  display: contents; /* lets dt/dd participate in the parent grid */
}

.sh-label {
  font-family: var(--f-mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  white-space: nowrap;
}

.sh-value {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  font-family: var(--f-mono);
  font-size: 12px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  justify-content: flex-end;
}

/* ── Status indicator dot ───────────────────────────────────────────────── */

.sh-indicator {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-faint);
}

.sh-row[data-status="ok"] .sh-indicator {
  background: var(--positive);
  box-shadow: 0 0 0 3px rgba(95,111,71,0.15);
}

.sh-row[data-status="warn"] .sh-indicator {
  background: var(--burgundy);
  box-shadow: 0 0 0 3px rgba(111,39,51,0.15);
}

/* ── RTT pane ───────────────────────────────────────────────────────────── */

.rtt-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 10px;
}

.rtt-cell {
  background: var(--cream-paper);
  border-radius: var(--r-md);
  padding: 12px 10px;
  text-align: center;
  border: 0.5px solid var(--rule);
}

.rtt-label {
  display: block;
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 6px;
}

.rtt-val {
  display: block;
  font-family: var(--f-display);
  font-variation-settings: "opsz" 72, "wght" 500;
  font-size: 22px;
  line-height: 1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.rtt-val.good { color: var(--positive); }
.rtt-val.warn { color: var(--burgundy); }

.rtt-footnote {
  font-family: var(--f-mono);
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.02em;
  margin-top: 2px;
}

.rtt-footnote .sep { opacity: 0.5; margin: 0 6px; }

/* ── Footer caption ─────────────────────────────────────────────────────── */

.sysheal-foot {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
  font-family: var(--f-mono);
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sysheal-foot .sep { opacity: 0.5; }

/* === LOGIN PAGE === */

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
}

.login-card {
  background: var(--cream-white);
  border: 0.5px solid var(--rule);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-card);
  padding: 48px 44px 36px;
  width: 360px;
  max-width: calc(100vw - 40px);
  text-align: center;
}

.login-eyebrow {
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold-deep);
  margin-bottom: 14px;
}

.login-word {
  font-family: var(--f-display);
  font-size: 32px;
  font-weight: 300;
  color: var(--ink);
  line-height: 1.15;
  margin-bottom: 0;
}

.login-word .amp {
  color: var(--gold);
  font-style: normal;
}

.login-word em {
  font-style: italic;
  font-weight: 300;
}

.login-form {
  margin-top: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}

.login-label {
  font-family: var(--f-mono);
  font-size: 10.5px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--ink-faint);
  display: block;
  margin-bottom: -6px;
}

.login-input {
  width: 100%;
  font-family: var(--f-display);
  font-size: 18px;
  font-weight: 300;
  color: var(--ink);
  background: var(--cream);
  border: 1px solid var(--rule-strong);
  border-radius: 14px;
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.18s var(--ease-out), box-shadow 0.18s var(--ease-out);
}

.login-input:focus {
  border-color: var(--burgundy);
  box-shadow: 0 0 0 3px rgba(111,39,51,0.12);
}

.login-btn {
  width: 100%;
  font-family: var(--f-body);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.03em;
  color: var(--cream-white);
  background: var(--burgundy);
  border: none;
  border-radius: 14px;
  padding: 12px;
  cursor: pointer;
  transition: background 0.16s var(--ease-out), box-shadow 0.16s var(--ease-out);
}

.login-btn:hover {
  background: var(--burgundy-rich);
  box-shadow: var(--shadow-sm);
}

.login-btn:active {
  background: var(--burgundy);
}

.login-err {
  font-family: var(--f-body);
  font-size: 12px;
  color: var(--burgundy-soft);
  text-align: center;
  margin-top: 4px;
}

.login-foot {
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-top: 22px;
}

.login-foot::before {
  content: "· ";
  color: var(--gold);
}

/* ========================================================================== *
   Week 7 — Strategy Engine UI additions
 * ========================================================================== */

/* ── Countdown bar ─────────────────────────────────────────────────────── */
.countdown-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 24px;
  margin: 0 0 16px;
  background: var(--cream-paper);
  border-top: 0.5px solid var(--rule-gold);
  border-bottom: 0.5px solid var(--rule-gold);
  font-family: var(--f-display);
}
.countdown-symbol { font-weight: 600; letter-spacing: 0.02em; color: var(--ink); }
.countdown-rate { color: var(--burgundy); font-variant-numeric: tabular-nums; }
.countdown-line-wrap {
  flex: 1;
  position: relative;
  height: 1px;
  background: var(--burgundy);
}
.countdown-line {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  background: var(--burgundy);
  transition: width 1s linear, background-color 0.5s var(--ease-out);
}
.countdown-line.warn { background: var(--gold); }
.countdown-line.danger { background: var(--burgundy-rich); animation: countdown-pulse 0.5s infinite alternate; }
@keyframes countdown-pulse {
  from { opacity: 1; }
  to   { opacity: 0.5; }
}
.countdown-cursor {
  position: absolute;
  top: -3px;
  width: 1px;
  height: 7px;
  background: var(--burgundy);
  transition: left 1s linear;
}
.countdown-remaining {
  font-family: var(--f-mono);
  font-variant-numeric: tabular-nums;
  min-width: 60px;
  text-align: right;
}

/* ── § 零三 · 乙 Auto-toggle ────────────────────────────────────────── */
.card-auto-toggle { background: var(--cream-paper); }
.auto-status {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
  font-family: var(--f-display);
  font-size: 1.4rem;
}
.auto-status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--ink-faint);
  transition: background-color 0.4s var(--ease-soft);
}
.auto-status-dot.on { background: var(--burgundy); animation: heartbeat 2s infinite ease-in-out; }
@keyframes heartbeat { 0%,100% { opacity: 1; } 50% { opacity: 0.55; } }
.auto-status-text { color: var(--ink-faint); transition: color 0.4s var(--ease-soft); }
.auto-status-text.on { color: var(--burgundy); }
.auto-phase { color: var(--ink-soft); font-style: italic; }
.auto-timer { font-family: var(--f-mono); color: var(--ink-faint); }
.auto-actions { margin-top: 14px; display: flex; gap: 12px; }

/* ── § 零八 · 乙 Active trade ──────────────────────────────────────── */
.card-active-trade {
  position: relative;
  border-left: 2px solid var(--burgundy);
  padding-left: 22px;
  animation: slide-in-right 300ms var(--ease-out);
}
.card-active-trade.closing { animation: fade-collapse 300ms var(--ease-soft) forwards; }
.card-active-trade.hot-flash { animation: hot-flash 500ms ease-out; }
@keyframes slide-in-right {
  from { transform: translateX(8px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
@keyframes fade-collapse {
  from { opacity: 1; max-height: 600px; }
  to   { opacity: 0; max-height: 0; padding-top: 0; padding-bottom: 0; margin-top: 0; margin-bottom: 0; }
}
@keyframes hot-flash {
  0%   { box-shadow: inset 2px 0 0 var(--burgundy); }
  15%  { box-shadow: inset 4px 0 0 var(--gold); }
  100% { box-shadow: inset 2px 0 0 var(--burgundy); }
}
.active-trade-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px 24px;
}
.active-trade-grid dt { color: var(--ink-faint); font-size: 0.85rem; }
.active-trade-grid dd { font-size: 1rem; }

/* ── § 拾壹 Emergency ───────────────────────────────────────────────── */
.card-emergency {
  background: var(--burgundy-ghost);
  border: 1px solid var(--burgundy);
  filter: url(#grain);
}
.emergency-desc { color: var(--ink); font-style: italic; }
.btn-emergency {
  background: var(--ink);
  color: var(--gold-pale);
  border: 1px solid var(--gold);
  font-family: var(--f-display);
  font-weight: 600;
  letter-spacing: 0.2em;
  padding: 12px 32px;
  transition: box-shadow 0.25s var(--ease-out), background-color 0.25s var(--ease-out);
  box-shadow: inset 0 0 0 0px var(--gold-pale);
}
.btn-emergency:hover {
  box-shadow: inset 0 0 0 1px var(--gold-pale), 0 0 0 2px var(--gold-ghost);
}
.btn-emergency:active { transform: scale(0.98); }

.emergency-modal {
  background: var(--cream-paper);
  padding: 32px;
  max-width: 520px;
  box-shadow: var(--shadow-dialog);
}
.emergency-modal .dialog-title em { font-family: var(--f-display); font-weight: 400; font-size: 1.8rem; }

.dialog-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.dialog-inner label {
  display: block;
  margin: 16px 0 8px;
  font-family: var(--f-body);
  font-size: 13px;
  color: var(--ink-soft);
  font-weight: 500;
}

.dialog-inner input[type="password"],
.dialog-inner input[type="text"] {
  width: 100%;
  font-family: var(--f-body);
  font-size: 14px;
  padding: 10px 14px;
  color: var(--ink);
  background: var(--cream-white);
  border: 1px solid var(--rule-strong);
  border-radius: 6px;
  transition: border-color 0.25s var(--ease-soft);
  box-sizing: border-box;
}

.dialog-inner input:focus {
  border-color: var(--burgundy);
  outline: none;
}

/* ── §零三·丙 资金费率候选 ──────────────────────────────────────────── */
.card-funding-top { padding: 1.25rem 1.5rem 1.5rem; }
.eyebrow-sub {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-mute);
  letter-spacing: 0.02em;
}
.funding-top-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.75rem;
  font-family: var(--font-body);
  font-size: 0.88rem;
}
.funding-top-table th {
  text-align: left;
  font-weight: 500;
  color: var(--ink-mute);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--rule);
}
.funding-top-table th.num { text-align: right; }
.funding-top-table td {
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid rgba(128, 128, 128, 0.08);
  font-variant-numeric: tabular-nums;
}
.funding-top-table td.num {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.82rem;
}
.funding-top-table tbody tr:last-child td { border-bottom: none; }
.funding-top-table tbody tr {
  transition: background-color 0.2s var(--ease-soft);
}
.funding-top-table tbody tr:hover {
  background-color: rgba(128, 14, 31, 0.04);
}
.funding-top-table .symbol {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--ink-strong);
}
.funding-top-table .rate-pos { color: #2f6a3a; }
.funding-top-table .rate-neg { color: var(--burgundy); }
.funding-top-table .countdown-urgent { color: var(--burgundy); font-weight: 500; }
.funding-top-table td.empty {
  text-align: center;
  color: var(--ink-mute);
  padding: 1.25rem 0;
  font-style: italic;
}

/* ── Reduced motion ─────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
