/* ============================================================
   GeoVisualizer — Modals, forms, tables, tweaks panel
   ============================================================ */

/* ---------------- Modal shell ---------------- */
.modal {
  position: fixed; inset: 0; z-index: 150;
  display: none; align-items: center; justify-content: center;
  padding: 24px;
  background: var(--scrim);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.modal.open { display: flex; }

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 480px;
  max-height: calc(100vh - 48px);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-card.wide { max-width: 560px; }
.modal-card.xwide { max-width: 880px; }
.modal-card.print-wide {
  width: calc(100vw - 28px);
  max-width: 1280px;
  height: calc(100vh - 28px);
  max-height: calc(100vh - 28px);
}
.modal-card.print-wide.print-fullscreen {
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  border-radius: 0;
  border-left: none;
  border-right: none;
}
@keyframes cardIn { from { opacity: 0; transform: translateY(10px) scale(0.985); } to { opacity: 1; transform: none; } }

.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 14px; padding: 18px 20px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-head .ht { display: flex; align-items: center; gap: 12px; }
.modal-head .h-ico {
  width: 36px; height: 36px; border-radius: var(--r-md); flex-shrink: 0;
  display: grid; place-items: center; background: var(--accent-soft); color: var(--accent);
}
.modal-head .h-ico svg { width: 19px; height: 19px; }
.modal-head h3 { font-size: 16px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.modal-head p { font-size: 12.5px; color: var(--text-3); margin: 2px 0 0; }
.modal-x {
  width: 32px; height: 32px; border-radius: var(--r-sm); flex-shrink: 0;
  display: grid; place-items: center; cursor: pointer;
  background: transparent; border: none; color: var(--text-3);
  transition: background 0.12s, color 0.12s;
}
.modal-x:hover { background: var(--surface-2); color: var(--text); }
.modal-x svg { width: 18px; height: 18px; }

.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 9px;
  padding: 14px 20px; border-top: 1px solid var(--border);
  background: var(--surface-2); flex-shrink: 0;
}
.modal-card.print-wide .modal-head {
  padding: 11px 14px;
  align-items: center;
  justify-content: flex-start;
}
.modal-card.print-wide .modal-head .ht {
  flex: 1;
  min-width: 0;
}
.modal-card.print-wide .modal-head .h-ico {
  width: 30px;
  height: 30px;
}
.modal-card.print-wide .modal-head .h-ico svg {
  width: 16px;
  height: 16px;
}
.modal-card.print-wide .modal-head h3 {
  font-size: 15px;
}
.modal-card.print-wide .modal-head p {
  font-size: 11.5px;
}
.modal-card.print-wide .modal-body {
  padding: 12px;
  overflow: hidden;
}
.modal-card.print-wide .modal-foot {
  padding: 8px 12px;
  gap: 8px;
}
.modal-card.print-wide .modal-foot .btn {
  min-height: 30px;
  padding: 6px 11px;
  font-size: 12.5px;
}
.modal-card.print-wide .print-max-btn.active {
  color: var(--accent);
  background: var(--accent-soft);
}
.modal-card.print-wide.print-minimized {
  width: auto;
  min-width: 260px;
  max-width: 520px;
  height: auto;
  max-height: none;
  border-radius: var(--r-xl);
}
.modal-card.print-wide.print-minimized .modal-body,
.modal-card.print-wide.print-minimized .modal-foot { display: none !important; }
.modal.print-pass-through {
  pointer-events: none;
  background: transparent !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  align-items: flex-end;
  justify-content: flex-start;
  padding: 16px;
}
.modal.print-pass-through .modal-card { pointer-events: auto; }

/* ---------------- Print layout designer ---------------- */
.print-designer {
  display: grid;
  grid-template-columns: 318px minmax(0, 1fr);
  gap: 12px;
  height: 100%;
  min-height: 0;
}
.print-tools {
  min-width: 0;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
}
.print-stage-wrap {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background:
    radial-gradient(circle at 18% 12%, rgba(31,111,235,.09), transparent 28%),
    linear-gradient(135deg, var(--surface-inset), var(--surface-2));
  overflow: hidden;
}
.print-stage {
  height: 100%;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  overflow: auto;
}
.print-page {
  position: relative;
  background: #fff;
  color: #111827;
  box-shadow: 0 20px 50px rgba(15,23,42,.22), 0 0 0 1px rgba(15,23,42,.08);
  overflow: hidden;
  flex-shrink: 0;
}
.print-map-bg {
  position: absolute;
  left: 5%;
  top: 14%;
  width: 70%;
  height: 74%;
  background: #e5e7eb center / cover no-repeat;
  border: 1px solid #cbd5e1;
}
.print-page-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(31,111,235,.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(31,111,235,.08) 1px, transparent 1px);
  background-size: 5% 5%;
  pointer-events: none;
}
.print-el {
  position: absolute;
  z-index: 2;
  border: 1px dashed rgba(31,111,235,.7);
  background: rgba(255,255,255,.78);
  border-radius: 4px;
  cursor: move;
  user-select: none;
  overflow: hidden;
}
.print-el.selected {
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 3px rgba(31,111,235,.14);
}
.print-el-name {
  position: absolute;
  left: 4px;
  top: 3px;
  z-index: 1;
  font: 9px var(--font-mono);
  color: #1f2937;
  background: rgba(255,255,255,.78);
  border-radius: 3px;
  padding: 1px 4px;
}
.print-el-content {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 14px 8px 6px;
  font-size: 11px;
  line-height: 1.25;
}
.print-el-title .print-el-content {
  display: block;
  font-size: 17px;
  font-weight: 700;
}
.print-el-legend i {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-right: 4px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.12);
}
.print-el-map {
  background: transparent;
}
.print-el-map .print-el-content {
  display: none;
}
.print-el-north .print-el-content,
.print-el-scale .print-el-content {
  align-items: center;
  text-align: center;
}
.print-scale-line {
  width: 72%;
  height: 3px;
  background: #111827;
  display: block;
  box-shadow: -1px 0 #111827, 1px 0 #111827;
}
.print-scale-blocks {
  width: 72%;
  height: 8px;
  display: block;
  background: repeating-linear-gradient(to right, #111827 0%, #111827 25%, #fff 25%, #fff 50%);
  border: 1.5px solid #111827;
  box-sizing: border-box;
}
.print-el-legend .print-el-content {
  justify-content: flex-start;
  overflow: hidden;
}
.print-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 12px;
  height: 12px;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 45%, var(--accent) 46%);
}
.print-element-list {
  display: grid;
  gap: 5px;
}
.print-list-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-inset);
  cursor: pointer;
  font-size: 12.5px;
}
.print-list-row.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.print-list-row.off {
  color: var(--text-3);
  background: transparent;
  border-style: dashed;
}
.print-list-row input {
  accent-color: var(--accent);
}
.print-selected {
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-inset);
  padding: 10px;
}
.print-selected-title {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 10px;
}
.print-selected .field {
  margin-bottom: 10px;
}
.print-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.print-logo-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.print-logo-preview {
  margin-top: 8px;
  min-height: 42px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-inset);
  color: var(--text-3);
  font-size: 12px;
  overflow: hidden;
}
.print-logo-preview img {
  max-width: 100%;
  max-height: 72px;
  object-fit: contain;
  display: block;
}
@media (max-width: 900px) {
  .print-designer { grid-template-columns: 1fr; }
  .modal-card.print-wide .modal-body { overflow: auto; }
  .print-stage { min-height: 360px; }
}

/* ---------------- Forms ---------------- */
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field > label {
  display: block; font-size: 12px; font-weight: 500; color: var(--text-2);
  margin-bottom: 6px;
}
.field .hint { font-size: 11.5px; color: var(--text-3); margin: 5px 0 0; line-height: 1.45; }

.input, .select, textarea.input {
  width: 100%;
  font-family: var(--font-sans); font-size: 13px; color: var(--text);
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 9px 11px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  outline: none;
}
.input::placeholder { color: var(--text-3); }
.input:focus, .select:focus, textarea.input:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface);
}
.select {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238b94a3' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
  padding-right: 34px; cursor: pointer;
}
.input-group { display: flex; }
.input-group .input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group .select {
  width: auto; border-left: none;
  border-top-left-radius: 0; border-bottom-left-radius: 0;
  background-color: var(--surface-2); color: var(--text-2);
}
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.prop-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.prop-tools span:last-child {
  display: flex;
  gap: 6px;
}
.prop-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 4px 10px;
  max-height: 190px;
  overflow: auto;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-inset);
}
.prop-check {
  min-width: 0;
  padding: 3px 0;
}
.prop-check .ctext {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.empty-note {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-inset);
  color: var(--text-3);
  font-size: 12px;
}

/* checkbox / radio */
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; padding: 4px 0; }
.field > label.check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 0;
}
.check input { margin: 0; position: absolute; opacity: 0; }
.check .box {
  width: 17px; height: 17px; border-radius: 5px; flex-shrink: 0; margin-top: 1px;
  border: 1.5px solid var(--border-strong); background: var(--surface-inset);
  display: grid; place-items: center; transition: all 0.15s;
}
.check .box svg { width: 12px; height: 12px; color: #fff; opacity: 0; transform: scale(0.6); transition: all 0.15s; }
.check input:checked + .box { background: var(--accent); border-color: var(--accent); }
.check input:checked + .box svg { opacity: 1; transform: scale(1); }
.check input:focus-visible + .box { box-shadow: 0 0 0 3px var(--accent-soft); }
.check .ctext { font-size: 13px; }
.check .ctext .ct { font-weight: 500; }
.check .ctext .cd { font-size: 11.5px; color: var(--text-3); margin-top: 1px; line-height: 1.4; }

/* segmented control */
.seg { display: inline-flex; background: var(--surface-inset); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 3px; gap: 2px; }
.seg button {
  font-family: var(--font-sans); font-size: 12.5px; font-weight: 500;
  padding: 6px 14px; border-radius: 5px; border: none; cursor: pointer;
  background: transparent; color: var(--text-2); transition: color 0.14s;
}
.seg button.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm), inset 0 0 0 1px var(--border); }

/* color picker chip */
.colorchip {
  display: flex; align-items: center; gap: 10px;
}
input[type="color"].swatch {
  -webkit-appearance: none; appearance: none; border: none; padding: 0;
  width: 32px; height: 32px; border-radius: var(--r-sm); cursor: pointer;
  background: transparent; box-shadow: inset 0 0 0 1px var(--border);
}
input[type="color"].swatch::-webkit-color-swatch-wrapper { padding: 3px; }
input[type="color"].swatch::-webkit-color-swatch { border: none; border-radius: 5px; }
.colorchip .hex { font-family: var(--font-mono); font-size: 12px; color: var(--text-2); }
.color-presets { display: flex; gap: 7px; flex-wrap: wrap; }
.color-presets button {
  width: 24px; height: 24px; border-radius: var(--r-sm); cursor: pointer;
  border: 1px solid rgba(0,0,0,0.12); transition: transform 0.1s;
}
.color-presets button:hover { transform: scale(1.12); }

/* marker type grid */
.marker-grid { display: flex; gap: 6px; flex-wrap: wrap; }
.marker-btn {
  width: 36px; height: 36px;
  border-radius: var(--r-sm);
  border: 1.5px solid var(--border);
  background: var(--surface-inset);
  color: var(--text-2);
  display: grid; place-items: center;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
  padding: 0;
}
.marker-btn svg { width: 17px; height: 17px; }
.marker-btn:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.marker-btn.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* line style grid */
.line-style-grid { display: flex; gap: 6px; flex-wrap: wrap; }
.line-btn {
  width: 62px; height: 32px;
  border-radius: var(--r-sm);
  border: 1.5px solid var(--border);
  background: var(--surface-inset);
  color: var(--text-2);
  display: grid; place-items: center;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
  padding: 0;
}
.line-btn svg { width: 40px; height: 12px; }
.line-btn:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.line-btn.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* gradient/ramp preview */
.ramp { height: 16px; border-radius: var(--r-sm); margin-top: 8px; box-shadow: inset 0 0 0 1px var(--border); }

/* ---------------- Drop zone ---------------- */
.dropzone {
  border: 1.5px dashed var(--border-strong); border-radius: var(--r-lg);
  padding: 34px 20px; text-align: center; cursor: pointer;
  background: var(--surface-inset);
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .dz-ico {
  width: 52px; height: 52px; margin: 0 auto 14px; border-radius: var(--r-lg);
  display: grid; place-items: center; background: var(--surface); border: 1px solid var(--border); color: var(--accent);
}
.dropzone .dz-ico svg { width: 26px; height: 26px; }
.dropzone .dz-title { font-size: 14px; font-weight: 500; }
.dropzone .dz-title b { color: var(--accent); }
.dropzone .dz-sub { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.format-chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 14px; }
.format-chips span {
  font-family: var(--font-mono); font-size: 10.5px; padding: 3px 9px; border-radius: var(--r-full);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
}

.app-drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 450;
  display: grid;
  place-items: center;
  padding: 22px;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition: opacity 0.14s ease, visibility 0.14s ease;
}
.app-drop-overlay.open {
  opacity: 1;
  visibility: visible;
}
.app-drop-card {
  width: min(420px, 100%);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  border: 1.5px dashed var(--accent);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}
.app-drop-ico {
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  border-radius: var(--r-lg);
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
}
.app-drop-ico svg { width: 26px; height: 26px; }
.app-drop-card b {
  display: block;
  margin-bottom: 3px;
  font-size: 14px;
  font-weight: 650;
}
.app-drop-card span {
  display: block;
  color: var(--text-3);
  font-size: 12px;
  line-height: 1.4;
}

.file-preview {
  display: flex; align-items: center; gap: 12px; margin-top: 16px;
  padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md);
}
.file-preview .fp-ico { width: 38px; height: 38px; border-radius: var(--r-sm); background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex-shrink: 0; }
.file-preview .fp-ico svg { width: 19px; height: 19px; }
.file-preview .fp-name { font-size: 13px; font-weight: 500; }
.file-preview .fp-meta { font-family: var(--font-mono); font-size: 11px; color: var(--text-3); margin-top: 2px; }
.file-preview.rich {
  display: block;
  padding: 14px;
}
.fp-top {
  display: flex;
  align-items: center;
  gap: 12px;
}
.fp-main { min-width: 0; flex: 1; }
.fp-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.fp-line .fp-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.import-pill {
  flex-shrink: 0;
  padding: 3px 8px;
  border-radius: var(--r-full);
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
}
.import-summary { margin-top: 10px; }

/* ---------------- Diagnostics panel ---------------- */
.diag-toolbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}
.modal-card.diagnostics-panel .modal-body,
.modal-card.floating-panel.diagnostics-panel .modal-body {
  display: block;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
}
.modal-card.floating-panel.diagnostics-panel {
  overflow: hidden;
}
#diag-root {
  min-height: 0;
}
.diag-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}
.diag-tile {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-inset);
  padding: 9px 10px;
}
.diag-tile b {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 15px;
  line-height: 1.1;
}
.diag-tile span {
  display: block;
  margin-top: 4px;
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
}
.diag-tile.warn { border-color: color-mix(in srgb, var(--c-amber) 42%, var(--border)); }
.diag-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}
.diag-card {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  padding: 12px;
  margin-bottom: 12px;
}
.diag-card h4 {
  margin: 0 0 9px;
  color: var(--text);
  font-size: 12px;
  font-weight: 650;
}
.diag-row {
  display: grid;
  grid-template-columns: minmax(100px, 0.7fr) minmax(0, 1.3fr);
  gap: 10px;
  align-items: start;
  padding: 5px 0;
  border-top: 1px solid var(--border);
}
.diag-row:first-of-type { border-top: 0; }
.diag-row span {
  color: var(--text-3);
  font-size: 11.5px;
}
.diag-row b {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--text-2);
  font-size: 11.5px;
  font-weight: 500;
  text-align: right;
}
.diag-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.diag-pill {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  border-radius: 999px;
  padding: 2px 8px;
  background: var(--surface-inset);
  color: var(--text-2);
  font-size: 10.5px;
  font-weight: 650;
  text-transform: uppercase;
}
.diag-pill.ok { color: var(--c-green); }
.diag-pill.warn { color: var(--c-amber); }
.diag-pill.err { color: var(--c-rose); }
.diag-layer-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.diag-layer-row {
  display: grid;
  grid-template-columns: auto minmax(80px, 1fr) auto auto auto;
  gap: 8px;
  align-items: center;
  font-size: 11.5px;
  color: var(--text-2);
}
.diag-layer-row b {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 12px;
}
.diag-event-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.diag-event-row {
  display: grid;
  grid-template-columns: auto auto minmax(80px, 0.4fr) minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  color: var(--text-2);
  font-size: 11.5px;
}
.diag-event-row b {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 11.5px;
}
.diag-event-row span:last-child {
  min-width: 0;
  overflow-wrap: anywhere;
}
.diag-empty {
  border: 1px dashed var(--border);
  border-radius: var(--r-sm);
  color: var(--text-3);
  font-size: 12px;
  padding: 12px;
  text-align: center;
}

@media (max-width: 760px) {
  .diag-toolbar,
  .diag-columns {
    grid-template-columns: 1fr;
  }
  .diag-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .diag-layer-row {
    grid-template-columns: auto minmax(80px, 1fr) auto;
  }
  .diag-layer-row span:nth-last-child(-n+2) {
    display: none;
  }
  .diag-event-row {
    grid-template-columns: auto auto minmax(0, 1fr);
  }
  .diag-event-row b {
    display: none;
  }
  .modal-card.diagnostics-panel .modal-body {
    overflow-y: auto;
  }
}

/* ---------------- Elevation profile ---------------- */
.modal-card.elevation-panel {
  min-width: 420px;
}
.modal-card.elevation-panel .ep-body,
.modal-card.floating-panel.elevation-panel .modal-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: 12px;
  overflow-x: hidden;
  overflow-y: auto !important;
}
.ep-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ep-spacer { flex: 1; }
.ep-unit {
  width: auto;
  min-width: 86px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-inset);
  padding: 8px 12px;
  color: var(--text);
  font-weight: 650;
  font-size: 12px;
}
.ep-hint {
  color: var(--text-2);
  font-size: 12.5px;
  line-height: 1.45;
}
.ep-stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}
.ep-stat {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-inset);
  padding: 8px 9px;
}
.ep-stat b {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 13px;
}
.ep-stat span {
  display: block;
  margin-top: 4px;
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 9.5px;
  text-transform: uppercase;
}
.ep-chart-wrap {
  height: 210px;
  min-height: 180px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-inset);
  padding: 10px;
}
.ep-export {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-3);
  font-size: 12px;
}
.ep-credit {
  margin-left: auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 760px) {
  .modal-card.elevation-panel {
    min-width: 0;
  }
  .ep-toolbar {
    flex-wrap: wrap;
  }
  .ep-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .ep-chart-wrap {
    height: 190px;
  }
  .ep-credit {
    display: none;
  }
}
.import-note {
  margin-top: 10px;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  font-size: 12px;
  line-height: 1.45;
}
.import-note.warn {
  background: color-mix(in srgb, var(--c-amber) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--c-amber) 30%, transparent);
  color: var(--text-2);
}
.import-note.err {
  background: color-mix(in srgb, var(--c-rose) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--c-rose) 28%, transparent);
  color: var(--text-2);
}
.import-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.import-stats span {
  min-width: 0;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  background: var(--surface-inset);
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.import-stats b {
  display: block;
  margin-bottom: 2px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0;
}
.import-section {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.import-section-title {
  margin-bottom: 8px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
}
.import-table-wrap {
  max-height: 180px;
  margin-top: 10px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
}
table.import-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
}
table.import-table th,
table.import-table td {
  max-width: 180px;
  padding: 7px 9px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
table.import-table th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--text-2);
  text-align: left;
  font-size: 10.5px;
  font-weight: 600;
  z-index: 1;
}
table.import-table tr:last-child td { border-bottom: none; }

@media (max-width: 560px) {
  .import-stats { grid-template-columns: 1fr; }
  .fp-line { align-items: flex-start; flex-direction: column; gap: 5px; }
}

/* ---------------- Floating panel (attribute table) ---------------- */
.modal.floating {
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  pointer-events: none;
  display: block;
}
.modal-card.floating-panel {
  position: fixed;
  pointer-events: all;
  max-width: none;
  max-height: none;
  min-width: 480px;
  min-height: 280px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.28), 0 2px 8px rgba(0,0,0,0.14), 0 0 0 1px var(--border);
  animation: cardIn 0.16s var(--ease, ease) both;
  overflow: visible; /* allow resize handle to show at corner */
}
/* Header: align-items center + grab cursor for drag */
.modal-card.floating-panel .modal-head {
  cursor: grab;
  user-select: none;
  align-items: center;
}
.modal-card.floating-panel .modal-head:active { cursor: grabbing; }
.modal-card.floating-panel .modal-body {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 16px 18px;
}
.modal-card.floating-panel .table-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.modal-card.floating-panel .table-scroll {
  flex: 1;
  max-height: none;
  overflow: auto;
}

/* Window controls group — keeps all header buttons together on the right */
.modal-win-controls {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.modal-win-btn {
  width: 28px; height: 28px; border-radius: var(--r-sm); flex-shrink: 0;
  display: grid; place-items: center; cursor: pointer;
  background: transparent; border: none; color: var(--text-3);
  transition: background 0.12s, color 0.12s;
}
.modal-win-btn:hover { background: var(--surface-2); color: var(--text); }
.modal-win-btn svg { width: 14px; height: 14px; }

/* Minimized → taskbar strip at bottom of screen */
.modal-card.floating-panel.minimized {
  min-height: 0;
  min-width: 0;
  border-radius: var(--r-xl);
  /* position + size are set by JS */
}
.modal-card.floating-panel.minimized .modal-body,
.modal-card.floating-panel.minimized .modal-foot,
.modal-card.floating-panel.minimized .modal-resize-handle { display: none !important; }
.modal-card.floating-panel.minimized .modal-head {
  border-bottom: none;
  cursor: default;
  padding: 10px 12px;
}
.modal-card.floating-panel.minimized .modal-head .h-ico {
  width: 28px; height: 28px;
}
.modal-card.floating-panel.minimized .modal-head .h-ico svg { width: 15px; height: 15px; }
.modal-card.floating-panel.minimized .modal-head .ht { min-width: 0; }
.modal-card.floating-panel.minimized .modal-head .ht > div:last-child { min-width: 0; }
.modal-card.floating-panel.minimized .modal-head h3 { font-size: 13px; }
.modal-card.floating-panel.minimized .modal-head p {
  display: block;
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Maximized state — full viewport */
.modal-card.floating-panel.maximized {
  left: 0 !important; top: 0 !important;
  width: 100vw !important; height: 100vh !important;
  border-radius: 0;
}
.modal-card.floating-panel.maximized .modal-head { cursor: default; }

/* Resize handle — bottom-right corner grip */
.modal-resize-handle {
  position: absolute;
  right: 0; bottom: 0;
  width: 22px; height: 22px;
  cursor: se-resize;
  display: flex; align-items: flex-end; justify-content: flex-end;
  padding: 5px;
  color: var(--text-3);
  opacity: 0.45;
  transition: opacity 0.15s;
  z-index: 1;
}
.modal-resize-handle:hover { opacity: 1; }
.modal-resize-handle::after {
  content: '';
  display: block;
  width: 9px; height: 9px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  border-radius: 0 0 2px 0;
}

/* ---------------- Data table ---------------- */
.tbl-top {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap;
}
.tbl-top .table-search { flex: 1; min-width: 180px; }
.tbl-top .select { width: auto; min-width: 130px; }
.table-search { position: relative; }
.table-search svg {
  width: 15px; height: 15px; position: absolute; left: 11px; top: 50%;
  transform: translateY(-50%); color: var(--text-3); pointer-events: none;
}
.table-search .input { padding-left: 32px; width: 100%; }

.tbl-cols-panel {
  margin-bottom: 10px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface-inset);
}
.tbl-cols-panel .prop-tools { margin-bottom: 6px; }
.table-col-list {
  max-height: 94px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  background: var(--surface);
}

.tbl-status {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 8px; flex-wrap: wrap;
}
#tbl-metrics { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.table-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 7px; border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface-inset); color: var(--text-3); font-size: 11px;
}
.table-chip b { color: var(--text-2); font-family: var(--font-mono); }
.table-chip.active {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 34%, var(--border));
  color: var(--accent);
}
.table-chip.active b { color: var(--accent); }
.tbl-acts { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.tbl-acts .btn { font-size: 11.5px; padding: 3px 8px; height: 27px; }
.tbl-acts .btn.active {
  background: var(--accent-soft); border-color: var(--accent); color: var(--accent);
}
.tbl-sep { width: 1px; height: 16px; background: var(--border); margin: 0 2px; flex-shrink: 0; }

.table-wrap { border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; }
.table-scroll { overflow: auto; max-height: 500px; }
table.data { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.data th {
  position: sticky; top: 0; z-index: 2;
  text-align: left; font-weight: 600; font-size: 11px; letter-spacing: 0.02em;
  color: var(--text-2); background: var(--surface-2);
  padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
  user-select: none;
}
table.data th[data-col] { cursor: pointer; }
table.data th[data-col]:hover { background: var(--surface-inset); }
table.data td { padding: 7px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--surface-inset); }
table.data tbody tr.selected { background: var(--accent-soft); }
table.data tbody tr { cursor: pointer; }
table.data td.sel { text-align: center; width: 34px; }
table.data td { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
table.data .num { font-family: var(--font-mono); color: var(--c-blue); text-align: right; }
.table-foot {
  padding: 7px 12px; background: var(--surface-2); border-top: 1px solid var(--border);
  font-family: var(--font-mono); font-size: 11px; color: var(--text-3);
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.table-pager { display: flex; align-items: center; gap: 5px; }
.tbl-pgsz { height: 25px; padding: 2px 5px; font-size: 11px; min-width: 70px; }
#tbl-page { min-width: 72px; text-align: center; }
#tbl-prev, #tbl-next { width: 26px; height: 25px; padding: 0; font-size: 13px; line-height: 1; }

.table-calc {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(180px, 1.2fr) minmax(140px, 0.8fr) auto;
  gap: 10px;
  align-items: end;
  margin: 10px 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-inset);
}
.table-calc .field { margin-bottom: 0; }
.tbl-edit {
  min-width: 110px;
  height: 28px;
  padding: 4px 6px;
  font-size: 12px;
  border-color: transparent;
  background: transparent;
}
.tbl-edit:focus {
  background: var(--surface);
  border-color: var(--accent);
}

/* help modal sections */
.help-section { margin-bottom: 26px; }
.help-section:last-child { margin-bottom: 0; }
.help-h {
  display: flex; align-items: center; gap: 10px; margin-bottom: 14px;
}
.help-h .hi { width: 30px; height: 30px; border-radius: var(--r-sm); display: grid; place-items: center; }
.help-h h4 { font-size: 14px; font-weight: 600; margin: 0; }
.help-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.help-card {
  padding: 14px; border-radius: var(--r-md); border: 1px solid var(--border); background: var(--surface-inset);
}
.help-card h5 { font-size: 13px; font-weight: 600; margin: 0 0 6px; }
.help-card p { font-size: 12px; color: var(--text-2); margin: 0 0 8px; line-height: 1.5; }
.help-card .uc { font-size: 11px; color: var(--text-3); }
.help-card .uc b { color: var(--text-2); font-weight: 600; }
.steps { display: flex; flex-direction: column; gap: 10px; }
.step { display: flex; gap: 12px; padding: 12px 14px; border-radius: var(--r-md); background: var(--surface-inset); border: 1px solid var(--border); }
.step .sn { width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-family: var(--font-mono); font-size: 12px; font-weight: 600; flex-shrink: 0; }
.step .stext h5 { margin: 0 0 3px; font-size: 13px; font-weight: 600; }
.step .stext p { margin: 0; font-size: 12px; color: var(--text-2); line-height: 1.5; }
.shortcut-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px,1fr)); gap: 8px; }
.shortcut { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-radius: var(--r-sm); background: var(--surface-inset); border: 1px solid var(--border); font-size: 12.5px; }

/* ============================================================
   APPEARANCE / TWEAKS PANEL
   ============================================================ */
.tweaks {
  position: fixed; top: calc(var(--topbar-h) + 10px); right: 12px; z-index: 180;
  width: 280px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  display: none; flex-direction: column; overflow: hidden;
}
.tweaks.open { display: flex; }
.tweaks-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.tweaks-head h4 { font-size: 13px; font-weight: 600; margin: 0; display: flex; align-items: center; gap: 8px; }
.tweaks-body { padding: 14px; display: flex; flex-direction: column; gap: 16px; max-height: 70vh; overflow-y: auto; }
.tw-group { display: flex; flex-direction: column; gap: 8px; }
.tw-label { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-3); }
.tw-swatches { display: flex; gap: 8px; }
.tw-swatch { width: 30px; height: 30px; border-radius: var(--r-sm); cursor: pointer; border: 2px solid transparent; transition: transform 0.1s; position: relative; }
.tw-swatch:hover { transform: scale(1.08); }
.tw-swatch.active { border-color: var(--text); }
.tw-swatch.active::after { content: ""; position: absolute; inset: 0; border-radius: 4px; box-shadow: inset 0 0 0 2px var(--surface); }

.fb-row { display: flex; align-items: center; gap: 7px; }
.fb-row .select, .fb-row .input { width: auto; min-width: 0; }
.fb-row .fb-field { flex: 1.1; }
.fb-row .fb-op { flex: none; width: 116px; }
.fb-row .fb-val { flex: 1.3; }
.fb-del {
  width: 32px; height: 34px; flex: none; border-radius: var(--r-sm);
  display: grid; place-items: center; cursor: pointer;
  background: transparent; border: 1px solid var(--border); color: var(--text-3);
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.fb-del:hover { background: color-mix(in srgb, var(--c-rose) 12%, transparent); color: var(--c-rose); border-color: var(--c-rose); }
.fb-del svg { width: 15px; height: 15px; }

/* responsive */
@media (max-width: 860px) {
  :root { --sidebar-w: 280px; }
  .sidebar { position: absolute; top: 0; bottom: 0; left: 0; box-shadow: var(--shadow-lg); }
  .row-2 { grid-template-columns: 1fr; }
  .tbl-top { flex-direction: column; align-items: stretch; }
  .tbl-top .select { width: 100%; min-width: 0; }
  .tbl-status { flex-direction: column; align-items: stretch; }
  .tbl-acts { flex-wrap: wrap; }
  .table-pager { justify-content: space-between; }
  .table-calc { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .modal {
    align-items: flex-end;
    padding: 10px;
    padding-bottom: calc(var(--statusbar-h) + env(safe-area-inset-bottom, 0px) + 10px);
  }
  .modal-card,
  .modal-card.wide,
  .modal-card.xwide {
    max-width: none;
    max-height: calc(100vh - var(--topbar-h) - var(--statusbar-h) - 20px);
    border-radius: 14px;
  }
  .modal-head {
    padding: 14px 16px;
  }
  .modal-head .h-ico {
    width: 32px;
    height: 32px;
  }
  .modal-body {
    padding: 16px;
  }
  .modal-foot {
    padding: 12px 16px;
  }
  .modal-foot .btn {
    flex: 1;
    justify-content: center;
  }
  .table-scroll {
    max-height: 48vh;
  }
  .modal.floating {
    pointer-events: none;
  }
  .modal-card.floating-panel,
  .modal-card.floating-panel.maximized {
    left: 8px !important;
    right: 8px !important;
    top: auto !important;
    bottom: calc(var(--statusbar-h) + env(safe-area-inset-bottom, 0px) + 8px) !important;
    width: auto !important;
    height: min(78vh, calc(100vh - var(--topbar-h) - var(--statusbar-h) - 18px)) !important;
    min-width: 0;
    min-height: 0;
    max-width: none;
    max-height: none;
    border-radius: 14px;
    overflow: hidden;
  }
  .modal-card.floating-panel .modal-head {
    cursor: default;
    padding: 12px 14px;
  }
  .modal-card.floating-panel .modal-head:active { cursor: default; }
  .modal-card.floating-panel .modal-head .ht {
    min-width: 0;
  }
  .modal-card.floating-panel .modal-head .ht > div:last-child {
    min-width: 0;
  }
  .modal-card.floating-panel .modal-head h3,
  .modal-card.floating-panel .modal-head p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .modal-card.floating-panel .modal-body {
    padding: 12px;
    overflow: hidden;
  }
  .modal-card.floating-panel .modal-foot {
    padding: 10px 12px;
  }
  .modal-card.floating-panel .modal-resize-handle,
  .modal-card.floating-panel #m-max {
    display: none !important;
  }
  .modal-card.floating-panel.minimized {
    left: 8px !important;
    right: 8px !important;
    bottom: calc(var(--statusbar-h) + env(safe-area-inset-bottom, 0px) + 8px) !important;
    top: auto !important;
    width: auto !important;
    height: auto !important;
  }
  .modal-card.floating-panel.minimized .modal-head p {
    max-width: min(58vw, 230px);
  }
  .tbl-top {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 7px;
  }
  .tbl-top .table-search,
  .tbl-top .select {
    grid-column: 1 / -1;
    min-width: 0;
    width: 100%;
  }
  .tbl-top .btn {
    width: 100%;
    justify-content: center;
    min-width: 0;
  }
  .tbl-status {
    gap: 8px;
  }
  #tbl-metrics {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
  }
  .tbl-acts {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }
  .tbl-acts .btn {
    width: 100%;
    padding-inline: 5px;
  }
  .tbl-sep {
    display: none;
  }
  .table-wrap {
    min-height: 0;
  }
  .modal-card.floating-panel .table-scroll {
    max-height: none;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
  }
  table.data th,
  table.data td {
    padding: 7px 9px;
    max-width: 170px;
  }
  .table-foot {
    flex-direction: column;
    align-items: stretch;
  }
  .table-pager {
    width: 100%;
  }
  .fb-row {
    flex-wrap: wrap;
  }
  .fb-row .fb-op,
  .fb-row .fb-val,
  .fb-row .fb-field {
    flex: 1 1 100%;
    width: 100%;
  }
}
