:root {
      --panel-bg: #f1f1f1;
      --panel-border: #d0d0d0;
      --button-bg: #f7f7f7;
      --button-border: #c5c5c5;
      --text-muted: #666;
      --disabled-bg: #f5f5f5;
      --disabled-text: #9a9a9a;
    }

    body {
      margin: 0;
      font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
      background: #ffffff;
      color: #111;
    }

    .page {
      display: grid;
      grid-template-columns: 300px 1fr 170px;
      min-height: 100vh;
    }

    .left-panel,
    .right-panel {
      background: var(--panel-bg);
      border-right: 1px solid var(--panel-border);
      box-sizing: border-box;
      padding: 7px 8px;
    }

    .right-panel {
      border-right: none;
      border-left: 1px solid var(--panel-border);
    }

    .center-panel {
      background: #ffffff;
      box-sizing: border-box;
      padding: 8px 12px;
      display: flex;
      flex-direction: column;
      min-width: 0;
    }

    .app-header {
      display: grid;
      grid-template-columns: 1fr auto 1fr;
      align-items: center;
      column-gap: 16px;
      min-height: 54px;
      margin-bottom: 4px;
      padding: 2px 4px 7px;
      border-bottom: 1px solid #e1e1e1;
      box-sizing: border-box;
    }

    .app-header-spacer {
      grid-column: 1;
    }

    .app-title-block {
      grid-column: 2;
      text-align: center;
      white-space: nowrap;
    }

    .app-name {
      font-size: 26px;
      line-height: 1.05;
      font-weight: 700;
      letter-spacing: 0.2px;
      color: #202124;
    }

    .app-subtitle {
      margin-top: 3px;
      font-size: 14px;
      line-height: 1.2;
      font-weight: 400;
      color: #666a70;
    }

    .app-status {
      grid-column: 3;
      justify-self: end;
      align-self: center;
      max-width: 260px;
      margin: 0;
      text-align: right;
      line-height: 1.3;
    }

    .application-footer {
      display: grid;
      grid-template-columns: 1fr auto 1fr;
      align-items: center;
      gap: 12px;
      margin-top: 8px;
      padding: 8px 4px 2px;
      border-top: 1px solid #dcdcdc;
      box-sizing: border-box;
      font-size: 12px;
      color: #686c72;
    }

    .footer-contact {
      grid-column: 2;
      text-align: center;
      white-space: nowrap;
    }

    .footer-label {
      font-weight: 600;
      color: #4b4f54;
    }

    .footer-separator {
      margin: 0 6px;
      color: #a0a4a8;
    }

    .application-footer a {
      color: #376da3;
      text-decoration: none;
    }

    .application-footer a:hover,
    .application-footer a:focus {
      text-decoration: underline;
    }

    .footer-version {
      grid-column: 3;
      justify-self: end;
      white-space: nowrap;
      color: #8a8e93;
    }

    .step-section,
    .tool-section {
      border-top: 1px solid #cfcfcf;
      padding-top: 8px;
      margin-top: 7px;
    }

    .step-section:first-of-type,
    .tool-section:first-of-type {
      border-top: none;
      padding-top: 0;
      margin-top: 0;
    }

    .step-title,
    .tool-title {
      font-weight: 700;
      font-size: 14px;
      margin-bottom: 7px;
      text-align: center;
    }
    .step-title {
      font-size: 13px;
      margin-bottom: 6px;
   }

    .step-title-row {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 6px;
      margin-bottom: 7px;
    }

    .help-btn {
      width: 20px;
      height: 20px;
      min-width: 20px;
      border-radius: 50%;
      padding: 0;
      font-size: 13px;
      font-weight: 700;
      line-height: 1;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      background: #fafafa;
    }

    label {
      display: block;
      font-size: 12px;
      margin: 4px 0 2px;
    }

    .sub-label {
      font-size: 11px;
      color: var(--text-muted);
      margin-bottom: 1px;
    }

    input, select, button {
      box-sizing: border-box;
      border-radius: 4px;
      border: 1px solid var(--button-border);
      font-size: 12px;
      padding: 5px 7px;
      background: #fff;
    }

    input, select { width: 100%; }

    button {
      width: 100%;
      background: var(--button-bg);
      cursor: pointer;
    }

    .row-2 {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 8px;
    }

    .compact-row {
      display: grid;
      grid-template-columns: 1.2fr 1fr;
      gap: 6px;
      align-items: center;
      margin-bottom: 4px;
    }

    .compact-row label {
      margin: 0;
      font-size: 12px;
    }

    .gamma-block {
      margin-bottom: 5px;
    }

    .component-grid {
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      gap: 6px;
      margin-top: 6px;
    }

    .component-tile {
      position: relative;
      border: 1px solid #d4d4d4;
      background: #f7f7f7;
      height: 50px;
      border-radius: 4px;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      user-select: none;
      padding: 3px;
      overflow: hidden;
    }

    .component-tile.active {
      border: 2px solid #888;
      background: #ececec;
      box-shadow: inset 0 0 0 1px #f8f8f8;
    }

    .component-tile.disabled {
      opacity: 0.45;
      cursor: not-allowed;
    }

    .component-tile img {
      max-width: 72%;
      max-height: 72%;
      display: block;
      object-fit: contain;
      pointer-events: none;
    }

    .component-tile .fallback-label {
      font-size: 10px;
      text-align: center;
      line-height: 1.15;
      padding: 2px;
    }

    .tile-help-btn {
      position: absolute;
      top: 3px;
      right: 3px;
      width: 16px;
      height: 16px;
      min-width: 16px;
      border-radius: 4px;
      padding: 0;
      font-size: 10px;
      font-weight: 700;
      line-height: 1;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      background: rgba(255,255,255,0.92);
      z-index: 2;
    }

    .small-note {
      font-size: 11px;
      color: var(--text-muted);
      line-height: 1.35;
      margin-top: 8px;
    }

    .tool-item {
      display: flex;
      align-items: center;
      gap: 8px;
      margin: 10px 0;
      font-size: 13px;
    }

    .tool-item input[type="checkbox"] {
      width: 14px;
      height: 14px;
      margin: 0;
    }

    .tool-btn {
      margin-top: 10px;
    }

    .chart-wrap {
      flex: 1;
      display: flex;
      flex-direction: column;
      min-height: 0;
    }

    .chart-summary {
      font-size: 13px;
      color: var(--text-muted);
      margin: 4px 0 10px;
      text-align: center;
    }

    .chart-box {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: center;
      min-height: 660px;
      overflow: auto;
    }

    #chart {
      width: 880px;
      max-width: 100%;
      height: auto;
    }

    svg {
      display: block;
      background: #fff;
    }

    details {
      margin-top: 10px;
    }

    details summary {
      cursor: pointer;
      font-size: 12px;
      color: #444;
    }

    pre {
      margin: 8px 0 0;
      max-height: 220px;
      overflow: auto;
      background: #fff;
      border: 1px solid #ddd;
      border-radius: 4px;
      padding: 8px;
      font-size: 11px;
      line-height: 1.35;
      white-space: pre-wrap;
      word-break: break-word;
    }

    .status-line {
      font-size: 12px;
      color: var(--text-muted);
      text-align: center;
      margin-top: 6px;
      min-height: 16px;
    }

    .status-error { color: #b00020; }
    .status-ok { color: #1b5e20; }

    .section-disabled {
      opacity: 0.6;
    }

    .section-disabled input,
    .section-disabled select,
    .section-disabled button {
      background: var(--disabled-bg);
      color: var(--disabled-text);
      cursor: not-allowed;
    }



    .chart-point-clickable {
      cursor: pointer;
    }

    .point-editor-grid {
      display: grid;
      grid-template-columns: 140px 1fr;
      gap: 8px 10px;
      align-items: center;
    }

    .point-editor-grid label {
      margin: 0;
      font-size: 12px;
    }

    .point-editor-grid input {
      width: 100%;
    }

    .point-editor-note {
      font-size: 12px;
      color: var(--text-muted);
      margin-top: 4px;
    }
    .modal-backdrop {
      position: fixed;
      inset: 0;
      background: rgba(0, 0, 0, 0.25);
      display: none;
      align-items: center;
      justify-content: center;
      z-index: 1000;
    }

    .modal-backdrop.show {
      display: flex;
    }

    .modal {
      width: 520px;
      max-width: calc(100vw - 40px);
      background: #ffffff;
      border: 1px solid #cfcfcf;
      border-radius: 8px;
      box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
      overflow: hidden;
    }

    .modal-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 12px 16px;
      background: #f5f5f5;
      border-bottom: 1px solid #dddddd;
      font-size: 14px;
      font-weight: 700;
    }

    .modal-close {
      width: 28px;
      height: 28px;
      min-width: 28px;
      padding: 0;
      border-radius: 4px;
      font-size: 16px;
      background: #fff;
    }

    .modal-body {
      display: grid;
      grid-template-columns: 48px 1fr;
      gap: 14px;
      padding: 18px 18px 10px;
      font-size: 13px;
      line-height: 1.45;
    }

    .modal-icon {
      width: 42px;
      height: 42px;
      border-radius: 50%;
      background: #1e88e5;
      color: #fff;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 28px;
      font-weight: 700;
    }

    .modal-footer {
      padding: 0 18px 18px;
      display: flex;
      justify-content: flex-end;
    }

    .modal-ok {
      width: 88px;
    }


    #pointEditorModal {
      background: transparent;
      display: none;
      position: fixed;
      inset: 0;
      pointer-events: none;
      z-index: 1100;
    }

    #pointEditorModal.show {
      display: block;
    }

    #pointEditorModal .modal {
      position: fixed;
      width: 300px;
      max-width: 300px;
      pointer-events: auto;
    }

    .point-editor-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 8px 10px;
      align-items: center;
    }

    .point-editor-grid label {
      margin: 0;
      font-size: 12px;
    }

    .point-editor-note {
      margin-top: 8px;
      font-size: 12px;
      color: var(--text-muted);
      line-height: 1.35;
    }

    .readonly-field {
      background: #f3f3f3 !important;
      color: #555;
      cursor: default;
    }


    .chart-point-draggable {
      cursor: grab;
    }

    .chart-point-dragging {
      cursor: grabbing !important;
    }


    #labelLayer, #labelLayer text, #labelLayer tspan {
      pointer-events: none;
      user-select: none;
    }

    .chart-point-dragging,
    .chart-point-dragging * {
      user-select: none !important;
      cursor: grabbing !important;
    }


    .hybrid-hidden-locus {
      pointer-events: none;
    }

    .hybrid-preview-point {
      pointer-events: none;
    }


    #guideLayer,
    .guide-overlay-image {
      pointer-events: none;
      user-select: none;
    }

/* User Guide button highlight */
.user-guide-btn {
  background-color: #f2f6ff;
  font-weight: 600;
  border: 1px solid #ccd6f6;
}

.user-guide-btn:hover {
  background-color: #e6edff;
}



/* Matching Report toolbox modal */
.matching-circuit-dialog {
  width: 760px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 40px);
  resize: both;
  overflow: auto;
}

.matching-circuit-body {
  padding: 14px 18px 8px;
  font-size: 13px;
  line-height: 1.4;
}

.matching-circuit-note {
  margin-bottom: 14px;
  color: #222;
  font-weight: 700;
}

.matching-circuit-schematic,
.matching-report-chart {
  padding: 12px;
  margin-bottom: 14px;
  border: 1px solid #dddddd;
  border-radius: 2px;
  box-sizing: border-box;
  background: #f8f8f8;
}

.matching-circuit-schematic {
  width: 100%;
  height: 224px;
  min-width: 260px;
  max-width: 100%;
  resize: horizontal;
  overflow-x: auto;
  overflow-y: hidden;
  background: #ffffff;
}

.matching-schematic-svg {
  display: block;
  width: auto;
  height: 198px;
  margin: 0;
}

.schem-wire,
.schem-symbol {
  stroke: #222222;
  stroke-width: 1.6;
  fill: none;
  vector-effect: non-scaling-stroke;
}

.schem-box {
  fill: #ffffff;
  stroke: #222222;
  stroke-width: 1.4;
}

.schem-node {
  fill: #222222;
}

.schem-open-end {
  stroke: #222222;
  stroke-width: 1.6;
  fill: none;
}

.matching-report-chart {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 0;
  height: 300px;
  max-height: 300px;
  overflow: hidden;
  background: #ffffff;
}

.matching-report-chart #chart,
.matching-report-chart-svg {
  display: block;
  width: 340px;
  max-width: 100%;
  height: auto;
  background: #ffffff;
}

.matching-chart-empty {
  color: #666666;
  padding: 12px;
}

.matching-circuit-footer {
  padding-top: 0;
  gap: 10px;
}

.matching-report-save {
  width: 120px;
}


/* Compact left-panel adjustment for laptop-height screens.
   Keeps Step 1 note, but removes the longer Step 2 explanatory note. */
#step2Section .small-note {
  display: none;
}


@media (max-width: 1050px) {
  .app-header {
    grid-template-columns: 1fr;
    row-gap: 5px;
  }

  .app-header-spacer {
    display: none;
  }

  .app-title-block,
  .app-status {
    grid-column: 1;
    justify-self: center;
    text-align: center;
  }

  .app-status {
    max-width: none;
  }

  .application-footer {
    grid-template-columns: 1fr;
    row-gap: 4px;
  }

  .footer-contact,
  .footer-version {
    grid-column: 1;
    justify-self: center;
    text-align: center;
  }
}

@media (max-height: 760px) {
  .left-panel {
    padding-top: 5px;
    padding-bottom: 5px;
  }

  .step-section {
    padding-top: 6px;
    margin-top: 6px;
  }

  .step-title,
  .tool-title {
    margin-bottom: 5px;
  }

  .component-grid {
    gap: 5px;
  }

  .component-tile {
    height: 46px;
  }
}
