/* OTOPILOT · Meta Workflow
   Swiss grid + operator console: a light map surface inside the incumbent shell. */

.mw {
  --mw-board: #f4f7fb;
  --mw-grid: rgba(53, 120, 255, .08);
  --mw-card: #ffffff;
  --mw-ink: #111827;
  --mw-muted: #667085;
  --mw-faint: #8b95a7;
  --mw-line: #d9e0ea;
  --mw-blue: #2f73ff;
  --mw-blue-soft: #e9f0ff;
  --mw-green: #13865f;
  --mw-green-soft: #e7f7ef;
  --mw-amber: #9b6500;
  --mw-amber-soft: #fff4d9;
  --mw-red: #b42318;
  --mw-red-soft: #fff0ee;
  width: 100%;
  min-width: 0;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: clip;
}

.mw,
.mw * { box-sizing: border-box; }

.mw button,
.mw select,
.mw input,
.mw textarea { min-height: 44px; }

.mw button { -webkit-tap-highlight-color: transparent; }
.mw button:disabled { cursor: default; }
.mw ::selection { background: rgba(47, 115, 255, .2); color: var(--mw-ink); }
.mw .mw-icon { width: 16px; height: 16px; flex: 0 0 auto; stroke: currentColor; stroke-width: 1.8; }

.mw-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 24px 18px;
  border-bottom: 1px solid var(--line);
}

.mw-header__copy { min-width: 0; }
.mw-header__copy h2 {
  margin: 0;
  color: var(--ink);
  font-size: 24px;
  font-weight: 760;
  letter-spacing: -.035em;
  line-height: 1.08;
}
.mw-header__copy p {
  max-width: 65ch;
  margin: 7px 0 0;
  color: var(--ink-3);
  font-size: 13px;
}

.mw-profile-field {
  display: flex;
  flex: 0 0 min(290px, 38%);
  flex-direction: column;
  gap: 5px;
}
.mw-profile-field label,
.mw-connection-editor label span,
.mw-field > span,
.mw-knowledge legend {
  color: var(--ink-3);
  font-size: 10px;
  font-weight: 760;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.mw-profile-field select,
.mw-connection-editor select,
.mw-field input,
.mw-field textarea,
.mw-field select {
  width: 100%;
  min-width: 0;
  padding: 0 12px;
  color: var(--mw-ink);
  background: var(--mw-card);
  border: 1px solid var(--mw-line);
  border-radius: 10px;
  outline: none;
}
.mw-field textarea { min-height: 86px; padding-top: 10px; padding-bottom: 10px; resize: vertical; line-height: 1.45; }
.mw-profile-field select:focus,
.mw-connection-editor select:focus,
.mw-field input:focus,
.mw-field textarea:focus { border-color: var(--mw-blue); box-shadow: 0 0 0 3px rgba(47, 115, 255, .14); }

.mw-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 18px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.mw-toolbar__left,
.mw-toolbar__actions { display: flex; align-items: center; gap: 8px; min-width: 0; }
.mw-toolbar__actions { justify-content: flex-end; flex-wrap: wrap; }
.mw-map-state,
.mw-save-state {
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
}
.mw-map-state::before,
.mw-save-state::before {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin: 0 7px 1px 0;
  content: '';
  background: var(--mw-green);
  border-radius: 50%;
}
.mw-map-state.is-dirty::before,
.mw-save-state.is-dirty::before { background: var(--warn); }
.mw-inline-warning {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--mw-amber);
  font-size: 11px;
  font-weight: 700;
}
.mw-inline-warning .mw-icon { width: 14px; height: 14px; }

.mw-btn,
.mw-link-button,
.mw-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  transition: color var(--fast), background var(--fast), border-color var(--fast), transform var(--fast);
}
.mw-btn {
  padding: 0 12px;
  color: var(--ink);
  background: var(--surface);
  font-size: 11.5px;
  font-weight: 650;
  white-space: nowrap;
}
.mw-btn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--mw-blue); }
.mw-btn:active:not(:disabled) { transform: translateY(1px); }
.mw-btn:disabled { opacity: .45; }
.mw-btn--quiet { color: var(--ink-2); border-color: transparent; background: transparent; }
.mw-btn--quiet:hover:not(:disabled) { color: var(--brand); background: var(--brand-soft); border-color: transparent; }
.mw-btn--primary { color: #fff; background: var(--mw-blue); border-color: var(--mw-blue); box-shadow: 0 5px 16px rgba(47, 115, 255, .2); }
.mw-btn--primary:hover:not(:disabled) { color: #fff; background: #1e62e8; border-color: #1e62e8; }
.mw-toolbar__rule { width: 1px; height: 25px; margin: 0 2px; background: var(--line); }

.mw-alert,
.mw-switch,
.mw-connection-editor { margin: 14px 18px 0; }
.mw-alert {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 11px 13px;
  border: 1px solid var(--mw-line);
  border-radius: 11px;
  color: var(--mw-muted);
  background: var(--mw-board);
  font-size: 12px;
}
.mw-alert .mw-icon { margin-top: 1px; }
.mw-alert--error { color: var(--mw-red); background: var(--mw-red-soft); border-color: #f2c8c3; }
.mw-alert--ok { color: var(--mw-green); background: var(--mw-green-soft); border-color: #b9e7d0; }
.mw-alert--warning { color: var(--mw-amber); background: var(--mw-amber-soft); border-color: #efd99e; }
.mw-alert--warning div { display: grid; gap: 2px; }
.mw-alert--warning strong { color: var(--mw-ink); font-size: 11px; }
.mw-alert--warning span { color: var(--mw-amber); }

.mw-switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  background: #fffaf0;
  border: 1px solid #ecd89f;
  border-radius: 12px;
  color: var(--mw-ink);
}
.mw-switch__copy { display: grid; gap: 2px; min-width: 0; }
.mw-switch__copy strong { font-size: 12px; }
.mw-switch__copy span { color: var(--mw-amber); font-size: 11.5px; }
.mw-switch__actions { display: flex; flex: 0 0 auto; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.mw-switch__actions .mw-btn { min-height: 44px; }

.mw-connection-editor {
  padding: 15px;
  background: var(--mw-board);
  border: 1px solid var(--mw-line);
  border-radius: 13px;
}
.mw-connection-editor__copy h3 { margin: 0; color: var(--mw-ink); font-size: 14px; letter-spacing: -.015em; }
.mw-connection-editor__copy p { margin: 3px 0 0; color: var(--mw-muted); font-size: 11px; }
.mw-connection-editor__fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 24px minmax(0, 1fr) minmax(140px, .8fr);
  align-items: end;
  gap: 9px;
  margin-top: 12px;
}
.mw-connection-editor__fields label { display: grid; gap: 5px; min-width: 0; }
.mw-connection-editor__arrow { display: grid; place-items: center; height: 44px; color: var(--mw-blue); }
.mw-connection-editor__arrow .mw-icon { width: 18px; height: 18px; }
.mw-connection-editor__actions { display: flex; justify-content: flex-end; gap: 7px; margin-top: 12px; }
.mw-form-error { display: flex; align-items: center; gap: 6px; margin: 10px 0 0; color: var(--mw-red); font-size: 11px; font-weight: 650; }
.mw-form-error .mw-icon { width: 14px; height: 14px; }

.mw-map-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 17px 20px 8px;
  color: var(--ink-3);
  font-size: 11px;
}
.mw-map-meta strong { color: var(--ink); font-weight: 700; }
.mw-map-meta span:last-child { font-variant-numeric: tabular-nums; }

.mw-map-shell {
  position: relative;
  min-width: 0;
  margin: 0 0 18px;
  animation: mw-map-in .42s var(--ease) both;
}
@keyframes mw-map-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.mw-map-scroll { min-width: 0; }
.mw-board {
  position: relative;
  min-height: 640px;
  padding: 20px 18px 28px;
  overflow: visible;
  background-color: var(--mw-board);
  background-image: linear-gradient(to right, var(--mw-grid) 1px, transparent 1px), linear-gradient(to bottom, var(--mw-grid) 1px, transparent 1px);
  background-size: 32px 32px;
  border-top: 1px solid var(--mw-line);
}
.mw-columns { position: relative; z-index: 2; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); align-items: start; gap: 14px; }
.mw-column { min-width: 0; }
.mw-column__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 32px; margin-bottom: 8px; padding: 0 3px; }
.mw-column__head > div { min-width: 0; }
.mw-column__label { display: block; overflow: hidden; color: #3d4655; font-size: 10px; font-weight: 800; letter-spacing: .12em; line-height: 1.3; text-overflow: ellipsis; text-transform: uppercase; white-space: nowrap; }
.mw-column__line { display: block; width: 36px; height: 2px; margin-top: 7px; background: var(--mw-blue); }
.mw-column__count { display: inline-flex; align-items: center; gap: 4px; flex: 0 0 auto; min-width: 22px; color: #697386; font-family: var(--mono); font-size: 10px; font-variant-numeric: tabular-nums; justify-content: flex-end; }
.mw-column__count em { color: #a1a9b6; font-style: normal; }
.mw-column__body { display: grid; gap: 10px; min-height: 92px; }
.mw-column__empty { display: grid; min-height: 82px; place-items: center; padding: 14px; color: #8993a3; border: 1px dashed #cbd3df; border-radius: 12px; font-size: 11px; text-align: center; }

.mw-node {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 126px;
  flex-direction: column;
  padding: 13px 13px 12px;
  color: var(--mw-ink);
  background: var(--mw-card);
  border: 1px solid #d5dce7;
  border-radius: 13px;
  box-shadow: 0 8px 22px rgba(27, 40, 64, .08);
  cursor: pointer;
  outline: none;
  transition: border-color var(--fast), box-shadow var(--fast), transform var(--fast), opacity var(--fast);
}
.mw-node:hover { border-color: #9db9f6; box-shadow: 0 11px 26px rgba(27, 40, 64, .12); transform: translateY(-1px); }
.mw-node:focus-visible { border-color: var(--mw-blue); box-shadow: 0 0 0 3px rgba(47, 115, 255, .2), 0 11px 26px rgba(27, 40, 64, .12); }
.mw-node.is-selected { border-color: var(--mw-blue); box-shadow: 0 0 0 3px rgba(47, 115, 255, .15), 0 12px 28px rgba(27, 40, 64, .13); }
.mw-node.is-dragging { opacity: .45; }
.mw-node.is-disabled { background: #f8fafc; opacity: .72; }
.mw-node.is-drop-target { border-color: var(--mw-blue); }
.mw-node__top,
.mw-node__bottom,
.mw-node__title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.mw-node__top { min-height: 17px; }
.mw-node__module,
.mw-inspector__module { overflow: hidden; color: #8a94a5; font-family: var(--mono); font-size: 9px; letter-spacing: .02em; text-overflow: ellipsis; white-space: nowrap; }
.mw-node__state { display: inline-flex; align-items: center; gap: 5px; flex: 0 0 auto; color: #697386; font-size: 9.5px; font-weight: 700; white-space: nowrap; }
.mw-node__state i { width: 6px; height: 6px; background: currentColor; border-radius: 50%; }
.mw-node--ok .mw-node__state { color: var(--mw-green); }
.mw-node--warn .mw-node__state { color: var(--mw-amber); }
.mw-node--error .mw-node__state { color: var(--mw-red); }
.mw-node__title-row { align-items: flex-start; margin-top: 9px; }
.mw-node h3 { min-width: 0; margin: 0; color: var(--mw-ink); font-size: 14px; font-weight: 760; letter-spacing: -.025em; line-height: 1.18; }
.mw-node__lock { display: inline-grid; place-items: center; flex: 0 0 auto; color: #8d98a8; }
.mw-node__lock .mw-icon { width: 13px; height: 13px; }
.mw-node__description { display: -webkit-box; overflow: hidden; margin: 7px 0 0; color: var(--mw-muted); font-size: 11px; line-height: 1.42; -webkit-box-orient: vertical; -webkit-line-clamp: 3; }
.mw-node__bottom { align-items: flex-end; min-height: 20px; margin-top: auto; padding-top: 9px; }
.mw-node__status-copy { min-width: 0; overflow: hidden; color: var(--mw-blue); font-size: 10.5px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.mw-node--ok .mw-node__status-copy { color: var(--mw-green); }
.mw-node__disabled { color: #8993a3; font-size: 10px; font-weight: 700; }
.mw-node__mobile-actions { display: none; }
.mw-edges { position: absolute; z-index: 1; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.mw-edge { fill: none; stroke: #7d899a; stroke-width: 1.7; vector-effect: non-scaling-stroke; }
.mw-edge.is-status { stroke: var(--mw-blue); stroke-dasharray: 6 6; }

.mw-inspector {
  position: absolute;
  z-index: 5;
  top: 16px;
  right: 16px;
  display: flex;
  width: min(360px, calc(100% - 32px));
  max-height: min(720px, calc(100vh - 190px));
  flex-direction: column;
  overflow: hidden auto;
  color: var(--mw-ink);
  background: var(--mw-card);
  border: 1px solid #cad5e5;
  border-radius: 16px;
  box-shadow: 0 18px 48px rgba(16, 35, 65, .2);
}
.mw-inspector__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 17px 17px 13px; border-bottom: 1px solid #e5e9f0; }
.mw-inspector__column { display: block; margin-bottom: 5px; color: var(--mw-blue); font-size: 9px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.mw-inspector h3 { margin: 0; color: var(--mw-ink); font-size: 18px; letter-spacing: -.03em; line-height: 1.15; }
.mw-close { width: 44px; padding: 0; color: #687386; background: #f5f7fa; border-color: #e0e5ed; }
.mw-close:hover { color: var(--mw-red); border-color: #edc0bb; background: var(--mw-red-soft); }
.mw-close .mw-icon { width: 17px; height: 17px; }
.mw-inspector__body { display: grid; gap: 13px; padding: 15px 17px 18px; }
.mw-inspector__summary { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mw-inspector__edit-state { display: inline-flex; align-items: center; gap: 5px; color: #7a8494; font-size: 10px; font-weight: 650; }
.mw-inspector__edit-state .mw-icon { width: 13px; height: 13px; }
.mw-inspector__description { margin: -4px 0 0; color: var(--mw-muted); font-size: 11px; line-height: 1.45; }
.mw-inspector__fields { display: grid; gap: 12px; }
.mw-field { display: grid; gap: 6px; }
.mw-field input,
.mw-field select { min-height: 44px; }
.mw-check-field { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 8px 10px; color: var(--mw-ink); background: #f7f9fc; border: 1px solid #e1e6ee; border-radius: 10px; }
.mw-check-field input { width: 18px; height: 18px; min-height: 18px; flex: 0 0 auto; accent-color: var(--mw-blue); }
.mw-check-field span { display: grid; gap: 2px; min-width: 0; }
.mw-check-field strong { font-size: 11.5px; }
.mw-check-field small { color: var(--mw-muted); font-size: 10.5px; line-height: 1.35; }
.mw-knowledge { display: grid; gap: 7px; min-width: 0; padding: 0; border: 0; }
.mw-knowledge legend { padding: 0; }
.mw-knowledge label { display: flex; align-items: center; gap: 9px; min-height: 44px; padding: 4px 8px; color: var(--mw-ink); background: #f7f9fc; border: 1px solid #e1e6ee; border-radius: 9px; font-size: 11px; }
.mw-knowledge input { width: 17px; height: 17px; min-height: 17px; accent-color: var(--mw-blue); }
.mw-readonly-field { display: grid; gap: 5px; padding-bottom: 11px; border-bottom: 1px solid #edf0f4; }
.mw-readonly-field > span { color: #7b8596; font-size: 10px; font-weight: 760; letter-spacing: .09em; text-transform: uppercase; }
.mw-readonly-field p { margin: 0; color: var(--mw-ink); font-size: 11.5px; line-height: 1.4; white-space: pre-wrap; }
.mw-empty-copy { margin: 0; color: var(--mw-muted); font-size: 11px; line-height: 1.45; }
.mw-inspector__connections { display: grid; gap: 9px; padding-top: 4px; border-top: 1px solid #e5e9f0; }
.mw-section-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mw-section-title h4 { margin: 0; color: var(--mw-ink); font-size: 11px; font-weight: 780; letter-spacing: .04em; text-transform: uppercase; }
.mw-link-button { min-height: 44px; padding: 0 9px; color: var(--mw-blue); background: var(--mw-blue-soft); border-color: transparent; font-size: 10.5px; font-weight: 750; }
.mw-link-button .mw-icon { width: 13px; height: 13px; }
.mw-edge-list { display: grid; gap: 7px; }
.mw-edge-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 7px; min-height: 40px; padding: 6px 7px 6px 9px; background: #f7f9fc; border: 1px solid #e1e6ee; border-radius: 9px; }
.mw-edge-row__route { overflow: hidden; color: var(--mw-ink); font-size: 10.5px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.mw-edge-row__route b { color: #a4adba; font-weight: 600; }
.mw-edge-row__kind { color: #657084; font-size: 9px; font-weight: 700; white-space: nowrap; }
.mw-edge-row__kind.is-status { color: var(--mw-blue); }
.mw-edge-row button { display: grid; width: 44px; min-height: 44px; place-items: center; color: #8893a3; background: transparent; border: 0; border-radius: 7px; }
.mw-edge-row button:hover { color: var(--mw-red); background: var(--mw-red-soft); }
.mw-edge-row button .mw-icon { width: 14px; height: 14px; }

.mw-loading { display: flex; align-items: center; justify-content: center; gap: 9px; min-height: 260px; padding: 24px; color: var(--ink-3); font-size: 12px; }
.mw-spinner { width: 17px; height: 17px; border: 2px solid var(--line-2); border-top-color: var(--brand); border-radius: 50%; animation: mw-spin .7s linear infinite; }
@keyframes mw-spin { to { transform: rotate(360deg); } }
.mw-state { display: grid; min-height: 300px; place-items: center; align-content: center; gap: 8px; padding: 32px 20px; text-align: center; }
.mw-state__icon { display: grid; width: 44px; height: 44px; place-items: center; color: var(--mw-blue); background: var(--mw-blue-soft); border-radius: 12px; }
.mw-state__icon .mw-icon { width: 21px; height: 21px; }
.mw-state h3 { margin: 3px 0 0; color: var(--ink); font-size: 16px; }
.mw-state p { max-width: 48ch; margin: 0; color: var(--ink-3); font-size: 12px; line-height: 1.5; }
.mw-state--error .mw-state__icon { color: var(--mw-red); background: var(--mw-red-soft); }

.mw.is-fit .mw-board { min-height: 540px; padding-top: 14px; padding-bottom: 18px; }
.mw.is-fit .mw-columns { gap: 10px; }
.mw.is-fit .mw-column__body { gap: 7px; }
.mw.is-fit .mw-node { min-height: 104px; padding: 10px; }
.mw.is-fit .mw-node h3 { font-size: 12.5px; }
.mw.is-fit .mw-node__description { margin-top: 5px; font-size: 10px; }

@media (max-width: 1080px) {
  .mw-header { align-items: stretch; flex-direction: column; gap: 15px; }
  .mw-profile-field { flex-basis: auto; max-width: 360px; }
  .mw-toolbar { align-items: flex-start; flex-direction: column; }
  .mw-toolbar__actions { justify-content: flex-start; width: 100%; }
}

@media (max-width: 760px) {
  .mw { border-radius: 13px; }
  .mw-header { padding: 20px 16px 15px; }
  .mw-header__copy h2 { font-size: 22px; }
  .mw-toolbar { padding: 10px 12px; }
  .mw-toolbar__left { width: 100%; }
  .mw-toolbar__actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .mw-toolbar__actions .mw-btn { width: 100%; padding: 0 7px; }
  .mw-toolbar__rule { display: none; }
  .mw-alert,
  .mw-switch,
  .mw-connection-editor { margin-right: 12px; margin-left: 12px; }
  .mw-switch { align-items: stretch; flex-direction: column; }
  .mw-switch__actions { justify-content: stretch; }
  .mw-switch__actions .mw-btn { flex: 1 1 130px; }
  .mw-connection-editor__fields { grid-template-columns: minmax(0, 1fr) 24px minmax(0, 1fr); }
  .mw-connection-editor__fields label:last-child { grid-column: 1 / -1; }
  .mw-map-meta { align-items: flex-start; flex-direction: column; padding: 15px 13px 8px; }
  .mw-board { min-height: 0; padding: 13px 11px 20px; background-size: 27px 27px; }
  .mw-columns { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .mw-column { padding: 10px 9px 9px; background: rgba(255, 255, 255, .72); border: 1px solid #dfe5ee; border-radius: 13px; }
  .mw-column__head { min-height: 34px; margin-bottom: 7px; padding: 0 3px; }
  .mw-column__body { gap: 8px; }
  .mw-node { min-height: 116px; padding: 12px; }
  .mw-node__mobile-actions { display: flex; align-items: center; gap: 4px; margin: 8px -3px -3px; }
  .mw-node__mobile-actions button { display: grid; width: 44px; min-height: 44px; place-items: center; color: #6d7890; background: #f3f6fb; border: 1px solid #e0e6ef; border-radius: 8px; }
  .mw-node__mobile-actions button:hover { color: var(--mw-blue); border-color: #a8c1f8; }
  .mw-node__mobile-actions .mw-icon { width: 15px; height: 15px; }
  .mw-edges { display: none; }
  .mw-inspector { position: relative; top: auto; right: auto; width: auto; max-height: none; margin: 12px 12px 0; overflow: visible; border-radius: 14px; }
  .mw.is-fit .mw-board { min-height: 0; }
}

@media (max-width: 420px) {
  .mw-header__copy p { font-size: 12px; }
  .mw-toolbar__actions { grid-template-columns: 1fr 1fr; }
  .mw-toolbar__actions .mw-btn { font-size: 10.5px; }
  .mw-connection-editor__fields { grid-template-columns: minmax(0, 1fr); }
  .mw-connection-editor__arrow { display: none; }
  .mw-connection-editor__fields label:last-child { grid-column: auto; }
}

@media (prefers-reduced-motion: reduce) {
  .mw-map-shell, .mw-spinner { animation: none; }
}
