:root {
  color-scheme: light;
  font-family: Arial, Helvetica, sans-serif;
  background: #f0f0f0;
  color: #111827;
  --inspector-width: 10%;
  --canvas-width: 90%;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
}

button,
input,
select,
textarea,
.note-editor {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
  background: #f0f0f0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  min-height: 38px;
  padding: 6px 10px;
  border-bottom: 1px solid #c6c6c6;
  background: #eeeeee;
}

.model-identity {
  text-align: right;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 15px;
  font-weight: 700;
}

h2 {
  margin-bottom: 8px;
  color: #374151;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

#model-meta {
  margin-top: 2px;
  color: #4b5563;
  font-size: 12px;
}

.save-failed-status {
  margin-top: 2px;
  color: #b91c1c;
  font-size: 12px;
  font-weight: 700;
}

.save-failed-status[hidden] {
  display: none;
}

.actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.file-button,
button {
  min-height: 26px;
  border: 1px solid #aeb6c0;
  border-radius: 3px;
  background: linear-gradient(#ffffff, #e8e8e8);
  color: #111827;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 12px;
}

.file-button input {
  display: none;
}

button:hover,
.file-button:hover {
  border-color: #6f7a85;
  background: linear-gradient(#ffffff, #dde8f6);
}

.view-tabs {
  display: flex;
  align-items: flex-end;
  gap: 0;
  min-height: 32px;
  padding: 4px 8px 0;
  border-bottom: 1px solid #aeb6c0;
  background: #e2e2e2;
  overflow-x: auto;
}

.view-tab {
  min-width: 88px;
  max-width: 190px;
  min-height: 28px;
  margin-right: -1px;
  padding: 5px 12px;
  border: 1px solid #aeb6c0;
  border-bottom-color: #aeb6c0;
  border-radius: 4px 4px 0 0;
  background: #d9d9d9;
  text-align: center;
  color: #111827;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.view-tab.active {
  position: relative;
  z-index: 1;
  border-bottom-color: #ffffff;
  background: #ffffff;
}

.editor-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(180px, var(--inspector-width)) minmax(0, var(--canvas-width));
}

.sidebar {
  grid-column: 1;
  grid-row: 1;
  overflow: auto;
  padding: 12px;
  border-right: 1px solid #c6c6c6;
  background: #f7f7f7;
}

.sidebar section + section {
  margin-top: 18px;
}

.stats {
  margin: 0;
  display: grid;
  border: 1px solid #d0d0d0;
  background: #ffffff;
  color: #111827;
  font-size: 12px;
  line-height: 1.45;
}

.stats div {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  min-height: 28px;
  padding: 6px 8px;
  border-bottom: 1px solid #eeeeee;
}

.stats div:last-child {
  border-bottom: 0;
}

.stats dt {
  color: #111827;
  font-weight: 400;
}

.stats dd {
  margin: 0;
  font-weight: 400;
}

.selection-panel {
  min-height: 126px;
  border: 1px solid #d0d0d0;
  border-radius: 0;
  padding: 0;
  background: #ffffff;
  color: #111827;
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.selection-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  min-height: 28px;
  padding: 6px 8px;
  border-bottom: 1px solid #eeeeee;
}

.selection-row span:last-child {
  text-align: right;
}

.selection-row:last-child {
  border-bottom: 0;
}

.field {
  display: grid;
  gap: 3px;
  color: #374151;
  font-size: 11px;
}

.field input,
.field select {
  min-width: 0;
  width: 100%;
  min-height: 24px;
  border: 1px solid #b8c2cc;
  border-radius: 2px;
  padding: 3px 5px;
  background: #ffffff;
  color: #111827;
  font-size: 12px;
}

.field textarea {
  min-width: 0;
  width: 100%;
  resize: vertical;
  border: 1px solid #b8c2cc;
  border-radius: 2px;
  padding: 5px;
  background: #ffffff;
  color: #111827;
  font: inherit;
  font-size: 12px;
}

.note-toolbar {
  display: flex;
  gap: 5px;
  align-items: center;
}

.note-toolbar button {
  min-width: 34px;
  min-height: 24px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 700;
}

.note-toolbar [data-note-command="italic"] {
  font-style: italic;
}

.note-editor {
  min-height: 96px;
  width: 100%;
  overflow: auto;
  border: 1px solid #b8c2cc;
  border-radius: 2px;
  padding: 5px;
  background: #ffffff;
  color: #111827;
  font-size: 12px;
  line-height: 1.35;
}

.note-editor:focus {
  outline: 2px solid #2563eb;
  outline-offset: -1px;
}

.note-editor ul,
.note-editor ol {
  margin: 4px 0 4px 22px;
  padding: 0;
}

.field output {
  color: #111827;
  font-size: 12px;
  font-weight: 700;
}

.checkbox-field {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.checkbox-field input {
  width: auto;
  min-height: 0;
}

.canvas-wrap {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #ffffff;
}

#graph {
  display: block;
  width: 100%;
  height: calc(100vh - 70px);
  min-height: 460px;
  background: #ffffff;
}

.link-path,
.link-arrow {
  fill: none;
  stroke: #374151;
  stroke-width: 2;
  stroke-linecap: round;
  cursor: pointer;
}

.placeholder-link,
.placeholder-arrow {
  fill: none;
  stroke: #9ca3af;
  stroke-width: 1.5;
  stroke-linecap: round;
  cursor: pointer;
}

.placeholder-link {
  stroke-dasharray: 6 5;
}

.link-path:hover,
.link-path.selected,
.link-arrow.selected,
.placeholder-link.selected,
.placeholder-arrow.selected {
  stroke: #2563eb;
  stroke-width: 3;
}

.link-weight,
.placeholder-label {
  fill: #6b7280;
  font-size: 9px;
  pointer-events: auto;
  cursor: pointer;
}

.placeholder-label {
  text-anchor: middle;
}

.link-handle {
  fill: #ffffff;
  stroke: #9ca3af;
  stroke-width: 1;
  cursor: pointer;
}

.link-handle.selected {
  stroke: #2563eb;
  stroke-width: 2;
}

.node {
  cursor: pointer;
  touch-action: none;
}

.node .process-box {
  width: 120px;
  height: 146px;
  rx: 0;
  stroke: #1f2937;
}

.node.selected .process-box {
  stroke: #2563eb;
  stroke-width: 3;
}

.node .process-set {
  font-size: 9px;
  font-weight: 700;
  text-anchor: end;
}

.node-icon {
  pointer-events: auto;
  cursor: default;
}

.node-icon-hit-area {
  fill: transparent;
  stroke: none;
}

.node-icon path {
  fill: none;
  stroke: #111827;
  stroke-width: 1.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.node-icon:hover path {
  stroke: #2563eb;
  stroke-width: 1.6;
}

.hyperlink-icon {
  cursor: pointer;
}

.note-tooltip {
  position: fixed;
  z-index: 20;
  max-width: 360px;
  padding: 7px 9px;
  border: 1px solid #6b7280;
  border-radius: 3px;
  background: #fffff0;
  color: #111827;
  box-shadow: 0 8px 22px rgb(0 0 0 / 0.18);
  font-size: 12px;
  line-height: 1.35;
  pointer-events: none;
  white-space: pre-wrap;
}

.note-tooltip[hidden] {
  display: none;
}

.process-dialog {
  width: min(980px, calc(100vw - 48px));
  border: 1px solid #9ca3af;
  border-radius: 3px;
  padding: 0;
  background: #f7f7f7;
  color: #111827;
  box-shadow: 0 18px 48px rgb(0 0 0 / 0.25);
}

.settings-dialog,
.server-dialog {
  width: min(340px, calc(100vw - 48px));
  border: 1px solid #9ca3af;
  border-radius: 3px;
  padding: 0;
  background: #f7f7f7;
  color: #111827;
  box-shadow: 0 18px 48px rgb(0 0 0 / 0.25);
}

.process-dialog::backdrop,
.settings-dialog::backdrop,
.server-dialog::backdrop {
  background: rgb(17 24 39 / 0.28);
}

.process-dialog form,
.settings-dialog form,
.server-dialog form {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.server-dialog {
  width: min(520px, calc(100vw - 48px));
}

.server-model-list {
  max-height: 300px;
  overflow: auto;
  border: 1px solid #d0d0d0;
  background: #ffffff;
}

.server-model-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: center;
  min-height: 32px;
  padding: 7px 8px;
  border-bottom: 1px solid #eeeeee;
  font-size: 12px;
}

.server-model-row:last-child {
  border-bottom: 0;
}

.server-model-row input {
  margin: 0;
}

.dialog-status {
  min-height: 18px;
  color: #374151;
  font-size: 12px;
}

.dialog-header {
  margin: -14px -14px 2px;
  padding: 8px 12px;
  border-bottom: 1px solid #c6c6c6;
  background: #eeeeee;
}

.dialog-header h2 {
  margin: 0;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin: 4px 0 0;
  padding: 0;
}

.dialog-actions button:disabled {
  color: #9ca3af;
  cursor: default;
  opacity: 0.65;
}

.evidence-field {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 12px;
  align-items: start;
  color: #374151;
  font-size: 12px;
}

.evidence-disabled {
  opacity: 0.48;
}

.evidence-slider {
  display: grid;
  gap: 12px;
  padding: 8px 12px 24px;
}

.slider-values {
  text-align: center;
  color: #111827;
  font-size: 15px;
}

.slider-track {
  position: relative;
  height: 52px;
  border: 2px solid #111827;
  background: #ffffff;
}

.slider-green,
.slider-white,
.slider-red {
  position: absolute;
  top: 0;
  bottom: 0;
}

.slider-green {
  left: 0;
  background: #00a03a;
}

.slider-white {
  background: #ffffff;
}

.slider-red {
  background: #f00;
}

.slider-handle {
  position: absolute;
  top: -34px;
  width: 2px;
  height: 78px;
  min-height: 0;
  padding: 58px 0 0;
  border: 0;
  border-radius: 0;
  background: #111827;
  color: #111827;
  font-size: 12px;
  transform: translateX(-1px);
}

.slider-handle::before {
  content: "";
  position: absolute;
  top: 0;
  left: -7px;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 13px solid #111827;
}

.slider-handle:disabled {
  cursor: default;
}

.judgement-grid {
  display: grid;
  grid-template-columns: minmax(160px, 1.1fr) repeat(5, minmax(112px, 1fr));
  gap: 4px;
  align-items: stretch;
}

.judgement-corner,
.judgement-header,
.judgement-row-header {
  color: #111827;
  font-size: 12px;
}

.judgement-header {
  text-align: center;
  font-weight: 700;
}

.judgement-row-header {
  display: flex;
  align-items: center;
}

.judgement-cell {
  position: relative;
  min-height: 34px;
  border: 1px solid #111827;
  border-radius: 0;
  background:
    linear-gradient(
      90deg,
      #00a03a 0 calc(var(--sn) * 100%),
      #ffffff calc(var(--sn) * 100%) calc(var(--sp) * 100%),
      #f00 calc(var(--sp) * 100%) 100%
    );
  color: #111827;
  font-weight: 700;
}

.judgement-cell.selected {
  outline: 3px solid #2563eb;
  outline-offset: -3px;
}

.connector {
  width: 12px;
  height: 12px;
  fill: #d1d5db;
  stroke: #6b7280;
  stroke-width: 1;
}

.node text {
  pointer-events: none;
  fill: #111827;
  font-size: 10px;
}

.node .node-id {
  font-size: 9px;
}

.node .node-label {
  font-size: 10px;
  font-weight: 700;
  text-anchor: middle;
}

.flag-outline {
  fill: none;
  stroke: #111827;
  stroke-width: 1;
}

.flag-green {
  fill: #159947;
}

.flag-white {
  fill: #ffffff;
}

.flag-red {
  fill: #d93025;
}

.evidence-marker {
  font-size: 10px;
  font-weight: 700;
  text-anchor: middle;
}

.interval-text {
  font-size: 9px;
  text-anchor: middle;
}

@media (max-width: 780px) {
  body {
    overflow: auto;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .editor-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }

  .sidebar {
    grid-column: 1;
    grid-row: 2;
    max-height: 38vh;
    border-right: 0;
    border-top: 1px solid #c6c6c6;
  }

  .canvas-wrap {
    grid-column: 1;
    grid-row: 1;
  }

  #graph {
    height: 58vh;
    min-height: 360px;
  }
}
