:root {
  --bg: #eef0f3;
  --panel: #ffffff;
  --panel-2: #f6f7f9;
  --text: #1f2933;
  --muted: #66727f;
  --border: #d9dee4;
  --accent: #2f6fd6;
  --accent-2: #e8f0fc;
  --danger: #c62828;
  --warn: #9a6700;
  --warn-bg: #fff6e0;
  --err-bg: #fdecec;
  --ok: #2e7d32;
  --radius: 8px;
  --font: "Segoe UI", "Tahoma", system-ui, -apple-system, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button, select, input { font: inherit; color: inherit; }
button {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { background: var(--panel-2); border-color: #c3cad3; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: #2760bd; }

/* ---------------------------------------------------------------- toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; margin-inline-end: 6px; }
.logo {
  width: 24px; height: 24px; border-radius: 6px; background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 800;
}
.group { display: flex; gap: 4px; align-items: center; padding-inline-end: 10px; border-inline-end: 1px solid var(--border); }
.group:last-of-type { border: 0; }
.spacer { flex: 1; }
.tool { display: inline-flex; gap: 6px; align-items: center; }
.tool .ico { font-size: 14px; line-height: 1; }
.tool.active { background: var(--accent-2); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.lang { font-weight: 600; }
.menu-group { position: relative; }
.menu {
  position: absolute; top: 34px; inset-inline-start: 0; z-index: 20;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 6px; display: flex; flex-direction: column; min-width: 220px;
}
.menu[hidden] { display: none; }
.menu button { border: 0; text-align: start; }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; width: 100%; }
select { border: 1px solid var(--border); border-radius: 6px; padding: 4px 6px; background: var(--panel); }

/* ---------------------------------------------------------------- layout */
.workspace { flex: 1; display: flex; min-height: 0; }
.stage { position: relative; flex: 1; min-width: 0; background: #f4f5f2; }
canvas { display: block; width: 100%; height: 100%; outline: none; touch-action: none; }
.sidebar {
  width: 320px;
  flex: 0 0 320px;
  overflow-y: auto;
  background: var(--panel);
  border-inline-start: 1px solid var(--border);
  padding: 10px 12px 24px;
}

.actions { display: flex; gap: 8px; }
.actions .primary { flex: 1; padding: 8px; font-size: 14px; }
.check { display: flex; align-items: center; gap: 6px; margin: 6px 0; cursor: pointer; }
.check.inline { color: var(--muted); }

details { border-top: 1px solid var(--border); padding: 6px 0; margin-top: 8px; }
summary { cursor: pointer; font-weight: 600; padding: 4px 0; user-select: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 6px; }
.grid2 label { display: flex; flex-direction: column; gap: 3px; color: var(--muted); font-size: 12px; }
.grid2 input[type=number], .grid2 select {
  border: 1px solid var(--border); border-radius: 6px; padding: 4px 6px; background: var(--panel); color: var(--text); width: 100%;
}
.grid2 input:disabled { background: var(--panel-2); color: var(--muted); }
.note { color: var(--muted); font-size: 12px; margin: 6px 0 0; line-height: 1.4; }

/* ---------------------------------------------------------------- messages */
.messages { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.msg { border-radius: 6px; padding: 7px 9px; line-height: 1.4; font-size: 12px; }
.msg .alt { display: block; opacity: .8; margin-top: 2px; }
.msg.error { background: var(--err-bg); color: var(--danger); border: 1px solid #f3c1c1; }
.msg.warn { background: var(--warn-bg); color: var(--warn); border: 1px solid #f0d99a; }
.msg.info { background: var(--accent-2); color: #1d4f9c; border: 1px solid #c9dbf6; }

/* ---------------------------------------------------------------- alternatives */
.alts { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.alt-row {
  display: grid; grid-template-columns: 22px 1fr auto; gap: 6px; align-items: center; text-align: start;
  padding: 6px 8px; border-radius: 6px;
}
.alt-row.active { background: var(--accent-2); border-color: var(--accent); }
.alt-row .rank { color: var(--muted); font-weight: 600; }
.alt-row .n { font-weight: 700; font-variant-numeric: tabular-nums; }
.alt-row .sub { color: var(--muted); font-size: 11px; }
.alt-row > span { min-width: 0; white-space: normal; }

/* ---------------------------------------------------------------- props */
.props { display: flex; flex-direction: column; gap: 6px; }
.props .empty { color: var(--muted); line-height: 1.5; }
.props .kv { display: flex; justify-content: space-between; color: var(--muted); }
.props .kv b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- overlays */
.stats {
  position: absolute; top: 12px; right: 12px;
  background: rgba(255,255,255,.95); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,.08); padding: 10px 12px; min-width: 220px; max-width: 300px;
}
.stats.stale { opacity: .6; }
.stats .big { display: flex; gap: 16px; margin-bottom: 8px; padding-inline-end: 28px; }
.stats .big div { display: flex; flex-direction: column; }
.stats .big b { font-size: 26px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stats .big span { color: var(--muted); font-size: 11px; }
.stats .acc b { color: var(--accent); }
.stats table { border-collapse: collapse; width: 100%; font-size: 12px; }
.stats td { padding: 2px 0; }
.stats td:first-child { padding-inline-end: 10px; }
.stats .collapse { position: absolute; top: 6px; inset-inline-end: 6px; width: 22px; height: 22px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel-2, #f3f4f6); color: var(--text, #1f2933); cursor: pointer; font-size: 12px; line-height: 1; padding: 0; }
.stats .collapse:hover { border-color: var(--accent); }
.stats.collapsed table, .stats.collapsed .share .legend { display: none; }
.stats.collapsed { min-width: 0; }
.stats td:last-child { direction: ltr; unicode-bidi: isolate; text-align: end; font-weight: 600; font-variant-numeric: tabular-nums; padding-inline-start: 12px; }
.stats td:first-child { color: var(--muted); }
.stats .flag { color: var(--danger); }
.stats .stale-note { color: var(--warn); font-size: 11px; margin-top: 6px; }

.hint {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  background: rgba(31,41,51,.85); color: #fff; padding: 6px 12px; border-radius: 16px;
  font-size: 12px; pointer-events: none; max-width: 80%; text-align: center;
}
.hint:empty { display: none; }
.coords {
  position: absolute; bottom: 12px; right: 12px; color: var(--muted); font-size: 11px;
  background: rgba(255,255,255,.8); padding: 2px 6px; border-radius: 4px; pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.busy {
  position: absolute; top: 12px; left: 12px; background: rgba(255,255,255,.95);
  border: 1px solid var(--border); border-radius: 16px; padding: 5px 12px; display: flex; gap: 8px; align-items: center;
}
.busy[hidden] { display: none; }
.spinner {
  width: 14px; height: 14px; border: 2px solid var(--accent-2); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.help { line-height: 1.6; font-size: 12px; }
.help kbd {
  background: var(--panel-2); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px;
  padding: 0 4px; font-size: 11px; font-family: inherit;
}
.help ul { padding-inline-start: 18px; margin: 4px 0; }

@media (max-width: 900px) {
  .sidebar { width: 270px; flex-basis: 270px; }
  .tool span[data-i18n] { display: none; }
}

/* ---------------------------------------------------------------- v1.1 additions */
.grid2 .span2 { grid-column: 1 / -1; }
details.sub { border-top: 0; margin-top: 4px; padding: 0; }
details.sub summary { font-weight: 500; color: var(--muted); font-size: 12px; }

.badge { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 10px; margin-inline-start: 6px; }
.badge.ok { background: #e6f4ea; color: var(--ok); }
.badge.bad { background: var(--err-bg); color: var(--danger); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }

.checks { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.checks h4 { margin: 6px 0 2px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.chk { display: grid; grid-template-columns: 18px 1fr; gap: 6px; font-size: 12px; line-height: 1.4; padding: 4px 0; border-bottom: 1px dashed var(--border); }
.chk:last-child { border-bottom: 0; }
.chk .ic { font-weight: 700; text-align: center; }
.chk.pass .ic { color: var(--ok); }
.chk.fail .ic { color: var(--danger); }
.chk.warn .ic { color: var(--warn); }
.chk.info .ic { color: #1d4f9c; }
.chk b { display: block; }
.chk .ref { color: var(--muted); font-size: 11px; }

.panel { border: 1px solid #d9c3e6; background: #faf5fd; border-radius: 8px; padding: 8px 10px; margin-top: 8px; font-size: 12px; }
.panel .row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.panel input { width: 90px; border: 1px solid var(--border); border-radius: 6px; padding: 3px 6px; }

.props .btns { display: flex; flex-wrap: wrap; gap: 6px; }

.modal { position: fixed; inset: 0; background: rgba(20, 28, 36, .45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal[hidden] { display: none; }
.modal .card { background: var(--panel); border-radius: 12px; padding: 18px 20px; width: min(520px, 92vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal h3 { margin: 0 0 8px; }
.modal .actions { margin-top: 12px; justify-content: flex-end; }
.modal .actions .primary { flex: 0 0 auto; padding: 7px 18px; }
.imp-info { background: var(--panel-2); border-radius: 8px; padding: 8px 10px; font-size: 12px; line-height: 1.5; margin-bottom: 6px; }

.stats .muted { color: var(--muted); font-weight: 400; font-size: 11px; }
.share { margin: 2px 0 8px; }
.share .bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--panel-2); }
.share .bar span { display: block; height: 100%; }
.share .legend { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 11px; color: var(--muted); margin-top: 4px; }
.share .legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-inline-end: 4px; }

/* measure panel */
#calib-panel .calib-len { font-size: 1.15em; font-weight: 600; margin-bottom: 4px; }
#calib-panel .calib-note { color: var(--muted); font-size: 11px; margin-bottom: 6px; }
#calib-panel button:disabled { opacity: 0.45; cursor: default; }
#calib-panel .row > span { flex-basis: 100%; }
#calib-panel .row input { flex: 1; min-width: 70px; }
.ico svg { vertical-align: -2px; }
