:root {
  color-scheme: light;
  --bg: #eef2f5;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #64717d;
  --border: #d5dde4;
  --accent: #1769aa;
  --accent-soft: #e8f2fb;
  --danger: #a83232;
  --shadow: 0 8px 28px rgba(20, 32, 44, .11);
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }
body {
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }

.topbar {
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 24px;
  background: #fff;
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0 0 5px; font-size: 25px; }
.topbar p { margin: 0; color: var(--muted); }

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.file-button input { display: none; }

.layout {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  min-height: calc(100vh - 88px);
}

.sidebar {
  padding: 16px;
  border-right: 1px solid var(--border);
  background: #f7f9fb;
  overflow: auto;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 15px;
  margin-bottom: 14px;
}
.panel h2 { margin: 0 0 13px; font-size: 17px; }
.panel.compact { max-height: 280px; overflow: auto; }
.panel.note { font-size: 13px; color: var(--muted); line-height: 1.45; }
.panel.note strong { color: var(--ink); }
.panel.note p { margin: 7px 0 0; }

.row {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 8px;
  margin: 8px 0;
  font-size: 13px;
}
.row span { color: var(--muted); }
.row strong { overflow-wrap: anywhere; }

.page-controls, .mode-buttons, .actions {
  display: grid;
  gap: 8px;
}
.page-controls { grid-template-columns: 1fr 1fr; margin-top: 12px; }
.mode-buttons { grid-template-columns: 1fr 1fr; }
.actions { grid-template-columns: 1fr 1fr; margin-top: 12px; }
.actions .primary { grid-column: 1 / -1; }

button {
  min-height: 42px;
  border: 1px solid #b9c5cf;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
}
button:hover:not(:disabled) { background: #f2f5f7; }
button.active, button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.help {
  min-height: 38px;
  margin: 11px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}
.result-card {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafb;
}
.result-card span { color: var(--muted); font-size: 13px; }
.result-card strong { font-size: 21px; text-align: right; }

.point-list { margin: 0; padding-left: 25px; font-size: 13px; }
.point-list li { margin: 7px 0; }
.point-list .muted { color: var(--muted); list-style: none; margin-left: -24px; }

.workspace {
  min-width: 0;
  overflow: auto;
  padding: 22px;
  background:
    linear-gradient(45deg, #e6ebef 25%, transparent 25%),
    linear-gradient(-45deg, #e6ebef 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e6ebef 75%),
    linear-gradient(-45deg, transparent 75%, #e6ebef 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}
.drop-zone {
  min-width: min-content;
  min-height: calc(100vh - 132px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px;
}
.drop-zone.dragover {
  outline: 3px dashed var(--accent);
  outline-offset: -10px;
  background: rgba(255,255,255,.45);
}
.drop-message {
  margin-top: 100px;
  min-width: 320px;
  padding: 28px;
  border: 2px dashed #aebac4;
  border-radius: 12px;
  text-align: center;
  background: rgba(255,255,255,.88);
  color: var(--muted);
}
.drop-message strong { display: block; margin-bottom: 8px; color: var(--ink); font-size: 18px; }

.page-stage {
  position: relative;
  flex: 0 0 auto;
  background: white;
  box-shadow: var(--shadow);
  user-select: none;
}
#pdfCanvas { display: block; }
#overlay {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  touch-action: manipulation;
  cursor: crosshair;
}

.measure-line {
  stroke: #d12f2f;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}
.measure-polygon {
  fill: rgba(23, 105, 170, .16);
  stroke: #1769aa;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}
.measure-point {
  fill: #fff;
  stroke: #d12f2f;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}
.area-point { stroke: #1769aa; }
.measure-label {
  font: 700 12px Arial, Helvetica, sans-serif;
  fill: #111;
  stroke: #fff;
  stroke-width: 4px;
  paint-order: stroke fill;
}

.status {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  max-width: min(620px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: 8px;
  background: #17202a;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease;
  z-index: 20;
}
.status.show { opacity: 1; }
.status.error { background: var(--danger); }

@media (max-width: 760px) {
  .topbar { align-items: stretch; flex-direction: column; gap: 12px; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
  .workspace { padding: 8px; }
  .drop-zone { justify-content: flex-start; padding: 8px; min-height: 400px; }
  .drop-message { margin: 40px auto 0; min-width: 0; width: 100%; }
}
