:root {
  color-scheme: light;
  --ink: #172126;
  --muted: #647077;
  --line: #d9dfe2;
  --surface: #ffffff;
  --surface-soft: #f4f6f6;
  --canvas: #e9edee;
  --brand: #e84f35;
  --brand-dark: #bd3420;
  --teal: #087e78;
  --green: #248457;
  --blue: #2377b9;
  --amber: #b56f09;
  --red: #c93a43;
  --shadow: 0 10px 24px rgb(25 40 46 / 10%);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--surface-soft);
  color: var(--ink);
  font-family: "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 62px;
  padding: 0 22px;
  background: var(--ink);
  color: #fff;
  border-bottom: 3px solid var(--brand);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  background: var(--brand);
  color: #fff;
  font-size: 19px;
  font-weight: 900;
  transform: skew(-8deg);
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 21px;
  line-height: 1;
}

.brand span {
  margin-top: 4px;
  color: #bec8cc;
  font-size: 11px;
}

.topbar-actions,
.workflow-actions,
.file-control,
.file-meta,
.status-copy,
.progress-wrap,
.drawing-toolbar,
.zoom-controls,
.drawing-note,
.result-actions {
  display: flex;
  align-items: center;
}

.topbar-actions {
  gap: 10px;
}

.demo-badge {
  padding: 5px 8px;
  border: 1px solid #536268;
  color: #dbe2e5;
  font-size: 11px;
}

.icon-button {
  display: inline-grid;
  width: 34px;
  height: 34px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.topbar .icon-button {
  border-color: #526168;
  background: transparent;
  color: #fff;
}

.app-shell {
  min-width: 0;
}

.workflow-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.file-control {
  min-width: 0;
  gap: 15px;
}

.file-meta {
  min-width: 0;
  gap: 9px;
}

.file-meta > svg {
  flex: 0 0 auto;
  color: var(--teal);
}

.file-meta strong,
.file-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-meta strong {
  max-width: 400px;
  font-size: 13px;
}

.file-meta span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.workflow-actions {
  flex: 0 0 auto;
  gap: 8px;
}

.button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 4px;
  font-weight: 700;
}

.button.primary {
  background: var(--brand);
  color: #fff;
}

.button.primary:hover {
  background: var(--brand-dark);
}

.button.secondary {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.button.confirm {
  background: var(--teal);
  color: #fff;
}

.button.compact {
  min-height: 34px;
  padding: 7px 9px;
  font-size: 12px;
}

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

.export-menu {
  position: relative;
}

.export-popover {
  position: absolute;
  top: 44px;
  right: 0;
  z-index: 30;
  width: 210px;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.export-popover button,
.export-popover a {
  display: block;
  width: 100%;
  padding: 10px;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  text-decoration: none;
}

.export-popover button:hover,
.export-popover a:hover {
  background: var(--surface-soft);
}

.status-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 8px 20px;
  background: #edf3f3;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}

.status-copy {
  min-width: 0;
  gap: 8px;
}

.status-copy span:last-child {
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #879399;
}

.status-dot.running {
  background: var(--amber);
  box-shadow: 0 0 0 4px rgb(181 111 9 / 15%);
}

.status-dot.done {
  background: var(--green);
}

.progress-wrap {
  flex: 0 0 auto;
  gap: 8px;
}

.progress-track {
  width: 150px;
  height: 6px;
  overflow: hidden;
  background: #d2dcdf;
}

#progressBar {
  width: 0;
  height: 100%;
  background: var(--teal);
  transition: width 180ms ease;
}

.workspace {
  display: grid;
  grid-template-columns: 230px minmax(500px, 1fr) 320px;
  min-height: calc(100vh - 144px);
}

.filter-panel,
.results-panel {
  min-width: 0;
  background: var(--surface);
}

.filter-panel {
  padding: 18px 14px;
  border-right: 1px solid var(--line);
}

.results-panel {
  border-left: 1px solid var(--line);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
}

.eyebrow {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

h2 {
  margin: 0;
  font-size: 15px;
}

.heading-icon {
  color: var(--muted);
}

.filter-list {
  display: grid;
  gap: 3px;
}

.filter-item {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 6px 7px;
  border: 1px solid transparent;
  cursor: pointer;
}

.filter-item:hover {
  background: var(--surface-soft);
}

.filter-item.active {
  border-color: #b9d9d6;
  background: #eaf5f4;
}

.filter-item input {
  width: 16px;
  height: 16px;
  accent-color: var(--teal);
}

.filter-item span {
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-item strong {
  font-size: 12px;
}

.legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px 5px;
  margin-top: 20px;
  padding-top: 15px;
  border-top: 1px solid var(--line);
}

.legend span {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 10px;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.legend-dot.target {
  background: var(--blue);
}

.legend-dot.review {
  background: var(--amber);
}

.legend-dot.manual {
  background: var(--green);
}

.legend-dot.excluded {
  background: #9ba4a8;
}

.drawing-panel {
  display: grid;
  min-width: 0;
  grid-template-rows: 68px minmax(0, 1fr) 34px;
  background: var(--canvas);
}

.drawing-toolbar {
  justify-content: space-between;
  padding: 0 13px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.drawing-toolbar > div:first-child {
  min-width: 0;
}

.drawing-identity {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 2px 8px;
}

.drawing-toolbar strong {
  font-size: 12px;
}

.drawing-toolbar span {
  margin-left: 8px;
  color: var(--muted);
  font-size: 11px;
}

.drawing-identity > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-tabs {
  display: flex;
  grid-column: 1 / -1;
  gap: 4px;
}

.page-tab {
  min-height: 26px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.page-tab.active {
  border-color: var(--teal);
  background: #eaf5f4;
  color: var(--teal);
}

.zoom-controls {
  gap: 5px;
}

.zoom-controls .icon-button {
  width: 30px;
  height: 30px;
}

.zoom-controls span {
  width: 42px;
  margin: 0;
  color: var(--ink);
  text-align: center;
}

.drawing-viewport {
  overflow: auto;
  padding: 18px;
}

.drawing-stage {
  position: relative;
  width: 100%;
  min-width: 650px;
  margin: 0 auto;
  overflow: hidden;
  background: #fff;
  box-shadow: var(--shadow);
  transform-origin: top left;
}

.drawing-stage > img {
  display: block;
  width: 100%;
  height: auto;
}

.marker-layer,
.scan-overlay {
  position: absolute;
  inset: 0;
}

.marker {
  position: absolute;
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  padding: 0;
  transform: translate(-50%, -50%);
  border: 3px solid currentColor;
  border-radius: 50%;
  background: rgb(255 255 255 / 12%);
  font-size: 0;
  font-weight: 900;
  box-shadow: 0 0 0 1px rgb(255 255 255 / 90%), 0 2px 7px rgb(0 0 0 / 18%);
  backdrop-filter: none;
}

.marker.target {
  color: var(--blue);
  background: rgb(35 119 185 / 13%);
}

.marker.review {
  color: var(--amber);
  background: rgb(181 111 9 / 13%);
}

.marker.partial {
  color: #855ab6;
  background: rgb(133 90 182 / 13%);
}

.marker.manual {
  color: var(--green);
  background: rgb(36 132 87 / 8%);
}

.marker.excluded {
  color: #8a959a;
  background: rgb(138 149 154 / 6%);
  opacity: 0.55;
}

.marker.hidden {
  display: none;
}

.marker.selected {
  z-index: 4;
  box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--brand), 0 3px 10px rgb(0 0 0 / 25%);
}

.scan-overlay {
  overflow: hidden;
  background: rgb(8 126 120 / 7%);
  pointer-events: none;
}

.scan-overlay::after {
  position: absolute;
  top: -5%;
  left: 0;
  width: 100%;
  height: 4px;
  content: "";
  background: var(--teal);
  box-shadow: 0 0 16px var(--teal);
  animation: scan 1.6s linear infinite;
}

@keyframes scan {
  to {
    top: 105%;
  }
}

.drawing-note {
  gap: 7px;
  padding: 0 14px;
  background: #fff8e9;
  color: #725216;
  border-top: 1px solid #ead9b6;
  font-size: 10px;
}

.drawing-note svg {
  width: 16px;
  height: 16px;
}

.summary {
  padding: 17px 15px 14px;
  border-bottom: 1px solid var(--line);
}

.summary-main {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}

.summary-main > div {
  min-width: 0;
  padding: 3px 9px;
  border-left: 1px solid var(--line);
}

.summary-main > div:first-child {
  padding-left: 0;
  border-left: 0;
}

.summary-main strong,
.summary-main span {
  display: block;
}

.summary-main strong {
  font-size: 25px;
  line-height: 1.1;
}

.summary-main span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
}

.result-actions {
  gap: 6px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

.result-actions .button {
  flex: 1;
}

.result-list {
  max-height: calc(100vh - 292px);
  overflow: auto;
}

.empty-state {
  display: grid;
  min-height: 350px;
  padding: 25px;
  place-items: center;
  align-content: center;
  text-align: center;
}

.empty-symbol {
  display: grid;
  width: 42px;
  height: 42px;
  margin-bottom: 13px;
  place-items: center;
  background: #e7eeee;
  color: var(--teal);
  font-weight: 900;
  transform: skew(-8deg);
}

.empty-state strong {
  font-size: 13px;
}

.empty-state span {
  max-width: 210px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

.result-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 57px;
  padding: 8px 10px;
  border-bottom: 1px solid #edf0f1;
  cursor: pointer;
}

.result-row:hover,
.result-row.selected {
  background: #f2f7f7;
}

.result-status {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 50%;
  background: #f3e7ce;
  color: var(--amber);
  font-size: 10px;
  font-weight: 900;
}

.result-status.target {
  background: #dcecf8;
  color: var(--blue);
}

.result-status.review {
  background: #f3e7ce;
  color: var(--amber);
}

.result-status.partial {
  background: #eee4f7;
  color: #855ab6;
}

.result-status.manual {
  background: #dcf0e6;
  color: var(--green);
}

.result-status.excluded {
  background: #e8ebec;
  color: #7b868b;
}

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

.result-copy strong,
.result-copy span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-copy em {
  display: block;
  overflow: hidden;
  margin-top: 3px;
  color: #8a5b0a;
  font-size: 9px;
  font-style: normal;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-copy strong {
  font-size: 12px;
}

.result-copy span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
}

.row-actions {
  display: flex;
  gap: 3px;
}

.row-actions button {
  display: grid;
  width: 27px;
  height: 27px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
}

.row-actions button:hover {
  color: var(--ink);
  border-color: #a8b4b9;
}

.row-actions svg {
  width: 15px;
  height: 15px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 80;
  max-width: 320px;
  padding: 11px 14px;
  transform: translateY(20px);
  background: var(--ink);
  color: #fff;
  border-left: 4px solid var(--brand);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transition: 160ms ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 190px minmax(500px, 1fr) 290px;
  }

  .file-meta strong {
    max-width: 260px;
  }
}

@media (max-width: 860px) {
  .workflow-bar,
  .status-strip {
    align-items: stretch;
  }

  .workflow-bar {
    flex-direction: column;
  }

  .workflow-actions .button {
    flex: 1;
  }

  .status-strip {
    flex-direction: column;
  }

  .progress-wrap {
    justify-content: flex-end;
  }

  .progress-track {
    flex: 1;
  }

  .workspace {
    display: flex;
    flex-direction: column;
  }

  .filter-panel {
    order: 2;
    padding: 12px;
    border-top: 1px solid var(--line);
    border-right: 0;
  }

  .panel-heading,
  .legend {
    display: none;
  }

  .filter-list {
    display: flex;
    overflow-x: auto;
  }

  .filter-item {
    flex: 0 0 auto;
  }

  .drawing-panel {
    order: 1;
    min-height: 520px;
  }

  .results-panel {
    order: 3;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .result-list {
    max-height: 420px;
  }
}

@media (max-width: 560px) {
  .topbar {
    padding: 0 13px;
  }

  .demo-badge {
    display: none;
  }

  .workflow-bar {
    padding: 11px;
  }

  .file-control {
    align-items: stretch;
    flex-direction: column;
  }

  .file-control .button {
    width: 100%;
  }

  .file-meta strong {
    max-width: calc(100vw - 70px);
  }

  .status-strip {
    padding: 8px 12px;
  }

  .status-copy span:last-child {
    white-space: normal;
  }

  .drawing-identity > span {
    display: none;
  }

  .drawing-toolbar {
    align-items: center;
  }

  .page-tabs {
    max-width: calc(100vw - 100px);
    overflow-x: auto;
  }

  .page-tab {
    flex: 0 0 auto;
  }

  .drawing-viewport {
    padding: 10px;
  }

  .drawing-stage {
    min-width: 620px;
  }
}
