:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --paper: #ffffff;
  --paper-2: #f9fbfb;
  --ink: #132220;
  --muted: #63716f;
  --line: #d8e2df;
  --soft: #edf5f3;
  --teal: #0b8580;
  --teal-dark: #0d4d51;
  --blue: #315fa8;
  --blue-soft: #e8effd;
  --amber: #b97816;
  --rose: #943946;
  --ok: #297a45;
  --warn: #b77417;
  --bad: #bd3041;
  --mesh: #51727d;
  --shadow: 0 18px 45px rgba(18, 32, 31, 0.10);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: linear-gradient(180deg, #fcfdfd 0%, var(--bg) 44%, #edf2f3 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
}

button,
input {
  font: inherit;
}

.topbar {
  min-height: 76px;
  padding: 13px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid rgba(18, 32, 31, 0.11);
  background: rgba(252, 253, 253, 0.92);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 15px;
  min-width: 0;
}

.brand-mark {
  position: relative;
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
  border: 2px solid var(--teal);
  border-radius: 50%;
  background:
    radial-gradient(circle at center, #fff 0 31%, transparent 32%),
    conic-gradient(from 20deg, var(--teal), var(--blue), var(--amber), var(--teal));
}

.brand-mark::after {
  content: "";
  position: absolute;
  left: 25px;
  top: -7px;
  width: 5px;
  height: 72px;
  border-radius: 99px;
  background: #3d4649;
  transform: rotate(-13deg);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.86);
}

.brand-copy {
  min-width: 0;
}

.brand-visual {
  position: relative;
  display: block;
  width: 72px;
  height: 18px;
  margin: 0 0 3px;
}

.brand-visual::before {
  content: "";
  position: absolute;
  left: 1px;
  top: 2px;
  width: 40px;
  height: 12px;
  border: 2px solid rgba(11, 133, 128, .82);
  border-bottom-width: 4px;
  border-radius: 3px;
  background: linear-gradient(90deg, rgba(49, 95, 168, .14), rgba(11, 133, 128, .08));
}

.brand-visual::after {
  content: "";
  position: absolute;
  left: 47px;
  top: 3px;
  width: 18px;
  height: 11px;
  border-radius: 8px 8px 4px 4px;
  border: 2px solid rgba(183, 120, 22, .9);
  border-bottom-color: rgba(61, 70, 73, .8);
  background: rgba(255, 255, 255, .8);
  box-shadow:
    -21px -3px 0 -5px rgba(61, 70, 73, .95),
    -14px -3px 0 -5px rgba(61, 70, 73, .95),
    -7px -3px 0 -5px rgba(61, 70, 73, .95);
}

.brand-kicker {
  display: block;
  margin-bottom: 2px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.topbar h1 {
  margin: 0;
  font-size: 21px;
  line-height: 1.05;
  letter-spacing: 0;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 11px;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 999px;
  color: var(--muted);
  white-space: nowrap;
}

.status-pill.ok {
  border-color: rgba(41, 122, 69, .28);
  background: #e9f5ed;
  color: var(--ok);
}

.status-pill.warn {
  border-color: rgba(183, 116, 23, .30);
  background: #fff3df;
  color: var(--warn);
}

.status-pill.bad {
  border-color: rgba(189, 48, 65, .28);
  background: #ffe9ec;
  color: var(--bad);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(560px, 1fr) auto;
  gap: 16px;
  padding: 16px;
  height: calc(100vh - 76px);
}

.viewer-panel,
.control-panel {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.viewer-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.quick-workflow {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  align-items: start;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--paper-2);
}

.quick-actions {
  display: grid;
  grid-template-columns: minmax(150px, .9fr) minmax(220px, 1.25fr) minmax(138px, .7fr);
  gap: 10px;
}

.quick-actions .action-main {
  min-height: 44px;
  margin: 0;
}

.quick-actions .export-action {
  border-color: rgba(49, 95, 168, .35);
  background: #eef4ff;
  color: var(--blue);
  font-weight: 800;
}

.quick-advanced {
  margin-top: 0;
}

.quick-advanced[open] {
  position: relative;
  z-index: 4;
}

.file-loader {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
  flex: 1 1 auto;
}

#fileInput,
#pairTogetherInput,
#upperPairInput,
#lowerPairInput {
  display: none;
}

#fileName,
#pairTogetherName,
#upperPairName,
#lowerPairName {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.label-tool {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper-2);
  color: var(--muted);
  white-space: nowrap;
}

.label-tool span {
  font-size: 12px;
  font-weight: 800;
  color: var(--teal-dark);
}

.label-tool input {
  width: 150px;
  min-height: 26px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 700;
}

.view-tabs,
.segmented,
.two-cols {
  display: flex;
  gap: 8px;
}

.two-cols > * {
  flex: 1;
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.tab-btn,
.seg-btn {
  min-height: 34px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: var(--paper);
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease, background .12s ease;
}

.primary-btn {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
  box-shadow: 0 8px 20px rgba(11, 133, 128, .18);
}

.secondary-btn {
  border-color: #b9c9c5;
  background: var(--soft);
  color: #173b3d;
}

.ghost-btn {
  background: transparent;
}

.tab-btn,
.seg-btn {
  min-width: 78px;
  background: var(--paper-2);
  color: var(--muted);
}

.tab-btn.active,
.seg-btn.active {
  border-color: var(--blue);
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 700;
}

button:hover,
.primary-btn:hover,
.secondary-btn:hover,
.ghost-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(18, 32, 31, 0.08);
}

button:active,
.primary-btn:active,
.secondary-btn:active,
.ghost-btn:active {
  transform: translateY(0);
}

button:disabled {
  opacity: .48;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.full {
  width: 100%;
}

.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #eef4f2;
}

#viewerCanvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}

#viewerCanvas:active {
  cursor: grabbing;
}

.cleanup-active #viewerCanvas,
.cleanup-active #viewerCanvas:active {
  cursor: crosshair;
}

.empty-state {
  position: absolute;
  inset: 24px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 7px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed #b7c7c3;
  border-radius: 8px;
  background: rgba(255, 255, 255, .54);
  pointer-events: none;
}

.empty-state strong {
  color: var(--ink);
  font-size: 18px;
}

.empty-state.hidden {
  display: none;
}

.cleanup-overlay {
  position: absolute;
  left: 18px;
  bottom: 18px;
  display: grid;
  gap: 3px;
  max-width: 300px;
  padding: 10px 12px;
  border: 1px solid rgba(11, 133, 128, .25);
  border-radius: 7px;
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 10px 28px rgba(18, 32, 31, .12);
  pointer-events: none;
}

.cleanup-overlay strong {
  color: var(--teal-dark);
}

.cleanup-overlay span {
  color: var(--muted);
  font-size: 12px;
}

.hidden {
  display: none !important;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  background: var(--paper);
}

.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  border-radius: 2px;
  vertical-align: -1px;
}

.swatch.mesh {
  background: var(--mesh);
}

.swatch.boundary {
  background: var(--bad);
}

.swatch.repaired {
  background: var(--teal);
}

.control-panel {
  width: 390px;
  overflow: auto;
}

.tools-panel {
  display: block;
  transition: width .16s ease;
}

.tools-panel:not([open]) {
  width: 126px;
  overflow: hidden;
}

.tools-toggle {
  min-height: 46px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.tools-toggle::-webkit-details-marker {
  display: none;
}

.tools-toggle::after {
  content: "Abrir";
  min-height: 28px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(11, 133, 128, .22);
  border-radius: 999px;
  background: var(--soft);
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
}

.tools-panel:not([open]) .tools-toggle::after {
  display: none;
}

.tools-panel[open] .tools-toggle {
  justify-content: space-between;
  padding: 0 14px;
}

.tools-panel[open] .tools-toggle {
  border-bottom: 1px solid var(--line);
}

.tools-panel[open] .tools-toggle::after {
  content: "Cerrar";
  background: #f7fbfa;
  color: var(--muted);
}

.tools-content {
  min-width: 390px;
}

.panel-section {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.panel-section h2 {
  margin: 0 0 12px;
  color: #103f42;
  font-size: 15px;
  letter-spacing: 0;
}

.diagnostic-section {
  padding: 0;
}

.diagnostic-section summary {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 52px;
  padding: 10px 14px;
  cursor: pointer;
  list-style: none;
}

.diagnostic-section summary::-webkit-details-marker {
  display: none;
}

.diagnostic-section summary > span {
  color: var(--teal-dark);
  font-weight: 800;
}

.diagnosis {
  min-width: 0;
  padding: 8px 10px;
  border-radius: 7px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: var(--paper-2);
  font-size: 12px;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.diagnosis.ok {
  border-color: rgba(41, 122, 69, .28);
  background: #e9f5ed;
  color: var(--ok);
}

.diagnosis.warn {
  border-color: rgba(183, 116, 23, .30);
  background: #fff3df;
  color: var(--warn);
}

.diagnosis.bad {
  border-color: rgba(189, 48, 65, .28);
  background: #ffe9ec;
  color: var(--bad);
}

.diagnostic-section[open] .diagnosis {
  white-space: normal;
}

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0;
  padding: 0 14px 14px;
}

.metrics div {
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper-2);
}

.metrics dt {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.metrics dd {
  margin: 0;
  color: var(--ink);
  font-weight: 800;
}

.hint {
  min-height: 34px;
  margin: 10px 0 12px;
  color: var(--muted);
  line-height: 1.35;
}

.compact-copy {
  min-height: 0;
  margin-top: -4px;
}

.action-main {
  min-height: 42px;
  margin-bottom: 10px;
  font-weight: 800;
}

.advanced-settings {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper-2);
}

.advanced-settings summary {
  min-height: 36px;
  padding: 9px 10px;
  cursor: pointer;
  color: var(--muted);
}

.advanced-settings[open] summary {
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  font-weight: 700;
}

.advanced-settings > label,
.advanced-settings > button {
  margin-left: 10px;
  margin-right: 10px;
}

.advanced-settings > label:first-of-type {
  margin-top: 10px;
}

.advanced-settings > button:last-child {
  margin-bottom: 10px;
}

.pair-files {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.pair-file-row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.pair-file-row .secondary-btn,
.pair-file-row .primary-btn {
  width: 100%;
}

.pair-export {
  margin-top: 12px;
}

.cleanup-tools {
  display: grid;
  gap: 9px;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper-2);
}

.cleanup-count {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 10px;
  color: var(--ink);
}

.switch-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
}

.range-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.range-row output {
  color: var(--teal);
  font-weight: 800;
}

.range-row input {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: var(--teal);
}

.pipeline-log {
  margin: 12px 0 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.45;
}

.pipeline-log li.done {
  color: var(--ok);
}

.pipeline-log li.warn {
  color: var(--warn);
}

.pipeline-log li.bad {
  color: var(--bad);
}

@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 1fr;
    height: auto;
  }

  .viewer-panel {
    min-height: 620px;
  }

  .control-panel,
  .tools-panel:not([open]) {
    width: 100%;
    overflow: visible;
  }

  .tools-content {
    min-width: 0;
  }
}

@media (max-width: 720px) {
  .topbar,
  .viewer-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .quick-workflow {
    grid-template-columns: 1fr;
  }

  .top-actions,
  .file-loader,
  .view-tabs,
  .quick-actions {
    flex-wrap: wrap;
  }

  .quick-actions {
    grid-template-columns: 1fr;
  }

  .workspace {
    padding: 10px;
  }

  .diagnostic-section summary,
  .metrics,
  .pair-file-row {
    grid-template-columns: 1fr;
  }
}
