.fkm {
  --fkm-green: #315d48;
  --fkm-muted: #687a70;
  --fkm-border: #cbd5c8;
  --fkm-paper: #fffefa;
  --fkm-bg: #f7f7f1;
  color: #284338;
  max-width: 1560px;
  padding-bottom: 80px;
}

.fkm button,
.fkm select,
.fkm input { font: inherit; }
.fkm button { cursor: pointer; }
.fkm button:focus-visible,
.fkm input:focus-visible,
.fkm select:focus-visible,
.fkm summary:focus-visible { outline: 3px solid #a263db; outline-offset: 3px; }
.fkm [hidden] { display: none !important; }

.fkm-header {
  display: flex;
  min-width: 0;
  max-width: 100%;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin: 28px 0 20px;
}
.fkm-header h1 { margin: 2px 0; font-size: 30px; }
.fkm-eyebrow,
.fkm-section-label { color: var(--fkm-muted); font-size: 12px; letter-spacing: .08em; margin: 0; }
.fkm-header > * { min-width: 0; max-width: 100%; }
.fkm-source-controls { display: grid; gap: 8px; width: min(560px, 55vw); }
.fkm-source-filter { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: var(--fkm-muted); }
.fkm-source-label { display: grid; grid-template-columns: minmax(0, 1fr); gap: 5px; width: 100%; min-width: 0; max-width: 100%; font-size: 13px; font-weight: 650; }
.fkm-source-label select { box-sizing: border-box; width: 100%; min-width: 0; max-width: 100%; }
.fkm-source-label select,
.fkm-search-results,
.fkm-toolbar input {
  border: 1px solid var(--fkm-border);
  border-radius: 8px;
  background: white;
  color: inherit;
  padding: 9px 11px;
}

.fkm-confirmation {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(310px, 520px);
  gap: 28px;
  align-items: center;
  border: 1px solid #dccfad;
  border-radius: 11px;
  background: #fbf6e8;
  padding: 20px 24px;
  margin: 18px 0;
}
.fkm-confirmation h2 { font-size: 21px; margin: 5px 0; }
.fkm-confirm-actions { text-align: right; }
.fkm-warning { color: #735c25; font-size: 13px; margin: 0 0 12px; text-align: left; }
.fkm-primary,
.fkm-toolbar button,
.fkm-link-button,
.fkm-panel button,
.fkm-outline button,
.fkm-search-results button {
  border: 1px solid #bdcbbb;
  border-radius: 8px;
  background: white;
  color: inherit;
  padding: 7px 12px;
}
.fkm-primary { background: var(--fkm-green); border-color: var(--fkm-green); color: white; font-weight: 650; }
.fkm-primary:disabled { cursor: not-allowed; opacity: .55; }
.fkm-link-button { color: var(--fkm-green); padding: 4px 8px; font-size: 13px; }

.fkm-run { display: flex; align-items: center; gap: 10px; margin: 16px 0; }
.fkm-status { border-radius: 999px; padding: 5px 12px; background: #ecefe9; font-size: 13px; font-weight: 650; }
.fkm-status[data-tone="working"] { background: #e8eef7; color: #345c88; display: inline-flex; align-items: center; gap: 7px; }
.fkm-status[data-tone="working"]::before {
  content: '';
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: fkm-spin .8s linear infinite;
}
@keyframes fkm-spin { to { transform: rotate(360deg); } }
.fkm-primary[aria-busy="true"] { opacity: .8; }
.fkm-status[data-tone="success"] { background: #e4f1e7; color: #2e6446; }
.fkm-status[data-tone="warning"] { background: #f5ecd4; color: #785f22; }
.fkm-status[data-tone="error"] { background: #f9e7e3; color: #934638; }
.fkm-meta { color: var(--fkm-muted); font-size: 12px; }
.fkm-alert { border-radius: 8px; padding: 10px 13px; margin: 10px 0; font-size: 13px; }
.fkm-alert.is-warning { background: #f7efd8; color: #725b22; }
.fkm-alert.is-error { background: #fff0ec; color: #9b4133; }
.fkm-alert.is-info { background: #e8eef7; color: #345c88; }
.fkm-map { transition: opacity .3s ease; }
.fkm-map.is-regenerating { opacity: .6; }

.fkm-limitation { border: 1px solid #d8c9a1; border-left: 4px solid #9a7d32; border-radius: 9px; background: #fffaf0; padding: 16px 20px; margin: 18px 0; }
.fkm-limitation h2 { margin: 0; font-size: 18px; }
.fkm-limitation-item { border-top: 1px solid #e7ddc4; padding: 11px 0; }

.fkm-map-heading {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 20px;
  border: 1px solid #b6c9b8;
  border-top: 4px solid var(--fkm-green);
  border-radius: 10px;
  background: var(--fkm-paper);
  padding: 19px 24px;
  margin: 22px 0 16px;
}
.fkm-map-heading h2 { margin: 5px 0; font-size: 21px; }
.fkm-map-notes p { margin: 7px 0 0; color: #715f34; font-size: 12px; }
.fkm-map-limitations { margin-top: 7px; }
.fkm-map-limitations summary { cursor: pointer; color: #715f34; font-size: 12px; }
.fkm-toolbar { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin: 14px 0; }
.fkm-toolbar label { display: grid; gap: 4px; min-width: min(430px, 50vw); font-size: 12px; font-weight: 650; }
.fkm-toolbar-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.fkm-font-controls { display: inline-flex; align-items: center; gap: 8px; }
.fkm-font-controls span { min-width: 2ch; text-align: center; }
.fkm-font-controls button:disabled { cursor: not-allowed; opacity: .55; }
.fkm-search-results { margin: -5px 0 12px; max-width: 600px; }
.fkm-search-results ul { list-style: none; margin: 0; padding: 0; }
.fkm-search-results button { width: 100%; text-align: left; border: 0; }

.fkm-relations { display: flex; flex-wrap: wrap; gap: 14px; border: 0; margin: 8px 0; padding: 0; font-size: 13px; }
.fkm-relations legend { float: left; margin-right: 14px; font-weight: 650; }
.fkm-legend { display: flex; flex-wrap: wrap; gap: 9px 16px; color: var(--fkm-muted); font-size: 11px; margin: 10px 0; }
.fkm-legend span { display: inline-flex; align-items: center; gap: 5px; }
.fkm-legend i { display: inline-block; width: 32px; height: 0; border-top: 2px solid; }
.fkm-legend .is-structure { border-color: #a7b3a7; }
.fkm-legend .is-flow { border-color: #8a702c; border-top-style: dashed; }
.fkm-legend .is-support { border-color: #397858; border-top-style: dashed; }
.fkm-legend .is-inference { border-color: #35689a; }
.fkm-legend .is-contrast { border-color: #ae692c; border-top-style: dotted; }
.fkm-legend .fkm-swatch { width: 14px; height: 14px; border: 2px solid; border-radius: 4px; }
.fkm-swatch[data-stage="针对"], .fkm-stage[data-stage="针对"] { border-color: #8a4b2c; background: #f9eee7; color: #8a4b2c; }
.fkm-swatch[data-stage="根源"], .fkm-stage[data-stage="根源"] { border-color: #7a3f7a; background: #f4e9f4; color: #7a3f7a; }
.fkm-swatch[data-stage="绝对"], .fkm-stage[data-stage="绝对"] { border-color: #2f6b4f; background: #e6f1ea; color: #2f6b4f; }
.fkm-swatch[data-stage="应对"], .fkm-stage[data-stage="应对"] { border-color: #2a5680; background: #e7eef7; color: #2a5680; }
.fkm-branch-badge { background: #eee8f4; color: #69507e; border-radius: 5px; padding: 2px 7px; font-weight: 500; }

.fkm-workspace { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: start; }
.fkm-graph-column { min-width: 0; }
.fkm-graph { height: 690px; width: 100%; border: 1px solid var(--fkm-border); border-radius: 11px; background: #fcfcf7; overflow: hidden; }
.fkm-panel { min-height: 240px; max-height: 690px; overflow: auto; border: 1px solid var(--fkm-border); border-radius: 11px; background: var(--fkm-paper); padding: 18px; }
.fkm-panel .fkm-meta .fkm-link-button {
  display: inline;
  border: 0;
  border-radius: 0;
  background: none;
  padding: 0;
  font-size: inherit;
  color: var(--fkm-green);
  text-decoration: underline;
}
.fkm-panel h2 { font-size: 19px; line-height: 1.6; margin: 4px 0 10px; }
.fkm-panel h3 { margin: 18px 0 7px; font-size: 15px; }
.fkm-panel-section { border-top: 1px solid #dde3d9; padding-top: 10px; margin-top: 12px; }
.fkm-panel-item { border-left: 3px solid #d1d9ce; padding: 7px 0 7px 10px; margin: 8px 0; font-size: 13px; }
.fkm-panel-item button { display: block; text-align: left; margin-top: 5px; }
.fkm-stage { display: inline-block; background: #e9efe8; border: 1px solid transparent; border-radius: 999px; padding: 3px 9px; color: #476454; font-size: 11px; font-weight: 650; }
.fkm-evidence { border-top: 1px solid #dde3d9; margin-top: 12px; padding-top: 8px; }
.fkm-evidence summary { cursor: pointer; font-size: 13px; }
.fkm-evidence-line { border-left: 2px solid #cad7c8; padding-left: 10px; margin: 10px 0; font-size: 13px; }
.fkm-evidence-line small { display: block; color: #7b8980; font-size: 10px; }
.fkm-outline { margin-top: 20px; border: 1px solid var(--fkm-border); border-radius: 10px; background: var(--fkm-paper); padding: 15px 18px; }
.fkm-outline ol { margin: 8px 0 8px 20px; padding: 0; }
.fkm-outline li { margin: 7px 0; }
.fkm-outline button { text-align: left; }

.fkm-map.is-fullscreen { position: fixed; inset: 0; z-index: 1000; display: flex; flex-direction: column; margin: 0; padding: 12px 16px; background: var(--fkm-bg); overflow: hidden; }
.fkm-map.is-fullscreen .fkm-map-heading,
.fkm-map.is-fullscreen .fkm-outline { display: none; }
.fkm-map.is-fullscreen .fkm-toolbar { margin: 0 0 8px; }
.fkm-map.is-fullscreen .fkm-workspace { flex: 1; min-height: 0; margin-top: 8px; align-items: stretch; grid-template-rows: minmax(0, 1fr); }
.fkm-map.is-fullscreen .fkm-graph-column { display: flex; flex-direction: column; min-height: 0; }
.fkm-map.is-fullscreen .fkm-graph { flex: 1; height: auto; min-height: 0; }
.fkm-map.is-fullscreen .fkm-panel { max-height: none; min-height: 0; }
.fkm-map.is-panel-hidden .fkm-workspace { grid-template-columns: minmax(0, 1fr); }

@media (max-width: 950px) {
  .fkm-workspace { grid-template-columns: minmax(0, 1fr) 300px; }
}

@media (max-width: 850px) {
  .fkm-header,
  .fkm-map-heading,
  .fkm-toolbar { align-items: stretch; flex-direction: column; }
  .fkm-source-controls,
  .fkm-source-label,
  .fkm-toolbar label { min-width: 0; width: 100%; }
  .fkm-confirmation { grid-template-columns: 1fr; gap: 10px; padding: 17px; }
  .fkm-confirm-actions { text-align: left; }
  .fkm-workspace { grid-template-columns: 1fr; }
  .fkm-graph { height: 520px; }
  .fkm-panel { max-height: none; }
  .fkm-map.is-fullscreen .fkm-workspace { grid-template-rows: minmax(0, 3fr) minmax(0, 2fr); }
  .fkm-map.is-fullscreen.is-panel-hidden .fkm-workspace { grid-template-rows: minmax(0, 1fr); }
  .fkm-map.is-fullscreen .fkm-legend,
  .fkm-map.is-fullscreen .fkm-search-results,
  .fkm-map.is-fullscreen .fkm-toolbar label { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .fkm * { scroll-behavior: auto !important; transition: none !important; }
  .fkm-status[data-tone="working"]::before { animation: none; border-right-color: currentColor; opacity: .55; }
}
