/* ============================================================
   GEOX — editor UI
   ============================================================ */

:root {
  --red: #FF2E4C;
  --red-dark: #E61E3C;
  --red-soft: #FFE5EA;
  --orange: #FF8A33;
  --blue: #4FA4D8;
  --green: #3BC47A;
  --purple: #A78BFA;
  --ink: #141427;
  --ink-2: #3A3A55;
  --muted: #6B6B85;
  --line: #E6E0D7;
  --line-2: #F0EBE3;
  --bg: #F7F3EC;
  --panel-bg: #ffffff;
  --sidebar-bg: #1C1C2E;
  --sidebar-ink: #D8D4E8;
  --sidebar-hover: #2A2A44;
}

* { box-sizing: border-box; }

/* HTML5 `hidden` must always win over `display:` rules. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }

body { display: grid; grid-template-rows: 56px 1fr; }

/* ============ TOPBAR ============ */
.topbar {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  align-items: center;
  padding: 0 16px;
  background: white;
  border-bottom: 1px solid var(--line);
  z-index: 30;
  gap: 16px;
}
.tb-left, .tb-right { display: flex; align-items: center; gap: 10px; }
.tb-right { justify-content: flex-end; }

.logo { font-weight: 800; font-size: 20px; color: var(--ink); letter-spacing: -0.02em; text-decoration: none; }
.logo-plus { color: var(--red); }

.divider { width: 1px; height: 22px; background: var(--line); margin: 0 6px; }

.project-name {
  border: 1px solid transparent;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 6px;
  min-width: 180px;
  color: var(--ink);
  font-family: inherit;
}
.project-name:hover { border-color: var(--line); }
.project-name:focus { outline: none; border-color: var(--red); background: white; }

.status {
  font-size: 12px;
  color: var(--muted);
  padding: 4px 10px;
  background: var(--line-2);
  border-radius: 999px;
  white-space: nowrap;
}
.status.busy { color: var(--red-dark); background: var(--red-soft); }
.status.busy::before {
  content: "";
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--red);
  margin-right: 6px;
  vertical-align: middle;
  animation: pulse 1s infinite;
}
@keyframes pulse { 50% { opacity: 0.3; } }

.btn-tb {
  background: white;
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 8px;
  transition: all .15s;
  white-space: nowrap;
}
.btn-tb:hover { border-color: var(--ink); }
.btn-tb.btn-primary { background: var(--red); color: white; border-color: var(--red); }
.btn-tb.btn-primary:hover { background: var(--red-dark); }

/* ============ SEARCH ============ */
.search-box {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--line-2);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0 10px;
  transition: all .15s;
  max-width: 520px;
  margin: 0 auto;
  width: 100%;
}
.search-box:focus-within {
  background: white;
  border-color: var(--red);
  box-shadow: 0 0 0 3px var(--red-soft);
}
.search-icon { color: var(--muted); font-size: 13px; }
#searchInput {
  flex: 1;
  border: none;
  background: transparent;
  padding: 9px 10px;
  font-size: 13px;
  font-family: inherit;
  color: var(--ink);
  outline: none;
}
.search-clear {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 4px;
}
.search-clear:hover { color: var(--ink); background: var(--line); }

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 16px 40px rgba(20,20,39,0.14);
  overflow: hidden;
  max-height: 320px;
  overflow-y: auto;
}
.search-result {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-2);
  cursor: pointer;
  font-size: 13px;
}
.search-result:last-child { border-bottom: none; }
.search-result:hover, .search-result.active { background: var(--red-soft); }
.search-result strong { display: block; color: var(--ink); }
.search-result small { color: var(--muted); font-size: 11px; }
.search-result .sr-badge {
  display: inline-block;
  background: var(--line-2);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  margin-right: 6px;
}

/* ============ LAYOUT ============ */
.main {
  display: grid;
  grid-template-columns: 56px 1fr 340px;
  min-height: 0;
}

/* ============ TOOLBAR ============ */
.toolbar {
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 0;
  gap: 4px;
}
.tool-group { display: flex; flex-direction: column; gap: 4px; padding: 4px 0; border-top: 1px solid rgba(255,255,255,0.06); border-bottom: 1px solid rgba(255,255,255,0.06); margin: 4px 0; }
.tool {
  width: 40px; height: 40px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--sidebar-ink);
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: all .12s;
}
.tool:hover { background: var(--sidebar-hover); color: white; }
.tool.active {
  background: var(--red);
  color: white;
  box-shadow: 0 4px 10px rgba(255,46,76,0.4);
}
.tool-sep { width: 24px; height: 1px; background: rgba(255,255,255,0.1); margin: 6px 0; }

/* ============ MAP ============ */
.map-wrap { position: relative; background: var(--bg); overflow: hidden; }
#map { position: absolute; inset: 0; }

.basemap-switcher {
  position: absolute;
  bottom: 16px;
  left: 16px;
  background: white;
  border-radius: 10px;
  padding: 4px;
  box-shadow: 0 4px 14px rgba(20,20,39,0.12);
  display: flex;
  gap: 2px;
  z-index: 5;
}
.bm {
  background: transparent; border: none;
  font-size: 12px; font-weight: 600;
  padding: 7px 12px; border-radius: 7px;
  color: var(--ink-2);
}
.bm:hover { background: var(--line-2); }
.bm.active { background: var(--ink); color: white; }
.bm-custom {
  border-left: 1px dashed var(--line);
  margin-left: 2px;
  padding-left: 12px;
}
#customBmModal .modal-card label { margin-bottom: 10px; }
#customBmModal textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }

/* A3.1 — Filter modal rules grid */
.filter-rules { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.filter-rule {
  display: grid;
  grid-template-columns: 1fr 110px 1fr 28px;
  gap: 6px; align-items: center;
}
.filter-rule select, .filter-rule input {
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px;
  font-size: 12px; background: white;
}
.filter-rule .fl-del {
  border: 1px solid var(--line); background: white; border-radius: 6px;
  cursor: pointer; padding: 4px 0; color: var(--muted);
}
.filter-rule .fl-del:hover { color: #FF2E4C; border-color: #FF2E4C; }
.filter-summary {
  font-size: 12px; color: var(--muted);
  padding: 6px 0 0; border-top: 1px dashed var(--line); margin-top: 8px;
}
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; margin-bottom: 8px; }
.seg button {
  background: transparent; border: none; padding: 6px 10px; cursor: pointer;
  font-size: 12px; color: var(--ink-2);
}
.seg button.active { background: var(--ink); color: white; }
.layer-controls .filter-btn {
  background: transparent; border: 1px solid transparent;
  padding: 4px 8px; cursor: pointer; border-radius: 6px;
  color: var(--ink-2); font-size: 12px;
}
.layer-controls .filter-btn:hover { background: var(--line-2); }

/* Phase N2 — worker progress bar */
.ss-progress-wrap {
  display: flex; align-items: center; gap: 8px; margin-top: 8px;
}
.ss-progress {
  flex: 1; height: 6px; border-radius: 3px;
  background: var(--line-2, #eee); overflow: hidden;
}
.ss-progress-fill {
  height: 100%; width: 0%;
  background: var(--red, #e6553f);
  border-radius: 3px;
  transition: width .2s ease;
}

/* Phase 2.2 — on-map legend */
.legend-toggle {
  position: absolute;
  bottom: 58px; left: 16px;
  z-index: 5;
  background: white;
  border: none;
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  color: var(--ink, #222);
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(20,20,39,0.12);
}
.legend-toggle[aria-pressed="true"] { background: #1d1d1f; color: #fff; }
.map-legend {
  position: absolute;
  bottom: 94px; left: 16px;
  z-index: 5;
  background: white;
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 4px 14px rgba(20,20,39,0.14);
  max-width: 240px;
  max-height: 45%;
  overflow-y: auto;
  font-size: 12px;
}
.map-legend h4 {
  margin: 0 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted, #888);
}
.map-legend .ml-row {
  display: flex; align-items: center; gap: 7px;
  padding: 2px 0;
  min-width: 0;
}
.map-legend .ml-row span.name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.map-legend .ml-swatch {
  width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto;
  border: 1px solid rgba(0,0,0,.15);
}
.map-legend .ml-sub { padding-left: 14px; }
.map-legend .ml-sub .ml-swatch { width: 10px; height: 10px; }
.map-legend .ml-sub .ml-row { color: #555; }

.coord-readout {
  position: absolute;
  bottom: 16px; right: 16px;
  background: rgba(20,20,39,0.85);
  color: white;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 11px;
  font-family: 'SF Mono', Menlo, monospace;
  z-index: 5;
}

.draw-hint {
  position: absolute;
  top: 16px; left: 50%;
  transform: translateX(-50%);
  background: var(--red);
  color: white;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(255,46,76,0.35);
  z-index: 5;
  display: flex; gap: 10px; align-items: center;
}
.draw-hint kbd {
  background: rgba(255,255,255,0.25);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
}
.draw-hint .metric {
  background: rgba(0,0,0,0.2);
  padding: 2px 8px;
  border-radius: 10px;
  font-family: 'SF Mono', Menlo, monospace;
  font-size: 12px;
}

.feature-popup {
  position: absolute;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(20,20,39,0.15);
  padding: 10px 14px;
  font-size: 12px;
  min-width: 200px;
  max-width: 320px;
  z-index: 10;
  pointer-events: none;
}
.feature-popup .fp-title {
  font-weight: 700;
  margin-bottom: 6px;
  display: flex; align-items: center; gap: 6px;
}
.feature-popup table { width: 100%; border-collapse: collapse; }
.feature-popup td { padding: 2px 6px 2px 0; vertical-align: top; }
.feature-popup td:first-child { color: var(--muted); font-size: 11px; }

.maplibregl-ctrl-bottom-left .maplibregl-ctrl { display: none; }
.maplibregl-ctrl-bottom-right { margin-right: 200px; }

/* ============ RIGHT PANEL ============ */
.panel {
  background: var(--panel-bg);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  padding: 0 12px;
  gap: 2px;
}
.ptab {
  background: transparent;
  border: none;
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.ptab:hover { color: var(--ink); }
.ptab.active { color: var(--red); border-bottom-color: var(--red); }

.panel-body {
  display: none;
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}
.panel-body.active { display: block; }

.panel-body h4 {
  margin: 18px 0 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.panel-body h4:first-child { margin-top: 0; }
.panel-help { font-size: 12px; color: var(--muted); margin: 0 0 10px; line-height: 1.5; }

.panel-body select,
.panel-body input[type="number"],
.panel-body input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: white;
  margin-bottom: 8px;
}
.panel-body select:focus,
.panel-body input:focus { outline: none; border-color: var(--red); }

.f-lbl {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 8px 0 4px;
}

.row { display: flex; gap: 8px; margin-bottom: 8px; }
.row input, .row select { margin-bottom: 0 !important; }

.row-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--ink-2);
  margin: 4px 0 8px;
  cursor: pointer;
}

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.btn-row .btn-block { margin: 0; }

.btn-block {
  display: block;
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  margin-top: 4px;
  margin-bottom: 8px;
  transition: all .15s;
  text-align: center;
}
.btn-block:hover { border-color: var(--ink); }
.btn-block.btn-primary { background: var(--red); color: white; border-color: var(--red); }
.btn-block.btn-primary:hover { background: var(--red-dark); }
.btn-block.btn-outline:hover { border-color: var(--red); color: var(--red); }
.btn-block.btn-ghost { border-color: transparent; background: var(--line-2); color: var(--ink-2); }
.btn-block.btn-ghost:hover { background: var(--line); color: var(--ink); }

/* ============ DROP ZONE ============ */
.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 24px 16px;
  border: 2px dashed var(--line);
  border-radius: 12px;
  cursor: pointer;
  transition: all .15s;
  text-align: center;
}
.drop-zone:hover, .drop-zone.drag-over { border-color: var(--red); background: var(--red-soft); }
.dz-icon { font-size: 26px; color: var(--red); }
.drop-zone strong { font-size: 13px; }
.drop-zone small { font-size: 11px; color: var(--muted); }

/* ============ EMPTY STATE ============ */
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty-icon { font-size: 36px; margin-bottom: 10px; }
.empty strong { display: block; color: var(--ink); margin-bottom: 6px; }
.empty p { font-size: 13px; margin: 0; line-height: 1.5; }

/* ============ LAYER LIST ============ */
.layer-list { list-style: none; padding: 0; margin: 0; }
.layer-item {
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 8px;
  overflow: hidden;
  transition: all .12s;
}
.layer-item.selected {
  border-color: var(--red);
  box-shadow: 0 0 0 3px var(--red-soft);
}
.layer-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; }
.layer-swatch {
  width: 14px; height: 14px;
  border-radius: 4px;
  flex-shrink: 0;
  cursor: pointer;
  border: 2px solid white;
  box-shadow: 0 0 0 1px var(--line);
}
.layer-geom-badge {
  display: inline-flex;
  align-items: center; justify-content: center;
  width: 22px; height: 22px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}
.geom-point { background: #FFE5EA; color: var(--red); }
.geom-line { background: #DEEFFB; color: #1B73B5; }
.geom-polygon { background: #D7F3E3; color: #1B7A45; }
.geom-mixed { background: #EDE4FE; color: #6539C7; }
.geom-empty { background: var(--line-2); color: var(--muted); }

.layer-name {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  border: none;
  background: transparent;
  padding: 2px 4px;
  border-radius: 4px;
  color: var(--ink);
  min-width: 0;
  font-family: inherit;
}
.layer-name:focus { outline: none; background: var(--line-2); }
.layer-count {
  font-size: 11px;
  color: var(--muted);
  background: var(--line-2);
  padding: 2px 6px;
  border-radius: 4px;
}
.layer-toggle, .layer-more {
  background: transparent;
  border: none;
  padding: 4px;
  color: var(--muted);
  border-radius: 4px;
  font-size: 14px;
}
.layer-toggle:hover, .layer-more:hover { background: var(--line-2); color: var(--ink); }
.layer-toggle.hidden { opacity: 0.35; }

.layer-controls { display: none; padding: 10px 12px; border-top: 1px solid var(--line-2); gap: 8px; flex-wrap: wrap; }
.layer-item.expanded .layer-controls { display: flex; }
.ctrl-group { display: flex; align-items: center; gap: 6px; width: 100%; font-size: 12px; color: var(--muted); }
.ctrl-group input[type="range"] { flex: 1; margin: 0; }
.layer-controls button {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 4px;
}
.layer-controls button:hover { background: var(--line-2); color: var(--ink); }
.layer-controls .danger:hover { background: var(--red-soft); color: var(--red-dark); }
.layer-controls .attr-btn { color: var(--red); }
.layer-controls .attr-btn:hover { background: var(--red-soft); color: var(--red-dark); }

.color-grid { display: flex; gap: 5px; flex-wrap: wrap; }
.color-chip {
  width: 18px; height: 18px;
  border-radius: 4px;
  border: 2px solid white;
  box-shadow: 0 0 0 1px var(--line);
  cursor: pointer;
}
.color-chip:hover { transform: scale(1.1); }
.color-chip.active { box-shadow: 0 0 0 2px var(--ink); }

/* ============ RENDER-MODE TOGGLE + PARAMS (A2) ============ */
.render-toggle { display: flex; gap: 2px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex: 1; }
.render-toggle button {
  flex: 1; background: white; border: 0; border-radius: 0 !important; padding: 6px 8px !important;
  font-size: 11px !important; color: var(--muted); border-right: 1px solid var(--line) !important;
}
.render-toggle button:last-child { border-right: 0 !important; }
.render-toggle button.active { background: var(--ink); color: white !important; }
.render-toggle button.active:hover { background: var(--ink); color: white !important; }
.ctrl-heatmap select, .ctrl-heatmap input[type="range"],
.ctrl-cluster select, .ctrl-cluster input[type="range"] { flex: 1; }
.ctrl-heatmap select, .ctrl-heatmap .heat-weight {
  padding: 5px 8px; font-size: 12px; border: 1px solid var(--line); border-radius: 6px; background: white; color: var(--ink);
}
.ctrl-heatmap .hm-rv, .ctrl-heatmap .hm-iv,
.ctrl-cluster .cl-rv, .ctrl-cluster .cl-zv {
  min-width: 32px; text-align: right; color: var(--ink); font-variant-numeric: tabular-nums;
}

.ctrl-style { gap: 6px; }
.ctrl-style .style-by-btn { flex: 1; }
.style-summary { color: var(--ink); font-weight: 600; font-size: 11px; }
.style-clear-btn { padding: 4px 8px !important; color: var(--muted) !important; }
.style-clear-btn:hover { color: var(--red-dark) !important; background: var(--red-soft) !important; }

.layer-legend {
  width: 100%; display: flex; flex-direction: column; gap: 3px;
  padding: 8px 10px; background: var(--line-2); border-radius: 6px; font-size: 11px;
}
.legend-row { display: flex; align-items: center; gap: 8px; color: var(--ink); }
.legend-swatch { width: 14px; height: 14px; border-radius: 3px; flex-shrink: 0; border: 1px solid rgba(0,0,0,0.1); }
.legend-label { flex: 1; font-variant-numeric: tabular-nums; }

/* ============ STYLE EDITOR MODAL (A2.6) ============ */
.style-editor-body { display: grid; gap: 10px; }
.style-editor-body .seg {
  display: flex; gap: 2px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
}
.style-editor-body .seg button {
  flex: 1; background: white; border: 0; padding: 8px 10px; font-size: 12px; color: var(--muted);
  border-right: 1px solid var(--line); cursor: pointer; font-family: inherit;
}
.style-editor-body .seg button:last-child { border-right: 0; }
.style-editor-body .seg button.active { background: var(--ink); color: white; }
.palette-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
}
.palette-chip {
  display: flex; border: 2px solid transparent; border-radius: 6px; overflow: hidden; cursor: pointer; height: 24px;
}
.palette-chip.active { border-color: var(--ink); }
.palette-chip span { flex: 1; }
.style-preview {
  display: flex; flex-direction: column; gap: 2px; max-height: 220px; overflow: auto;
  padding: 8px; background: var(--line-2); border-radius: 6px; font-size: 12px;
}
.style-preview .legend-row { padding: 2px 0; }

/* ============ SUGGESTIONS ============ */
.suggestions {
  background: linear-gradient(135deg, #FFF5F1 0%, #FFE0EB 100%);
  border: 1px solid var(--red-soft);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 16px;
}
.sug-head {
  font-size: 12px;
  font-weight: 700;
  color: var(--red-dark);
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}
.sug-empty { font-size: 12px; color: var(--muted); }
.sug-body { display: flex; flex-wrap: wrap; gap: 6px; }
.sug-item {
  background: white;
  border: 1px solid var(--red-soft);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: all .12s;
}
.sug-item:hover { background: var(--red); color: white; border-color: var(--red); }
.sug-note {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255,255,255,0.5);
}
.sug-warn {
  font-size: 11px;
  color: #A84F00;
  background: #FFE8D3;
  padding: 6px 10px;
  border-radius: 6px;
  margin-top: 8px;
  font-weight: 600;
}

/* ============ ACCORDION ============ */
.accord {
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 8px;
  overflow: hidden;
}
.accord summary {
  list-style: none;
  padding: 12px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
}
.accord summary::-webkit-details-marker { display: none; }
.accord summary::after {
  content: "▾";
  margin-left: auto;
  color: var(--muted);
  font-size: 11px;
  transition: transform .15s;
}
.accord[open] summary::after { transform: rotate(180deg); }
.accord summary:hover { background: var(--line-2); }
.a-icon {
  width: 22px; height: 22px;
  background: var(--red-soft);
  color: var(--red);
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}
.a-tag {
  background: var(--line-2);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}
.accord-body {
  padding: 12px 14px;
  border-top: 1px solid var(--line-2);
}

/* ============ STATS ============ */
.stats-out {
  margin-top: 10px;
  background: var(--line-2);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--ink-2);
  font-family: 'SF Mono', Menlo, monospace;
  min-height: 1.5em;
  white-space: pre-line;
}
.stats-out:empty::before {
  content: "Run 'Compute' to see stats";
  color: var(--muted);
  font-family: inherit;
}

/* ============ ATTRIBUTE DRAWER ============ */
.attr-drawer {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 42%;
  min-height: 220px;
  background: white;
  border-top: 1px solid var(--line);
  box-shadow: 0 -8px 24px rgba(20,20,39,0.1);
  z-index: 20;
  display: flex;
  flex-direction: column;
  animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } }

.attr-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  gap: 10px;
}
.attr-title strong { font-size: 13px; display: block; }
.attr-sub { font-size: 11px; color: var(--muted); }
.attr-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.attr-actions input[type="text"] {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  width: 160px;
}
.attr-actions input:focus { outline: none; border-color: var(--red); }
.attr-close:hover { color: var(--red-dark); border-color: var(--red); }

.attr-body {
  flex: 1;
  overflow: auto;
}

.attr-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-family: 'SF Mono', Menlo, monospace;
}
.attr-table thead th {
  position: sticky;
  top: 0;
  background: var(--line-2);
  color: var(--ink-2);
  font-weight: 700;
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  z-index: 2;
  min-width: 80px;
  white-space: nowrap;
}
.attr-table thead th.col-idx { min-width: 48px; }
.attr-table thead th .col-act {
  opacity: 0;
  transition: opacity .12s;
  color: var(--muted);
  cursor: pointer;
  padding: 0 4px;
  font-size: 11px;
}
.attr-table thead th:hover .col-act { opacity: 1; }
.attr-table thead th .col-act:hover { color: var(--red); }
.attr-table tbody td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--line-2);
  border-right: 1px solid var(--line-2);
  color: var(--ink);
  white-space: nowrap;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attr-table tbody td.col-idx {
  background: var(--line-2);
  color: var(--muted);
  font-weight: 600;
  position: sticky;
  left: 0;
  z-index: 1;
}
.attr-table tbody tr:hover td { background: var(--red-soft); cursor: pointer; }
.attr-table tbody tr:hover td.col-idx { background: #FFD3DA; }
.attr-table tbody tr.sel td { background: #FFD3DA !important; }
.attr-table td[contenteditable]:focus {
  outline: 2px solid var(--red);
  background: white;
  border-radius: 3px;
}

.attr-empty {
  padding: 40px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* ============ DROPDOWN ============ */
.dropdown {
  position: absolute;
  top: 52px; right: 16px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(20,20,39,0.14);
  overflow: hidden;
  z-index: 40;
  min-width: 220px;
}
.dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  background: transparent;
  border: none;
  font-size: 13px;
  color: var(--ink);
  font-family: inherit;
}
.dropdown button:hover { background: var(--line-2); }

/* ============ MODAL ============ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(20,20,39,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal-card {
  background: white;
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 24px 60px rgba(20,20,39,0.3);
}
.modal-card h3 { margin: 0 0 16px; font-size: 18px; }
.modal-card label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}
.modal-card input, .modal-card select {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  margin-top: 6px;
}
.modal-card input:focus, .modal-card select:focus { outline: none; border-color: var(--red); }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.modal-actions .btn-block { margin: 0; }

/* ============ TOASTS ============ */
.toast-wrap {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--ink);
  color: white;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 8px 28px rgba(20,20,39,0.3);
  animation: toastIn .25s ease;
  pointer-events: auto;
}
.toast.success { background: #1B7A45; }
.toast.error { background: var(--red-dark); }
.toast.warn { background: #A84F00; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }

/* ============ PROJECT MENU ============ */
.project-menu-wrap { position: relative; display: flex; align-items: center; }
.project-menu-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 11px;
  padding: 4px 6px;
  border-radius: 6px;
  margin-left: -2px;
  transition: all .15s;
}
.project-menu-btn:hover { background: var(--line-2); color: var(--ink); border-color: var(--line); }

.project-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 240px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(20,20,39,0.12);
  padding: 6px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.project-menu button {
  text-align: left;
  background: transparent;
  border: none;
  padding: 9px 12px;
  font-size: 13px;
  color: var(--ink);
  border-radius: 6px;
  font-weight: 500;
}
.project-menu button:hover { background: var(--line-2); }
.project-menu button.pm-danger { color: var(--red-dark); }
.project-menu button.pm-danger:hover { background: var(--red-soft); }
.project-menu .pm-sep { height: 1px; background: var(--line); margin: 4px 2px; }
.project-menu .pm-section-title { font-size: 11px; color: var(--muted); padding: 6px 12px 2px; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.project-menu .pm-recent { display: flex; flex-direction: column; gap: 1px; max-height: 180px; overflow-y: auto; }
.project-menu .pm-recent .pm-empty { padding: 4px 12px 8px; color: var(--muted); font-size: 12px; }
.project-menu .pm-recent .pm-recent-item { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.project-menu .pm-recent .pm-recent-item .pm-recent-name { flex: 1; }
.project-menu .pm-recent .pm-recent-item .pm-recent-del {
  opacity: 0;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 4px;
  transition: opacity .15s;
}
.project-menu .pm-recent .pm-recent-item:hover .pm-recent-del { opacity: 1; }
.project-menu .pm-recent .pm-recent-item .pm-recent-del:hover { background: var(--red-soft); color: var(--red-dark); }

/* ============ SAVE INDICATOR ============ */
.save-indicator {
  font-size: 11px;
  color: var(--muted);
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--line-2);
  white-space: nowrap;
  margin-left: 4px;
  transition: all .2s;
}
.save-indicator.dirty { color: var(--orange); background: rgba(255,138,51,0.12); }
.save-indicator.saving { color: var(--red-dark); background: var(--red-soft); }
.save-indicator.saving::before {
  content: "";
  display: inline-block;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--red);
  margin-right: 5px;
  vertical-align: 1px;
  animation: pulse 1s infinite;
}
.save-indicator.saved { color: var(--green); background: rgba(59,196,122,0.12); }

/* ============ UNDO / REDO ============ */
.btn-tb[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* ============ DANGER VARIANT ============ */
.btn-tb.btn-danger { background: var(--red-soft); color: var(--red-dark); border-color: var(--red-soft); }
.btn-tb.btn-danger:hover { background: var(--red); color: white; border-color: var(--red); }

/* ============ EDIT MODE BAR ============ */
.edit-bar {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  padding: 8px 14px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
  z-index: 12;
  box-shadow: 0 8px 24px rgba(20,20,39,0.25);
}
.edit-bar-title { font-weight: 700; color: var(--orange); }
.edit-bar-help { color: rgba(255,255,255,0.7); font-size: 12px; }
.edit-bar .btn-tb { padding: 4px 10px; font-size: 12px; }

/* ============ SELECTION ACTIONS ============ */
.selection-actions {
  position: absolute;
  background: white;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px;
  display: flex;
  gap: 2px;
  box-shadow: 0 6px 18px rgba(20,20,39,0.15);
  z-index: 11;
  transform: translate(-50%, -130%);
}
.selection-actions .btn-tb { padding: 4px 10px; font-size: 12px; border: none; background: transparent; }
.selection-actions .btn-tb:hover { background: var(--line-2); }
.selection-actions .btn-tb.btn-danger { background: transparent; }
.selection-actions .btn-tb.btn-danger:hover { background: var(--red-soft); }

/* ============ RESPONSIVE ============ */
@media (max-width: 900px) {
  .main { grid-template-columns: 48px 1fr; }
  .panel {
    position: absolute;
    top: 56px; right: 0; bottom: 0;
    width: 320px;
    box-shadow: -8px 0 24px rgba(20,20,39,0.1);
    z-index: 10;
  }
  .topbar { grid-template-columns: auto 1fr auto; }
  .project-name { display: none; }
  .attr-drawer { height: 60%; }
}
