/* ============================================================
   Supertags / Typed Objects  (.st-)
   Theme-aware: light by default, dark via html[data-theme="dark"].
   Reuses the app's CSS variables (--text, --bg, --border, --accent…)
   and the pageprops chip visuals so seeded properties feel native.
   ============================================================ */

/* ---- shared scrim + chips ---- */
.st-scrim {
  position: fixed;
  inset: 0;
  z-index: 1400;
  background: rgba(15, 18, 26, 0.42);
  backdrop-filter: blur(1.5px);
}
html[data-theme="dark"] .st-scrim { background: rgba(0, 0, 0, 0.55); }

.st-chip,
.st-inst-prop-v {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 550;
  padding: 2px 9px;
  border-radius: 999px;
  color: color-mix(in srgb, var(--c, #64748b) 88%, #000 30%);
  background: color-mix(in srgb, var(--c, #64748b) 18%, transparent);
  white-space: nowrap;
}
html[data-theme="dark"] .st-chip { color: color-mix(in srgb, var(--c, #64748b) 55%, #fff 60%); }

.st-btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.st-btn:hover { background: var(--bg-hover); }
.st-btn.st-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.st-btn.st-primary:hover { background: var(--accent-hover, var(--accent)); }
.st-btn.st-ghost { color: var(--text-muted, var(--text)); }
.st-btn.st-danger { color: #c0492f; border-color: color-mix(in srgb, #c0492f 30%, var(--border)); }
.st-btn.st-danger:hover { background: color-mix(in srgb, #c0492f 10%, transparent); }

/* ============================================================
   Type picker popover
   ============================================================ */
.st-pop {
  position: absolute;
  z-index: 1500;
  min-width: 240px;
  max-width: 300px;
  background: var(--bg-modal, var(--bg));
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-popover, 0 10px 40px rgba(0, 0, 0, 0.18));
  padding: 8px;
}
.st-pop-h {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  padding: 4px 6px 6px;
}
.st-pop-list { display: flex; flex-direction: column; gap: 1px; max-height: 300px; overflow-y: auto; }
.st-pop-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  border: 0;
  background: none;
  padding: 7px 8px;
  border-radius: 7px;
  font-size: 13px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.st-pop-item:hover { background: var(--bg-hover); }
.st-pop-item.on { background: var(--bg-hover); }
.st-pop-ic { width: 18px; text-align: center; opacity: 0.9; flex: 0 0 auto; }
.st-pop-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-pop-check { color: var(--accent); font-size: 12px; }
.st-pop-empty { color: var(--text-faint); font-size: 12.5px; padding: 6px; }
.st-pop-clear { color: #c0492f; margin-top: 2px; }
.st-pop-manage { color: var(--text-faint); border-top: 1px solid var(--border); margin-top: 4px; padding-top: 9px; }

/* page-header affordance app.js can render (see INTEGRATION HOOKS) */
.st-type-chip-add,
.st-type-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px dashed var(--border);
  background: none;
  color: var(--text-faint);
  font-size: 12.5px;
  padding: 3px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
}
.st-type-chip-add:hover { color: var(--accent); border-color: var(--accent); }
.st-type-chip {
  border-style: solid;
  border-color: transparent;
  color: color-mix(in srgb, var(--c, var(--accent)) 88%, #000 25%);
  background: color-mix(in srgb, var(--c, var(--accent)) 16%, transparent);
  font-weight: 550;
}
html[data-theme="dark"] .st-type-chip { color: color-mix(in srgb, var(--c, var(--accent)) 60%, #fff 55%); }

/* ============================================================
   Instances overlay — the "live search node"
   ============================================================ */
.st-inst {
  position: fixed;
  z-index: 1500;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(760px, 94vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-modal, var(--bg));
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-popover, 0 24px 70px rgba(0, 0, 0, 0.28));
  overflow: hidden;
}
.st-inst-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
}
.st-inst-title {
  flex: 1;
  min-width: 0;
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -0.2px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.st-inst-count { font-size: 12.5px; color: var(--text-faint); white-space: nowrap; }
.st-inst-new {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.st-inst-new:hover { background: var(--accent-hover, var(--accent)); }
.st-inst-close {
  border: 0;
  background: none;
  color: var(--text-faint);
  font-size: 16px;
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: 7px;
}
.st-inst-close:hover { background: var(--bg-hover); color: var(--text); }

.st-inst-tools { padding: 12px 18px; border-bottom: 1px solid var(--border); }
.st-inst-search {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  padding: 8px 11px;
  border-radius: 8px;
  outline: none;
}
.st-inst-search:focus { border-color: var(--accent); }

.st-inst-list { overflow-y: auto; padding: 8px; }
.st-inst-row {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  width: 100%;
  border: 0;
  background: none;
  text-align: left;
  padding: 10px 12px;
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.12s;
}
.st-inst-row:hover { background: var(--bg-hover); }
.st-inst-ic { flex: 0 0 auto; font-size: 18px; line-height: 1.4; width: 22px; text-align: center; }
.st-inst-main { flex: 1; min-width: 0; }
.st-inst-name { font-size: 14.5px; font-weight: 550; color: var(--text); }
.st-inst-props { display: flex; flex-wrap: wrap; gap: 6px 10px; margin-top: 4px; }
.st-inst-prop { display: inline-flex; align-items: baseline; gap: 4px; font-size: 12px; min-width: 0; }
.st-inst-prop-k { color: var(--text-faint); }
.st-inst-prop-v { color: var(--text-muted, var(--text)); background: none; padding: 0; border-radius: 0; font-weight: 500; }
.st-inst-empty { color: var(--text-faint); font-size: 13.5px; padding: 26px 12px; text-align: center; }

/* ============================================================
   Type Manager modal
   ============================================================ */
.st-modal {
  position: fixed;
  z-index: 1500;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(900px, 95vw);
  height: min(640px, 90vh);
  display: flex;
  flex-direction: column;
  background: var(--bg-modal, var(--bg));
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-popover, 0 24px 70px rgba(0, 0, 0, 0.28));
  overflow: hidden;
}
.st-modal-head {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.st-modal-title { flex: 1; font-size: 18px; font-weight: 650; letter-spacing: -0.2px; color: var(--text); }
.st-modal-close {
  border: 0;
  background: none;
  color: var(--text-faint);
  font-size: 16px;
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: 7px;
}
.st-modal-close:hover { background: var(--bg-hover); color: var(--text); }

.st-modal-body { flex: 1; display: flex; min-height: 0; }

/* left: type list */
.st-list-col {
  flex: 0 0 240px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  min-height: 0;
}
.st-list { flex: 1; overflow-y: auto; padding: 8px; }
.st-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  background: none;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.st-list-item:hover { background: var(--bg-hover); }
.st-list-item.on { background: var(--bg-hover); }
.st-list-ic { flex: 0 0 auto; font-size: 17px; width: 22px; text-align: center; }
.st-list-meta { display: flex; flex-direction: column; min-width: 0; }
.st-list-name { font-size: 14px; font-weight: 550; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-list-sub { font-size: 11.5px; color: var(--text-faint); }
.st-new-type {
  margin: 8px;
  border: 1px dashed var(--border);
  background: none;
  color: var(--text-faint);
  font: inherit;
  font-size: 13px;
  padding: 9px;
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
}
.st-new-type:hover { color: var(--accent); border-color: var(--accent); }
.st-empty { color: var(--text-faint); font-size: 13px; padding: 14px 10px; }

/* right: editor */
.st-editor { flex: 1; overflow-y: auto; padding: 20px 22px; min-width: 0; }
.st-editor-empty { color: var(--text-faint); font-size: 13.5px; padding: 30px 4px; }
.st-field { margin-bottom: 14px; }
.st-id-row { display: flex; gap: 10px; align-items: center; }
.st-input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  padding: 8px 11px;
  border-radius: 8px;
  outline: none;
  transition: border-color 0.12s;
}
.st-input:focus { border-color: var(--accent); }
.st-icon-in {
  flex: 0 0 46px;
  width: 46px;
  text-align: center;
  font-size: 20px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 8px;
  padding: 6px 0;
  outline: none;
}
.st-icon-in:focus { border-color: var(--accent); }
.st-name-in { flex: 1; font-size: 15px; font-weight: 550; }

.st-swatches { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.st-swatch {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}
.st-swatch.on { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg-modal, var(--bg)) inset; }

.st-sub-h {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  margin-bottom: 8px;
}
.st-props { display: flex; flex-direction: column; gap: 8px; }
.st-prop-row { display: flex; align-items: center; gap: 8px; }
.st-prop-glyph {
  flex: 0 0 24px;
  width: 24px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
}
.st-prop-name { flex: 1; min-width: 0; }
.st-prop-type {
  flex: 0 0 130px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.st-prop-del {
  flex: 0 0 auto;
  border: 0;
  background: none;
  color: var(--text-faint);
  font-size: 14px;
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: 7px;
}
.st-prop-del:hover { background: color-mix(in srgb, #c0492f 12%, transparent); color: #c0492f; }
.st-prop-optswrap { padding: 6px 0 2px 32px; }
.st-prop-opts { font-size: 12.5px; }

.st-add-prop {
  margin-top: 10px;
  border: 0;
  background: none;
  color: var(--text-faint);
  font: inherit;
  font-size: 13px;
  padding: 6px 4px;
  border-radius: 7px;
  cursor: pointer;
}
.st-add-prop:hover { color: var(--accent); }

.st-modal-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 26px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.st-foot-left { flex: 1; display: flex; gap: 8px; }

/* ---- small screens ---- */
@media (max-width: 640px) {
  .st-modal { height: 92vh; width: 96vw; }
  .st-modal-body { flex-direction: column; }
  .st-list-col { flex: 0 0 auto; max-height: 34%; border-right: 0; border-bottom: 1px solid var(--border); }
  .st-prop-type { flex-basis: 108px; }
}
