:root {
  --bg-base: #f3f7fb;
  --bg-accent-1: #dcfce7;
  --bg-accent-2: #fde68a;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-strong: rgba(255, 255, 255, 0.94);
  --ink: #0f172a;
  --muted: #4b5563;
  --line: #d7e3ef;
  --line-strong: #afc5da;
  --teal: #0f766e;
  --teal-soft: #d9f8f2;
  --amber: #b45309;
  --sky: #0369a1;
  --danger: #b91c1c;
  --ok: #166534;
  --shadow-soft: 0 14px 36px rgba(15, 23, 42, 0.09);
  --shadow-hard: 0 20px 56px rgba(15, 23, 42, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  overflow: hidden;
  color: var(--ink);
  font-family: "Avenir Next", "IBM Plex Sans", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 4% 4%, rgba(15, 118, 110, 0.18), transparent 30%),
    radial-gradient(circle at 96% 94%, rgba(180, 83, 9, 0.16), transparent 26%),
    linear-gradient(135deg, rgba(220, 252, 231, 0.22), transparent 35%),
    var(--bg-base);
}

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 0.65rem;
  align-items: center;
  padding: 0.38rem 0.62rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.35);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.88), rgba(248, 250, 252, 0.72));
  backdrop-filter: blur(10px);
}

.brand-block h1 {
  margin: 0;
  font-size: 0.94rem;
  letter-spacing: 0.01em;
  display: inline-flex;
  align-items: baseline;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.brand-block h1 span {
  font-size: 0.68rem;
  color: #64748b;
  font-weight: 500;
}

.header-inline-btn {
  margin-left: 0.28rem;
  padding: 0.08rem 0.48rem;
  border-radius: 999px;
  border: 1px solid rgba(15, 118, 110, 0.2);
  background: rgba(15, 118, 110, 0.08);
  color: var(--teal);
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1.45;
  vertical-align: middle;
}

.header-inline-btn:hover {
  background: rgba(15, 118, 110, 0.14);
  border-color: rgba(15, 118, 110, 0.36);
  box-shadow: 0 4px 10px rgba(15, 118, 110, 0.14);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.34rem;
}

.header-actions button,
.header-actions .file-btn {
  padding: 0.3rem 0.5rem;
  font-size: 0.77rem;
  border-radius: 0.48rem;
}

#clearCacheBtn {
  border-color: rgba(185, 28, 28, 0.35);
  color: #7f1d1d;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(320px, 360px) 1fr;
  gap: 0.72rem;
  padding: 0.72rem;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.content-grid.panel-collapsed {
  grid-template-columns: 58px 1fr;
}

.panel {
  overflow: auto;
  min-height: 0;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 1rem;
  background: linear-gradient(150deg, var(--panel-strong), var(--panel));
  box-shadow: var(--shadow-soft);
  padding: 0.58rem;
}

.panel-collapsed-tools {
  display: none;
  flex-direction: column;
  gap: 0.42rem;
}

.panel-collapsed-tools button {
  width: 100%;
  min-width: 0;
  padding: 0.38rem 0.2rem;
  font-weight: 700;
  border-radius: 0.5rem;
}

.content-grid.panel-collapsed .panel {
  padding: 0.38rem;
}

.content-grid.panel-collapsed .panel section {
  display: none;
}

.content-grid.panel-collapsed .panel-collapsed-tools {
  display: flex;
}

.panel section {
  border: 1px solid var(--line);
  border-radius: 0.72rem;
  padding: 0;
  background: rgba(255, 255, 255, 0.7);
}

.panel section + section {
  margin-top: 0.68rem;
}

.section-toggle {
  width: 100%;
  border: 0;
  border-radius: 0.72rem;
  padding: 0.56rem 0.64rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.88rem;
  font-weight: 650;
  color: #0f172a;
  background: rgba(255, 255, 255, 0.65);
  box-shadow: inset 0 -1px 0 rgba(148, 163, 184, 0.2);
}

.section-toggle .chevron {
  font-size: 0.76rem;
  color: #64748b;
  transition: transform 180ms ease;
}

.panel section.open .section-toggle {
  background: rgba(217, 248, 242, 0.45);
  box-shadow: inset 0 -1px 0 rgba(15, 118, 110, 0.18);
}

.panel section.open .section-toggle .chevron {
  transform: rotate(180deg);
}

.section-body {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  padding: 0 0.72rem;
  transition: max-height 210ms ease, opacity 170ms ease, padding 170ms ease;
}

.panel section.open .section-body {
  max-height: 1200px;
  opacity: 1;
  padding: 0.62rem 0.72rem 0.72rem;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 0.42rem;
  flex-wrap: wrap;
  margin-bottom: 0.45rem;
}

label {
  font-size: 0.82rem;
  color: var(--muted);
}

input[type="number"],
input[type="text"],
select,
button,
.file-btn {
  border: 1px solid var(--line-strong);
  border-radius: 0.55rem;
  padding: 0.36rem 0.56rem;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
  font-size: 0.81rem;
}

button,
.file-btn {
  cursor: pointer;
  transition: transform 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
}

button:hover,
.file-btn:hover {
  background: #f0f9ff;
  border-color: #7dd3fc;
  transform: translateY(-1px);
  box-shadow: 0 3px 9px rgba(14, 116, 144, 0.16);
}

button:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  box-shadow: none;
}

input[type="range"] {
  width: 140px;
}

.file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.subtle {
  color: #64748b;
  font-size: 0.79rem;
}

.inline-link {
  text-decoration: underline;
  text-decoration-style: dotted;
  color: #0f766e;
}

.canvas-wrap {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  border-radius: 1rem;
  border: 1px solid rgba(148, 163, 184, 0.35);
  overflow: hidden;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(248, 250, 252, 0.82));
  box-shadow: var(--shadow-hard);
}

.canvas-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.3rem;
  padding: 0.25rem 0.4rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.38);
  color: var(--muted);
  font-size: 0.72rem;
  background: linear-gradient(90deg, rgba(207, 250, 254, 0.32), rgba(254, 243, 199, 0.24));
  overflow-x: auto;
}

.toolbar-group {
  display: inline-flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.3rem;
}

.toolbar-advanced {
  border-left: 1px dashed rgba(148, 163, 184, 0.5);
  padding-left: 0.45rem;
}

.toolbar-group label {
  font-size: 0.74rem;
  color: #475569;
}

/* 状态文本优化 - 防止换行并提供省略号 */
#modeLabel {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: help;
}

#mousePos {
  min-width: 90px;
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#statusText {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: help;
}

#zoomLabel {
  min-width: 3.2rem;
  text-align: center;
  font-weight: 600;
  color: var(--sky);
}

#iconScaleInput {
  width: 100px;
}

#iconScaleValue {
  min-width: 3.4rem;
  text-align: center;
  color: #0369a1;
  font-weight: 600;
}

#textColorInput {
  width: 30px;
  height: 28px;
  border-radius: 0.4rem;
  padding: 0.12rem;
}

#textSizeInput {
  width: 56px;
}

.toolbar-group button {
  padding: 0.28rem 0.45rem;
  font-size: 0.7rem;
}

#textToolBtn.active {
  background: #cffafe;
  border-color: #06b6d4;
  box-shadow: inset 0 0 0 1px rgba(14, 116, 144, 0.35);
}

.canvas-viewport {
  overflow: auto;
  position: relative;
  min-height: 0;
  overscroll-behavior: contain;
  background:
    linear-gradient(45deg, #ebf1f8 25%, transparent 25%),
    linear-gradient(-45deg, #ebf1f8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ebf1f8 75%),
    linear-gradient(-45deg, transparent 75%, #ebf1f8 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  padding: 1rem;
}

.canvas-viewport.pan-ready {
  cursor: grab;
}

.canvas-viewport.pan-ready * {
  cursor: inherit !important;
}

.canvas-viewport.pan-active {
  cursor: grabbing;
}

.canvas-viewport.pan-active * {
  cursor: inherit !important;
}

#mainCanvas {
  display: block;
  background: #ffffff;
  border: 1px solid rgba(148, 163, 184, 0.5);
  box-shadow: 0 4px 18px rgba(15, 23, 42, 0.12);
  image-rendering: auto;
  transform-origin: top left;
}

.canvas-inline-text-editor {
  position: absolute;
  z-index: 8;
  min-width: 88px;
  max-width: 340px;
  padding: 3px 8px;
  border: 1px solid #dc2626;
  border-radius: 0.45rem;
  background: rgba(255, 255, 255, 0.96);
  color: #dc2626;
  line-height: 1.2;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.16);
  outline: none;
}

.canvas-inline-text-editor:focus {
  box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.22), 0 4px 14px rgba(15, 23, 42, 0.16);
}

.contact-modal[hidden] {
  display: none;
}

.contact-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 1rem;
  animation: contact-modal-fade-in 160ms ease;
}

.contact-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(3px);
}

.contact-modal__dialog {
  position: relative;
  width: min(100%, 440px);
  padding: 1.2rem 1.1rem 1rem;
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 1rem;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 250, 252, 0.96));
  box-shadow: var(--shadow-hard);
  text-align: left;
}

.contact-modal__dialog h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.contact-modal__dialog p {
  margin: 0.28rem 0;
  color: #334155;
  font-size: 0.9rem;
  line-height: 1.6;
  word-break: break-word;
}

.contact-modal__dialog button {
  margin-top: 0.9rem;
  min-width: 88px;
}

@keyframes contact-modal-fade-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@media (max-width: 640px) {
  .contact-modal__dialog {
    width: min(100%, 360px);
    padding: 1rem 0.9rem 0.92rem;
  }
}

.camera-list,
.candidate-list,
.metrics-panel {
  max-height: 170px;
  overflow: auto;
  border: 1px solid #bfd2e4;
  border-radius: 0.55rem;
  padding: 0.45rem;
  background: rgba(248, 252, 255, 0.72);
  font-size: 0.78rem;
}

.camera-item,
.candidate-item {
  padding: 0.38rem;
  border-bottom: 1px dashed rgba(148, 163, 184, 0.4);
}

.camera-item:last-child,
.candidate-item:last-child {
  border-bottom: 0;
}

.tag {
  display: inline-block;
  padding: 0.1rem 0.36rem;
  border-radius: 0.4rem;
  font-size: 0.72rem;
  margin-left: 0.35rem;
}

.tag.ok {
  color: var(--ok);
  background: rgba(22, 101, 52, 0.12);
}

.tag.warn {
  color: var(--amber);
  background: rgba(180, 83, 9, 0.14);
}

.tag.bad {
  color: var(--danger);
  background: rgba(185, 28, 28, 0.12);
}

.pdf-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 0.45rem;
  padding: 0.45rem;
  max-height: 198px;
  overflow: auto;
  border: 1px solid #bfd2e4;
  border-radius: 0.55rem;
  background: rgba(248, 252, 255, 0.78);
}

.pdf-thumb {
  border: 1px solid #bdd2e7;
  background: #fff;
  border-radius: 0.55rem;
  overflow: hidden;
  cursor: pointer;
  padding: 0;
  text-align: left;
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
}

.pdf-thumb:hover {
  transform: translateY(-1px);
  border-color: #22d3ee;
  box-shadow: 0 6px 18px rgba(14, 116, 144, 0.18);
}

.pdf-thumb img {
  display: block;
  width: 100%;
  aspect-ratio: 0.72;
  object-fit: cover;
  background: #f8fafc;
}

.pdf-thumb span {
  display: block;
  padding: 0.25rem 0.4rem 0.35rem;
  font-size: 0.73rem;
  color: #334155;
}

.pdf-thumb.active {
  border-color: #0f766e;
  box-shadow: inset 0 0 0 1px #0f766e;
}

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

  .app-shell {
    height: auto;
    overflow: visible;
  }

  .content-grid {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .content-grid.panel-collapsed {
    grid-template-columns: 1fr;
  }

  .content-grid.panel-collapsed .panel section {
    display: block;
  }

  .content-grid.panel-collapsed .panel-collapsed-tools {
    display: none;
  }

  .panel {
    max-height: 46vh;
  }

  .canvas-wrap {
    min-height: 58vh;
  }
}
