/* Brand + dense finance overrides on Tabler
   Light/dark split: shared tokens in :root, dark overrides in [data-bs-theme="dark"].
   Default is dark (the html tag has data-bs-theme from session); light is opt-in. */
:root {
  /* Shared (both themes) */
  --ibc-up: #3dd68c;
  --ibc-down: #ff6b6b;
  --ibc-long: #5ec8ff;
  --ibc-short: #ffb020;
  --ibc-accent: #c8f06c;
  --ibc-accent-ink: #13200f;
  --tblr-border-radius: 0.5rem;
  --tblr-spacer-2: 0.4rem;
  --tblr-spacer-3: 0.65rem;
  --ibc-serif: "Source Serif 4", "Noto Sans SC", Georgia, serif;
  --ibc-mono: "IBM Plex Mono", ui-monospace, monospace;
  --ibc-sans: "Noto Sans SC", var(--tblr-font-sans-serif), sans-serif;

  /* Light theme (default overridden by [data-bs-theme="dark"]) */
  --tblr-body-bg: #f6f8f7;
  --tblr-bg-surface: #ffffff;
  --tblr-primary: #65a30d;
  --tblr-primary-rgb: 101, 163, 13;
  --tblr-primary-fg: #ffffff;
  --tblr-link-color: #65a30d;
  --tblr-link-hover-color: #4d7c0f;
  --ibc-muted: #6b7280;
}

[data-bs-theme="dark"] {
  /* Dark theme (default) */
  --tblr-body-bg: #0f1412;
  --tblr-bg-surface: #17201c;
  --tblr-primary: #c8f06c;
  --tblr-primary-rgb: 200, 240, 108;
  --tblr-primary-fg: #13200f;
  --tblr-link-color: #c8f06c;
  --tblr-link-hover-color: #d8f58a;
  --ibc-muted: #9aaca0;
}

/* —— Density / workspace —— */
.page-wrapper > .page-header {
  min-height: 0;
  padding-top: 0.45rem;
  padding-bottom: 0.45rem;
  margin: 0;
  border-bottom: 1px solid var(--tblr-border-color);
}

.page-body {
  margin: 0;
  padding-top: 0.5rem !important;
  padding-bottom: 0.65rem !important;
}

.page-body > .container-fluid,
.page-header > .container-fluid,
.footer > .container-fluid {
  padding-left: 0.65rem;
  padding-right: 0.65rem;
  max-width: none;
}

@media (min-width: 992px) {
  .page-body > .container-fluid,
  .page-header > .container-fluid,
  .footer > .container-fluid {
    padding-left: 1rem;
    padding-right: 1rem;
  }
}

.page-title {
  font-size: 1.35rem;
  margin: 0;
  line-height: 1.2;
}

.page-pretitle,
.page-subtitle {
  font-size: 0.8rem;
  color: var(--ibc-muted);
  margin: 0.15rem 0 0;
}

.card {
  box-shadow: none;
}

.card + .card,
.card.mb-2 { margin-bottom: 0.55rem !important; }
.card.mb-3 { margin-bottom: 0.65rem !important; }

.card-sm .card-body,
.card-body.card-body-sm {
  padding: 0.65rem 0.8rem;
}

.card-body {
  padding: 0.75rem 0.85rem;
}

.card-header,
.card-footer {
  padding: 0.55rem 0.85rem;
  min-height: 0;
}

.card-title {
  font-size: 0.95rem;
  margin: 0;
}

.subheader {
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ibc-muted);
  margin-bottom: 0.2rem;
}

.kpi .h2,
.kpi .h3,
.card .h2,
.card .h3 {
  font-size: 1.15rem;
  margin: 0;
  line-height: 1.2;
}

.row-cards {
  --tblr-gutter-x: 0.45rem;
  --tblr-gutter-y: 0.45rem;
}

.table > :not(caption) > * > * {
  padding: 0.38rem 0.55rem;
  font-size: 0.82rem;
}

.table thead th {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ibc-muted);
  white-space: nowrap;
}

.form-label,
.filters > label {
  font-size: 0.75rem;
  margin-bottom: 0.2rem;
  color: var(--ibc-muted);
}

.form-control,
.form-select {
  min-height: 2.1rem;
  padding-top: 0.35rem;
  padding-bottom: 0.35rem;
  font-size: 0.85rem;
}

.btn-sm {
  --tblr-btn-padding-y: 0.28rem;
  --tblr-btn-padding-x: 0.65rem;
  font-size: 0.8rem;
}

.alert {
  padding: 0.55rem 0.75rem;
  margin-bottom: 0.65rem;
  font-size: 0.85rem;
}

.navbar-vertical .navbar-nav .nav-link {
  padding-top: 0.4rem;
  padding-bottom: 0.4rem;
}

.navbar-vertical .nav .nav-link {
  padding-top: 0.28rem;
  padding-bottom: 0.28rem;
  font-size: 0.86rem;
}

.footer {
  padding-top: 0.55rem !important;
  padding-bottom: 0.55rem !important;
  font-size: 0.75rem;
}

.empty {
  padding: 1.25rem 0.75rem !important;
}

.empty-icon {
  margin-bottom: 0.35rem !important;
}

/* —— Brand typography / finance colors —— */
body.lang-zh { font-family: var(--ibc-sans); }

.navbar-brand-text,
.page-title,
h1, h2, h3 {
  font-family: var(--ibc-serif);
  letter-spacing: -0.02em;
}

.mono, code, .exec-id, .tag-code,
.num, th.num, td.num {
  font-family: var(--ibc-mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.num, th.num, td.num { text-align: right; }
.num.up, .num.long { color: var(--ibc-up); }
.num.down, .num.short { color: var(--ibc-down); }
.num.flat { color: inherit; }
.num.long { color: var(--ibc-long); }
.num.short { color: var(--ibc-short); }

.symbol { font-weight: 600; letter-spacing: 0.02em; }
.meta, .lede { color: var(--ibc-muted); }
.lede { max-width: 52rem; line-height: 1.45; font-size: 0.88rem; margin: 0; }

.side {
  display: inline-block;
  min-width: 3rem;
  text-align: center;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.12rem 0.35rem;
  border-radius: 4px;
  border: 1px solid transparent;
}
.side.buy {
  color: var(--ibc-up);
  background: rgba(61, 214, 140, 0.12);
  border-color: rgba(61, 214, 140, 0.28);
}
.side.sell {
  color: var(--ibc-down);
  background: rgba(255, 107, 107, 0.12);
  border-color: rgba(255, 107, 107, 0.28);
}
.side.flat {
  color: var(--ibc-muted);
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--tblr-border-color);
}

.time-multi {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  line-height: 1.2;
  white-space: nowrap;
}
.time-multi .time-label {
  display: inline-block;
  min-width: 5.2rem;
  color: var(--ibc-muted);
  font-size: 0.68rem;
  font-weight: 600;
}

.btn-primary {
  --tblr-btn-color: var(--ibc-accent-ink);
  --tblr-btn-bg: var(--ibc-accent);
  --tblr-btn-border-color: var(--ibc-accent);
  --tblr-btn-hover-bg: #d4f585;
  --tblr-btn-hover-border-color: #d4f585;
  --tblr-btn-hover-color: var(--ibc-accent-ink);
}

.navbar-brand-logo {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 0.4rem;
  background: var(--ibc-accent);
  color: var(--ibc-accent-ink);
  display: inline-grid;
  place-items: center;
  font-family: var(--ibc-mono);
  font-size: 0.7rem;
  font-weight: 700;
}

/* Mini sidebar */
body.shell-collapsed .navbar-vertical {
  width: 4.25rem !important;
  max-width: 4.25rem;
}
body.shell-collapsed .navbar-vertical .nav-link-title,
body.shell-collapsed .navbar-vertical .navbar-brand-text {
  display: none;
}
body.shell-collapsed .navbar-vertical .nav-link {
  justify-content: center;
  padding-left: 0.55rem;
  padding-right: 0.55rem;
}
body.shell-collapsed .navbar-vertical .nav-link-icon { margin-right: 0 !important; }
body.shell-collapsed .page { --tblr-navbar-width: 4.25rem; }
@media (min-width: 992px) {
  body.shell-collapsed .page-wrapper {
    margin-inline-start: 4.25rem !important;
  }
}

@media (max-width: 991.98px) {
  body.shell-collapsed .navbar-vertical {
    width: auto !important;
    max-width: none;
  }
  body.shell-collapsed .navbar-vertical .nav-link-title,
  body.shell-collapsed .navbar-vertical .navbar-brand-text {
    display: inline;
  }
}

.account-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  border: 1px solid var(--tblr-border-color);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.14);
  font-size: 0.8rem;
}

.lang-switch {
  display: inline-flex;
  border: 1px solid var(--tblr-border-color);
  border-radius: 999px;
  overflow: hidden;
}
.lang-btn {
  color: var(--ibc-muted);
  text-decoration: none;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.28rem 0.55rem;
}
.lang-btn.active {
  background: var(--ibc-accent);
  color: var(--ibc-accent-ink);
}
.lang-btn:hover { text-decoration: none; color: inherit; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: end;
  margin: 0;
}
.filters > label {
  display: grid;
  gap: 0.2rem;
  margin: 0;
}
.filter-range { display: grid; gap: 0.2rem; }
.filter-range-title {
  color: var(--ibc-muted);
  font-size: 0.72rem;
}
.filter-range-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: end;
}
.date-field { min-width: 10.5rem; }
.date-field .date-input { min-width: 10.5rem; }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin: 0.55rem 0 0.35rem;
  flex-wrap: wrap;
}
.section-head h2 {
  font-size: 1.05rem;
  margin: 0;
}
.section-head:first-child { margin-top: 0; }
.section-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.stats-row,
.dash-kpis,
.status-grid,
.kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.55rem;
  margin: 0 0 0.65rem;
}

.panel,
.stat,
.summary-chip {
  background: var(--tblr-bg-surface);
  border: 1px solid var(--tblr-border-color);
  border-radius: var(--tblr-border-radius);
  padding: 0.65rem 0.75rem;
}

.stat strong,
.summary-chip strong {
  display: block;
  margin-top: 0.15rem;
  font-size: 1.05rem;
}

.panel.tall { margin-top: 0.55rem; }

.dash-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}
.chart-wide { grid-column: 1 / -1; }
.chart-panel canvas { width: 100% !important; max-height: 260px; }

.table-wrap { width: 100%; overflow-x: auto; }

dl.metrics {
  margin: 0.4rem 0 0;
  display: grid;
  gap: 0.3rem;
}
dl.metrics div {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  border-top: 1px solid var(--tblr-border-color);
  padding-top: 0.3rem;
}
dt { color: var(--ibc-muted); font-size: 0.8rem; }
dd { margin: 0; text-align: right; }

.status { font-size: 1.05rem; font-weight: 600; margin: 0.25rem 0; }
.status.ok { color: var(--ibc-up); }
.status.bad { color: var(--ibc-down); }

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--ibc-accent);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.7rem;
}

.hero { padding: 0 0 0.45rem; }
.hero h1 { font-size: 1.45rem; margin: 0; line-height: 1.15; }
.hero .lede { margin-top: 0.25rem; font-size: 0.85rem; max-width: 48rem; }

.steps {
  margin: 0.4rem 0 0;
  padding-left: 1.1rem;
  color: var(--ibc-muted);
  line-height: 1.55;
  font-size: 0.88rem;
}

.preset-option {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--tblr-border-color);
  border-radius: 0.5rem;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.12);
  width: 100%;
}
.preset-option.selected,
.preset-option:has(input:checked) {
  border-color: var(--ibc-accent);
  background: rgba(200, 240, 108, 0.08);
}
.preset-option span {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
}

.connection-form {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.55rem;
}

.error-box {
  white-space: pre-wrap;
  background: rgba(255, 143, 122, 0.08);
  border: 1px solid rgba(255, 143, 122, 0.25);
  color: var(--ibc-down);
  border-radius: 0.45rem;
  padding: 0.55rem;
  overflow: auto;
  font-size: 0.75rem;
}

.job-status {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--tblr-border-color);
}
.job-status-queued { color: var(--ibc-muted); }
.job-status-running { color: var(--ibc-long); }
.job-status-succeeded { color: var(--ibc-up); }
.job-status-failed { color: var(--ibc-down); }
.job-status-cancelled { color: var(--ibc-short); }
.order-status {
  display: inline-block;
  font-family: var(--ibc-mono, ui-monospace, monospace);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  border: 1px solid var(--tblr-border-color);
}
.order-status-working { color: var(--ibc-long); border-color: color-mix(in srgb, var(--ibc-long) 35%, var(--tblr-border-color)); }
.order-status-filled { color: var(--ibc-up); border-color: color-mix(in srgb, var(--ibc-up) 35%, var(--tblr-border-color)); }
.order-status-cancelled { color: var(--ibc-muted); }
.order-status-rejected { color: var(--ibc-down); border-color: color-mix(in srgb, var(--ibc-down) 35%, var(--tblr-border-color)); }
.order-status-other { color: var(--ibc-short); }
.job-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.job-error { color: var(--ibc-down); font-size: 0.75rem; margin-top: 0.15rem; }
.row-highlight td { background: rgba(200, 240, 108, 0.06); }
.inline-form { display: inline; margin: 0; }

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

@media (max-width: 900px) {
  .dash-grid { grid-template-columns: 1fr; }
  .chart-wide { grid-column: auto; }
  .hero h1 { font-size: 1.4rem; }
}


/* Dense KPI cells used after bulk migration */
.kpi-fix {
  background: var(--tblr-bg-surface);
  border: 1px solid var(--tblr-border-color);
  border-radius: var(--tblr-border-radius);
  padding: 0.65rem 0.8rem;
  min-width: 0;
}
.kpi-fix .meta,
.kpi-fix .subheader {
  display: block;
  color: var(--tblr-secondary);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.2rem;
}
.kpi-fix strong {
  display: block;
  font-size: 1.15rem;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}


/* Chart / JSON / list polish */
.card.chart-panel .card-header,
.card .card-header {
  padding: 0.45rem 0.75rem;
}
.card.chart-panel .card-body {
  padding: 0.55rem 0.7rem 0.7rem;
}
.card.chart-panel canvas {
  max-height: 240px;
}
.job-json {
  margin: 0;
  padding: 0.55rem 0.65rem;
  background: rgba(0,0,0,0.22);
  border: 1px solid var(--tblr-border-color);
  border-radius: 0.4rem;
  font-size: 0.75rem;
  max-height: 280px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---- Job execution timeline / observability ---- */
.status-pulse {
  display: inline-block;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--ibc-long);
  margin-right: 0.35rem;
  vertical-align: middle;
  animation: ibc-pulse 1.1s ease-in-out infinite;
}
@keyframes ibc-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.75); }
}
.job-events .event-dot {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--ibc-muted);
}
.event-dot-created { background: var(--ibc-muted); }
.event-dot-started { background: var(--ibc-long); }
.event-dot-progress { background: var(--ibc-accent); }
.event-dot-succeeded { background: var(--ibc-up); }
.event-dot-failed { background: var(--ibc-down); }
.event-dot-cancelled { background: var(--ibc-short); }
.event-dot-retrying { background: var(--ibc-warn, #f0ad4e); }
.event-dot-stale_reclaimed { background: var(--ibc-warn, #f0ad4e); }
.event-tag {
  display: inline-block;
  font-size: 0.68rem;
  font-family: var(--tblr-font-monospace, monospace);
  padding: 0.05rem 0.35rem;
  border-radius: 0.3rem;
  background: rgba(127,127,127,0.18);
  text-transform: lowercase;
}
.progress-sm { height: 0.5rem; }
.job-events details > summary { list-style: none; cursor: zoom-in; }
.job-events details > summary::-webkit-details-marker { display: none; }
.alert-banner { font-size: 0.85rem; }
.ghost-btn {
  background: transparent;
  border: 1px solid var(--tblr-border-color);
  color: var(--ibc-muted);
  border-radius: 0.35rem;
  padding: 0.15rem 0.45rem;
  font-size: 0.75rem;
  cursor: pointer;
}
.ghost-btn:hover { color: inherit; border-color: var(--ibc-accent); }
.list-compact {
  margin: 0.35rem 0 0;
  padding-left: 1.1rem;
  color: var(--ibc-muted);
  font-size: 0.82rem;
  line-height: 1.45;
}
.row.row-cards > [class*="col-"].kpi-fix {
  /* column acts as compact KPI tile */
}
.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 0.55rem;
  margin-bottom: 0.65rem;
}
.page-title .ti { opacity: 0.85; }
.h3.meta-sub { font-size: 0.75rem; font-weight: 500; margin-top: 0.15rem; }

/* Full-page wait cue for slow navigations (e.g. /rounds FIFO). */
.page-loading {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--tblr-body-bg) 72%, transparent);
  backdrop-filter: blur(2px);
}
.page-loading[hidden] { display: none !important; }
.page-loading__panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  padding: 1rem 1.25rem;
  border-radius: 0.5rem;
  background: var(--tblr-bg-surface);
  border: 1px solid var(--tblr-border-color);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  min-width: 10rem;
}
.page-loading__text {
  font-size: 0.85rem;
  color: var(--ibc-muted);
  font-family: var(--ibc-sans);
}
