.kfbt {
  --kfbt-bg: #f8fafc;
  --kfbt-card: #ffffff;
  --kfbt-border: #d9e2ec;
  --kfbt-text: #172033;
  --kfbt-muted: #64748b;
  --kfbt-accent: #0f766e;
  --kfbt-accent-dark: #115e59;
  --kfbt-danger: #b91c1c;
  --kfbt-success: #047857;
  color: var(--kfbt-text);
  max-width: 1120px;
  margin: 0 auto;
  line-height: 1.7;
}
.kfbt * { box-sizing: border-box; }
.kfbt-hero {
  background: linear-gradient(135deg, #ecfeff, #f8fafc);
  border: 1px solid var(--kfbt-border);
  border-radius: 18px;
  padding: 28px;
  margin: 20px 0;
}
.kfbt-eyebrow {
  margin: 0 0 6px;
  color: var(--kfbt-accent);
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-size: 12px;
}
.kfbt h2, .kfbt h3 { margin-top: 0; }
.kfbt-card {
  background: var(--kfbt-card);
  border: 1px solid var(--kfbt-border);
  border-radius: 16px;
  padding: 22px;
  margin: 18px 0;
  box-shadow: 0 8px 22px rgba(15, 23, 42, .04);
}
.kfbt-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
.kfbt label span {
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
}
.kfbt input[type="date"],
.kfbt input[type="number"],
.kfbt select {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--kfbt-border);
  border-radius: 10px;
  background: #fff;
  color: var(--kfbt-text);
}
.kfbt-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 22px;
  margin-top: 18px;
}
.kfbt-checks label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
}
.kfbt-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 20px;
}
.kfbt-button {
  border: none;
  border-radius: 999px;
  background: var(--kfbt-accent);
  color: #fff;
  font-weight: 700;
  padding: 11px 18px;
  cursor: pointer;
}
.kfbt-button:hover { background: var(--kfbt-accent-dark); }
.kfbt-button:disabled { opacity: .6; cursor: wait; }
.kfbt-button-secondary {
  background: #334155;
}
.kfbt-status {
  padding: 12px 14px;
  background: #f1f5f9;
  border: 1px solid var(--kfbt-border);
  border-radius: 12px;
  color: var(--kfbt-muted);
}
.kfbt-status.is-success {
  color: var(--kfbt-success);
  background: #ecfdf5;
  border-color: #a7f3d0;
}
.kfbt-status.is-error {
  color: var(--kfbt-danger);
  background: #fef2f2;
  border-color: #fecaca;
}
.kfbt-error-box {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #fef2f2;
  color: var(--kfbt-danger);
  border: 1px solid #fecaca;
}
.kfbt-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.kfbt-metric {
  padding: 14px;
  border: 1px solid var(--kfbt-border);
  border-radius: 14px;
  background: #f8fafc;
}
.kfbt-metric-label {
  color: var(--kfbt-muted);
  font-size: 13px;
  margin-bottom: 4px;
}
.kfbt-metric-value {
  font-weight: 800;
  font-size: 20px;
}
.kfbt-meta-table {
  width: 100%;
  border-collapse: collapse;
}
.kfbt-meta-table th,
.kfbt-meta-table td {
  border-bottom: 1px solid var(--kfbt-border);
  padding: 9px 6px;
  text-align: left;
  vertical-align: top;
}
.kfbt-meta-table th {
  width: 220px;
  color: var(--kfbt-muted);
}
@media (max-width: 860px) {
  .kfbt-grid, .kfbt-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .kfbt-grid, .kfbt-summary-grid { grid-template-columns: 1fr; }
  .kfbt-card, .kfbt-hero { padding: 16px; }
}

.kfbt-status.is-running {
  color: #075985;
  background: #eff6ff;
  border-color: #bfdbfe;
}
.kfbt-table-scroll {
  width: 100%;
  overflow-x: auto;
}
.kfbt-compare-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}
.kfbt-compare-table th,
.kfbt-compare-table td {
  border-bottom: 1px solid var(--kfbt-border);
  padding: 10px 8px;
  text-align: right;
  white-space: nowrap;
}
.kfbt-compare-table thead th {
  background: #f8fafc;
  font-weight: 800;
}
.kfbt-compare-table th:first-child,
.kfbt-compare-table td:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  background: #fff;
  z-index: 1;
}
.kfbt-compare-table thead th:first-child {
  background: #f8fafc;
  z-index: 2;
}

/* ===== v6 async + compact summary table ===== */
.kfbt {
  width: min(96vw, 1480px);
  max-width: none;
  margin-left: 50%;
  margin-right: 0;
  transform: translateX(-50%);
}
.kfbt-table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 6px;
}
.kfbt-compare-table {
  width: max-content;
  min-width: 900px;
  border-collapse: collapse;
  table-layout: auto;
  font-size: 13px;
}
.kfbt-compare-table th,
.kfbt-compare-table td {
  padding: 8px 10px;
  min-width: 110px;
  font-size: 13px;
  line-height: 1.35;
  white-space: nowrap;
}
.kfbt-compare-table th:first-child,
.kfbt-compare-table td:first-child {
  min-width: 130px;
  width: 130px;
  max-width: 150px;
  font-weight: 700;
  text-align: left;
  position: sticky;
  left: 0;
  background: #f8fafc;
  color: #334155;
  z-index: 1;
}
.kfbt-compare-table thead th {
  background: #eef2ff;
  color: #1e293b;
  font-weight: 700;
}
.kfbt-compare-table thead th:first-child {
  background: #e0e7ff;
  z-index: 2;
}
.kfbt-compare-table td {
  text-align: right;
}
@media (max-width: 760px) {
  .kfbt {
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    transform: none;
  }
  .kfbt-compare-table {
    min-width: 820px;
    font-size: 12px;
  }
  .kfbt-compare-table th,
  .kfbt-compare-table td {
    padding: 7px 8px;
    min-width: 96px;
    font-size: 12px;
  }
  .kfbt-compare-table th:first-child,
  .kfbt-compare-table td:first-child {
    min-width: 118px;
    width: 118px;
  }
}

/* ===== v7 async: restore comparison-summary table, remove 4-split card layout ===== */
.kfbt-summary-table-wrap,
#kfbt-summary-grid.kfbt-summary-table-wrap,
#kfbt-summary-grid {
  display: block !important;
  grid-template-columns: none !important;
  gap: 0 !important;
  width: 100%;
}

.kfbt-summary .kfbt-summary-grid,
.kfbt-summary-grid {
  display: block !important;
  grid-template-columns: none !important;
}

.kfbt-summary .kfbt-metric,
.kfbt-summary .kfbt-metric-label,
.kfbt-summary .kfbt-metric-value {
  display: none !important;
}

.kfbt-table-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 8px;
}

.kfbt-compare-table {
  width: max-content;
  min-width: 900px;
  border-collapse: collapse;
  table-layout: auto;
  font-size: 13px;
}

.kfbt-compare-table th,
.kfbt-compare-table td {
  border-bottom: 1px solid var(--kfbt-border);
  padding: 8px 10px;
  min-width: 110px;
  font-size: 13px;
  line-height: 1.35;
  white-space: nowrap;
}

.kfbt-compare-table thead th {
  background: #eef2ff;
  color: #1e293b;
  font-weight: 700;
  text-align: right;
}

.kfbt-compare-table th:first-child,
.kfbt-compare-table td:first-child,
.kfbt-compare-table tbody th {
  min-width: 130px;
  width: 130px;
  max-width: 150px;
  font-weight: 700;
  text-align: left;
  position: sticky;
  left: 0;
  background: #f8fafc;
  color: #334155;
  z-index: 1;
}

.kfbt-compare-table thead th:first-child {
  background: #e0e7ff;
  color: #1e293b;
  z-index: 2;
  text-align: left;
}

.kfbt-compare-table td {
  text-align: right;
}

.kfbt-chart-wrap {
  position: relative;
  width: 100%;
}

.kfbt-chart-wrap-equity {
  height: 420px;
}

.kfbt-chart-wrap-dd {
  height: 340px;
}

.kfbt-chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

@media (max-width: 760px) {
  .kfbt {
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    transform: none;
  }

  .kfbt-compare-table {
    min-width: 820px;
    font-size: 12px;
  }

  .kfbt-compare-table th,
  .kfbt-compare-table td {
    padding: 7px 8px;
    min-width: 96px;
    font-size: 12px;
  }

  .kfbt-compare-table th:first-child,
  .kfbt-compare-table td:first-child,
  .kfbt-compare-table tbody th {
    min-width: 118px;
    width: 118px;
    max-width: 130px;
  }

  .kfbt-chart-wrap-equity {
    height: 360px;
  }

  .kfbt-chart-wrap-dd {
    height: 320px;
  }
}

/* ===== v8: benchmark basis help ===== */
.kfbt-help {
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.6;
  color: #64748b;
}

/* ===== series-cache monthly chart ===== */
.kfbt-chart-wrap-monthly {
  height: 360px;
}

@media (max-width: 760px) {
  .kfbt-chart-wrap-monthly {
    height: 320px;
  }
}

/* ===== series-cache v3 display controls ===== */
.kfbt-view-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 14px 0 0;
}

.kfbt-control-block {
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 12px;
  background: #fafafa;
}

.kfbt-control-title {
  font-weight: 700;
  margin-bottom: 8px;
}

.kfbt-radio-row,
.kfbt-month-range {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
}

.kfbt-radio-row label,
.kfbt-monthly-series-checks label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.kfbt-month-range {
  margin-top: 10px;
}

.kfbt-month-range label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.kfbt-month-range input[type="month"] {
  min-width: 150px;
}

.kfbt-monthly-series-checks input:disabled + span,
.kfbt-monthly-series-checks label:has(input:disabled) {
  opacity: 0.55;
}

@media (max-width: 760px) {
  .kfbt-view-controls {
    grid-template-columns: 1fr;
  }
}

/* ===== series-cache UI v4 controls ===== */
.kfbt-field > span {
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
}
.kfbt-radio-field {
  min-width: 0;
}
.kfbt-radio-row-compact {
  min-height: 42px;
  align-items: center;
  padding: 7px 10px;
  border: 1px solid var(--kfbt-border);
  border-radius: 10px;
  background: #fff;
}
.kfbt-display-series-checks,
.kfbt-monthly-series-checks {
  margin-top: 10px;
}
.kfbt input[type="checkbox"],
.kfbt input[type="radio"] {
  accent-color: var(--kfbt-accent);
}

/* ===== series-cache UI v6 ===== */
.kfbt-mode-block,
.kfbt-benchmark-basis-wrap {
  display: block;
  margin-top: 16px;
}
.kfbt-mode-block {
  padding: 16px;
  border: 1px solid var(--kfbt-border);
  border-radius: 14px;
  background: #fbfdff;
}
.kfbt-mode-capital-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 240px));
  gap: 14px;
  margin-top: 12px;
}
.kfbt input[type="month"] {
  min-height: 34px;
  padding: 6px 8px;
  border: 1px solid var(--kfbt-border);
  border-radius: 8px;
  background: #fff;
  color: var(--kfbt-text);
}
.kfbt input:disabled,
.kfbt select:disabled {
  background: #f1f5f9;
  color: #94a3b8;
  cursor: not-allowed;
}
.kfbt-control-block-wide {
  grid-column: 1 / -1;
}
.kfbt-display-series-checks,
.kfbt-monthly-series-checks {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px 18px;
}
.kfbt-display-series-checks label,
.kfbt-monthly-series-checks label {
  margin: 0;
}
@media (max-width: 960px) {
  .kfbt-display-series-checks,
  .kfbt-monthly-series-checks {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 560px) {
  .kfbt-mode-capital-row,
  .kfbt-display-series-checks,
  .kfbt-monthly-series-checks {
    grid-template-columns: 1fr;
  }
}

/* ===== series-cache UI v8 ===== */
.kfbt-radio-row label.is-disabled {
  color: #94a3b8;
  cursor: not-allowed;
}
.kfbt-radio-row label.is-disabled input {
  cursor: not-allowed;
}
