:root {
  --pv-blue: #1060a8;
  --pv-orange: #ea9624;
  --pv-green: #609818;
  --pv-ink: #103870;
  --pv-bg: #f4f7fb;
}

body {
  margin: 0;
  background: var(--pv-bg);
  color: var(--pv-ink);
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  overflow: hidden;
}

.app-shell {
  max-width: 1520px;
  margin: 0 auto;
  padding: 0 12px 8px;
  height: 100vh;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.logo-block {
  height: 86px;
  margin-top: 0;
  margin-bottom: -4px;
  text-align: center;
}

.logo-block img {
  height: 82px;
  width: auto;
  padding-top: 0;
  object-fit: contain;
}

.panel {
  background: #fff;
  border: 1px solid #c9d7ea;
  border-radius: 10px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.03);
  padding: 12px;
  height: 100%;
  min-height: 0;
}

.wide {
  width: 100%;
}

.center {
  margin: 0 auto;
}

#dotfile {
  width: 100%;
  height: min(260px, 24vh);
  min-height: 120px;
  border: 1px solid #c9d7ea;
  border-radius: 8px;
  resize: vertical;
  padding: 10px;
  font-size: 0.92rem;
  line-height: 1.35;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

#dotfile::placeholder {
  color: #95a3b8;
  font-size: 0.8rem;
  line-height: 1.3;
}

.small-link {
  font-size: 0.85rem;
  color: var(--pv-blue);
  text-decoration: none;
  cursor: pointer;
  margin-right: 3px;
}

.small-link:hover {
  text-decoration: underline;
}

.sample-row {
  margin-bottom: 16px;
  display: block;
}

.sample-select {
  display: inline-block;
  width: 146px;
  min-height: 24px;
  margin-left: 0;
  vertical-align: middle;
  padding-top: 1px;
  padding-bottom: 1px;
  font-size: 0.875rem;
  line-height: 1.2;
}

.sample-select.is-default {
  color: #7f8ea5;
  font-style: italic;
}

.sample-select option {
  color: var(--pv-ink);
  font-style: normal;
}

.sample-row .muted {
  display: block;
  margin-bottom: 6px;
}

.sample-table {
  border-collapse: separate;
  border-spacing: 6px 6px;
}

.sample-table td {
  padding: 0;
  vertical-align: top;
}

#submit:disabled,
#submit.btn:disabled,
#submit.btn-primary:disabled {
  background: #d9e1ee;
  border-color: #bcc9db;
  color: #7c8ba3;
  opacity: 1;
  cursor: not-allowed;
  box-shadow: none;
}

.muted {
  color: #6b7d96;
  font-size: 0.88rem;
}

.stats-subpanel {
  margin-top: 14px;
  border: 1px solid #c9d7ea;
  border-radius: 8px;
  padding: 14px 10px 8px;
  background: #fbfdff;
  position: relative;
}

.stats-subpanel + .stats-subpanel {
  margin-top: 14px;
}

#drawing-stats-panel {
  height: min(196px, 22vh);
  min-height: 120px;
  overflow: visible;
}

#drawing-stats-panel .stats-scroll-body {
  height: 100%;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.stats-title {
  position: absolute;
  top: -10px;
  left: 10px;
  margin: 0;
  padding: 0 6px;
  line-height: 1.1;
  background: var(--pv-bg);
  color: var(--pv-ink);
  font-size: 0.84rem;
  font-weight: 600;
}

.stats-check {
  margin: 4px 0 0;
  font-size: 0.9rem;
  color: var(--pv-ink);
}

.stats-row-inline {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
}

.stats-value-item {
  font-size: 0.88rem;
  color: var(--pv-ink);
  font-weight: 400;
}

.stats-value-item span {
  font-weight: 400;
}

.stats-value-item-right {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.stats-plot-wrap {
  margin-top: 8px;
  border-top: 1px solid #d6e2f2;
  padding-top: 6px;
}

.stats-plot-wrap-standalone {
  margin-top: 0;
  border-top: none;
  padding-top: 0;
}

.stats-plot-wrap.is-hidden {
  display: none;
}

.stats-plot-label {
  font-size: 0.88rem;
  color: var(--pv-ink);
  font-weight: 400;
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.drawing-metric-link {
  color: var(--pv-blue);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.drawing-metric-link:hover {
  text-decoration-thickness: 2px;
}

#stats-face-plot,
#stats-edge-plot,
#stats-angle-plot {
  width: 100%;
  height: 120px;
  display: block;
  border: 1px solid #d6e2f2;
  border-radius: 6px;
  background: #fbfdff;
}

.stats-check .form-check-input[disabled] {
  opacity: 1;
}

.stats-check .form-check-input:disabled ~ .form-check-label,
.stats-check .form-check-input[disabled] ~ .form-check-label {
  color: var(--pv-ink);
  opacity: 1;
}

#cy {
  width: 100%;
  border: 1px solid #c9d7ea;
  border-radius: 8px;
  background-color: #fbfdff;
  background-image:
    linear-gradient(to right, #e9edf3 1px, transparent 1px),
    linear-gradient(to bottom, #e9edf3 1px, transparent 1px);
  background-size: 24px 24px;
}

.drawing-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.drawing-panel #cy {
  flex: 1;
  min-height: 0;
  height: auto;
  min-width: 0;
}

.layout-toolbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  justify-content: stretch;
  gap: 8px;
}

.layout-group {
  position: relative;
  border: 1px solid #c9d7ea;
  border-radius: 8px;
  padding: 14px 6px 6px;
  background: #fbfdff;
}

.layout-group-planar {
  min-width: 0;
}

.layout-group + .layout-group {
  margin-left: 0;
}

.layout-group-title {
  position: absolute;
  top: -10px;
  left: 10px;
  margin: 0;
  padding: 0 6px;
  line-height: 1.1;
  background: var(--pv-bg);
  color: var(--pv-ink);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.layout-group-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.layout-group-buttons.planar-layout-buttons {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  justify-items: center;
}

.reset-zoom-btn {
  position: absolute;
  top: 10px;
  right: 224px;
  z-index: 5;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid #9fb4cf;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.save-svg-btn {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 5;
  width: 36px;
  height: 36px;
  padding: 0;
  margin: 0;
  border: 1px solid #9fb4cf;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}

.debug-augmentation-toggle {
  position: absolute;
  top: 10px;
  left: 52px;
  z-index: 5;
  height: 36px;
  padding: 2px 8px;
  margin: 0;
  border: 1px solid #9fb4cf;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.9);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--pv-ink);
  user-select: none;
}

.augmentation-mode-toggle {
  position: absolute;
  top: 10px;
  left: 114px;
  z-index: 5;
  height: 36px;
  padding: 2px 8px;
  margin: 0;
  border: 1px solid #9fb4cf;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.9);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--pv-ink);
  user-select: none;
}

.debug-augmentation-toggle input {
  margin: 0;
}

.augmentation-mode-toggle input {
  margin: 0;
}

.debug-augmentation-toggle span {
  font-weight: 600;
}

.augmentation-mode-toggle span {
  font-weight: 600;
}

.save-svg-btn img {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  display: block;
  object-fit: contain;
}

.style-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 5;
  width: 210px;
  border: 1px solid #c9d7ea;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.08);
  padding: 3px 6px;
}

.interactive-toggle-btn {
  position: absolute;
  top: 10px;
  right: 262px;
  z-index: 5;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid #9fb4cf;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.9);
}

.interactive-toggle-btn[aria-pressed="true"] {
  background: #e5f0fb;
  border-color: #6f9dcb;
}

.interactive-toggle-btn.is-inactive {
  background: rgba(243, 246, 251, 0.92);
  border-color: #c9d7ea;
}

.align-axis-btn {
  position: absolute;
  top: 10px;
  right: 300px;
  z-index: 5;
  width: 34px;
  height: 34px;
  padding: 0;
  margin: 0;
  border: 1px solid #9fb4cf;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.align-axis-btn:disabled {
  background: rgba(243, 246, 251, 0.92);
  border-color: #c9d7ea;
  opacity: 1;
}

.align-axis-btn img {
  width: 100%;
  height: 100%;
  padding: 3px;
  margin: 0;
  display: block;
  object-fit: contain;
}

.align-axis-btn:disabled img {
  opacity: 0.45;
}

#cy-static-wrap {
  display: none;
  flex: 1;
  min-height: 0;
  min-width: 0;
  height: auto;
  border: 1px solid #c9d7ea;
  border-radius: 8px;
  background-color: #fbfdff;
  background-image:
    linear-gradient(to right, #e9edf3 1px, transparent 1px),
    linear-gradient(to bottom, #e9edf3 1px, transparent 1px);
  background-size: 24px 24px;
  overflow: hidden;
}

#cy-static-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: hidden;
}

.style-control-row {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.74rem;
  color: var(--pv-ink);
}

.style-control-row + .style-control-row {
  margin-top: 1px;
}

.style-control-row label {
  width: 34px;
  margin: 0;
}

.style-control-row input[type="range"] {
  flex: 1;
  min-width: 0;
}

.style-control-value {
  width: 26px;
  text-align: right;
  color: #5f6c80;
}

.reset-zoom-btn img,
.interactive-toggle-btn img {
  width: 100%;
  height: 100%;
  padding: 3px;
  margin: 0;
  display: block;
  object-fit: contain;
}

.interactive-toggle-btn.is-inactive img {
  opacity: 0.35;
}

.interactive-toggle-btn[aria-pressed="true"] img {
  opacity: 1;
}

#status {
  margin-top: 4px;
  min-height: 0;
  max-height: none;
  flex: 1 1 auto;
  overflow-y: auto;
  padding-right: 4px;
  color: #5f6c80;
  font-size: 0.85rem;
}

.status-entry {
  color: var(--pv-ink);
  line-height: 1.25;
}

.status-entry + .status-entry {
  margin-top: 2px;
}

.status-entry.is-error {
  color: #ba1b1b;
}

.status-panel {
  position: relative;
  height: 96px;
  max-height: 96px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: visible;
  padding-top: 14px;
  z-index: 1001;
}

.status-panel.is-collapsed {
  height: 34px;
  max-height: 34px;
  padding-top: 8px;
  padding-bottom: 8px;
}

.status-panel.is-collapsed #status {
  display: none;
}

.status-title {
  position: absolute;
  top: -8px;
  left: 14px;
  margin: 0;
  padding: 0 6px;
  line-height: 1.1;
  background: var(--pv-bg);
  color: var(--pv-ink);
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 1010;
}

.status-collapse-btn,
.status-clear-btn {
  position: absolute;
  top: 3px;
  width: 16px;
  height: 16px;
  border: 1px solid #b7c6db;
  border-radius: 4px;
  background: #f5f8fc;
  color: #4f6078;
  font-size: 10px;
  line-height: 1;
  padding: 0;
}

.status-collapse-btn {
  right: 8px;
}

.status-clear-btn {
  right: 28px;
}

.status-collapse-btn:hover,
.status-clear-btn:hover {
  background: #e9f0f9;
}

#submit.btn-primary {
  background-color: var(--pv-blue);
  border-color: var(--pv-blue);
}

#submit.btn-primary:hover,
#submit.btn-primary:focus {
  background-color: #0d5391;
  border-color: #0d5391;
}

.layout-toolbar .btn-outline-secondary {
  color: var(--pv-ink);
  border-color: #9fb4cf;
}

.layout-toolbar .layout-btn {
  width: 98px;
  min-height: 24px;
  padding-top: 1px;
  padding-bottom: 1px;
  font-size: 0.8rem;
}

.layout-toolbar .btn-outline-secondary:hover {
  color: #fff;
  background-color: var(--pv-green);
  border-color: var(--pv-green);
}

.layout-toolbar .btn-outline-secondary:disabled,
.layout-toolbar .btn-outline-secondary.disabled {
  color: #8a97ab;
  background-color: #eef2f7;
  border-color: #c8d2e0;
  border-style: dashed;
  opacity: 1;
  cursor: not-allowed;
}

.layout-toolbar .btn-outline-secondary:disabled:hover,
.layout-toolbar .btn-outline-secondary.disabled:hover {
  color: #8a97ab;
  background-color: #eef2f7;
  border-color: #c8d2e0;
}

.layout-toolbar .layout-btn.is-active,
.layout-toolbar .layout-btn.is-active:hover,
.layout-toolbar .layout-btn.is-active:focus {
  color: #fff;
  background-color: var(--pv-green);
  border-color: var(--pv-green);
}

@media (max-width: 991px) {
  .app-shell {
    padding: 0 8px 8px;
    gap: 8px;
  }
}

@media (min-width: 992px) and (max-width: 1200px) {
  .main-row .input-col {
    flex: 0 0 320px;
    width: 320px;
  }

  .style-controls {
    right: 8px;
    width: 186px;
    padding: 3px 5px;
  }

  .reset-zoom-btn {
    right: 196px;
  }

  .interactive-toggle-btn {
    right: 234px;
  }

  .align-axis-btn {
    right: 272px;
  }

  .layout-toolbar .layout-btn {
    width: 92px;
  }
}

@media (max-height: 860px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
    gap: 6px;
  }

  .logo-block {
    height: 68px;
  }

  .logo-block img {
    height: 62px;
  }

  #dotfile {
    height: min(210px, 22vh);
    min-height: 120px;
  }

  #drawing-stats-panel {
    height: min(168px, 20vh);
  }

  .status-panel {
    height: 82px;
    max-height: 82px;
  }
}

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

  .app-shell {
    height: auto;
    min-height: 100vh;
    max-width: 100%;
    padding: 6px 8px 10px;
  }

  .logo-block {
    height: 66px;
    margin-bottom: 0;
  }

  .logo-block img {
    height: 60px;
  }

  .main-row,
  .status-row {
    flex: 0 0 auto;
  }

  .main-row > section > .panel {
    overflow: visible;
  }

  #dotfile {
    height: 170px;
    min-height: 130px;
  }

  .sample-select {
    width: 100%;
  }

  .sample-table {
    width: 100%;
    border-spacing: 4px 6px;
    table-layout: fixed;
  }

  .sample-table td {
    width: 50%;
  }

  .drawing-panel {
    gap: 8px;
    overflow: visible;
  }

  .drawing-panel #cy,
  #cy-static-wrap {
    min-height: 48vh;
  }

  .save-svg-btn,
  .augmentation-mode-toggle,
  .debug-augmentation-toggle,
  .reset-zoom-btn,
  .align-axis-btn {
    height: 32px;
    top: 8px;
  }

  .save-svg-btn {
    left: 8px;
  }

  .debug-augmentation-toggle {
    left: 48px;
    padding: 2px 6px;
    font-size: 0.78rem;
  }

  .augmentation-mode-toggle {
    left: 102px;
    padding: 2px 6px;
    font-size: 0.78rem;
  }

  .reset-zoom-btn {
    right: 8px;
  }

  .interactive-toggle-btn {
    top: 8px;
    right: 46px;
    width: 32px;
    height: 32px;
  }

  .align-axis-btn {
    right: 82px;
    width: 32px;
  }

  .style-controls {
    top: 42px;
    left: 8px;
    right: 8px;
    width: auto;
    padding: 4px 6px;
  }

  .style-control-row {
    font-size: 0.76rem;
    gap: 4px;
  }

  .style-control-row label {
    width: 36px;
  }

  .layout-toolbar {
    display: flex;
    justify-content: stretch;
    gap: 10px;
    flex-wrap: wrap;
  }

  .layout-group {
    width: 100%;
    padding: 14px 6px 6px;
  }

  .layout-group-planar {
    flex: 1 1 auto;
  }

  .layout-group + .layout-group {
    margin-left: 0;
  }

  .layout-group-buttons.planar-layout-buttons {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .layout-toolbar .layout-btn {
    width: 100%;
    min-height: 28px;
  }

  #drawing-stats-panel {
    height: 180px;
  }

  .status-panel {
    height: 88px;
    max-height: 88px;
  }
}

.main-row {
  flex: 1 1 auto;
  min-height: 0;
  --bs-gutter-y: 0.35rem;
}

.main-row > section {
  display: flex;
  min-height: 0;
}

.main-row > section > .panel {
  flex: 1 1 auto;
  width: 100%;
  overflow: hidden;
}

.main-row .input-col,
.main-row .draw-col {
  min-width: 0;
}

.main-row .input-col > .panel {
  overflow-y: auto;
}

.status-row {
  flex: 0 0 auto;
  --bs-gutter-x: 0;
  --bs-gutter-y: 0;
  margin-top: 14px;
  position: relative;
  z-index: 1000;
}

.status-row > section {
  padding-top: 0;
}

@media (min-width: 992px) {
  .main-row .input-col {
    flex: 0 0 360px;
    width: 360px;
  }

  .main-row .draw-col {
    flex: 1 1 auto;
    width: auto;
  }
}
