* { box-sizing: border-box; }
:root {
  --bg: #1e1f22;
  --panel: #2b2d31;
  --line: #3a3d42;
  --text: #e6e7ea;
  --muted: #9aa0a6;
  --accent: #4f8cff;
  --accent-2: #ffb020;
}
html, body { height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", "Microsoft JhengHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
header h1 { font-size: 16px; margin: 0; }
.file-area { display: flex; align-items: center; gap: 10px; }

.layout { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 280px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 14px;
  overflow-y: auto;
}
.sidebar h2 { font-size: 13px; color: var(--muted); margin: 0 0 8px; text-transform: uppercase; letter-spacing: .5px; }
.sidebar section { margin-bottom: 22px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; font-size: 14px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 8px; cursor: pointer; user-select: none; }
.check input { width: 18px; height: 18px; }
.field .inline { display: flex; align-items: center; gap: 6px; }
input[type="number"], select {
  background: #1b1c1f;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 14px;
  width: 100%;
}
input[type="number"] { width: 90px; }

.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
  text-align: center;
}
.btn:hover { filter: brightness(1.1); }
.btn-outline { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn-sm { padding: 4px 9px; font-size: 13px; }
.btn.active { background: var(--accent-2); color: #1b1c1f; }
.sidebar .btn { width: 100%; margin-bottom: 8px; }

.hint { font-size: 12px; color: var(--muted); margin: 4px 0 0; line-height: 1.5; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.calib-box { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }

.mode-tag {
  margin-top: 6px;
  font-size: 13px;
  color: var(--accent-2);
  min-height: 18px;
}

.results { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.results li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-bottom: 6px;
  background: #1b1c1f;
}
.results .dist { font-weight: 600; color: var(--accent); }
.results .del { cursor: pointer; color: var(--muted); border: none; background: none; font-size: 14px; align-self: center; }
.results .del:hover { color: #ff6b6b; }

.file-item { align-items: stretch; }
.file-info { flex: 1; min-width: 0; cursor: pointer; }
.file-info:hover .file-name { color: var(--accent); }
.file-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-meta { font-size: 11px; color: var(--muted); margin-top: 3px; }

.viewer { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.toolbar .sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }

.canvas-wrap {
  flex: 1;
  overflow: auto;
  position: relative;
  background: #16171a;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  touch-action: none;            /* 手勢自行處理 */
  -webkit-overflow-scrolling: touch;
}
.placeholder {
  margin: auto;
  color: var(--muted);
  font-size: 15px;
}
.stage { position: relative; margin: 20px; line-height: 0; }
#pdfCanvas { display: block; background: #fff; box-shadow: 0 0 0 1px var(--line); }
#overlay {
  position: absolute;
  top: 0; left: 0;
  cursor: crosshair;
  pointer-events: auto;          /* 量測永遠可用 */
  touch-action: none;
}

/* 漢堡鈕(手機顯示) */
.menu-btn { display: none; background: none; border: none; color: var(--text); font-size: 22px; cursor: pointer; padding: 0 6px; }
.backdrop { display: none; }

/* ---- 響應式:手機 ---- */
@media (max-width: 720px) {
  header h1 { font-size: 15px; }
  .menu-btn { display: inline-block; }

  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100%;
    width: 80%;
    max-width: 320px;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 2px 0 16px rgba(0,0,0,.5);
  }
  .sidebar.open { transform: translateX(0); }

  .backdrop.show {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 20;
  }

  /* 觸控友善:加大可點區域 */
  .btn { padding: 11px 14px; }
  .btn-sm { padding: 9px 12px; font-size: 15px; }
  .toolbar { gap: 6px; flex-wrap: wrap; padding: 8px; }
  input[type="number"], select { padding: 10px; font-size: 16px; } /* 16px 防 iOS 自動放大 */
  .results li { padding: 11px 10px; }
}
